8000
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 150 additions & 9 deletions software/SchemaTerms/sdotermsource.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,152 @@
LOADEDDEFAULT = False


def bindNameSpaces(graph):
# --- Standard / W3C / Dublin Core ---
graph.bind("dc", "http://purl.org/dc/elements/1.1/")
graph.bind("dcat", "http://www.w3.org/ns/dcat#")
graph.bind("dct", "http://purl.org/dc/terms/")
graph.bind("dctype", "http://purl.org/dc/dcmitype/")
graph.bind("foaf", "http://xmlns.com/foaf/0.1/")
graph.bind("owl", "http://www.w3.org/2002/07/owl#")
graph.bind("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
graph.bind("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
graph.bind("skos", "http://www.w3.org/2004/02/skos/core#")
graph.bind("void", "http://rdfs.org/ns/void#")

# --- OMG Commons ---
graph.bind("cmns-cls", "https://www.omg.org/spec/Commons/Classifiers/")
graph.bind("cmns-col", "https://www.omg.org/spec/Commons/Collections/")
graph.bind("cmns-dt", "https://www.omg.org/spec/Commons/DatesAndTimes/")
graph.bind("cmns-ge", "https://www.omg.org/spec/Commons/GeopoliticalEntities/")
graph.bind("cmns-id", "https://www.omg.org/spec/Commons/Identifiers/")
graph.bind("cmns-loc", "https://www.omg.org/spec/Commons/Locations/")
graph.bind("cmns-q", "https://www.omg.org/spec/Commons/Quantities/")
graph.bind("cmns-txt", "https://www.omg.org/spec/Commons/Text/")

# --- OMG LCC (ISO Codes) ---
graph.bind(
"lcc-3166-1", "https://www.omg.org/spec/LCC/Countries/ISO3166-1-CountryCodes/"
)
graph.bind(
"lcc-4217", "https://www.omg.org/spec/LCC/Countries/ISO4217-CurrencyCodes/"
)
graph.bind(
"lcc-lr", "https://www.omg.org/spec/LCC/Languages/LanguageRepresentation/"
)

# --- FIBO (Financial Industry Business Ontology) ---
graph.bind(
"fibo-be-corp-corp",
"https://spec.edmcouncil.org/fibo/ontology/BE/Corporations/Corporations/",
)
graph.bind(
"fibo-be-ge-ge",
"https://spec.edmcouncil.org/fibo/ontology/BE/GovernmentEntities/GovernmentEntities/",
)
graph.bind(
"fibo-be-le-cb",
"https://spec.edmcouncil.org/fibo/ontology/BE/LegalEntities/CorporateBodies/",
)
graph.bind(
"fibo-be-le-lp",
"https://spec.edmcouncil.org/fibo/ontology/BE/LegalEntities/LegalPersons/",
)
graph.bind(
"fibo-be-nfp-nfp",
"https://spec.edmcouncil.org/fibo/ontology/BE/NotForProfitOrganizations/NotForProfitOrganizations/",
)
graph.bind(
"fibo-be-oac-cctl",
"https://spec.edmcouncil.org/fibo/ontology/BE/OwnershipAndControl/CorporateControl/",
)
graph.bind(
"fibo-fbc-dae-dbt",
"https://spec.edmcouncil.org/fibo/ontology/FBC/DebtAndEquities/Debt/",
)
graph.bind(
"fibo-fbc-pas-fpas",
"https://spec.edmcouncil.org/fibo/ontology/FBC/ProductsAndServices/FinancialProductsAndServices/",
)
graph.bind(
"fibo-fnd-acc-cur",
"https://spec.edmcouncil.org/fibo/ontology/FND/Accounting/CurrencyAmount/",
)
graph.bind(
"fibo-fnd-agr-ctr",
"https://spec.edmcouncil.org/fibo/ontology/FND/Agreements/Contracts/",
)
graph.bind(
"fibo-fnd-arr-doc",
"https://spec.edmcouncil.org/fibo/ontology/FND/Arrangements/Documents/",
)
graph.bind(
"fibo-fnd-arr-lif",
"https://spec.edmcouncil.org/fibo/ontology/FND/Arrangements/Lifecycles/",
)
graph.bind(
"fibo-fnd-dt-oc",
"https://spec.edmcouncil.org/fibo/ontology/FND/DatesAndTimes/Occurrences/",
)
graph.bind(
"fibo-fnd-org-org",
"https://spec.edmcouncil.org/fibo/ontology/FND/Organizations/Organizations/",
)
graph.bind(
"fibo-fnd-pas-pas",
"https://spec.edmcouncil.org/fibo/ontology/FND/ProductsAndServices/ProductsAndServices/",
)
graph.bind(
"fibo-fnd-plc-adr",
"https://spec.edmcouncil.org/fibo/ontology/FND/Places/Addresses/",
)
graph.bind(
"fibo-fnd-plc-fac",
"https://spec.edmcouncil.org/fibo/ontology/FND/Places/Facilities/",
)
graph.bind(
"fibo-fnd-plc-loc",
"https://spec.edmcouncil.org/fibo/ontology/FND/Places/Locations/",
)
graph.bind(
"fibo-fnd-pty-pty",
"https://spec.edmcouncil.org/fibo/ontology/FND/Parties/Parties/",
)
graph.bind(
"fibo-fnd-rel-rel",
"https://spec.edmcouncil.org/fibo/ontology/FND/Relations/Relations/",
)
graph.bind(
"fibo-pay-ps-ps",
"https://spec.edmcouncil.org/fibo/ontology/PAY/PaymentServices/PaymentServices/",
)

# --- Other External Vocabularies ---
graph.bind("gleif-L1", "https://www.gleif.org/ontology/L1/")
graph.bind("gs1", "https://ref.gs1.org/voc/")
graph.bind(
"lcc-cr", "https://www.omg.org/spec/LCC/Countries/CountryRepresentation/"
)
graph.bind("unece", "http://unece.org/vocab#")
graph.bind("vcard", "http://www.w3.org/2006/vcard/ns#")
graph.bind("bibo", "http://purl.org/ontology/bibo/")
graph.bind("sarif", "http://sarif.info/")

# --- Libraries and Health ---
graph.bind("lrmoo", "http://iflastandards.info/ns/lrm/lrmoo/")
graph.bind("snomed", "http://purl.bioontology.org/ontology/SNOMEDCT/")

# --- European Legislation Identifier (ELI) ---
graph.bind("eli", "http://data.europa.eu/eli/ontology#")

# --- W3C Standard extensions ---
graph.bind("prov", "http://www.w3.org/ns/prov#")
graph.bind("hydra", "http://www.w3.org/ns/hydra/core#")

# --- Music Ontology ---
graph.bind("mo", "http://purl.org/ontology/mo/")


class _TermAccumulator:
"""Temporary holder to accumulate term information."""

Expand Down Expand Up @@ -313,9 +459,9 @@ def getAcknowledgements(self) -> typing.Sequence[str]:
) # To accept later ttl versions.
for obj in objs:
if obj:
cont = sdocollaborators.collaborator.getContributor(obj)
if cont:
acks.append(cont)
cont = sdocollaborators.collaborator.getContributor(obj)
if cont:
acks.append(cont)
self.acks = sorted(acks, key=lambda t: t.title)
return self.acks

Expand Down Expand Up @@ -954,12 +1100,7 @@ def setSourceGraph(cls, g: rdflib.graph.Graph):
global VOCABURI
cls.SOURCEGRAPH = g
g.bind("schema", VOCABURI)
g.bind("owl", "http://www.w3.org/2002/07/owl#")
g.bind("dc", "http://purl.org/dc/elements/1.1/")
g.bind("dct", "http://purl.org/dc/terms/")
g.bind("dctype", "http://purl.org/dc/dcmitype/")
g.bind("void", "http://rdfs.org/ns/void#")
g.bind("dcat", "http://www.w3.org/ns/dcat#")
bindNameSpaces(g)

cls.TERMS = {} # Clear cache
cls.EXPANDEDTERMS = {}
Expand Down
2 changes: 1 addition & 1 deletion software/tests/test_sdotermsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def testUriForPrefix(self):
sdotermsource.uriForPrefix("dc"),
rdflib.term.URIRef("http://purl.org/dc/elements/1.1/"),
)
self.assertIsNone(sdotermsource.uriForPrefix("gs1"))
self.assertIsNone(sdotermsource.uriForPrefix("feedf 8000 ace"))

def testPrefixedIdFromUri(self):
self.assertEqual(
Expand Down
56 changes: 47 additions & 9 deletions software/util/buildfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,33 +188,73 @@ def exportrdf(exportType, subdirectory_path: str | None = None):
global allGraph, currentGraph

if not allGraph:
# The bindings need to be done for each graph
# as they are not copied over.
allGraph = rdflib.Graph()
allGraph.bind("schema", VOCABURI)
sdotermsource.bindNameSpaces(allGraph)
currentGraph = rdflib.Graph()
sdotermsource.bindNameSpaces(currentGraph)
currentGraph.bind("schema", VOCABURI)

# Loads triples AND the bindings you added to sourceGraph()
allGraph += sdotermsource.SdoTermSource.sourceGraph()

protocol, altprotocol = protocols()

log.debug("Cleanup non schema org things.")
# We delete everything where Subject is not schema.org.
# Since we haven't created the new types yet, they are safe.
deloddtriples = """DELETE {?s ?p ?o}
WHERE {
?s ?p ?o.
FILTER (! strstarts(str(?s), "%s://schema.org") ).
}""" % (protocol)
WHERE {
?s ?p ?o.
FILTER (! strstarts(str(?s), "%s://schema.org") ).
}""" % (protocol)
allGraph.update(deloddtriples)

log.debug("Generate Foreign types – SPARQL INSERT")
# Insert all the types and properties that are equivalent or inherited from.
insert_foreign_types = """
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

INSERT {
?classNode a rdfs:Class .
?propNode a rdf:Property .
}
WHERE {
# Find Foreign Classes (used in subClassOf or equivalentClass)
{
{ ?s rdfs:subClassOf ?classNode } UNION { ?s owl:equivalentClass ?classNode }
FILTER (isURI(?classNode) && !strstarts(str(?classNode), "%s://schema.org"))
}
UNION
# Find Foreign Properties (used in subPropertyOf or equivalentProperty)
{
{ ?s rdfs:subPropertyOf ?propNode } UNION { ?s owl:equivalentProperty ?propNode }
FILTER (isURI(?propNode) && !strstarts(str(?propNode), "%s://schema.org"))
}
}
""" % (protocol, protocol)

allGraph.update(insert_foreign_types)

log.debug("Merge")
currentGraph += allGraph

log.debug("Delete items from the attic")
delattic = """PREFIX schema: <%s://schema.org/>
DELETE {?s ?p ?o}
WHERE{
?s ?p ?o;
schema:isPartOf <%s://attic.schema.org>.
?s ?p ?o;
schema:isPartOf <%s://attic.schema.org>.
}""" % (protocol, protocol)

currentGraph.update(delattic)

formats = ["json-ld", "turtle", "nt", "nquads", "rdf"]
extype = exportType[len("RDFExport."):]
extype = exportType[len("RDFExport.") :]
if exportType == "RDFExports":
for output_format in sorted(formats):
_exportrdf(output_format, allGraph, currentGraph, subdirectory_path)
Expand All @@ -229,7 +269,6 @@ def exportrdf(exportType, subdirectory_path: str | None = None):


def _exportrdf(output_format, all, current, subdirectory_path: str | None = None):

protocol, altprotocol = protocols()

if output_format in completed_rdf_exports:
Expand All @@ -250,7 +289,6 @@ def _exportrdf(output_format, all, current, subdirectory_path: str | None = None
qg += g
g = gr


for p in fileutils.FILESET_PROTOCOLS:
fn = fileutils.releaseFilePath(
output_dir=schemaglobals.getOutputDir(),
Expand Down
0