Skip to content

Conversation

@samwaseda
Copy link
Member

@samwaseda samwaseda commented Jan 8, 2026

I would like to suggest a new way to deal with SPARQL queries: Use one-to-one conversion to a networkx.DiGraph. In particular, it has nodes consisting of subjects and objects, and the predicates are stored in the metadata. You can see this also in the construct in the code:

G = nx.DiGraph()
G.add_edge(subj, obj, predicate=pred)

Then nodes for which the output should be computed get the extra argument output=True in the metadata. All BNodes are translated into local variables, while URIRefs are treated as URIs.

The main reason why I'm suggesting this is because it makes extensions easier, i.e. if I have a more complicated query, where for example I would like to specify the units or user-defined URIs, I have the possibility to append the lines to a given graph.

For the usual kinetic energy example, the SPARQL text looks like this:

print(sw.get_query_text(comp.my_workflow.inputs.distance, comp.my_workflow.outputs.kinetic_energy))

Output:

SELECT ?http___pyiron_org_ontology_my_workflow_inputs_distance_data_value ?http___pyiron_org_ontology_my_workflow_get_kinetic_energy_0_outputs_output_data_value WHERE {
?http___pyiron_org_ontology_my_workflow_inputs_distance_data a <http://pyiron.org/ontology/my_workflow-inputs-distance_data> .
?http___pyiron_org_ontology_my_workflow_inputs_distance_data rdf:value ?http___pyiron_org_ontology_my_workflow_inputs_distance_data_value .
?http___pyiron_org_ontology_my_workflow_get_kinetic_energy_0_outputs_output_data a <http://pyiron.org/ontology/my_workflow-get_kinetic_energy_0-outputs-output_data> .
?http___pyiron_org_ontology_my_workflow_get_kinetic_energy_0_outputs_output_data rdf:value ?http___pyiron_org_ontology_my_workflow_get_kinetic_energy_0_outputs_output_data_value .
?http___pyiron_org_ontology_my_workflow_inputs_distance <http://purl.obolibrary.org/obo/OBI_0000293> ?http___pyiron_org_ontology_my_workflow_inputs_distance_data .
?http___pyiron_org_ontology_my_workflow <http://purl.obolibrary.org/obo/BFO_0000051> ?http___pyiron_org_ontology_my_workflow_inputs_distance .
?http___pyiron_org_ontology_my_workflow <http://purl.obolibrary.org/obo/BFO_0000051> ?http___pyiron_org_ontology_my_workflow_outputs_kinetic_energy .
?http___pyiron_org_ontology_my_workflow_outputs_kinetic_energy <http://purl.obolibrary.org/obo/OBI_0000299> ?http___pyiron_org_ontology_my_workflow_get_kinetic_energy_0_outputs_output_data .
}

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

Binder 👈 Launch a binder notebook on branch pyiron/semantikon/query

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.30%. Comparing base (58eeb54) to head (2eecb0e).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #350      +/-   ##
==========================================
+ Coverage   97.28%   97.30%   +0.01%     
==========================================
  Files           9        9              
  Lines        1435     1445      +10     
==========================================
+ Hits         1396     1406      +10     
  Misses         39       39              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samwaseda samwaseda merged commit dcbf050 into main Jan 8, 2026
22 checks passed
@samwaseda samwaseda deleted the query branch January 8, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants