Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove semantikon_class condition #115

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading