How to use CONSTRUCT / WHERE in a SPARQL SPIN rule declaration

1.3k views Asked by At

Summary

Thank you in advance for helping me write a CONSTRUCT/WHERE statement that can be declared as a SPIN Rule in TopBraid Composer Free Edition and used.

I am trying to embed a SPARQL CONSTRUCT/WHERE statement in a spin:rule declaration and then execute it. I am returning zero inferences to Statements 1 or 2 below. I am using Java 7, and Eclipse 4.3., and TopBraid Composer Free Edition. I have been successful running Statement 3 as a SPIN Constructor Declaration in the classes form (Statement 3). I have been successful running Statement 4 in the SPARQL query editor (interpreter) I have cross-posted to the user forum.

Details

Fact 1: I have not been able to run Statement 1 as a SPIN Rule.

----Statement 1---

CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
BIND (spif:generateUUID() AS ?x) .
}

Fact 2: I have not been able to run Statement 2 as a SPIN Rule.

----Statement 2----

CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
?this rdfs:subClassOf node:entity .
BIND (spif:generateUUID() AS ?x) .
}
--No Error Message--

Fact 3: However I have been successful with Statement 3 in the constructor field of the classes form.

----Statement 3----

CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
BIND (spif:generateUUID() AS ?x) .
}
Success: When a new instance is created a new triple indicating a key is created.

Fact 4: I have been successful with Statement 4 in the SPARQL query editor which is analogous.

----Statement 4----

CONSTRUCT {
?s owl:hasKey ?x .
}
WHERE {
?s rdf:type node:word_use
BIND (spif:generateUUID() AS ?x) .
}
Success: When statement is run all current instances get keys.

Fact 5: I do not have any SPARQL Rules libraries checked in the Ontology Profile form.

Fact 6: I have imported the following two libraries.

<http://spinrdf.org/spin> from local file TopBraid/SPIN/spin.ttl.
<http://spinrdf.org/sp> from local file TopBraid/SPIN/sp.ttl

Fact 7: The namespaces in the file are:

Base URI (Location) - http://example.org/
Default Namespace - http://example.org/

But the Base URI keeps getting reset to:
http://www.semanticweb.org/owl/owlapi/turtle

ace_lexicon - http://attempto.ifi.uzh.ch/ace_lexicon#
arc - http://example.org/arc#
arg - http://spinrdf.org/arg#
concept - http://example.org/concept#
node - http://www.example.org/node#
owl - http://www.w3.org/2002/07/owl#
rdf - http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs - http://www.w3.org/2001/01/rdf-schema#
skos - http://www.w3.org/2004/02/skos/core#
sp - http://spinrdf.org/sp#
spif - http://spinrdf.org/spif#
spin - http://spinrdf.org/spin#
spl - http://spinrdf.org/spl#
word_sense - http://example.org/word_sense#
word_term - http://example.org/word_term#
word_use - http://example.org/word_use#

Fact 8: The class that I am using has the following assertions.

Name - node:unclassified_concept
SubClassOf - node:entity

Fact 9: An instance of the node:unclassified_concept class is described below.

URI - http://example.org/concept#regardless_of1
rdfs:comment - without attention to
rdfs:isDefinedBy - <http://en.wiktionary.org/wiki/regardless_of>
rdfs:label - regardless of

Fact 10: I have been successful using Jena Generic Rules reasoning as well as the OWL_MEM_RULE_INF OntModelSpec, reading/writing, base models, inf models, and ont models.

Context

The context of my problem is the following. I am building and iteratively executing an ontology and rule set using Java and Jena to prove the concept of OWL/RDF representing, considering, and responding to non-trivial type-written English. The sentence I am using is non-trivial (41 words, three clauses, etc.). The current ontology has 1422 assertions when not run against any OWL/RDF rules (transitivity, etc.). I am using TopBraid Composer when possible to complement Jena programming to make sure I am compliant with conventions and standards.

1

There are 1 answers

0
user3688465 On

This post outlines the solution to the problem I posted. I was able to come to this solution via a person who responds to their user forum. https://groups.google.com/forum/#!forum/topbraid-users

The CONSTRUCT/WHERE statement (after revision) I wanted to run was:

CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
?this rdf:type node:unclassified_concept .
BIND (spif:generateUUID() AS ?x) .
}

However, if I placed this statement in the spin:rule field of the classes form in TBC and pressed the icon for inferencing, I would receive no inferences and much time would be spent churning by the inferencer.

The solution was to create a subproperty of spin:rule that had spin:rulePropertyMaxIterationCount set to 1 (to avoid infinite loops generated by running the built-in function -- in my case spin:generateUUID().)

Then I needed to "pull" or place that new subproperty (which I named "runOnce") into the classes form that I was trying to create a dependent-upon-a-built-in CONSTRUCT/WHERE rule for.

Finally, in the classes form I needed to select add blank row on the new subproperty RunOnce, and then enter my original CONSTRUCT/WHERE statement there.

Then I ran inferencing and the class used the rule.

In short, if you want to embed a rule in a class in TBC, and that rule uses a builtin function, you need to

-Create a subproperty of spin:rule that has rulePropertyMaxIterationCount 
   set to 1.
-Include this subproperty in the classes form.
-Embed your CONSTRUCT/WHERE statement that uses the built-in within that 
   subproperty on the classes form by selecting insert blank line and 
   copying/pasting it       in there.

Note the TBC supported SPIN built-in functions is a smaller set than I believe is in the SPIN API documentation. The list of TBC supported built-ins is here in the TBC product.

Help>
  Help Contents>
    TopBraid Composer>
      Application Development Tools>
        SPARQL Motion Scripts>
          SPARQL Motion Functions Reference

Hope this helps someone.