Package: rdf-cty-ccy
RDF Country and Currency Graph LibraryThis 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 theFIBO ontologiesThe 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.BuildingThe TTL files are extracted from the ontology locations (FIBO and OMG) and written tordf_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:Currency CodesCountry Codesmakebuild_cty_ccy_ontoUsageRDFLib Triples ModeThe triples are read into an inmemory RDFLib graph.  Therefore, using the rdflib.triples query format is supported.The modulerdf_cty_ccy.graph.rdf_prefixprovides 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/")Thereforerdf_prefix.lcc_3166_1.NZLis equivalent to the URIhttps://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/NZLThe 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].fromrdf_cty_ccy.graphimportgraph,graph_queryfromrdf_cty_ccy.graphimportrdf_prefixasPresult=graph_query.query((None,P.lcc_lr.hasTag,Literal("NZL",datatype=XSD.string)))s,_,_=result[0]s==P.lcc_3166_1.NZLSPARQL ModePython Objects ModeThe graph can be queried using a python API interface; from the modulerdf_cty_ccy.query.query.  It returns aCountryobject which has the following properties (note thatURIRefandLiteralcomes from RDFLib:country_uri: URIRefidentifies: URIReflabel: Literalcurrency: Currency:currency_uri: URIRefidentifies: URIReflabel: Literalfromrdf_cty_ccy.queryimportqueryasQcountry=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')