-- Raw Data -- Cleanup SPARQL CLEAR GRAPH ; SPARQL PREFIX rel: PREFIX wdrs: WITH INSERT { ## Entity Relationships ## a <#Person>, <#MalePerson> ; schema:name "Prince William" ; rel:siblingOf . a <#Person>, <#FemalePerson> ; schema:name "Queen Mother" ; rel:parentOf . a <#Person>, <#FemalePerson> ; schema:name "Queen Elizabeth II" ; rel:parentOf , , , ; rel:siblingOf . a <#Person>, <#MalePerson> ; schema:name "Prince Charles" ; rel:parentOf , . a <#Person>, <#FemalePerson> ; schema:name "Princess Margaret" . a <#Person>, <#FemalePerson> ; schema:name "Princess Anne" ; rel:parentOf , . a <#Person>, <#FemalePerson> ; schema:name "Princess Zara Phillips" . a <#Person>, <#FemalePerson> ; schema:name "Princess Beatrice" . a <#Person>, <#FemalePerson> ; schema:name "Princess Eugenie" . a <#Person>, <#MalePerson> ; schema:name "Prince Andrew" ; rel:parentOf , . a <#Person>, <#MalePerson> ; schema:name "Prince Edward" . a <#Person>, <#MalePerson> ; schema:name "Prince Harry" . a <#Person>, <#MalePerson> ; schema:name "Prince Peter Phillips" . ## Custom Entity Relationship Types (Relations) Defined by Custom Inference Rules ## <#hasUncle> a rdf:Property ; 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. """ ; wdrs:describedby <#> . <#hasAuntie> a rdf:Property ; 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. """ ; wdrs:describedby <#> . <#hasCousin> a rdf:Property ; 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. """ ; wdrs:describedby <#> . ## Custom Entity Types (Classes) <#Person> rdfs:subClassOf foaf:Person, schema:Person ; rdfs:label "Person Class" ; rdfs:comment """ A person that inherits properties of both the foaf:Person and schema:Person classes from their respective vocabularies. The properties of this class are defined using custom inference rules using SPARQL via SPIN Rules Language.""" ; wdrs:describedby <#> . <#FemalePerson> rdfs:subClassOf <#Person> ; rdfs:label "Female Person Class" ; rdfs:comment """ A female person that inherits properties of the Person class identified by relative URI: <#Person>. The properties of this class are defined using custom inference rules using SPARQL via SPIN Rules Language. """ ; wdrs:describedby <#> . <#MalePerson> rdfs:subClassOf <#Person> ; rdfs:label "Male Person Class" ; rdfs:comment """ A male person that inherits properties of the Person class identified by relative URI: <#Person>. The properties of this class are defined using custom inference rules using SPARQL via SPIN Rules Language. """ ; wdrs:describedby <#> . } ; -- Load Relationship Vocabulary Data SPARQL CLEAR GRAPH ; SPARQL DEFINE get:soft "no-sponge" SELECT * FROM WHERE { ?s ?p ?o }; -- Custom Inference Rules using SPIN -- For newer release of SPIN Engine -- SPARQL DROP SPIN LIBRARY ; SPARQL DROP MACRO LIBRARY ; SPARQL PREFIX rel: CREATE SPIN LIBRARY { CLASS <#Person> { comment """ Class instance generated from a Macro that customizes relations such as rel:siblingOf while introducing new relations such as <#hasAuntie>, <#hasUncle>, and <#hasCousin> . """ defmacro rel:ancestorOf { ?this rel:ancestorOf ?n } {{ { ?this rel:parentOf+ ?n . } union { ?this rel:siblingOf ?n . } }} defmacro rel:sibingOf { ?this rel:siblingOf ?n } {{ [] rel:parentOf ?this, ?n. FILTER (?n != ?this) . }} defmacro <#hasAuntie> { ?this <#hasAuntie> ?n } {{ [] rel:parentOf ?this ; rel:siblingOf ?n . ?n a <#FemalePerson> . }} defmacro <#hasUncle> { ?this <#hasUncle> ?n } {{ [] rel:parentOf ?this ; rel:siblingOf ?n . ?n a <#MalePerson> . }} defmacro <#hasCousin> { ?this <#hasCousin> ?n } {{ [] rel:parentOf ?n ; rel:siblingOf [ rel:parentOf ?this ] . }} } } ASK FROM virtrdf: WHERE { ?s ?o } ; -- Test 1 SPARQL DEFINE input:macro-lib PREFIX rel: WITH SELECT ?person rel:ancestorOf as ?relation ?descendant WHERE { ?person a <#Person> ; rel:ancestorOf ?descendant } ; -- Test 2 SPARQL DEFINE input:macro-lib WITH SELECT DISTINCT ?s rel:siblingOf as ?relation ?y WHERE { ?s a <#Person> ; rel:siblingOf ?y. } ; -- Test 3 SPARQL DEFINE input:macro-lib WITH SELECT ?s <#hasAuntie> ?y WHERE { ?s a <#Person> ; <#hasAuntie> ?y } ; -- Test 4 SPARQL DEFINE input:macro-lib WITH SELECT ?s <#hasUncle> ?y WHERE { ?s a <#Person> ; <#hasUncle> ?y } ; -- Test 5 SPARQL DEFINE input:macro-lib WITH SELECT ?s <#hasCousin> ?y WHERE { ?s a <#Person> ; <#hasCousin> ?y } ; -- Test 6 SPARQL DEFINE input:macro-lib WITH SELECT ?s as ?ancestor ?descendant WHERE { ?s a <#Person> ; rel:ancestorOf ?descendant }; -- Test 7 SPARQL DEFINE input:macro-lib WITH SELECT DISTINCT * WHERE { { ?parent a <#Person> ; rel:parentOf ?parentOf .} UNION { ?person a <#Person>; <#hasAuntie> ?hasAuntie .} UNION { ?person a <#Person>; <#hasUncle> ?hasUncle .} UNION { ?person a <#Person>; <#hasCousin> ?hasCousin .} UNION { ?person a <#Person>; rel:siblingOf ?hasSibling . } UNION { ?person a <#Person>; rel:ancestorOf ?hasDescendant . } } ; COMMIT WORK ;