Skip to content

Commit

Permalink
Adding referenceTo and fixing properties of data type OBJECT
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Jan 22, 2025
1 parent d24e1aa commit 784aa8f
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions bam_masterdata/cli/entities_to_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from structlog._config import BoundLoggerLazyProxy

import click
from rdflib import Literal, Namespace
from rdflib import BNode, Literal, Namespace
from rdflib.namespace import DC, OWL, RDF, RDFS, SKOS

from bam_masterdata.utils import import_module
from bam_masterdata.utils import code_to_class_name, import_module

BAM = Namespace("http://bam.de/masterdata/")

Expand Down Expand Up @@ -39,29 +39,33 @@ def rdf_graph_init(g: "Graph") -> None:
bam_props_uri = {
BAM["hasMandatoryProperty"]: [
(RDF.type, OWL.ObjectProperty),
(RDFS.subPropertyOf, OWL.topObjectProperty),
(RDFS.domain, OWL.Thing),
(RDFS.domain, BAM.ObjectType),
(RDFS.range, BAM.PropertyType),
(SKOS.prefLabel, Literal("hasMandatoryProperty", lang="en")),
],
BAM["hasOptionalProperty"]: [
(RDF.type, OWL.ObjectProperty),
(RDFS.subPropertyOf, OWL.topObjectProperty),
(RDFS.domain, OWL.Thing),
(RDFS.domain, BAM.ObjectType),
(RDFS.range, BAM.PropertyType),
(SKOS.prefLabel, Literal("hasOptionalProperty", 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
(SKOS.prefLabel, Literal("referenceTo", lang="en")),
],
}
for prop_uri, obj_properties in bam_props_uri.items():
for prop in obj_properties:
g.add((prop_uri, prop[0], prop[1]))
for prop in obj_properties: # type: ignore
g.add((prop_uri, prop[0], prop[1])) # type: ignore

# Adding base entity types objects
for entity in ["PropertyType", "ObjectType", "CollectionType", "DatasetType"]:
entity_uri = BAM[entity]
g.add((entity_uri, RDF.type, OWL.Class))
g.add((entity_uri, SKOS.prefLabel, Literal(entity, lang="en")))

return g


def entities_to_rdf(
graph: "Graph", module_path: str, logger: "BoundLoggerLazyProxy"
Expand Down Expand Up @@ -104,6 +108,19 @@ def entities_to_rdf(
)
graph.add((prop_uri, SKOS.altLabel, Literal(obj.property_label, lang="en")))
graph.add((prop_uri, DC.type, Literal(obj.data_type.value)))
if obj.data_type.value == "OBJECT":
# entity_ref_uri = BAM[code_to_class_name(obj.object_code)]
# graph.add((prop_uri, BAM.referenceTo, entity_ref_uri))
entity_ref_uri = BAM[code_to_class_name(obj.object_code)]

# Create a restriction with referenceTo
restriction = BNode()
graph.add((restriction, RDF.type, OWL.Restriction))
graph.add((restriction, OWL.onProperty, BAM["referenceTo"]))
graph.add((restriction, OWL.someValuesFrom, entity_ref_uri))

# Add the restriction as a subclass of the property
graph.add((prop_uri, RDFS.subClassOf, restriction))
return None

# All other datamodel modules
Expand Down

1 comment on commit 784aa8f

@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.py635353 16%
   fill_masterdata.py187174174 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.py873030 66%
bam_masterdata/openbis
   get_entities.py534343 19%
   login.py633 50%
bam_masterdata/utils
   utils.py4277 83%
TOTAL1696055197% 

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

Please sign in to comment.