Skip to content

Commit

Permalink
Adding back the placeholders for object, collections and datasets
Browse files Browse the repository at this point in the history
Changed OWL.Class to OWL.Thing

Added descriptions for relationships
  • Loading branch information
JosePizarro3 committed Jan 30, 2025
1 parent a8dcec7 commit 254f2eb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
41 changes: 33 additions & 8 deletions bam_masterdata/cli/entities_to_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions bam_masterdata/metadata/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 254f2eb

Please sign in to comment.