SPARQL CLEAR GRAPH ; SPARQL PREFIX rel: PREFIX wdrs: PREFIX schema: PREFIX owl: PREFIX sp: PREFIX spl: PREFIX spin: PREFIX rdf: PREFIX rdfs: PREFIX xsd: PREFIX ex: PREFIX kennedys: PREFIX : WITH INSERT { ex:Parent a rdfs:Class ; rdfs:label "Parent"^^xsd:string ; rdfs:subClassOf ex:Person ; spin:constraint [ a sp:Ask ; sp:text """ # must be at least 18 years old PREFIX rel: PREFIX wdrs: PREFIX sp: PREFIX spl: ASK WHERE { ?this ex:age ?age . FILTER (?age < 18) . }""" ] . owl:Thing spin:constraint [ a sp:Construct ; sp:text """ PREFIX rel: PREFIX wdrs: PREFIX sp: PREFIX spl: CONSTRUCT { _:violation a spin:ConstraintViolation ; spin:violationRoot ?this ; spin:violationPath kennedys:spouse ; rdfs:label "Same-sex marriage not permitted (in this model)" } WHERE { ?this kennedys:spouse ?spouse . ?this kennedys:gender ?gender . ?spouse kennedys:gender ?spouseGender . FILTER (?gender = ?spouseGender) . }""" ] . ex:Person a rdfs:Class ; rdfs:label "Person"^^xsd:string ; rdfs:subClassOf owl:Thing ; spin:rule [ a sp:Construct ; sp:text """ PREFIX rel: PREFIX wdrs: PREFIX sp: PREFIX spl: CONSTRUCT { ?this ex:grandParent ?grandParent . } WHERE { ?parent ex:child ?this . ?grandParent ex:child ?parent . }""" ] . ex:USCitizen a rdfs:Class ; rdfs:label "US citizen"^^xsd:string ; rdfs:subClassOf ex:Person ; spin:constructor [ a sp:Construct ; sp:text """ PREFIX rel: PREFIX wdrs: PREFIX sp: PREFIX spl: CONSTRUCT { ?this ex:birthCountry ex:USA . } WHERE { }""" ] . ex:Parent a owl:Class ; rdfs:label "Parent"^^xsd:string ; rdfs:subClassOf owl:Thing ; spin:constraint [ a ex:MinCardinality ; ex:count 1 ; ex:predicate ex:child ] . ex:cardinality a spin:Function ; rdfs:subClassOf spin:Functions ; rdfs:comment "Gets the number of values of a given property at the current subject (?this)." ; rdfs:label "cardinality"^^xsd:string ; spin:constraint [ a spl:Argument ; rdfs:comment "The property to get the cardinality of." ; spl:predicate sp:arg1 ] ; spin:body [ a sp:Select ; sp:text """ PREFIX rel: PREFIX wdrs: PREFIX sp: PREFIX spl: SELECT (COUNT(?object) AS ?result) WHERE { ?this ?arg1 ?object . }""" ] . :grandParent a spin:MagicProperty ; rdfs:label "grand parent"^^xsd:string ; rdfs:subClassOf spin:MagicProperties ; spin:constraint [ a spl:Argument ; rdfs:comment "The Person to get the grandparent(s) of."^^xsd:string ; spl:predicate sp:arg1 ; spl:valueType kennedys:Person ] ; spin:body [ a sp:Select ; sp:text """ PREFIX rel: PREFIX wdrs: PREFIX sp: PREFIX spl: SELECT ?grandParent WHERE { ?parent kennedys:child ?arg1 . ?grandParent kennedys:child ?parent . }""" ] . } ; -- Then Execute SELECT DB.DBA.SPARQL_SPIN_GRAPH_TO_DEFSPIN ('urn:spin:nanotation:demo:kennedy:family') as x long varchar ;