-- 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 ; SPARQL CLEAR GRAPH ; SPARQL DROP SPIN LIBRARY ; -- create a named graph -- SPARQL CREATE GRAPH ; SPARQL PREFIX shapes: PREFIX rdf: PREFIX owl: WITH 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 . } ; -- Test Generated Data Control Check SPARQL PREFIX shapes: PREFIX spin: PREFIX sp: PREFIX xsd: PREFIX owl: # CONSTRUCT { ?this ?area . } SELECT ?this ?area FROM WHERE { ?this ?width . ?this ?height . BIND ((xsd:float(?height) * xsd:float(?width)) AS ?area) . } ; -- create the rule -- SPARQL CREATE GRAPH ; SPARQL PREFIX shapes: PREFIX spin: PREFIX sp: PREFIX xsd: PREFIX owl: WITH INSERT { shapes:Rectangle rdf:type owl:Class; rdfs:label "Rectangle class"; spin:rule [ a sp:Construct; sp:text """ CONSTRUCT { ?this ?area } WHERE { { SELECT ?this (xsd:float(?height) * xsd:float(?width)) AS ?area WHERE { ?this ?width ; ?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 -- Test 1 (Reasoning & Inference Context Enabled ) SPARQL DEFINE input:macro-lib PREFIX shapes: SELECT * FROM WHERE { ?s a shapes:Rectangle ; shapes:area ?area . } ; -- Test 2 (Reasoning & Inference Context Disabled ) SPARQL # DEFINE input:macro-lib PREFIX shapes: SELECT * FROM WHERE { ?s a shapes:Rectangle ; shapes:area ?area . } ; -- Test 3 (Reasoning & Inference Context Enabled ) SPARQL DEFINE input:macro-lib PREFIX shapes: SELECT ?s xsd:float(?w) as ?width xsd:float(?h) as ?height xsd:float(?area) as ?area FROM WHERE { ?s a shapes:Rectangle; shapes:width ?w ; shapes:height ?h . OPTIONAL { ?s shapes:area ?area }. } ; -- Test 4 (Reasoning & Inference Context Disabled ) SPARQL # DEFINE input:macro-lib PREFIX shapes: SELECT ?s xsd:float(?w) as ?width xsd:float(?h) as ?height xsd:float(?area) as ?area FROM WHERE { ?s a shapes:Rectangle; shapes:width ?w ; shapes:height ?h . OPTIONAL { ?s shapes:area ?area }. }