# 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 # 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 . } # 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 shapes:area ?area . } WHERE { ?this shapes:width ?width . ?this 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 DEFINE input:macro-lib PREFIX shapes: select * { ?s shapes:width ?w. ?s shapes:height ?h. OPTIONAL { ?s shapes:area ?area. } } # Additional commands SPARQL CLEAR GRAPH ; SPARQL CLEAR GRAPH ; SPARQL DROP SPIN LIBRARY ;