The Power and Pitfalls of Inferencing

Kurt Cagle
May 31 · 13 min read

Inferencing Starts With Logic

class:_Person
    a class:_Class.class:_Gender 
    a class:_Class.person:hasGeneticParent
    a class:_Property;
    property:hasDomain class:_Person;
    property:hasRange  class:_Person;
    .person:hasBirthGender
    a class:_Property;
    property:hasDomain class:_Person;
    property:hasRange  class:_Gender;
    .
person:_JaneDoe
     a class:_Person;
     person:hasBirthGender gender:_Female;
     .
person:_JohnDoe
    a class:_Person;
    person:hasBirthGender gender:_Male;
    .person:_EleanorJones
    a class:_Person;
    person:hasBirthGender gender:_Female;
    .
person:_JaneDoe  person:hasBioParent person:_JohnDoe,
                 person:_EleanorJones.
person:_EricDoe
    a class:_Person;
    person:hasBirthGender gender:_Male;
    person:hasBioParent person:_JohnDoe,
                        person:_EleanorJones;
.
# SPARQL 1.0 construct  statement
construct {?person1 person:hasBirthSibling ?person2} 
where {
    ?person1 a class:_Person.
    ?person2 a class:_Person.
    ?person1 person:hasBioParent ?parent.
    ?person2 person:hasBioParent ?parent.
    filter (!(sameTerm(?person1,?person2)
    }
person:_JaneDoe person:hasBirthSibling persion:_EricDoe.
person:_EricDoe person:hasBirthSibling person:_JaneDoe.

SPARQL vs. Reasoners

# SPARQL 1.1 insert statement
insert {?person1 person:hasBirthSibling ?person2} 
where {
    ?person1 a class:_Person.
    ?person2 a class:_Person.
    ?person1 person:hasBioParent ?parent.
    ?person2 person:hasBioParent ?parent.
    filter (!(sameTerm(?person1,?person2)
    }
# SPARQL 1.1 insert statement
insert {?person1 person:hasBirthSibling ?person2} 
where {
    ?person1 a class:_Person.
    ?person2 a class:_Person.
    ?person1 person:hasBioParent ?parent.
    ?person2 person:hasBioParent ?parent.
    filter (!(sameTerm(?person1,?person2))
    filter(not exists {?person1 person:hasBirthSibling ?person2})    }
describe person:_JaneDoe
# =>
person:_JaneDoe
    a class:_Person;
    person:hasBirthGender gender:_Female;
    person:hasBioParent person:_JohnDoe,
                        person:_EleanorJones;
    person:hasBioSibling person:_EricDoe;
.
insert {?person1 person:hasBirthMother ?person2} 
where {
    ?person1 a class:_Person.
    ?person2 a class:_Person.
    ?person1 person:hasBioParent ?person2.
    ?person2 person:hasBirthGender gender:_Female.
    filter (!(sameTerm(?person1,?person2))
}
# Note: script revised
person:hasBirthMother rdfs:subPropertyOf persons:hasBioParent.
person:hasBirthFather rdfs:subPropertyOf persons:hasBioParent.
select ?person ?parent where {
    ?prop rdfs:subPropertyOf* person:hasBioParent.
    ?person ?prop ?parent
    }
select ?person ?parent where {
    ?person person:hasBioParent ?parent
    }

Inferencing as Query and Construction

construct {
    ?property a owl:Property.
    ?property rdfs:domain ?domain.
    ?property rdfs:range ?range.
    ?property rdfs:datatype ?datatype.
    }
where {
    ?s ?property ?o.
    ?s a ?domain.
    optional {
        ?o a ?range 
       }
    optional {
        bind(datatype(?o) as ?datatype)
    }
}    
person:hasBioParent
    a owl:Property;
    rdfs:domain class:_Person;
    rdfs:range class:_Person;
    .person:hasBirthMother 
     a owl:Property;
     rdfs:domain class:_Person;
     rdfs:range class:_Person;
.person:hasBirthMother 
     a owl:Property;
     rdfs:domain class:_Person;
     rdfs:range class:_Person;
.person:hasBirthGender 
     a owl:Property;
     rdfs:domain class:_Person;
     rdfs:range class:_Gender;
.person:hasBioSibling 
     a owl:Property;
     rdfs:domain class:_Person;
     rdfs:range class:_Person;
.

Traversing a Graph Anonymously

insert {?s term:hasTarget ?o}
where {
   ?s ?p ?o
   }
construct {
  ?s ?p ?o.
  ?s1 ?p1 ?o1.
} where {
  bind (person:_JaneDoe as ?s1)
  ?s1 term:hasTarget ?s.
  ?s term:hasTarget+ ?o.
  ?s ?p ?o.
  ?p rdfs:subPropertyOf term:hasTarget.
  optional {
  ?s1 ?p1 ?o1.
  }
  filter(!sameTerm(?s1,?s))
}
select (?s1 ?city ?state) where {
  bind (person:_JaneDoe as ?s1){{construct {
  ?s ?p ?o.
  ?s1 ?p1 ?o1.
} where {
  ?s1 term:hasTarget ?s.
  ?s term:hasTarget+ ?o.
  ?s ?p ?o.
  ?p rdfs:subPropertyOf term:hasTarget.
  optional {
  ?s1 ?p1 ?o1.
  }
  filter(!sameTerm(?s1,?s))
}}}
?s address:hasCity ?city.
?s address:hasState ?state.
}

Conclusion

The Startup

Medium's largest active publication, followed by +469K people. Follow to join our community.

Kurt Cagle

Written by

The Startup

Medium's largest active publication, followed by +469K people. Follow to join our community.