From e0c31a6449a1d5ff24d9b387d4f0aba7101ad36b Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Tue, 9 Jun 2026 12:24:58 +0200 Subject: [PATCH 1/7] proposal to incorporate owl:versionIRI ans owl:versionInfo --- src/si_ref_point/settings.py | 3 ++- src/si_ref_point/tboxes/si_tbox.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/si_ref_point/settings.py b/src/si_ref_point/settings.py index 150961e..41cd78c 100644 --- a/src/si_ref_point/settings.py +++ b/src/si_ref_point/settings.py @@ -11,6 +11,7 @@ SKOSURL = "http://www.w3.org/2004/02/skos/core#" DCTURL = "http://purl.org/dc/terms#" SIDFWBASE = "https://si-digital-framework.org" +SIRPVERSION = "1.0.0" # Base URL for the SI Digital Framework # from this URL, sub-URLs are defined @@ -35,7 +36,7 @@ # TTL_FILES_FOLDER = TTLPATH # JSONLD_FILES_FOLDER = JLDPATH -GITHUB_BASE_PATH = "https://github.com/TheBIPM/SI-Reference-Point-2023/" +GITHUB_BASE_PATH = "https://github.com/TheBIPM/SI-Reference-Point-generation-scripts/" # SI_BROCHURE_PID="SI_Brochure_ed3_V3_01" # will be transformed into a PID '(SIDFWBASE)/SI/entities/(SI_BROCHURE_PID)' diff --git a/src/si_ref_point/tboxes/si_tbox.py b/src/si_ref_point/tboxes/si_tbox.py index ef95401..9bd48ce 100644 --- a/src/si_ref_point/tboxes/si_tbox.py +++ b/src/si_ref_point/tboxes/si_tbox.py @@ -8,7 +8,8 @@ from rdflib import Graph, OWL, RDF, RDFS, URIRef, Literal, BNode, SKOS, PROV from rdflib.collection import Collection from rdflib.namespace import XSD, DCTERMS -from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, GITHUB_BASE_PATH, SIDFWBASE +from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION + RES_BOD_NS = SIDFWBASE + "/bodies#" bodies_list = ['cgpm', 'cipm', 'cctf'] @@ -94,6 +95,10 @@ def __init__(self, namespace: str = SIDFWBASE + "/SI#", ns_prefix: str = "si"): uri_timestamp = timestamp.strftime("%Y%m%d%H%M%SZ") # used to identify uniquely the produced TTL file (entity) startedAt_timestamp = timestamp.strftime("%Y-%m-%dT%H:%M:%SZ") # used with the predicate 'startedAtTime' of the corresponding activity + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/SI#") + self.g.add((URIRef(self.namespace), OWL.versionIRI, version_iri)) + self.g.add((URIRef(self.namespace), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + ### `generate_turtle_files` repo = git.Repo(PKG_ROOT, search_parent_directories=True) sha = repo.head.object.hexsha From 0f9bbf9f0df153389019b03d4aacfd25dc783293 Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Tue, 9 Jun 2026 12:36:47 +0200 Subject: [PATCH 2/7] /bodies annotates with owl:versionIRI and owl:versionInfo --- src/si_ref_point/tboxes/rb_tbox.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/si_ref_point/tboxes/rb_tbox.py b/src/si_ref_point/tboxes/rb_tbox.py index 17bf6bd..3b3a850 100644 --- a/src/si_ref_point/tboxes/rb_tbox.py +++ b/src/si_ref_point/tboxes/rb_tbox.py @@ -2,13 +2,18 @@ from datetime import date from rdflib import URIRef, RDF, OWL, SKOS, XSD, RDFS, DCTERMS, Graph, Literal -from si_ref_point.settings import SIDFWBASE, SKOSURL +from si_ref_point.settings import SIDFWBASE, SKOSURL, SIRPVERSION RES_BOD_NS = SIDFWBASE + "/bodies#" class ResBod: def __init__(self, namespace: str = RES_BOD_NS, prefix: str = 'rb'): + + # 1) Define namespaces self.namespace = namespace + + # 2) Add annotations to the ontology + # 2.1 General annotations (type, comments etc) self._g = Graph() # a triple store as the main data structure self._g.bind(prefix, namespace) self._g.bind("skos", SKOSURL) @@ -21,6 +26,14 @@ def __init__(self, namespace: str = RES_BOD_NS, prefix: str = 'rb'): "resolutions, decisions, etc", datatype=XSD.string))) self._g.add((URIRef(RES_BOD_NS), DCTERMS.created, Literal(str(date.today()), datatype=XSD.date))) + # 2.2 Versioning + + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/bodies#") + self._g.add((URIRef(self.namespace), OWL.versionIRI, version_iri)) + self._g.add((URIRef(self.namespace), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + + + # 3) Define classes and predicates used by different A boxes self.ResBod = self.set_uri('ResBod') self._g.add((self.ResBod, RDF.type, SKOS.Concept)) self._g.add((self.ResBod, RDFS.label, Literal('Responsible Body', lang='en'))) From 00d7194d54a9ec4c5c1666897148c4f532223043 Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Tue, 9 Jun 2026 12:46:44 +0200 Subject: [PATCH 3/7] /constants annotated with owl:versionIRI and owl:versionInfo --- src/si_ref_point/aboxes/constants_abox.py | 10 +++++++++- src/si_ref_point/tboxes/si_tbox.py | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/si_ref_point/aboxes/constants_abox.py b/src/si_ref_point/aboxes/constants_abox.py index 62aabc7..c19203e 100644 --- a/src/si_ref_point/aboxes/constants_abox.py +++ b/src/si_ref_point/aboxes/constants_abox.py @@ -10,7 +10,7 @@ from si_ref_point.tboxes.si_tbox import SiElements import si_ref_point.aboxes.symbols_format as sf from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, \ - SI_FILES_FOLDER, GITHUB_BASE_PATH + SI_FILES_FOLDER, GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION from si_ref_point.aboxes.units_abox import transform_to_graph @@ -58,6 +58,14 @@ def main(): "%Y-%m-%dT%H:%M:%SZ") # used with the predicate 'startedAtTime' of the corresponding activity repo = git.Repo(PKG_ROOT, search_parent_directories=True) sha = repo.head.object.hexsha + + # SemVer + + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/constants/") + constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionIRI, version_iri)) + constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + + # 2.2.1 Agent # declare this code as an 'agent' (in the sense of PROVENANCE) # and define URI to a specific version by using its commit on GitHub diff --git a/src/si_ref_point/tboxes/si_tbox.py b/src/si_ref_point/tboxes/si_tbox.py index 9bd48ce..4068c5e 100644 --- a/src/si_ref_point/tboxes/si_tbox.py +++ b/src/si_ref_point/tboxes/si_tbox.py @@ -8,7 +8,8 @@ from rdflib import Graph, OWL, RDF, RDFS, URIRef, Literal, BNode, SKOS, PROV from rdflib.collection import Collection from rdflib.namespace import XSD, DCTERMS -from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION +from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, \ + GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION RES_BOD_NS = SIDFWBASE + "/bodies#" From 20e093bd059c40ebac02452ba7b656147bb04323 Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Tue, 9 Jun 2026 14:34:12 +0200 Subject: [PATCH 4/7] /decisions annotated with owl:versionIRI. Namespace defined. TBox removed (#97) from that ABox --- src/si_ref_point/aboxes/decisions_abox.py | 60 ++++++++++++++--------- src/si_ref_point/tboxes/si_tbox.py | 3 ++ 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/si_ref_point/aboxes/decisions_abox.py b/src/si_ref_point/aboxes/decisions_abox.py index 4062ee7..c35937c 100644 --- a/src/si_ref_point/aboxes/decisions_abox.py +++ b/src/si_ref_point/aboxes/decisions_abox.py @@ -3,9 +3,9 @@ import os import yaml from datetime import date -from rdflib import RDF, OWL, URIRef, RDFS, DCTERMS, Literal, SKOS, XSD +from rdflib import Graph, RDF, OWL, URIRef, RDFS, DCTERMS, Literal, SKOS, XSD from si_ref_point.tboxes.si_tbox import SiElements -from si_ref_point.settings import SI_FILES_FOLDER +from si_ref_point.settings import SI_FILES_FOLDER, SIDFWBASE, SIRPVERSION def cap1(instr): """Utility method""" @@ -13,19 +13,33 @@ def cap1(instr): def main(): """main of Decision A-box""" + # get the predicates and classes that are common to all cuq files si_graph = SiElements() - # Annotations to the ontology (name, Version number) - si_graph.g.add((URIRef(si_graph.namespace_decisions), RDF.type, OWL.Ontology)) - si_graph.g.add((URIRef(si_graph.namespace_decisions), SKOS.prefLabel, + # produce a separate graph for the decisions + decisions_graph = Graph() + + # 1) Define the namespaces + decisions_graph.bind("si", si_graph.namespace) + decisions_graph.bind("decisions", si_graph.namespace_decisions) + + # 2) Annotations to the ontology (name, Version number) + decisions_graph.add((URIRef(si_graph.namespace_decisions), RDF.type, OWL.Ontology)) + decisions_graph.add((URIRef(si_graph.namespace_decisions), SKOS.prefLabel, Literal("SI Reference Point - Decisions", datatype=XSD.string))) - si_graph.g.add((URIRef(si_graph.namespace_decisions), RDFS.comment, + decisions_graph.add((URIRef(si_graph.namespace_decisions), RDFS.comment, Literal("Ontology, part of the SI reference point, " "covering decisions", datatype=XSD.string))) - si_graph.g.add((URIRef(si_graph.namespace_decisions), DCTERMS.created, + decisions_graph.add((URIRef(si_graph.namespace_decisions), DCTERMS.created, Literal(str(date.today()), datatype=XSD.date))) + # SemVer + + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/decisions/") + decisions_graph.add((URIRef(si_graph.namespace_decisions), OWL.versionIRI, version_iri)) + decisions_graph.add((URIRef(si_graph.namespace_decisions), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + # crawl through the items of the YAML file with open(os.path.join(SI_FILES_FOLDER, 'decisions.yaml'), encoding="utf8") as fp: @@ -34,44 +48,44 @@ def main(): # create an instance of scope if necessary, using the scope code as # local name [TODO] : is it really only doing it if necessary ? scope = si_graph.set_decision_uri(dec['scopeCode']) - si_graph.g.add((scope, RDF.type, si_graph.si_decision_scope)) + decisions_graph.add((scope, RDF.type, si_graph.si_decision_scope)) # add labels to scope (capitalize the first character) - si_graph.g.add((scope, RDFS.label, + decisions_graph.add((scope, RDFS.label, Literal(cap1(dec['scopeEN']), lang="en"))) - si_graph.g.add((scope, RDFS.label, + decisions_graph.add((scope, RDFS.label, Literal(cap1(dec['scopeFR']), lang="fr"))) # create instance of target if necessary using target code as local # name target = si_graph.set_decision_uri(dec['targetCode']) - si_graph.g.add((target, RDF.type, si_graph.si_decision_target)) + decisions_graph.add((target, RDF.type, si_graph.si_decision_target)) # add labels to target - si_graph.g.add((target, RDFS.label, + decisions_graph.add((target, RDFS.label, Literal(cap1(dec['targetEN']), lang="en"))) - si_graph.g.add((target, RDFS.label, + decisions_graph.add((target, RDFS.label, Literal(cap1(dec['targetFR']), lang="fr"))) # add links between target and scope - si_graph.g.add((scope, si_graph.has_target, target)) - si_graph.g.add((target, si_graph.is_target_of, scope)) + decisions_graph.add((scope, si_graph.has_target, target)) + decisions_graph.add((target, si_graph.is_target_of, scope)) # create instance of decision if necessary using decision code as local # name decision = si_graph.set_decision_uri(dec['decisionCode']) - si_graph.g.add((decision, RDF.type, si_graph.si_decision)) + decisions_graph.add((decision, RDF.type, si_graph.si_decision)) # add labels to decision - si_graph.g.add((decision, RDFS.label, + decisions_graph.add((decision, RDFS.label, Literal(cap1(dec['decisionEN']), lang="en"))) - si_graph.g.add((decision, RDFS.label, + decisions_graph.add((decision, RDFS.label, Literal(cap1(dec['decisionFR']), lang="fr"))) # add links between decision and target - si_graph.g.add((target, si_graph.has_decision, decision)) - si_graph.g.add((decision, si_graph.is_decision_of, target)) + decisions_graph.add((target, si_graph.has_decision, decision)) + decisions_graph.add((decision, si_graph.is_decision_of, target)) # add link between decision and resolution (retrieved from one of # cgpm.ttl, cipm.ttl or cctf.ttl) using the ‘correspondingResolution’ # object property - si_graph.g.add((decision, si_graph.corresponding_resolution, + decisions_graph.add((decision, si_graph.corresponding_resolution, si_graph.set_resolution_uri(dec['ID-resolution']))) if 'crossReferences' in dec: for xref in dec['crossReferences']: # add link between decision and the cross-referenced decision - si_graph.g.add((decision, SKOS.related, si_graph.set_decision_uri(xref))) + decisions_graph.add((decision, SKOS.related, si_graph.set_decision_uri(xref))) - return si_graph.g + return decisions_graph diff --git a/src/si_ref_point/tboxes/si_tbox.py b/src/si_ref_point/tboxes/si_tbox.py index 4068c5e..795c434 100644 --- a/src/si_ref_point/tboxes/si_tbox.py +++ b/src/si_ref_point/tboxes/si_tbox.py @@ -38,6 +38,9 @@ def __init__(self, namespace: str = SIDFWBASE + "/SI#", ns_prefix: str = "si"): self.namespace_constants = SIDFWBASE + "/constants/" # Explicitly binding a constants namespace to the URI self.g.bind("constants", self.namespace_constants) + + # Explicitly binding a decisions namespace to the URI + self.g.bind("decisions", self.namespace_decisions) # Define the namespaces within (base)/bodies # ~/bodies From ac5f64a2c080791e7aee377ecd8e58d9935bbff6 Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Tue, 9 Jun 2026 15:19:47 +0200 Subject: [PATCH 5/7] /prefixes annotated with owl:versionIRI and owl:versionInfo --- src/si_ref_point/aboxes/constants_abox.py | 10 +++++----- src/si_ref_point/aboxes/prefixes_abox.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/si_ref_point/aboxes/constants_abox.py b/src/si_ref_point/aboxes/constants_abox.py index c19203e..4fa40a7 100644 --- a/src/si_ref_point/aboxes/constants_abox.py +++ b/src/si_ref_point/aboxes/constants_abox.py @@ -46,6 +46,11 @@ def main(): "seven underpinning constants of the SI"), datatype=XSD.string)) ) + # SemVer + + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/constants/") + constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionIRI, version_iri)) + constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) # 2.2 Versioning (using PROVENANCE vocabulary) # The `timestamp` variable in the code is used to capture the current system time in UTC timezone. @@ -59,11 +64,6 @@ def main(): repo = git.Repo(PKG_ROOT, search_parent_directories=True) sha = repo.head.object.hexsha - # SemVer - - version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/constants/") - constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionIRI, version_iri)) - constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) # 2.2.1 Agent diff --git a/src/si_ref_point/aboxes/prefixes_abox.py b/src/si_ref_point/aboxes/prefixes_abox.py index 69a9656..560f803 100644 --- a/src/si_ref_point/aboxes/prefixes_abox.py +++ b/src/si_ref_point/aboxes/prefixes_abox.py @@ -8,7 +8,8 @@ from decimal import Decimal from rdflib import Graph, URIRef, RDF, OWL, SKOS, XSD, RDFS, DCTERMS, Literal, PROV from si_ref_point.tboxes.si_tbox import SiElements -from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, GITHUB_BASE_PATH +from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, \ + GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION def main(): @@ -20,8 +21,8 @@ def main(): prefix_graph = Graph() # 1) Define the namespaces within (base)/SI - prefix_graph.bind("prefixes",si_graph.namespace_prefixes) - prefix_graph.bind("si",si_graph.namespace) + prefix_graph.bind("prefixes", si_graph.namespace_prefixes) + prefix_graph.bind("si", si_graph.namespace) # 2) Annotations to the prefix-graph @@ -43,6 +44,11 @@ def main(): "prefixes for the SI measurement units.")) ) + # SemVer + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/prefixes/") + prefix_graph.add((URIRef(si_graph.namespace_prefixes), OWL.versionIRI, version_iri)) + prefix_graph.add((URIRef(si_graph.namespace_prefixes), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + # 2.2 Versioning (using PROVENANCE vocabulary) timestamp = datetime.now(timezone.utc) # get the system time (in UTC) uri_timestamp = timestamp.strftime("%Y%m%d%H%M%SZ") # used to identify uniquely the produced TTL file (entity) From 55761cce8a49763fbde033459727c93701693241 Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Tue, 9 Jun 2026 15:43:43 +0200 Subject: [PATCH 6/7] /quantities, /bodies and /units annotated with owl:versionIRI and owl:versionInfo --- src/si_ref_point/aboxes/constants_abox.py | 2 +- src/si_ref_point/aboxes/quantities_abox.py | 366 +++++++++++---------- src/si_ref_point/aboxes/rb_utils.py | 8 +- src/si_ref_point/aboxes/units_abox.py | 8 +- 4 files changed, 201 insertions(+), 183 deletions(-) diff --git a/src/si_ref_point/aboxes/constants_abox.py b/src/si_ref_point/aboxes/constants_abox.py index 4fa40a7..f1cf7f9 100644 --- a/src/si_ref_point/aboxes/constants_abox.py +++ b/src/si_ref_point/aboxes/constants_abox.py @@ -46,8 +46,8 @@ def main(): "seven underpinning constants of the SI"), datatype=XSD.string)) ) + # SemVer - version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/constants/") constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionIRI, version_iri)) constants_graph.add((URIRef(si_graph.namespace_constants), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) diff --git a/src/si_ref_point/aboxes/quantities_abox.py b/src/si_ref_point/aboxes/quantities_abox.py index a18b802..4c8f705 100644 --- a/src/si_ref_point/aboxes/quantities_abox.py +++ b/src/si_ref_point/aboxes/quantities_abox.py @@ -1,180 +1,186 @@ -""" Quantities ABox """ - -import git -import os -import logging -import yaml -from datetime import datetime, timezone -from rdflib import Graph, RDF, OWL, URIRef, RDFS, DCTERMS, Literal, SKOS, XSD, PROV -from si_ref_point.tboxes.si_tbox import SiElements -from si_ref_point.aboxes.units_abox import transform_to_graph -from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, GITHUB_BASE_PATH - - -def main(): - """Main of Quantities A-box""" - # get the predicates and classes that are common to all cuq files - si_graph = SiElements() - # produce a separate graphe for the units - quantities_graph = Graph() - - # 1) Define the namespaces within (base)/SI - quantities_graph.bind("quantities",si_graph.namespace_quantities) - quantities_graph.bind("units",si_graph.namespace_units) - quantities_graph.bind("si",si_graph.namespace) - - # 2) Add annotations to the quantity graph - - # 2.1 General annotations (type, labels, comments etc) - - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDF.type, - OWL.Ontology) - ) - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - SKOS.prefLabel, - Literal("SI Reference Point - Quantities", datatype=XSD.string)) - ) - - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDFS.comment, - Literal("Ontology, part of the SI reference point, " - "covering quantities", - datatype=XSD.string)) - ) - - # 2.2 Versioning (using PROVENANCE vocabulary) - timestamp = datetime.now(timezone.utc) # get the system time (in UTC) - uri_timestamp = timestamp.strftime("%Y%m%d%H%M%SZ") # used to identify uniquely the produced TTL file (entity) - startedAt_timestamp = timestamp.strftime("%Y-%m-%dT%H:%M:%SZ") # used with the predicate 'startedAtTime' of the corresponding activity - repo = git.Repo(PKG_ROOT, search_parent_directories=True) - sha = repo.head.object.hexsha - # 2.2.1 Agent - # declare this code as an 'agent' (in the sense of PROVENANCE) - # and define UàRI to a specific version by using its commit on GitHub - agents = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/si_tbox.py", - GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/quantities_abox.py"] - - for agent_sw in agents: - quantities_graph.add( - (URIRef(agent_sw), - RDF.type, - PROV.Agent) - ) - - # 2.2.2 Entity - # declare the sources (YAML files) as 'entity' (in the sense of PROVENANCE) - # The manually produced YAML files are stored on GitHub. Their hexsha together - # with the path is used to define a unique URI for each file. - source_files = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_core.yaml", - GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_other.yaml"] - for source in source_files: - quantities_graph.add( - (URIRef(source), - RDF.type, - PROV.Entity) - ) - quantities_out_entity ="quantities_" + uri_timestamp + ".ttl" - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - RDF.type, - PROV.Entity) - ) - - # 2.2.3 Activity - # declare the constants_ttl_generation as 'activity' (in the sense of PROVENANCE) - # make the activity unique by adding the timestamp to the identifier of the activity - activity = 'quantities_'+uri_timestamp + '.ttl_generation' - - quantities_graph.add( - (si_graph.set_activity_uri(activity), - RDF.type, - PROV.Activity) - ) - - # 2.2.4 Relation activity, agent, entities - # activity - agent - for agent_sw in agents: - quantities_graph.add( - (si_graph.set_activity_uri(activity), - PROV.wasAssociatedWith, - URIRef(agent_sw)) - ) - quantities_graph.add( - (si_graph.set_activity_uri(activity), - PROV.startedAtTime, - Literal(str(startedAt_timestamp), datatype=XSD.dateTime)) - ) - # output entity - source entities - for source in source_files: - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - PROV.wasDerivedFrom, - URIRef(source)) - ) - # output entity - agent - for agent_sw in agents: - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - PROV.wasAttributedTo, - URIRef(agent_sw)) - ) - # output entity - activity - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - PROV.wasGeneratedBy, - si_graph.set_activity_uri(activity)) - ) - - # 2.3 License information - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - DCTERMS.license, - URIRef(CC_LICENCE)) - ) - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDFS.comment, - Literal(CC_LICENCE_TEXT_EN,lang="en")) - ) - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDFS.comment, - Literal(CC_LICENCE_TEXT_FR,lang="fr")) - ) - - # 3) Build quantity graph - # crawl through the list of YAML files - qty_files = ['quantities_core.yaml', 'quantities_other.yaml'] - qty_code_list = [] - - # open YAML files with information - for filename in qty_files: - with open(os.path.join(SI_FILES_FOLDER, filename), encoding="utf8") as fp: - qty_list = yaml.safe_load(fp) - - # add the individual quantities to the graph - for qty in qty_list["data"]: - if qty['identifier'] not in qty_code_list: - qty_code_list.append(qty['identifier']) - else: - logging.error("quantity %s already defined !", qty['identifier'] ) - element = si_graph.set_quantity_uri(qty['identifier']) - quantities_graph.add((element, RDF.type, si_graph.quantity_kind)) - quantities_graph.add((element, SKOS.prefLabel, - Literal(qty['quantity-en'], lang="en"))) - quantities_graph.add((element, SKOS.prefLabel, - Literal(qty['quantity-fr'], lang="fr"))) - quantities_graph.add((element, SKOS.altLabel, Literal(qty['identifier'], - datatype=XSD.string))) - if 'Unit' in qty and qty['Unit'] is not None: - quantities_graph, cmpnd_node = transform_to_graph(qty['Unit'], si_graph, quantities_graph) - quantities_graph.add((element, si_graph.has_unit, cmpnd_node)) - - return quantities_graph - -if __name__ == "__main__": - main() +""" Quantities ABox """ + +import git +import os +import logging +import yaml +from datetime import datetime, timezone +from rdflib import Graph, RDF, OWL, URIRef, RDFS, DCTERMS, Literal, SKOS, XSD, PROV +from si_ref_point.tboxes.si_tbox import SiElements +from si_ref_point.aboxes.units_abox import transform_to_graph +from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, \ + GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION + + +def main(): + """Main of Quantities A-box""" + # get the predicates and classes that are common to all cuq files + si_graph = SiElements() + # produce a separate graphe for the units + quantities_graph = Graph() + + # 1) Define the namespaces within (base)/SI + quantities_graph.bind("quantities",si_graph.namespace_quantities) + quantities_graph.bind("units",si_graph.namespace_units) + quantities_graph.bind("si",si_graph.namespace) + + # 2) Add annotations to the quantity graph + + # 2.1 General annotations (type, labels, comments etc) + + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDF.type, + OWL.Ontology) + ) + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + SKOS.prefLabel, + Literal("SI Reference Point - Quantities", datatype=XSD.string)) + ) + + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDFS.comment, + Literal("Ontology, part of the SI reference point, " + "covering quantities", + datatype=XSD.string)) + ) + + # SemVer + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/quantities/") + quantities_graph.add((URIRef(si_graph.namespace_quantities), OWL.versionIRI, version_iri)) + quantities_graph.add((URIRef(si_graph.namespace_quantities), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + + # 2.2 Versioning (using PROVENANCE vocabulary) + timestamp = datetime.now(timezone.utc) # get the system time (in UTC) + uri_timestamp = timestamp.strftime("%Y%m%d%H%M%SZ") # used to identify uniquely the produced TTL file (entity) + startedAt_timestamp = timestamp.strftime("%Y-%m-%dT%H:%M:%SZ") # used with the predicate 'startedAtTime' of the corresponding activity + repo = git.Repo(PKG_ROOT, search_parent_directories=True) + sha = repo.head.object.hexsha + # 2.2.1 Agent + # declare this code as an 'agent' (in the sense of PROVENANCE) + # and define UàRI to a specific version by using its commit on GitHub + agents = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/si_tbox.py", + GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/quantities_abox.py"] + + for agent_sw in agents: + quantities_graph.add( + (URIRef(agent_sw), + RDF.type, + PROV.Agent) + ) + + # 2.2.2 Entity + # declare the sources (YAML files) as 'entity' (in the sense of PROVENANCE) + # The manually produced YAML files are stored on GitHub. Their hexsha together + # with the path is used to define a unique URI for each file. + source_files = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_core.yaml", + GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_other.yaml"] + for source in source_files: + quantities_graph.add( + (URIRef(source), + RDF.type, + PROV.Entity) + ) + quantities_out_entity ="quantities_" + uri_timestamp + ".ttl" + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + RDF.type, + PROV.Entity) + ) + + # 2.2.3 Activity + # declare the constants_ttl_generation as 'activity' (in the sense of PROVENANCE) + # make the activity unique by adding the timestamp to the identifier of the activity + activity = 'quantities_'+uri_timestamp + '.ttl_generation' + + quantities_graph.add( + (si_graph.set_activity_uri(activity), + RDF.type, + PROV.Activity) + ) + + # 2.2.4 Relation activity, agent, entities + # activity - agent + for agent_sw in agents: + quantities_graph.add( + (si_graph.set_activity_uri(activity), + PROV.wasAssociatedWith, + URIRef(agent_sw)) + ) + quantities_graph.add( + (si_graph.set_activity_uri(activity), + PROV.startedAtTime, + Literal(str(startedAt_timestamp), datatype=XSD.dateTime)) + ) + # output entity - source entities + for source in source_files: + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + PROV.wasDerivedFrom, + URIRef(source)) + ) + # output entity - agent + for agent_sw in agents: + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + PROV.wasAttributedTo, + URIRef(agent_sw)) + ) + # output entity - activity + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + PROV.wasGeneratedBy, + si_graph.set_activity_uri(activity)) + ) + + # 2.3 License information + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + DCTERMS.license, + URIRef(CC_LICENCE)) + ) + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDFS.comment, + Literal(CC_LICENCE_TEXT_EN,lang="en")) + ) + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDFS.comment, + Literal(CC_LICENCE_TEXT_FR,lang="fr")) + ) + + # 3) Build quantity graph + # crawl through the list of YAML files + qty_files = ['quantities_core.yaml', 'quantities_other.yaml'] + qty_code_list = [] + + # open YAML files with information + for filename in qty_files: + with open(os.path.join(SI_FILES_FOLDER, filename), encoding="utf8") as fp: + qty_list = yaml.safe_load(fp) + + # add the individual quantities to the graph + for qty in qty_list["data"]: + if qty['identifier'] not in qty_code_list: + qty_code_list.append(qty['identifier']) + else: + logging.error("quantity %s already defined !", qty['identifier'] ) + element = si_graph.set_quantity_uri(qty['identifier']) + quantities_graph.add((element, RDF.type, si_graph.quantity_kind)) + quantities_graph.add((element, SKOS.prefLabel, + Literal(qty['quantity-en'], lang="en"))) + quantities_graph.add((element, SKOS.prefLabel, + Literal(qty['quantity-fr'], lang="fr"))) + quantities_graph.add((element, SKOS.altLabel, Literal(qty['identifier'], + datatype=XSD.string))) + if 'Unit' in qty and qty['Unit'] is not None: + quantities_graph, cmpnd_node = transform_to_graph(qty['Unit'], si_graph, quantities_graph) + quantities_graph.add((element, si_graph.has_unit, cmpnd_node)) + + return quantities_graph + +if __name__ == "__main__": + main() diff --git a/src/si_ref_point/aboxes/rb_utils.py b/src/si_ref_point/aboxes/rb_utils.py index cfcb6ac..c3cb617 100644 --- a/src/si_ref_point/aboxes/rb_utils.py +++ b/src/si_ref_point/aboxes/rb_utils.py @@ -6,7 +6,7 @@ from rdflib import Graph, Literal, Namespace, URIRef from rdflib.namespace import DCTERMS, OWL, RDF, RDFS, SKOS, XSD from si_ref_point.tboxes.rb_tbox import RES_BOD_NS -from si_ref_point.settings import SIDFWBASE +from si_ref_point.settings import SIDFWBASE, SIRPVERSION RB = Namespace(RES_BOD_NS) @@ -63,6 +63,12 @@ def add_general_description(self): ) ) + # SemVer + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/bodies/" + self.own_acronym + "#") + self.g.add((URIRef(self.OWN_NS), OWL.versionIRI, version_iri)) + self.g.add((URIRef(self.OWN_NS), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + + self.g.add( ( URIRef(self.OWN_NS), diff --git a/src/si_ref_point/aboxes/units_abox.py b/src/si_ref_point/aboxes/units_abox.py index 2dce6bb..30e1ce8 100644 --- a/src/si_ref_point/aboxes/units_abox.py +++ b/src/si_ref_point/aboxes/units_abox.py @@ -11,7 +11,8 @@ from rdflib import Graph, URIRef, BNode, Literal, RDF, OWL, SKOS, XSD, RDFS, DCTERMS, PROV from si_ref_point.tboxes.si_tbox import SiElements import si_ref_point.aboxes.symbols_format as sf -from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, GITHUB_BASE_PATH +from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, \ + GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION def nest_mult(expr): @@ -171,6 +172,11 @@ def main(): datatype=XSD.string)) ) + # SemVer + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/units/") + units_graph.add((URIRef(si_graph.namespace_units), OWL.versionIRI, version_iri)) + units_graph.add((URIRef(si_graph.namespace_units), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + # 2.2 Versioning (using PROVENANCE vocabulary) timestamp = datetime.now(timezone.utc) # get the system time (in UTC) uri_timestamp = timestamp.strftime("%Y%m%d%H%M%SZ") # used to identify uniquely the produced TTL file (entity) From d5e15dd32cd02c8c801a799124f8fb26b19e8975 Mon Sep 17 00:00:00 2001 From: Cristhian PAREDES Date: Tue, 9 Jun 2026 15:59:19 +0200 Subject: [PATCH 7/7] undo changes in /quantities LF (being replaced for CRLF by VisualStudio) --- src/si_ref_point/aboxes/quantities_abox.py | 372 ++++++++++----------- 1 file changed, 186 insertions(+), 186 deletions(-) diff --git a/src/si_ref_point/aboxes/quantities_abox.py b/src/si_ref_point/aboxes/quantities_abox.py index 4c8f705..78b6af7 100644 --- a/src/si_ref_point/aboxes/quantities_abox.py +++ b/src/si_ref_point/aboxes/quantities_abox.py @@ -1,186 +1,186 @@ -""" Quantities ABox """ - -import git -import os -import logging -import yaml -from datetime import datetime, timezone -from rdflib import Graph, RDF, OWL, URIRef, RDFS, DCTERMS, Literal, SKOS, XSD, PROV -from si_ref_point.tboxes.si_tbox import SiElements -from si_ref_point.aboxes.units_abox import transform_to_graph -from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, \ - GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION - - -def main(): - """Main of Quantities A-box""" - # get the predicates and classes that are common to all cuq files - si_graph = SiElements() - # produce a separate graphe for the units - quantities_graph = Graph() - - # 1) Define the namespaces within (base)/SI - quantities_graph.bind("quantities",si_graph.namespace_quantities) - quantities_graph.bind("units",si_graph.namespace_units) - quantities_graph.bind("si",si_graph.namespace) - - # 2) Add annotations to the quantity graph - - # 2.1 General annotations (type, labels, comments etc) - - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDF.type, - OWL.Ontology) - ) - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - SKOS.prefLabel, - Literal("SI Reference Point - Quantities", datatype=XSD.string)) - ) - - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDFS.comment, - Literal("Ontology, part of the SI reference point, " - "covering quantities", - datatype=XSD.string)) - ) - - # SemVer - version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/quantities/") - quantities_graph.add((URIRef(si_graph.namespace_quantities), OWL.versionIRI, version_iri)) - quantities_graph.add((URIRef(si_graph.namespace_quantities), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) - - # 2.2 Versioning (using PROVENANCE vocabulary) - timestamp = datetime.now(timezone.utc) # get the system time (in UTC) - uri_timestamp = timestamp.strftime("%Y%m%d%H%M%SZ") # used to identify uniquely the produced TTL file (entity) - startedAt_timestamp = timestamp.strftime("%Y-%m-%dT%H:%M:%SZ") # used with the predicate 'startedAtTime' of the corresponding activity - repo = git.Repo(PKG_ROOT, search_parent_directories=True) - sha = repo.head.object.hexsha - # 2.2.1 Agent - # declare this code as an 'agent' (in the sense of PROVENANCE) - # and define UàRI to a specific version by using its commit on GitHub - agents = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/si_tbox.py", - GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/quantities_abox.py"] - - for agent_sw in agents: - quantities_graph.add( - (URIRef(agent_sw), - RDF.type, - PROV.Agent) - ) - - # 2.2.2 Entity - # declare the sources (YAML files) as 'entity' (in the sense of PROVENANCE) - # The manually produced YAML files are stored on GitHub. Their hexsha together - # with the path is used to define a unique URI for each file. - source_files = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_core.yaml", - GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_other.yaml"] - for source in source_files: - quantities_graph.add( - (URIRef(source), - RDF.type, - PROV.Entity) - ) - quantities_out_entity ="quantities_" + uri_timestamp + ".ttl" - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - RDF.type, - PROV.Entity) - ) - - # 2.2.3 Activity - # declare the constants_ttl_generation as 'activity' (in the sense of PROVENANCE) - # make the activity unique by adding the timestamp to the identifier of the activity - activity = 'quantities_'+uri_timestamp + '.ttl_generation' - - quantities_graph.add( - (si_graph.set_activity_uri(activity), - RDF.type, - PROV.Activity) - ) - - # 2.2.4 Relation activity, agent, entities - # activity - agent - for agent_sw in agents: - quantities_graph.add( - (si_graph.set_activity_uri(activity), - PROV.wasAssociatedWith, - URIRef(agent_sw)) - ) - quantities_graph.add( - (si_graph.set_activity_uri(activity), - PROV.startedAtTime, - Literal(str(startedAt_timestamp), datatype=XSD.dateTime)) - ) - # output entity - source entities - for source in source_files: - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - PROV.wasDerivedFrom, - URIRef(source)) - ) - # output entity - agent - for agent_sw in agents: - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - PROV.wasAttributedTo, - URIRef(agent_sw)) - ) - # output entity - activity - quantities_graph.add( - (si_graph.set_entity_uri(quantities_out_entity), - PROV.wasGeneratedBy, - si_graph.set_activity_uri(activity)) - ) - - # 2.3 License information - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - DCTERMS.license, - URIRef(CC_LICENCE)) - ) - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDFS.comment, - Literal(CC_LICENCE_TEXT_EN,lang="en")) - ) - quantities_graph.add( - (URIRef(si_graph.namespace_quantities), - RDFS.comment, - Literal(CC_LICENCE_TEXT_FR,lang="fr")) - ) - - # 3) Build quantity graph - # crawl through the list of YAML files - qty_files = ['quantities_core.yaml', 'quantities_other.yaml'] - qty_code_list = [] - - # open YAML files with information - for filename in qty_files: - with open(os.path.join(SI_FILES_FOLDER, filename), encoding="utf8") as fp: - qty_list = yaml.safe_load(fp) - - # add the individual quantities to the graph - for qty in qty_list["data"]: - if qty['identifier'] not in qty_code_list: - qty_code_list.append(qty['identifier']) - else: - logging.error("quantity %s already defined !", qty['identifier'] ) - element = si_graph.set_quantity_uri(qty['identifier']) - quantities_graph.add((element, RDF.type, si_graph.quantity_kind)) - quantities_graph.add((element, SKOS.prefLabel, - Literal(qty['quantity-en'], lang="en"))) - quantities_graph.add((element, SKOS.prefLabel, - Literal(qty['quantity-fr'], lang="fr"))) - quantities_graph.add((element, SKOS.altLabel, Literal(qty['identifier'], - datatype=XSD.string))) - if 'Unit' in qty and qty['Unit'] is not None: - quantities_graph, cmpnd_node = transform_to_graph(qty['Unit'], si_graph, quantities_graph) - quantities_graph.add((element, si_graph.has_unit, cmpnd_node)) - - return quantities_graph - -if __name__ == "__main__": - main() +""" Quantities ABox """ + +import git +import os +import logging +import yaml +from datetime import datetime, timezone +from rdflib import Graph, RDF, OWL, URIRef, RDFS, DCTERMS, Literal, SKOS, XSD, PROV +from si_ref_point.tboxes.si_tbox import SiElements +from si_ref_point.aboxes.units_abox import transform_to_graph +from si_ref_point.settings import PKG_ROOT, CC_LICENCE, CC_LICENCE_TEXT_EN, CC_LICENCE_TEXT_FR, SI_FILES_FOLDER, \ + GITHUB_BASE_PATH, SIDFWBASE, SIRPVERSION + + +def main(): + """Main of Quantities A-box""" + # get the predicates and classes that are common to all cuq files + si_graph = SiElements() + # produce a separate graphe for the units + quantities_graph = Graph() + + # 1) Define the namespaces within (base)/SI + quantities_graph.bind("quantities",si_graph.namespace_quantities) + quantities_graph.bind("units",si_graph.namespace_units) + quantities_graph.bind("si",si_graph.namespace) + + # 2) Add annotations to the quantity graph + + # 2.1 General annotations (type, labels, comments etc) + + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDF.type, + OWL.Ontology) + ) + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + SKOS.prefLabel, + Literal("SI Reference Point - Quantities", datatype=XSD.string)) + ) + + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDFS.comment, + Literal("Ontology, part of the SI reference point, " + "covering quantities", + datatype=XSD.string)) + ) + + # SemVer + version_iri = URIRef(SIDFWBASE + "/" + SIRPVERSION + "/quantities/") + quantities_graph.add((URIRef(si_graph.namespace_quantities), OWL.versionIRI, version_iri)) + quantities_graph.add((URIRef(si_graph.namespace_quantities), OWL.versionInfo, Literal(SIRPVERSION, datatype=XSD.string))) + + # 2.2 Versioning (using PROVENANCE vocabulary) + timestamp = datetime.now(timezone.utc) # get the system time (in UTC) + uri_timestamp = timestamp.strftime("%Y%m%d%H%M%SZ") # used to identify uniquely the produced TTL file (entity) + startedAt_timestamp = timestamp.strftime("%Y-%m-%dT%H:%M:%SZ") # used with the predicate 'startedAtTime' of the corresponding activity + repo = git.Repo(PKG_ROOT, search_parent_directories=True) + sha = repo.head.object.hexsha + # 2.2.1 Agent + # declare this code as an 'agent' (in the sense of PROVENANCE) + # and define UàRI to a specific version by using its commit on GitHub + agents = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/si_tbox.py", + GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/cuq/quantities_abox.py"] + + for agent_sw in agents: + quantities_graph.add( + (URIRef(agent_sw), + RDF.type, + PROV.Agent) + ) + + # 2.2.2 Entity + # declare the sources (YAML files) as 'entity' (in the sense of PROVENANCE) + # The manually produced YAML files are stored on GitHub. Their hexsha together + # with the path is used to define a unique URI for each file. + source_files = [GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_core.yaml", + GITHUB_BASE_PATH + "blob/" + sha + "/src/si_ref_point/si/quantities_other.yaml"] + for source in source_files: + quantities_graph.add( + (URIRef(source), + RDF.type, + PROV.Entity) + ) + quantities_out_entity ="quantities_" + uri_timestamp + ".ttl" + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + RDF.type, + PROV.Entity) + ) + + # 2.2.3 Activity + # declare the constants_ttl_generation as 'activity' (in the sense of PROVENANCE) + # make the activity unique by adding the timestamp to the identifier of the activity + activity = 'quantities_'+uri_timestamp + '.ttl_generation' + + quantities_graph.add( + (si_graph.set_activity_uri(activity), + RDF.type, + PROV.Activity) + ) + + # 2.2.4 Relation activity, agent, entities + # activity - agent + for agent_sw in agents: + quantities_graph.add( + (si_graph.set_activity_uri(activity), + PROV.wasAssociatedWith, + URIRef(agent_sw)) + ) + quantities_graph.add( + (si_graph.set_activity_uri(activity), + PROV.startedAtTime, + Literal(str(startedAt_timestamp), datatype=XSD.dateTime)) + ) + # output entity - source entities + for source in source_files: + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + PROV.wasDerivedFrom, + URIRef(source)) + ) + # output entity - agent + for agent_sw in agents: + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + PROV.wasAttributedTo, + URIRef(agent_sw)) + ) + # output entity - activity + quantities_graph.add( + (si_graph.set_entity_uri(quantities_out_entity), + PROV.wasGeneratedBy, + si_graph.set_activity_uri(activity)) + ) + + # 2.3 License information + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + DCTERMS.license, + URIRef(CC_LICENCE)) + ) + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDFS.comment, + Literal(CC_LICENCE_TEXT_EN,lang="en")) + ) + quantities_graph.add( + (URIRef(si_graph.namespace_quantities), + RDFS.comment, + Literal(CC_LICENCE_TEXT_FR,lang="fr")) + ) + + # 3) Build quantity graph + # crawl through the list of YAML files + qty_files = ['quantities_core.yaml', 'quantities_other.yaml'] + qty_code_list = [] + + # open YAML files with information + for filename in qty_files: + with open(os.path.join(SI_FILES_FOLDER, filename), encoding="utf8") as fp: + qty_list = yaml.safe_load(fp) + + # add the individual quantities to the graph + for qty in qty_list["data"]: + if qty['identifier'] not in qty_code_list: + qty_code_list.append(qty['identifier']) + else: + logging.error("quantity %s already defined !", qty['identifier'] ) + element = si_graph.set_quantity_uri(qty['identifier']) + quantities_graph.add((element, RDF.type, si_graph.quantity_kind)) + quantities_graph.add((element, SKOS.prefLabel, + Literal(qty['quantity-en'], lang="en"))) + quantities_graph.add((element, SKOS.prefLabel, + Literal(qty['quantity-fr'], lang="fr"))) + quantities_graph.add((element, SKOS.altLabel, Literal(qty['identifier'], + datatype=XSD.string))) + if 'Unit' in qty and qty['Unit'] is not None: + quantities_graph, cmpnd_node = transform_to_graph(qty['Unit'], si_graph, quantities_graph) + quantities_graph.add((element, si_graph.has_unit, cmpnd_node)) + + return quantities_graph + +if __name__ == "__main__": + main()