diff --git a/pyiron_ontology/parser.py b/pyiron_ontology/parser.py index 9c39fdf..b5144d7 100644 --- a/pyiron_ontology/parser.py +++ b/pyiron_ontology/parser.py @@ -5,6 +5,7 @@ from rdflib import Graph, Literal, RDF, RDFS, URIRef, OWL, PROV, Namespace from pyiron_workflow import NOT_DATA, Workflow, Macro from pyiron_workflow.node import Node +from dataclasses import is_dataclass class PNS: @@ -63,10 +64,6 @@ def get_inputs_and_outputs(node: Node) -> dict: } -def _is_semantikon_class(dtype: type) -> bool: - return hasattr(dtype, "_is_semantikon_class") and dtype._is_semantikon_class - - def _translate_has_value( graph: Graph, label: URIRef, @@ -78,13 +75,13 @@ def _translate_has_value( ) -> Graph: tag_uri = URIRef(tag + ".value") graph.add((label, PNS.hasValue, tag_uri)) - if _is_semantikon_class(dtype): + if is_dataclass(dtype): warnings.warn( "semantikon_class is experimental - triples may change in the future", FutureWarning, ) for k, v in dtype.__dict__.items(): - if isinstance(v, type) and _is_semantikon_class(v): + if isinstance(v, type) and is_dataclass(v): _translate_has_value( graph=graph, label=label, diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index 231fce0..e1e9a34 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -11,7 +11,6 @@ ) from pyiron_workflow import Workflow from semantikon.typing import u -from semantikon.converter import semantikon_class from dataclasses import dataclass from rdflib import Namespace @@ -223,26 +222,23 @@ def test_parsing_without_running(self): ) -@semantikon_class @dataclass class Input: T: u(float, units="kelvin") n: int - # This line should be removed with the next version of semantikon - _is_semantikon_class = True + @dataclass class parameters: - _is_semantikon_class = True a: int = 2 + class not_dataclass: + b: int = 3 + -@semantikon_class @dataclass class Output: E: u(float, units="electron_volt") L: u(float, units="angstrom") - # This line should be removed with the next version of semantikon - _is_semantikon_class = True @Workflow.wrap.as_function_node @@ -268,10 +264,14 @@ def test_dataclass(self): (URIRef(o_txt), PNS.hasValue, URIRef(f"{o_txt}.E.value")), ) s = graph.serialize(format="turtle") - for triple in triples: - self.assertEqual( - len(list(graph.triples(triple))), 1, msg=f"{triple} not found in {s}" - ) + for ii, triple in enumerate(triples): + with self.subTest(i=ii): + self.assertEqual( + len(list(graph.triples(triple))), + 1, + msg=f"{triple} not found in {s}", + ) + self.assertIsNone(graph.value(URIRef(f"{i_txt}.not_dataclass.b.value"))) if __name__ == "__main__":