Skip to content

Commit

Permalink
Change triple and restriction plural
Browse files Browse the repository at this point in the history
  • Loading branch information
samwaseda committed Jan 21, 2025
1 parent 071ac40 commit 779ce37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
40 changes: 20 additions & 20 deletions pyiron_ontology/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ def get_triples(

def _get_triples_from_restrictions(data, EX):
triples = []
if data.get("restriction", None) is not None:
triples = restriction_to_triple(data["restriction"])
if data.get("triple", None) is not None:
if isinstance(data["triple"][0], tuple | list):
triples.extend(list(data["triple"]))
if data.get("restrictions", None) is not None:
triples = restriction_to_triple(data["restrictions"])
if data.get("triples", None) is not None:
if isinstance(data["triples"][0], tuple | list):
triples.extend(list(data["triples"]))
else:
triples.extend([data["triple"]])
triples.extend([data["triples"]])
return triples


def restriction_to_triple(restriction):
def restriction_to_triple(restrictions):
triples = []
assert isinstance(restriction, tuple) and isinstance(restriction[0], tuple)
if not isinstance(restriction[0][0], tuple):
restriction = (restriction,)
for r in restriction:
assert isinstance(restrictions, tuple) and isinstance(restrictions[0], tuple)
if not isinstance(restrictions[0][0], tuple):
restrictions = (restrictions,)
for r in restrictions:
assert len(r[0]) == 2
label = r[0][1] + "Restriction"
triples.append((label, RDF.type, OWL.Restriction))
Expand All @@ -115,11 +115,11 @@ def restriction_to_triple(restriction):
return triples


def _parse_triple(triple, EX, label=None, data=None):
if len(triple) == 2:
subj, pred, obj = label, triple[0], triple[1]
elif len(triple) == 3:
subj, pred, obj = triple
def _parse_triple(triples, EX, label=None, data=None):
if len(triples) == 2:
subj, pred, obj = label, triples[0], triples[1]
elif len(triples) == 3:
subj, pred, obj = triples
else:
raise ValueError("Triple must have 2 or 3 elements")
if obj.startswith("inputs.") or obj.startswith("outputs."):
Expand Down Expand Up @@ -155,11 +155,11 @@ def inherit_properties(graph, NS, n=None):

def validate_values(graph):
missing_triples = []
for restriction in graph.subjects(RDF.type, OWL.Restriction):
on_property = graph.value(restriction, OWL.onProperty)
some_values_from = graph.value(restriction, OWL.someValuesFrom)
for restrictions in graph.subjects(RDF.type, OWL.Restriction):
on_property = graph.value(restrictions, OWL.onProperty)
some_values_from = graph.value(restrictions, OWL.someValuesFrom)
if on_property and some_values_from:
for cls in graph.subjects(OWL.equivalentClass, restriction):
for cls in graph.subjects(OWL.equivalentClass, restrictions):
for instance in graph.subjects(RDF.type, cls):
if not (instance, on_property, some_values_from) in graph:
missing_triples.append(
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def calculate_speed(
) -> u(
float,
units="meter/second",
triple=(
triples=(
(EX.isOutputOf, "inputs.time"),
(EX.subject, EX.predicate, EX.object)
)
Expand All @@ -26,14 +26,14 @@ def calculate_speed(


@Workflow.wrap.as_function_node("result")
def add(a: float, b: float) -> u(float, triple=(EX.HasOperation, EX.Addition)):
def add(a: float, b: float) -> u(float, triples=(EX.HasOperation, EX.Addition)):
return a + b


@Workflow.wrap.as_function_node("result")
def multiply(a: float, b: float) -> u(
float,
triple=(
triples=(
(EX.HasOperation, EX.Multiplication),
(EX.inheritsPropertiesFrom, "inputs.a")
)
Expand All @@ -45,7 +45,7 @@ def multiply(a: float, b: float) -> u(
def correct_analysis(
a: u(
float,
restriction=(
restrictions=(
(OWL.onProperty, EX.HasOperation),
(OWL.someValuesFrom, EX.Addition)
)
Expand All @@ -58,7 +58,7 @@ def correct_analysis(
def wrong_analysis(
a: u(
float,
restriction=(
restrictions=(
(OWL.onProperty, EX.HasOperation),
(OWL.someValuesFrom, EX.Division)
)
Expand Down

0 comments on commit 779ce37

Please sign in to comment.