Skip to content

Commit

Permalink
small bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samwaseda committed Jan 9, 2025
1 parent e43109e commit c446523
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions pyiron_ontology/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from semantikon.converter import parse_input_args, parse_output_args
from rdflib import Graph, Literal, RDF, RDFS


def get_source_output(var):
if not var.connected:
return None
connection = var.connections[0]
return f"{connection.owner.label}.outputs.{connection.label}"


def get_inputs_and_outputs(node):
Expand All @@ -18,9 +26,10 @@ def get_inputs_and_outputs(node):
if isinstance(outputs, dict):
outputs = (outputs,)
outputs = {key: out for key, out in zip(node.outputs.labels, outputs)}
for key, value in node.inputs.to_value_dict().items():
inputs[key]["value"] = value
for key, value in node.inputs.items():
inputs[key]["value"] = value.value
inputs[key]["var_name"] = key
inputs[key]["connection"] = get_source_output(value)
for key, value in node.outputs.to_value_dict().items():
outputs[key]["value"] = value
outputs[key]["var_name"] = key
Expand All @@ -30,3 +39,29 @@ def get_inputs_and_outputs(node):
"function": node.node_function.__name__,
"label": node.label,
}


def get_triples(data, EX):
graph = Graph()
label_def_triple = (EX[data["label"]], EX.hasSourceFunction, EX[data["function"]])
if len(list(graph.triples(label_def_triple))) > 0:
return graph
graph.add(label_def_triple)
for io_ in ["inputs", "outputs"]:
for key, d in data[io_].items():
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"])))
graph.add((label, EX[io_[:-1] + "Of"], EX[data["label"]]))
if d["units"] is not None:
graph.add((label, EX.hasUnits, EX[d["units"]]))
if "connection" in d:
graph.add((label, EX.comesFrom, EX[d["connection"]]))
if d["triple"] is not None:
obj = d["triple"][1]
if obj.startswith("inputs.") or obj.startswith("outputs."):
obj = data["label"] + "." + obj
graph.add((label, d["triple"][0], EX[obj]))
return graph

0 comments on commit c446523

Please sign in to comment.