Provides the FIBO and OMG Country and Currency Ontology in a queryable form.
Project description
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')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file rdf_cty_ccy-0.1.7.tar.gz
.
File metadata
- Download URL: rdf_cty_ccy-0.1.7.tar.gz
- Upload date:
- Size: 340.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.9.7 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 605663b9303d93e91497ff4ca1a60e86837aabfda323530ea671a8db01e974dc |
|
MD5 | d1dac072dcfc679bf7fae37c7b017b65 |
|
BLAKE2b-256 | 104ff5423f93f87dcf9c572783b8de1932cf08f48aa8eeb6b71c6c91263a2e5e |
File details
Details for the file rdf_cty_ccy-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: rdf_cty_ccy-0.1.7-py3-none-any.whl
- Upload date:
- Size: 352.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.9.7 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5c136dfa055fbede241d9a4ef9d0f4a8462d99571b3c65e4fe67a3dc1035609 |
|
MD5 | 4395c9b9080b2a9ac89965754a742451 |
|
BLAKE2b-256 | 51248cabb90f8587b33b7820f007f341dc754f3131f958ee823c88c6dd2c7f88 |