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

Reply via email to