Getting started: Corese / KGRAM API

Create a graph:

Graph graph = Graph.create();

Create a graph with RDFS entailment:

Graph graph = Graph.create(true);

Load RDF/S documents:

Load ld = Load.create(graph);
ld.load("dataset.rdf");

SPARQL query

QueryProcess exec = QueryProcess.create(graph);
String query = "select * where {?x ?p ?y}";
Mappings map = exec.query(query);

Query Result

for (Mapping m : map){
   IDatatype dt = (IDatatype) map.getValue("?x");
   dt.intValue();
   dt.doubleValue();
   dt.booleanValue();
   dt.stringValue();
   dt.getLabel();
   dt.getDatatypeURI();
   dt.getLang();
   dt.isURI();
   dt.isLiteral();
   dt.isBlank();
}

Graph result of a construct-where query:

Graph g = exec.getGraph(map);
Graph g = (Graph) map.getGraph();

Command line:

java -cp corese.jar fr.inria.edelweiss.kgtool.Start 
  -load data.rdf 
  -query "select * where {?x ?p ?y}"

SPARQL XML or RDF/XML Results

Mappings map = exec.query(query);
ResultFormat f = ResultFormat.create(map);
System.out.println(f);

Turtle Format

Mappings map = exec.query(query);
Graph g = exec.getGraph(map);
TripleFormat f = TripleFormat.create(g);
System.out.println(f);

Turtle Format with named graphs

TripleFormat f = TripleFormat.create(g, true);
System.out.println(f);

Turtle Format with/without selected named graphs

TripleFormat f = TripleFormat.create(g, true);
f.with("http://example.org/g1");
f.without("http://example.org/g2");
System.out.println(f);

Save graph into a file

TripleFormat f = TripleFormat.create(g, true);
f.write(fileName);

Rule Engine

RuleEngine engine = RuleEngine.create(graph);
RuleLoad ld = RuleLoad.create(engine);
ld.load("rule.rul");
engine.process();

OWL RL

RuleEngine engine = RuleEngine.create(graph);
engine.setProfile(RuleEngine.OWL_RL);
engine.process();

 

Query Engine

QueryEngine engine = QueryEngine.create(graph);
QueryLoad ld = QueryLoad.create(engine);
ld.load("q1.rq");
ld.load("q2.rq");
engine.process();