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 24, 2025
1 parent f020504 commit 0816954
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

1 comment on commit 0816954

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
bam_masterdata
   logger.py80100% 
bam_masterdata/cli
   cli.py824949 40%
   entities_to_excel.py5433 94%
   entities_to_json.py3655 86%
   entities_to_rdf.py726161 15%
   fill_masterdata.py188175175 7%
bam_masterdata/datamodel
   collection_types.py370100% 
   dataset_types.py184184184 0%
   object_types.py15150100% 
   property_types.py8000100% 
   vocabulary_types.py137210100% 
bam_masterdata/metadata
   definitions.py850100% 
   entities.py883030 66%
bam_masterdata/openbis
   get_entities.py534343 19%
   login.py633 50%
bam_masterdata/utils
   utils.py4277 83%
TOTAL1697156097% 

Tests Skipped Failures Errors Time
65 1 💤 0 ❌ 0 🔥 19.210s ⏱️

Please sign in to comment.