RDF Country and Currency Graph Library
This library builds an RDF graph of country and currency codes based on the following ontologies:
- https://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/
- https://spec.edmcouncil.org/fibo/ontology/FND/Accounting/ISO4217-CurrencyCodes/
Both of these graphs are in Turtle format and are used extensively in the FIBO ontologies
The Library is designed to support querying these triples in 3 modes:
- Using the Python RDFLib library. The graph is queried using the RDFLib triples mode. Returns RDF triples.
- Using a SPARQL query. Returns an RDFLib SPARQL result.
- Via an OO query approach, which returns country and currency objects.
Building
The TTL files are extracted from the ontology locations (FIBO and OMG) and written to rdf_cty_ccy/rdfdata. To re-get and re-build the ttl files, run the Makefile.
The Country and Currency ontologies are sourced from the following locations:
make build_cty_ccy_onto
Usage
RDFLib Triples Mode
The triples are read into an inmemory RDFLib graph. Therefore, using the rdflib.triples query format is supported.
The module rdf_cty_ccy.graph.rdf_prefix provides shorthand prefixes for the various RDF prefixes using in the ontologies.
fibo_fnd_acc_cur = Namespace('https://spec.edmcouncil.org/fibo/ontology/FND/Accounting/CurrencyAmount/')
fibo_fnd_acc_4217 = Namespace('https://spec.edmcouncil.org/fibo/ontology/FND/Accounting/ISO4217-CurrencyCodes/')
fibo_fnd_utl_av = Namespace("https://spec.edmcouncil.org/fibo/ontology/FND/Utilities/AnnotationVocabulary/")
lcc_3166_1 = Namespace('https://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/')
lcc_cr = Namespace('https://www.omg.org/spec/LCC/Countries/CountryRepresentation/')
lcc_lr = Namespace("https://www.omg.org/spec/LCC/Languages/LanguageRepresentation/")
Therefore rdf_prefix.lcc_3166_1.NZL is equivalent to the URI https://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/NZL
The RDFLib triples query produces a list of RDF triples which match the triples provided. (See the docs at rdflib)[https://rdflib.readthedocs.io/en/stable/intro_to_graphs.html#basic-triple-matching].
from rdf_cty_ccy.graph import graph, graph_query
from rdf_cty_ccy.graph import rdf_prefix as P
result = graph_query.query((None, P.lcc_lr.hasTag, Literal("NZL", datatype=XSD.string)))
s, _, _ = result[0]
s == P.lcc_3166_1.NZL
SPARQL Mode
Python Objects Mode
The graph can be queried using a python API interface; from the module rdf_cty_ccy.query.query. It returns a Country object which has the following properties (note that URIRef and Literal comes from RDFLib:
country_uri: URIRefidentifies: URIReflabel: Literalcurrency: Currency:currency_uri: URIRefidentifies: URIReflabel: Literal
from rdf_cty_ccy.query import query as Q
country = Q.by_country_code(code='NZL')
country.country_uri # => rdflib.term.URIRef('https://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/NZL')
str(country.country_uri) # => 'https://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/NZL'
Provide the currency filter to obtain the currency properties for the country.
country = Q.by_country_code(code='NZL', filters=[Q.Filter.WithCurrency])
country.currency.currency_uri # => rdflib.term.URIRef('https://spec.edmcouncil.org/fibo/ontology/FND/Accounting/ISO4217-CurrencyCodes/NZD')
You can also query by the country URI (as a string) as follow:
country = Q.by_country_uri(uri='https://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/NZL')
Metadata
Release files for rdf-cty-ccy 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rdf_cty_ccy-0.1.7.tar.gz | 340.0 kB | Without provenance | Details for rdf_cty_ccy-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rdf_cty_ccy-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for rdf_cty_ccy-0.1.7-py3-none-any.whl |
Total release size: 692.3 kB
Release files / rdf_cty_ccy-0.1.7.tar.gz
| Download URL | rdf_cty_ccy-0.1.7.tar.gz |
|---|---|
| Size | 340.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
605663b9303d93e91497ff4ca1a60e86837aabfda323530ea671a8db01e974dc
|
|
BLAKE2b-256 checksum How to use checksums |
104ff5423f93f87dcf9c572783b8de1932cf08f48aa8eeb6b71c6c91263a2e5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.1 CPython/3.9.7 Darwin/21.6.0
|
Release files / rdf_cty_ccy-0.1.7-py3-none-any.whl
| Download URL | rdf_cty_ccy-0.1.7-py3-none-any.whl |
|---|---|
| Size | 352.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5c136dfa055fbede241d9a4ef9d0f4a8462d99571b3c65e4fe67a3dc1035609
|
|
BLAKE2b-256 checksum How to use checksums |
51248cabb90f8587b33b7820f007f341dc754f3131f958ee823c88c6dd2c7f88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.1 CPython/3.9.7 Darwin/21.6.0
|
Security for rdf-cty-ccy 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.