Hi Holger, All,Just to make sure I understand correctly. The SPARQL query can not be converted into SPIN rules automatically only the other way round is possible. ie. SPIN -> SPARQL OK while SPARQL->SPIN !OK. Mostly because the SPARQL construct query can not be associated with a class in SPARQL (at least I think so).
Which means that I need to generate SPIN rules as input not SPARQL. Regards, Jerven On 01/26/2011 12:16 AM, Holger Knublauch wrote:
Hi Jerven, I recommend using a tool (TBC Free Edition) to edit SPIN files. Creating them by hand is tricky, and TBC has some design patterns built in to help you get started. In particular, the file you have sent does not contain an owl:Ontology and no owl:imports (http://spinrdf.org/spin should be imported). Another issue is that the classes are untyped. But the main issue that your CONSTRUCT query is not attached to any class. If you want the SPIN engine to execute it, you need to link a class with the constraints using spin:constraint. I have done this in the attached version of your file. Use TBC FE (or higher) to open it, and you will see that I have changed your query to be attached to :Protein. Instead of ?entry as a variable, I am using ?this to refer to "all instances of :Protein". Use the Refresh and Show problems (constraints) to see the violation (which works fine in principle). If you want to run the same in the SPIN API, you may need to make sure that you also add the imported SPIN graph (and its SP import) to the OntModel. HTH Holger On Jan 26, 2011, at 12:24 AM, [email protected] wrote:Hi Everyone, I am having difficulty getting beyond the examples in SPIN API. I try to get a SPARQL query to construct a constraint violation. Which will be triggered by SPIN. The data I start with is in Turtle: @prefix :<http://purl.uniprot.org/core/> . @prefix keyword:<http://purl.uniprot.org/keywords/> . @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> . uniprot:P00001 a :Protein ; :annotation<http://purl.uniprot.org/uniprot/ #_503030303031001> ; :reviewed "false" . <http://purl.uniprot.org/uniprot/#_503030303031001> a :PTM_Annotation ; rdfs:comment "ubiquitination" . The construct query I am trying is this PREFIX :<http://purl.uniprot.org/core/> PREFIX keyword:<http://purl.uniprot.org/keywords/> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX spin:<http://spinrdf.org/spin#> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> CONSTRUCT { _:violation a spin:ConstraintViolation ; spin:violationRoot ?entry; spin:violationPath :classifiedWith; rdfs:label "If word ubiquitination is found: keyword:832 is required" } WHERE { ?entry a :Protein . ?entry :annotation ?annotation . ?annotation rdf:type :PTM_Annotation ; } This is combined into one ontModel @prefix :<http://purl.uniprot.org/core/> . @prefix citation:<http://purl.uniprot.org/citations/> . @prefix sp:<http://spinrdf.org/sp#> . @prefix keyword:<http://purl.uniprot.org/keywords/> . @prefix dcterms:<http://purl.org/dc/terms/> . @prefix annotation:<http://purl.uniprot.org/annotation/> . @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> . @prefix xsd:<http://www.w3.org/2001/XMLSchema#> . @prefix owl:<http://www.w3.org/2002/07/owl#> . @prefix spin:<http://spinrdf.org/spin#> . @prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix skos:<http://www.w3.org/2004/02/skos/core#> . @prefix uniprot:<http://purl.uniprot.org/uniprot/> . _:b1 sp:varName "comment"^^xsd:string . uniprot:P00001 a :Protein ; :annotation<http://purl.uniprot.org/uniprot/ #_503030303031001> ; :reviewed "false" . [] a sp:Construct ; sp:templates ([ sp:object spin:ConstraintViolation ; sp:predicate rdf:type ; sp:subject _:b2 ] [ sp:object _:b3 ; sp:predicate spin:violationRoot ; sp:subject _:b2 ] [ sp:object :classifiedWith ; sp:predicate spin:violationPath ; sp:subject _:b2 ] [ sp:object "If word ubiquitination is found: keyword:832 is required" ; sp:predicate rdfs:label ; sp:subject _:b2 ]) ; sp:where ([ sp:object :Protein ; sp:predicate rdf:type ; sp:subject _:b3 ] [ a sp:Filter ; sp:expression [ a sp:notExists ; sp:elements ([ sp:object<http:// purl.uniprot.org/keywords/832> ; sp:predicate :classifiedWith ; sp:subject _:b3 ]) ] ] [ sp:object _:b4 ; sp:predicate :annotation ; sp:subject _:b3 ] [ sp:object :PTM_Annotation ; sp:predicate rdf:type ; sp:subject _:b4 ] [ sp:object _:b1 ; sp:predicate rdf:comment ; sp:subject _:b4 ] [ a sp:Filter ; sp:expression [ a sp:regex ; sp:arg1 _:b1 ; sp:arg2 "ubiquitination" ] ]) . <http://purl.uniprot.org/uniprot/#_503030303031001> a :PTM_Annotation ; rdfs:comment "ubiquitination" . _:b4 sp:varName "annotation"^^xsd:string . _:b3 sp:varName "entry"^^xsd:string . This all seems ok to my inexperienced eyes. So I expect the SPARQL construct query to trigger. The example SPARQL triggers when tested against a SPARQL store (e.g.this returns data at linkedlifedata.com). Therefore I assume I am adding the SPARQL incorrectly to the OntModel. This is the main part of the code. Model model = ModelFactory.createDefaultModel(ReificationStyle.Minimal); setPrefixes(model); ARQ2SPIN arq2SPIN = new ARQ2SPIN(model); query = arq2SPIN.createQuery(ARQFactory.get().createQuery(model, rule), null); public List<ConstraintViolation> runRule() { SPINModuleRegistry.get().init(); // Create OntModel with imports OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, entryModel); setPrefixes(ontModel); ontModel.add(query.getModel()); ontModel.write(System.out, FileUtils.langN3); //Prints out ontModel shown above. // Create and add Model for inferred triples Model newTriples = ModelFactory.createDefaultModel(ReificationStyle.Minimal); ontModel.addSubModel(newTriples); SPINModuleRegistry.get().registerAll(ontModel); // Run all inferences SPINInferences.run(ontModel, newTriples, null, null, false, null); System.out.println("Inferred triples: " + newTriples.size()); // Run all constraints List<ConstraintViolation> cvs = SPINConstraints.check(ontModel, null); System.out.println("Constraint violations:"); for (ConstraintViolation cv : cvs) { System.out.println(" - at " + SPINLabels.get().getLabel(cv.getRoot()) + ": " + cv.getMessage()); } return cvs; //Empty but I expect at least one hit. } Could anyone be so nice as to tell me where I am going wrong? Thanks very much! Regards, Jerven -- You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include TopBraid Composer, TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/topbraid-users?hl=en
-- You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include TopBraid Composer, TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/topbraid-users?hl=en
<<attachment: jerven_bolleman.vcf>>
