From 0816954929e9082603ad960a24f37694f85968fe Mon Sep 17 00:00:00 2001 From: jpizarro Date: Fri, 24 Jan 2025 13:05:53 +0100 Subject: [PATCH] Adding back the placeholders for object, collections and datasets Changed OWL.Class to OWL.Thing Added descriptions for relationships --- bam_masterdata/cli/entities_to_rdf.py | 41 +++++++++++++++++++++------ bam_masterdata/metadata/entities.py | 22 +++++++------- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/bam_masterdata/cli/entities_to_rdf.py b/bam_masterdata/cli/entities_to_rdf.py index 3ec514b..94d41d7 100644 --- a/bam_masterdata/cli/entities_to_rdf.py +++ b/bam_masterdata/cli/entities_to_rdf.py @@ -80,30 +80,50 @@ def rdf_graph_init(g: "Graph") -> None: bam_props_uri = { BAM["hasMandatoryProperty"]: [ (RDF.type, OWL.ObjectProperty), - (RDFS.domain, BAM.ObjectType), + # (RDFS.domain, OWL.Class), (RDFS.range, BAM.PropertyType), (RDFS.label, Literal("hasMandatoryProperty", lang="en")), + ( + RDFS.comment, + Literal( + "The property must be mandatorily filled when creating the object in openBIS.", + lang="en", + ), + ), ], BAM["hasOptionalProperty"]: [ (RDF.type, OWL.ObjectProperty), - (RDFS.domain, BAM.ObjectType), + # (RDFS.domain, OWL.Class), (RDFS.range, BAM.PropertyType), (RDFS.label, Literal("hasOptionalProperty", lang="en")), + ( + RDFS.comment, + Literal( + "The property is optionally filled when creating the object in openBIS.", + lang="en", + ), + ), ], BAM["referenceTo"]: [ (RDF.type, OWL.ObjectProperty), (RDFS.domain, BAM.PropertyType), # Restricting domain to PropertyType - (RDFS.range, BAM.ObjectType), # Explicitly setting range to ObjectType + # (RDFS.range, OWL.Class), # Explicitly setting range to ObjectType (RDFS.label, Literal("referenceTo", lang="en")), + ( + RDFS.comment, + Literal( + "The property is referencing an object existing in openBIS.", + lang="en", + ), + ), ], } for prop_uri, obj_properties in bam_props_uri.items(): for prop in obj_properties: # type: ignore g.add((prop_uri, prop[0], prop[1])) # type: ignore - # Adding base PropertyType object as a placeholder for all properties - prop_uri = BAM.PropertyType - g.add((prop_uri, RDF.type, OWL.Class)) + # Adding base PropertyType and other objects as placeholders + # ! add only PropertyType prop_type_description = """A conceptual placeholder used to define and organize properties as first-class entities. PropertyType is used to place properties and define their metadata, separating properties from the entities they describe. @@ -112,7 +132,12 @@ def rdf_graph_init(g: "Graph") -> None: - PropertyType can align with `BFO:Quality` for inherent attributes. - PropertyType can represent `BFO:Role` if properties serve functional purposes. - PropertyType can be treated as a `prov:Entity` when properties participate in provenance relationships.""" - g.add((prop_uri, RDFS.comment, Literal(prop_type_description, lang="en"))) + for entity in ["PropertyType", "ObjectType", "CollectionType", "DatasetType"]: + entity_uri = BAM[entity] + g.add((entity_uri, RDF.type, OWL.Thing)) + g.add((entity_uri, RDFS.label, Literal(entity, lang="en"))) + if entity == "PropertyType": + g.add((entity_uri, RDFS.comment, Literal(prop_type_description, lang="en"))) def entities_to_rdf( @@ -136,7 +161,7 @@ def entities_to_rdf( prop_uri = BAM[obj.id] # Define the property as an OWL class inheriting from PropertyType - graph.add((prop_uri, RDF.type, OWL.Class)) + graph.add((prop_uri, RDF.type, OWL.Thing)) graph.add((prop_uri, RDFS.subClassOf, BAM.PropertyType)) # Add attributes like id, code, description in English and Deutsch, property_label, data_type diff --git a/bam_masterdata/metadata/entities.py b/bam_masterdata/metadata/entities.py index e6d5e98..a521290 100644 --- a/bam_masterdata/metadata/entities.py +++ b/bam_masterdata/metadata/entities.py @@ -96,20 +96,20 @@ def to_rdf(self, namespace: "Namespace", graph: "Graph") -> None: entity_uri = namespace[self.defs.id] # Define the entity as an OWL class inheriting from the specific namespace type - graph.add((entity_uri, RDF.type, OWL.Class)) + graph.add((entity_uri, RDF.type, OWL.Thing)) parent_classes = self.__class__.__bases__ for parent_class in parent_classes: if issubclass(parent_class, BaseEntity) and parent_class != BaseEntity: - if parent_class.__name__ in [ - "ObjectType", - "CollectionType", - "DatasetType", - ]: - # ! add here logic of subClassOf connecting with PROV-O or BFO - # ! maybe via classes instead of ObjectType/CollectionType/DatasetType? - # ! Example: - # ! graph.add((entity_uri, RDFS.subClassOf, "http://www.w3.org/ns/prov#Entity")) - continue + # if parent_class.__name__ in [ + # "ObjectType", + # "CollectionType", + # "DatasetType", + # ]: + # # ! add here logic of subClassOf connecting with PROV-O or BFO + # # ! maybe via classes instead of ObjectType/CollectionType/DatasetType? + # # ! Example: + # # ! graph.add((entity_uri, RDFS.subClassOf, "http://www.w3.org/ns/prov#Entity")) + # continue parent_uri = namespace[parent_class.__name__] graph.add((entity_uri, RDFS.subClassOf, parent_uri))