Skip to content

Commit

Permalink
Merge pull request #115 from pyiron/semantikon_class
Browse files Browse the repository at this point in the history
Remove semantikon_class condition
  • Loading branch information
samwaseda authored Jan 31, 2025
2 parents c5e1267 + 4235026 commit 41af49a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
9 changes: 3 additions & 6 deletions pyiron_ontology/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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__":
Expand Down

0 comments on commit 41af49a

Please sign in to comment.