To embed JTP in a Java application, you have to create and configure an instance of BasicReasoningContext. Here is an example of a basic context setup(full source here):
BasicReasoningContext context = new BasicReasoningContext(); context.defaultSetup(); context.setMaxDepth(10); //A KB for FOL clauses ClauseOrientationKB ckb = new ClauseOrientationKB(); context.add(ckb); //Add to context //A reasoner for processing complex query AskingQueryProcessor aqp = new AskingQueryProcessor(); context.add(aqp); //Add to context //Add basic reasoners to asking dispatcher DispatcherUtils.addToDispatcher(ckb.getAskingReasoner(), context.getAskingDispatcher()); DispatcherUtils.addToDispatcher(aqp, context.getAskingDispatcher()); //Add basic reasoners to telling dispatcher DispatcherUtils.addToDispatcher(ckb.getTellingReasoner(), context.getTellingDispatcher()); DispatcherUtils.addToDispatcher(new ClauseOrientation.Factory(), context.getTellingDispatcher());
After that, you can assert (tell) information in KIF format like this:
context.tellString("(age fred 42)");
If your query is a literal, you can then ask it like this:
ReasoningStepIterator rsi = context.ask("(age fred ?x)"); ReasoningStep rs = null; while ((rs = rsi.next()) != null) { Literal lit = SubstUtils.deReferenceLiterals((Literal)rs.getGoal()); System.out.println("X = " + lit.getArgs().get(1)); }
Using non-literal queries is currently a little more complicated. Here is a usage example.
This illustrates embedding a DAML reasoning context.