On 9/14/17 4:52 PM, Kingsley Idehen wrote:
> On 9/13/17 10:28 AM, Adam Sanchez wrote:
>> Hi all,
>>
>> I am testing SPIN rules in the demo version of Virtuoso 8 but I have
>> still no success.
>> I wrote a simple SPIN rule to compute the area of an instance of a
>> class Rectangle given its width and its height. In this script you can
>> see all the queries I used. This script must be executed in the SQL
>> console of Virtuoso 8.
>>
>> https://tinyurl.com/yb359owr
>>
>> As you can see here at the bottom,
>>
>> http://imageshack.com/a/img923/1182/qG4HmJ.png
>>
>> the rule is loaded but it does not work when I run a query
>>
>> http://imagizer.imageshack.us/a/img922/7629/it260O.png
>>
>> For you reference, I was using this output as reference to see how the
>> loaded rule must look.
>>
>> https://tinyurl.com/ycm3zp6p
>>
>> Also, I have read these links so far
>>
>> https://medium.com/virtuoso-blog/virtuoso-8-0-creating-a-custom-inference-rules-using-spin-vocabulary-d7a060f859ef
>> https://www.mail-archive.com/virtuoso-users@lists.sourceforge.net/msg07790.html
>> https://www.linkedin.com/pulse/reasoning-inference-using-british-royal-family-part-idehen
>> https://medium.com/virtuoso-blog/using-british-royal-family-data-snippets-to-demonstrate-sparql-query-language-based-reasoning-56626a152419
>> http://docs.openlinksw.com/virtuoso/udt_overview/
>>
>> BTW, in RDF4j works. I do not need to load the rule separately, I just
>> loaded the full ontology and that's all, the SPIN rule worked. See
>>
>> http://imagizer.imageshack.us/a/img924/7717/Q9JYau.png
>> http://imagizer.imageshack.us/a/img924/9828/4dQPzg.png
>>
>>
>> Any idea?
>>
>> Thanks in advance,
>>
>> Adam
> Hi Adam,
>
> We don't have a problem with Virtuoso's SPIN Rules handling, once a few
> errors (I assume typos) in your example are fixed. Here's my rendition
> of what you shared:
>
> -- This a SPARQL script to test SPIN Rules in Virtuoso 8
> --  It should compute the area of an instance of the class Rectangle
> given its width and its height.
> -- This script must be run in the SQL console of Virtuoso
>
> --  Additional commands
>
> SPARQL CLEAR GRAPH <http://geometry> ;
> SPARQL CLEAR GRAPH <urn:spin:rule:geometry:lib> ;
> SPARQL DROP SPIN LIBRARY <urn:spin:rule:geometry:lib> ;
>
> -- create a named graph
>
> -- SPARQL CREATE GRAPH <http://geometry> ;
>
> SPARQL
> PREFIX shapes: <http://example.org/shapes#>
> PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX owl: <http://www.w3.org/2002/07/owl#>
>
> WITH <http://geometry>
> INSERT {
>         shapes:Rectangle
>         rdf:type owl:Class .
>        
>         shapes:rectangle_1
>         rdf:type  shapes:Rectangle ;
>         shapes:height "5" ;
>         shapes:width  "49" .
>         shapes:area rdf:type owl:DatatypeProperty .
>         shapes:height rdf:type owl:DatatypeProperty .
>         shapes:width rdf:type owl:DatatypeProperty .
> } ;
>
> --  create the rule
> -- SPARQL CREATE GRAPH <urn:spin:rule:geometry:lib> ;
>
> SPARQL
> PREFIX shapes: <http://example.org/shapes#>
> PREFIX spin:    <http://spinrdf.org/spin#>
> PREFIX sp: <http://spinrdf.org/sp#>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
> PREFIX owl: <http://www.w3.org/2002/07/owl#>
>
> WITH <urn:spin:rule:geometry:lib>
> INSERT {
>           shapes:Rectangle
>         rdf:type  owl:Class;
>         rdfs:label "Rectangle class";
>         spin:rule [
>                    a sp:Construct;
>                    sp:text """ CONSTRUCT { ?this
> <http://example.org/shapes#area> ?area . }
>                                WHERE { ?this
> <http://example.org/shapes#width> ?width .
>                                           ?this
> <http://example.org/shapes#height> ?height .
>                                        BIND ((xsd:float(?height) *
> xsd:float(?width)) AS ?area) .
>                                      }
>                           """
>                   ] .
> } ;
>
> EXEC ('SPARQL ' ||
> SPARQL_SPIN_GRAPH_TO_DEFSPIN('urn:spin:rule:geometry:lib'));
>
> --  run a sparql query to test the spin rule
>
> SPARQL
> DEFINE input:macro-lib <urn:spin:rule:geometry:lib>
> PREFIX shapes: <http://example.org/shapes#>
>
> SELECT *
> WHERE
>     {
>         ?s shapes:width ?w.
>         ?s shapes:height ?h.
>         OPTIONAL { ?s shapes:area  ?area }.
>     } ;
>
>
> All you have to do is copy, paste, and then run the script above  via
> the HTM-based Admin UI (Conductor) or iSQL command-line (using LOAD
> <{file-name}>).
>
> As proof, I've loaded the script above into our public URIBurner
> instance, and have a sample SPARQL Query Result URI to share [1].
>
> In relation to RDF4J and SPIN, you are making the mistake of comparing a
> RDF Data Access Layer  (what RDF4J is) and a DBMS engine (what Virtuoso
> is). In both cases, a context for handling Custom Inference Rules needs
> to be established. In the case of Virtuoso, why should loading an
> Ontology imply Reasoning and Inference Context initialization for all
> users? In our opinion that is extremely dangerous and impractical, hence
> our use of pragmas that explicitly initialize Reasoning & Inference
> Context per SPARQL Query.
>
> Links:
>
> [1]
> http://linkeddata.uriburner.com/sparql?default-graph-uri=&query=DEFINE+input%3Amacro-lib+%3Curn%3Aspin%3Arule%3Ageometry%3Alib%3E%0D%0APREFIX+shapes%3A+%3Chttp%3A%2F%2Fexample.org%2Fshapes%23%3E%0D%0A%0D%0ASELECT+*%0D%0AWHERE%0D%0A++++%7B%0D%0A++++++++%3Fs+shapes%3Awidth+%3Fw.%0D%0A++++++++%3Fs+shapes%3Aheight+%3Fh.%0D%0A++++++++OPTIONAL+%7B+%3Fs+shapes%3Aarea++%3Farea+%7D.%0D%0A++++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000000
> -- SPARQL Query Results page where solution is constructed with Custom
> Reasoning & Inference Context enabled.


Adam,

Okay, the syntax worked, but I just realized the solution is incorrect
i.e., it doesn't change in response to enabling or disabling inference
context pragma.

The rule itself might be suffering from an issue with BIND. Either way,
I'll confirm in another mail.

-- 
Regards,

Kingsley Idehen       
Founder & CEO 
OpenLink Software   (Home Page: http://www.openlinksw.com)

Weblogs (Blogs):
Legacy Blog: http://www.openlinksw.com/blog/~kidehen/
Blogspot Blog: http://kidehen.blogspot.com
Medium Blog: https://medium.com/@kidehen

Profile Pages:
Pinterest: https://www.pinterest.com/kidehen/
Quora: https://www.quora.com/profile/Kingsley-Uyi-Idehen
Twitter: https://twitter.com/kidehen
Google+: https://plus.google.com/+KingsleyIdehen/about
LinkedIn: http://www.linkedin.com/in/kidehen

Web Identities (WebID):
Personal: http://kingsley.idehen.net/public_home/kidehen/profile.ttl#i
        : 
http://id.myopenlink.net/DAV/home/KingsleyUyiIdehen/Public/kingsley.ttl#this

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users

Reply via email to