Skip to content

Help with intended use #427

Description

@liamhuber

I'm working on updating the tests for pyiron_workflow's integration of semantikon to handle v1. In this process I'm finding things I'm not super clear on, and would appreciate some teaching.

The example I'm working with is an artificially annotated version of the speed example. In reality I'm getting the wf_dict from pyiron_workflow graphs, but all my questions hold just as well if we stay in the semantikon universe:

import rdflib
import semantikon
from semantikon.ontology import SNS
from semantikon.workflow import workflow

EX = rdflib.Namespace("http://example.org/")

uri_object = semantikon.SemantikonURI(EX.Object)
uri_subject = semantikon.SemantikonURI(EX.Subject)

def calculate_speed(
    distance: semantikon.u(float, units="meter") = 10.0,
    time: semantikon.u(float, units="second") = 2.0,
) -> semantikon.u(
    float,
    units="meter/second",
    triples=(
        (EX.somehowRelatedTo, "inputs.time"),
        (uri_subject, EX.predicate, uri_object),
        (uri_subject, EX.predicate, uri_object),
        (None, EX.predicate, uri_object),
    ),
):
    return distance / time


@workflow
def speed_wf(d, t):
    s = calculate_speed(d, t)
    return s

wf_dict = speed_wf.get_semantikon_dict()
g = semantikon.get_knowledge_graph(wf_dict)

Question 1: When to use semantikon.SemantikonURI

I see in the documentation notebook that it will resolve to both A- and T-boxes, but is there some less technical advice on when I want to use this? I would naively think that if I want to call get_knowledge_graph with it's default values where both include_t_box and include_a_box are true, I would want this dual-resolving object. In reality, the rest of what I'm working with here all runs totally fine if I don't bother.

Is it for when I have, e.g., EX.Object appearing multiple times throughout my annotation but I want to indicate in the A-box when we're talking about the same object? In this light, is it right understanding that I might need it for subjects and objects, but never for predicates?

Question 2: How to grab workflow graph elements?

Here I have a workflow port that is at the lexical location speed_wf-calculate_speed_0-outputs-output, and I know from my return annotation triples that it should be EX.somehowRelatedTo the time input. I can use the graph operations to search for this:

list(g.subject_objects(predicate=EX.somehowRelatedTo))
>>> [
...     (
...         rdflib.term.URIRef('http://pyiron.org/ontology/b9fe6da1931c768bada9a7fc7af0ca2a_speed_wf-calculate_speed_0-outputs-output_data'),
...         rdflib.term.URIRef('http://pyiron.org/ontology/b9fe6da1931c768bada9a7fc7af0ca2a_speed_wf-inputs-t_data')
...     )
... ]

First, I'm a bit confused why there is only one pair with the objectspeed_wf-inputs-t? I can see that because of the graph topology there might be some transience that it is, indeed, ultimately EX.somehowRelatedTo the terminal input, so it's presence makes sense, but why don't I see the more proximate port speed_wf-calculate_speed_0-inputs-time?

Second, for the sake of my tests I'm trying to verify that the terms I expect actually appear. To that end, I'd like to somehow grab the triplestore terms I'm interested in. However, these URI refs start with some opaque (and stochastic?) hash, and then end with a knowable but not trivially obvious "_data". Is there/can we add helper tools for accessing specific terms given the graph and the lexical path? get_port_data_term(lexical_path: str, G: rdflib.Graph) -> rdflib.term.URIRef? Right now I'm stuck confirming that the string version of the path contains the lexical path, which feels ugly and fragile. E.g.,

obj, subj = list(g.subject_objects(predicate=EX.somehowRelatedTo))[0]
assert "speed_wf-calculate_speed_0-outputs-output" in str(obj)

Metadata

Metadata

Assignees

Labels

questionCategory: Further information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions