<dependencies>
<dependency>
<groupId>fr.lirmm.graphik</groupId>
<artifactId>graal-core</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>fr.lirmm.graphik</groupId>
<artifactId>graal-io-dlgp</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>fr.lirmm.graphik</groupId>
<artifactId>graal-kb</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
public static void main(String[] args) throws Exception {
// 0 - Create a KBBuilder
KBBuilder kbb = new KBBuilder();
// 1 - Add a rule
kbb.add(DlgpParser.parseRule("mortal(X) :- human(X)."));
// 2 - Add a fact
kbb.add(DlgpParser.parseAtom("human(socrate)."));
// 3 - Generate the KB
KnowledgeBase kb = kbb.build();
// 4 - Create a DLGP writer to print data
DlgpWriter writer = new DlgpWriter();
// 5 - Parse a query from a Java String
ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- mortal(X).");
// 6 - Query the KB
CloseableIterator resultIterator = kb.query(query);
// 7 - Iterate and print results
writer.write("\n= Answers =\n");
if (resultIterator.hasNext()) {
do {
writer.write(resultIterator.next());
writer.write("\n");
} while (resultIterator.hasNext());
} else {
writer.write("No answers.\n");
}
// 8 - Close resources
kb.close();
writer.close();
}
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.