-- set autocommit on; -- set blobs on; -- Load Raw Data about Royals SPARQL CLEAR GRAPH ; SPARQL PREFIX wdrs: PREFIX schema: PREFIX rel: WITH INSERT { ## Custom Entity Relationship Types (Relations) ## <#hasRelative> a rdf:Property ; rdfs:label "hasRelative" ; rdfs:comment """Generic Family Relationship""" ; rdfs:domain foaf:Person ; rdfs:range <#MalePerson>, <#FemalePerson>, <#RoyalPerson>, foaf:Person, schema:Person ; wdrs:describedby <#> . <#hasUncle> a rdf:Property ; rdfs:subPropertyOf <#hasRelative> ; rdfs:label "hasUncle" ; rdfs:comment """Relationship Type that's derived from a SPARQL-based Custom Inference Rule that associates a Person with a Male Person that's a sibling of one of their Parents. """ ; rdfs:domain foaf:Person ; rdfs:range <#MalePerson> ; wdrs:describedby <#> . <#hasAuntie> a rdf:Property ; rdfs:subPropertyOf <#hasRelative> ; rdfs:label "hasAuntie" ; rdfs:comment """Relationship Type that's derived from a SPARQL-based Custom Inference Rule that associates a Person with a Female Person that's a sibling of one of their Parents. """ ; rdfs:domain foaf:Person ; rdfs:range <#FemalePerson> ; wdrs:describedby <#> . <#hasCousin> a rdf:Property ; rdfs:subPropertyOf <#hasRelative> ; rdfs:label "hasCousin" ; rdfs:comment """Relationship Type that's derived from a SPARQL-based Custom Inference Rule that associates a Person with another Person; that's a child of the sibling of one of their Parents. """ ; rdfs:domain foaf:Person ; rdfs:range <#FemalePerson>, <#MalePerson> ; wdrs:describedby <#> . ## Custom Entity Types (Classes) ## <#FemalePerson> rdfs:subClassOf foaf:Person ; rdfs:label "Female Person Class" ; rdfs:comment """ A female person that inherits properties of the Person class identified by relative URI: foaf:Person. The properties of this class are defined using custom inference rules using SPARQL via . """ ; wdrs:describedby <#> . <#MalePerson> rdfs:subClassOf foaf:Person ; rdfs:label "Male Person Class" ; rdfs:comment """ A male person that inherits properties of the Person class identified by relative URI: foaf:Person. The properties of this class are defined using custom inference rules using SPARQL via . """ ; wdrs:describedby <#> . ## Entity Relationships ## a foaf:Person, <#MalePerson> ; schema:name "Prince William" ; rel:siblingOf . a foaf:Person, <#FemalePerson> ; schema:name "Queen Mother" ; rel:parentOf . a foaf:Person, <#FemalePerson> ; schema:name "Queen Elizabeth II" ; rel:parentOf , , , ; rel:siblingOf . a foaf:Person, <#MalePerson> ; schema:name "Prince Charles" ; rel:parentOf , . a foaf:Person, <#FemalePerson> ; schema:name "Princess Margaret" . a foaf:Person, <#FemalePerson> ; schema:name "Princess Anne" ; rel:parentOf , . a foaf:Person, <#FemalePerson> ; schema:name "Princess Zara Phillips" . a foaf:Person, <#FemalePerson> ; schema:name "Princess Beatrice" . a foaf:Person, <#FemalePerson> ; schema:name "Princess Eugenie" . a foaf:Person, <#MalePerson> ; schema:name "Prince Andrew" ; rel:parentOf , . a foaf:Person, <#MalePerson> ; schema:name "Prince Edward" . a foaf:Person, <#MalePerson> ; schema:name "Prince Harry" . a foaf:Person, <#MalePerson> ; schema:name "Prince Peter Phillips" . } ; SPARQL prefix foaf: WITH INSERT { ?s a <#RoyalPerson> } where { ?s a foaf:Person } ; -- Class Definition that includes SPIN Rules SPARQL CLEAR GRAPH ; TTLP (' @prefix owl: . @prefix sp: . @prefix spl: . @prefix spin: . @prefix rdf: . @prefix rdfs: . @prefix xsd: . @prefix foaf: . @prefix rel: . @prefix wdrs: . @prefix schema: . <#RoyalPerson> a rdfs:Class ; rdfs:label "A Royal Person"^^xsd:string ; rdfs:subClassOf foaf:Person, schema:Person ; spin:rule [ a sp:Construct ; sp:text """ # must be related to Queen Elizabeth II CONSTRUCT { ?n a ?this . } WHERE { { ?n rel:descendantOf+|rel:ancestorOf+|rel:siblingOf|^rel:siblingOf . } } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this ?x } WHERE { { ?this ?parent . ?parent ?x . } } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this rel:ancestorOf ?n } WHERE { { ?this rel:parentOf+|^rel:descendantOf ?n . } } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this rel:descendantOf ?n } WHERE { { ?this ^rel:parentOf+ ?n . } } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this rel:siblingOf ?n } WHERE { { [] rel:parentOf ?this, ?n. FILTER (?n != ?this) . } } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this <#hasAuntie> ?n } WHERE { [] rel:parentOf ?n , ?prnt . ?prnt rel:parentOf ?this . FILTER (?n != ?prnt) ?n a <#FemalePerson> . } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this <#hasUncle> ?n } WHERE { [] a <#RoyalPerson> ; rel:parentOf ?this ; rel:siblingOf ?n . ?n a <#MalePerson> . } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this <#hasCousin> ?n } WHERE { [] a <#RoyalPerson> ; rel:parentOf ?this ; rel:siblingOf ?n . ?n a <#MalePerson> . } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this <#hasUncle2> ?n } WHERE { [] rel:parentOf ?n , ?prnt . ?prnt rel:parentOf ?this . FILTER (?n != ?prnt) ?n a <#MalePerson> . } """ ] ; spin:rule [ a sp:Construct ; sp:text """ CONSTRUCT { ?this <#hasCousin2> ?n } WHERE { [] rel:parentOf ?n_prnt, ?this_prnt . ?n_prnt rel:parentOf ?n . ?this_prnt rel:parentOf ?this . filter (?n_prnt != ?this_prnt) } """ ] . ', '', 'urn:spin:nanotation:demo:royal:family:lib2', 4096) ; -- Macro Generation SELECT SPARQL_SPIN_GRAPH_TO_DEFSPIN('urn:spin:nanotation:demo:royal:family:lib2'); STRING_TO_FILE ('urn_spin_nanotation_demo_royal_family_lib2.sparql.sql', 'SPARQL ' || SPARQL_SPIN_GRAPH_TO_DEFSPIN('urn:spin:nanotation:demo:royal:family:lib2') || ';', -2); EXEC ('SPARQL ' || SPARQL_SPIN_GRAPH_TO_DEFSPIN('urn:spin:nanotation:demo:royal:family:lib2')); RECONNECT "dba"; SET echo ON; -- Test Queries -- Test 1 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT * WHERE { ?s a <#RoyalPerson> . }; -- Test 2 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT * WHERE { ?s a ?t . }; -- Test 3 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT * WHERE { ?s a <#RoyalPerson> ; rel:siblingOf ?sibling . }; -- Test 4 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT * WHERE { ?s a <#RoyalPerson> ; rel:grandParent ?gp . }; -- Test 5 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?person rel:ancestorOf as ?relation ?descendant WHERE { ?person a <#RoyalPerson> ; rel:ancestorOf ?descendant . } ; -- Test 6 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT DISTINCT ?person rel:siblingOf as ?relation ?siblingOf WHERE { ?person a <#RoyalPerson> ; rel:siblingOf ?siblingOf } ; -- Test 7 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?person <#hasAuntie> as ?relation ?hasAuntie WHERE { ?person a <#RoyalPerson> ; <#hasAuntie> ?hasAuntie } ; -- Test 8 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?person <#hasUncle> as ?relation ?hasUncle WHERE { ?person a <#RoyalPerson> ; <#hasUncle> ?hasUncle } ; -- Test 9 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?person <#hasUncle2> as ?relation ?hasUncle2 WHERE { ?person a <#RoyalPerson> ; <#hasUncle2> ?hasUncle2 } ; -- Test 10 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?person <#hasCousin> as ?relation ?hasCousin WHERE { ?person a <#RoyalPerson> ; <#hasCousin> ?hasCousin } ; -- Test 11 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?person <#hasCousin2> as ?relation ?hasCousin2 WHERE { ?person a <#RoyalPerson> ; <#hasCousin2> ?hasCousin2 } ; -- Test 12 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?s as ?ancestor ?descendant WHERE { ?s a <#RoyalPerson> ; rel:ancestorOf ?descendant }; -- Test 13 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT DISTINCT * WHERE { { ?parent a <#RoyalPerson> ; rel:parentOf ?parentOf .} UNION { ?person a foaf:Person; <#hasAuntie> ?hasAuntie .} UNION { ?person a foaf:Person; <#hasUncle> ?hasUncle .} UNION { ?person a foaf:Person; <#hasCousin> ?hasCousin .} UNION { ?person a foaf:Person; <#hasUncle2> ?hasUncle2 .} UNION { ?person a foaf:Person; <#hasCousin2> ?hasCousin2 .} UNION { ?person a foaf:Person; rel:siblingOf ?hasSibling . } UNION { ?person a foaf:Person; rel:ancestorOf ?hasDescendant . } } ; COMMIT WORK ;