Embedding JTP in a Java application

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();
	//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(aqp, context.getAskingDispatcher());
	//Add basic reasoners to telling dispatcher
	DispatcherUtils.addToDispatcher(new ClauseOrientation.Factory(),

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.

Gleb Frank
Last modified: Tue Feb 5 02:59:57 PST 2002