diff --git a/pyiron_ontology/parser.py b/pyiron_ontology/parser.py index ee6afbd..564aace 100644 --- a/pyiron_ontology/parser.py +++ b/pyiron_ontology/parser.py @@ -52,8 +52,10 @@ def get_triples(data, EX): full_key = data["label"] + f".{io_}." + key label = EX[full_key] graph.add((label, RDFS.label, Literal(full_key))) - graph.add((label, RDF.type, d["uri"])) - graph.add((label, RDF.value, Literal(d["value"]))) + if d["uri"]: + graph.add((label, RDF.type, d["uri"])) + if d["value"]: + graph.add((label, RDF.value, Literal(d["value"]))) graph.add((label, EX[io_[:-1] + "Of"], EX[data["label"]])) if d["units"] is not None: graph.add((label, EX.hasUnits, EX[d["units"]])) diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index 393458b..8f35b2f 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -1,7 +1,8 @@ import unittest -from pyiron_ontology.parser import get_inputs_and_outputs +from pyiron_ontology.parser import get_inputs_and_outputs, get_triples from pyiron_workflow import Workflow from semantikon.typing import u +from rdflib import Namespace @Workflow.wrap.as_function_node("speed") @@ -19,6 +20,15 @@ def test_parser(self): for label in ["inputs", "outputs", "function", "label"]: self.assertIn(label, output_dict) + def test_triples(self): + EX = Namespace("http://example.org/") + speed = calculate_speed() + data = get_inputs_and_outputs(speed) + graph = get_triples(data, EX) + self.assertGreater( + len(list(graph.triples((None, EX.hasUnits, EX["meter/second"])))), 0 + ) + if __name__ == "__main__": unittest.main()