On 28 April 2016 at 16:25, Enrico Daga (enridaga) <[email protected]> wrote: > Hi, > > I am using the taverna API to explore workflows downloaded from MyExperiment. > At the moment, I converted the files to the .wfbundle format using the > taverna command line tools. Everything looks fine. > Unzipping a wfbundle I can read a set of .ttl files in the annotations/ > folder, but I am not able to do that through the Java API. > In the simplest form, my code is as follows: > > WorkflowBundleIO io = new WorkflowBundleIO(); > final WorkflowBundle wb = io.readBundle(__f(“file.wfbundle"), > null); > System.out.println("Annotations: " + > wb.getAnnotations().size()); >
Hi! I think the API docs need improvements on this (suggestions welcome!) - but it should give you a good start for the basics. Add a dependency for the module taverna-scufl2-annotation. Then you can instantiate AnnotationTools: http://taverna.staging.apache.org/javadoc/taverna-language/org/apache/taverna/scufl2/annotation/AnnotationTools.html > What is the recommended way to get: > - The description of a workflow (as I can see it on the myexperiment portal) AnnotationTools ann = new AnnotationTools(); Scufl2Tools scufl2Tools = new Scufl2Tools(); Workflow wf = wb.getMainWorkflow(); System.out.println(ann.getDescription(wf); > - All the annotations in a bundle for (Annotation ann: wb.getAnnotations()) { System.out.println(ann.getRDFContent()) // Or more elaborate: // (in case you want to replace the content you will need the path) //String path = getResourcePath(); //System.out.println(wb.getResources().getResourceAsString(path)); } > - The annotations of a given WorkflowBean element InputPort inp = wf.getInputPorts().first(); Dataset ds = ann.annotationDatasetFor(inp); // Print as NQuads // https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html RDFDataMgr.write(System.out, ds, Lang.NQUADS); > - To access/modify/extend the annotations To add a new annotation with a single statement: Annotation a = ann.createNewAnnotation(wb, inp, AnnotationTools. EXAMPLE_DATA , "GATTACCAEXAMPLE"); a.setAnnotatedBy(URI.create("http://orcid.org/0000-0001-9842-9718")); Anything more complex you will have to manually edit with Jena APIs and then save back with workflowBundle.getResources().addResourceUsingOutputStream(path) or similar. > I am using release 0.15.0-incubating. You should be able to use version 0.15.1-incubating which fixes some smaller bugs in the taverna-scufl2-api. Let us know if something doesn't work in upgrading! :) I think AnnotationTools could be improved to use Commons RDF rather than exposing Jena's Dataset - and add setters as well as the getters. (The setters are slightly more complicated because you would need to remove/edit the existing annotation - so more helper methods could be useful here as well). Also you might see that there's a big (but incompatible) overlap between WorkflowBundle annotations and the taverna-robundle Manifest API http://taverna.staging.apache.org/javadoc/taverna-language/org/apache/taverna/robundle/manifest/Manifest.html This is because taverna-ucfpackage predates taverna-robundle and didn't have access to the nice java.nio.Path API - which complicates things like reading the annotation file. The branch https://github.com/apache/incubator-taverna-language/tree/ucfpackage-robundle tries to align these. (However the robundle lacks such convenience methods of AnnotationTools - so another task would be to add something like that) -- Stian Soiland-Reyes Apache Taverna (incubating), Apache Commons RDF (incubating) http://orcid.org/0000-0001-9842-9718
