Skip to content
Erwan Demairy edited this page Oct 25, 2017 · 3 revisions

SPARQL

How to obtain infered triples ?

  • Get all the inferred triples
select *
from kg:entailment
where { ?x ?p ?y }
  • Get only the inferred triples
select * 
where { 
graph kg:entailment { ?x ?p ?y } 
filter not exists { graph ?g { ?x ?p ?y } filter (?g != kg:entailment) } 
} 
  • get rule entailment
select *
from kg:rule
where { ?x ?p ?y }

Development

How to populate a Graph?

Use the following extract of the API of the Graph class:

class Graph 


// named graph and property nodes *must* be created by these 2 functions:
public Node addGraph(String label) 
public Node addProperty(String label)

public Node addResource(String label) 
public Node addBlank() 
public Node addLiteral(String label, String datatype) 
public Node addLiteral(String label, String datatype, String lang) 

public Node addLiteral(String label)
public Node addLiteral(int n) 
public Node addLiteral(long n)
public Node addLiteral(double n)
public Node addLiteral(float n)
public Node addLiteral(boolean n)

// for graph vertex only: subject or object, (not property, not named graph)
public Node addNode(IDatatype dt) 

    
// create Edge
public Edge addEdge(Node subject, Node predicate, Node object) 
public Edge addEdge(Node namedGraph, Node subject, Node predicate, Node object) 


// to skolemize blank nodes as URI
// do it *before* graph population
public void setSkolem(boolean isSkolem) 

How to test in a GraphListener wether a triple comes from an inference?

In a user-class inheriting from GraphListener

void insert(Graph g, Entity ent){
  Node name = ent.getGraph();
  // rule entailment 
  name.equals(Entailment.RULE);
  // RDFS entailment 
  name.equals(Entailment.ENTAIL);
}