-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from simleo/more_queries
Add SPARQL queries for CQ7, CQ8, CQ9
- Loading branch information
Showing
5 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""\ | ||
This script contains the SPARQL query for Competency Question 7 "Was the | ||
execution successful?". In the discussion on | ||
https://github.com/ResearchObject/workflow-run-crate/issues/15 we decided to | ||
represent this by adding an "actionStatus" property to actions, and consider | ||
an execution successful if its value is "CompletedActionStatus" and not | ||
successful if the value is "FailedActionStatus". | ||
""" | ||
|
||
import rdflib | ||
from pathlib import Path | ||
|
||
CRATE = Path("crate") | ||
|
||
g = rdflib.Graph() | ||
g.parse(CRATE/"ro-crate-metadata.json") | ||
|
||
QUERY = """\ | ||
PREFIX s: <http://schema.org/> | ||
SELECT ?action ?status | ||
WHERE { | ||
?action a s:CreateAction . | ||
?action s:actionStatus ?status . | ||
} | ||
""" | ||
|
||
qres = g.query(QUERY) | ||
for row in qres: | ||
print(f"{row.action}, {row.status}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""\ | ||
This script contains the SPARQL query for Competency Question 8 "What are the | ||
inputs and outputs of the overall workflow?". In the discussion on | ||
https://github.com/ResearchObject/workflow-run-crate/issues/16 we identified | ||
them as the "object" and "result" of the action corresponding to the | ||
workflow's execution. | ||
""" | ||
|
||
import rdflib | ||
from pathlib import Path | ||
|
||
CRATE = Path("crate") | ||
|
||
g = rdflib.Graph() | ||
g.parse(CRATE/"ro-crate-metadata.json") | ||
|
||
QUERY = """\ | ||
PREFIX s: <http://schema.org/> | ||
PREFIX bioschemas: <https://bioschemas.org/> | ||
SELECT ?obj | ||
WHERE { | ||
?action a s:CreateAction . | ||
?workflow a bioschemas:ComputationalWorkflow . | ||
?action s:instrument ?workflow . | ||
OPTIONAL { ?action s:object ?obj } . | ||
} | ||
""" | ||
|
||
qres = g.query(QUERY) | ||
print("INPUTS") | ||
print("======") | ||
for row in qres: | ||
print(row.obj) | ||
|
||
QUERY = """\ | ||
PREFIX s: <http://schema.org/> | ||
PREFIX bioschemas: <https://bioschemas.org/> | ||
SELECT ?res | ||
WHERE { | ||
?action a s:CreateAction . | ||
?workflow a bioschemas:ComputationalWorkflow . | ||
?action s:instrument ?workflow . | ||
OPTIONAL { ?action s:result ?res } . | ||
} | ||
""" | ||
|
||
qres = g.query(QUERY) | ||
print("OUTPUTS") | ||
print("=======") | ||
for row in qres: | ||
print(row.res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""\ | ||
This script contains the SPARQL query for Competency Question 9 "What is the | ||
source code version of the component executed in a workflow step?". In | ||
https://github.com/ResearchObject/workflow-run-crate/pull/42 we ended up using | ||
"softwareVersion" with a fallback on "version" on the "SoftwareApplication" | ||
entity, which is used both in Process Run Crates and Provenance Run Crates for | ||
individual tools. | ||
""" | ||
|
||
import rdflib | ||
from pathlib import Path | ||
|
||
CRATE = Path("process_run_crate") | ||
|
||
g = rdflib.Graph() | ||
g.parse(CRATE/"ro-crate-metadata.json") | ||
|
||
QUERY = """\ | ||
PREFIX s: <http://schema.org/> | ||
SELECT ?name ?version | ||
WHERE { | ||
?app a s:SoftwareApplication . | ||
?app s:name ?name . | ||
OPTIONAL { ?app s:softwareVersion ?version } . | ||
OPTIONAL { ?app s:version ?version } . | ||
} | ||
""" | ||
|
||
qres = g.query(QUERY) | ||
for row in qres: | ||
print(row.name, row.version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"@context": "https://w3id.org/ro/crate/1.1/context", | ||
"@graph": [ | ||
{ | ||
"@id": "ro-crate-metadata.json", | ||
"@type": "CreativeWork", | ||
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"}, | ||
"about": {"@id": "./"} | ||
}, | ||
{ | ||
"@id": "./", | ||
"@type": "Dataset", | ||
"conformsTo": {"@id": "https://w3id.org/ro/wfrun/process/0.1"}, | ||
"hasPart": [ | ||
{"@id": "pics/2017-06-11%2012.56.14.jpg"}, | ||
{"@id": "pics/sepia_fence.jpg"} | ||
], | ||
"mentions": {"@id": "#SepiaConversion_1"}, | ||
"name": "My Pictures" | ||
}, | ||
{ | ||
"@id": "https://w3id.org/ro/wfrun/process/0.1", | ||
"@type": "CreativeWork", | ||
"name": "Process Run Crate", | ||
"version": "0.1" | ||
}, | ||
{ | ||
"@id": "https://www.imagemagick.org/", | ||
"@type": "SoftwareApplication", | ||
"url": "https://www.imagemagick.org/", | ||
"name": "ImageMagick", | ||
"softwareVersion": "6.9.7-4" | ||
}, | ||
{ | ||
"@id": "#SepiaConversion_1", | ||
"@type": "CreateAction", | ||
"name": "Convert dog image to sepia", | ||
"description": "convert -sepia-tone 80% test_data/sample/pics/2017-06-11\\ 12.56.14.jpg test_data/sample/pics/sepia_fence.jpg", | ||
"endTime": "2018-09-19T17:01:07+10:00", | ||
"instrument": {"@id": "https://www.imagemagick.org/"}, | ||
"object": {"@id": "pics/2017-06-11%2012.56.14.jpg"}, | ||
"result": {"@id": "pics/sepia_fence.jpg"}, | ||
"agent": {"@id": "https://orcid.org/0000-0001-9842-9718"} | ||
}, | ||
{ | ||
"@id": "pics/2017-06-11%2012.56.14.jpg", | ||
"@type": "File", | ||
"description": "Original image", | ||
"encodingFormat": "image/jpeg", | ||
"name": "2017-06-11 12.56.14.jpg (input)" | ||
}, | ||
{ | ||
"@id": "pics/sepia_fence.jpg", | ||
"@type": "File", | ||
"description": "The converted picture, now sepia-colored", | ||
"encodingFormat": "image/jpeg", | ||
"name": "sepia_fence (output)" | ||
}, | ||
{ | ||
"@id": "https://orcid.org/0000-0001-9842-9718", | ||
"@type": "Person", | ||
"name": "Stian Soiland-Reyes" | ||
} | ||
] | ||
} |