diff --git a/pyiron_ontology/parser.py b/pyiron_ontology/parser.py index 56f6268..15db3c2 100644 --- a/pyiron_ontology/parser.py +++ b/pyiron_ontology/parser.py @@ -373,6 +373,7 @@ def parse_workflow( graph: Graph | None = None, inherit_properties: bool = True, ontology=PNS, + append_missing_items: bool = True, ) -> Graph: """ Generate RDF graph from a pyiron workflow object @@ -405,4 +406,22 @@ def parse_workflow( ) if inherit_properties: _inherit_properties(graph, ontology=ontology) + if append_missing_items: + graph = _append_missing_items(graph) + return graph + + +def _append_missing_items(graph: Graph) -> Graph: + """ + This function makes sure that all properties defined in the descriptions + become valid. + """ + for p, o in zip( + [OWL.onProperty, OWL.someValuesFrom, OWL.allValuesFrom], + [RDF.Property, OWL.Class, OWL.Class], + ): + for obj in graph.objects(None, p): + triple = (obj, RDF.type, o) + if not triple in graph: + graph.add(triple) return graph diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index 5df83f8..08c9461 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -136,13 +136,7 @@ def test_triples(self): def test_correct_analysis(self): def get_graph(wf): - graph = Graph() - graph.add((EX.HasOperation, RDF.type, RDF.Property)) - graph.add((EX.Addition, RDF.type, OWL.Class)) - graph.add((EX.Multiplication, RDF.type, OWL.Class)) - for value in wf.children.values(): - data = get_inputs_and_outputs(value) - graph += get_triples(data=data) + graph = parse_workflow(wf) _inherit_properties(graph) DeductiveClosure(OWLRL_Semantics).expand(graph) return graph @@ -173,12 +167,12 @@ def test_parse_workflow(self): graph = parse_workflow(wf) tag = "correct_analysis.addition.inputs.a" self.assertEqual( - len(list(graph.triples((URIRef(tag), RDFS.label, Literal(tag))))), 1, + len(list(graph.triples((URIRef(tag), RDFS.label, Literal(tag))))), + 1, ) self.assertTrue( - EX.Addition in list( - graph.objects(URIRef("correct_analysis.addition"), RDF.type) - ) + EX.Addition + in list(graph.objects(URIRef("correct_analysis.addition"), RDF.type)) ) def test_macro(self):