Previous topic  Top  Next topic  Print this Topic



As already explained, requests circumvent any reasoning and fetch axioms as explicitly entered in the knowledge base. The following illustrates requesting axioms with a simple condition.

Obtaining a Request Object

Axioms can be retrieved using a Request object; a Request instance can be obtained by calling the Ontology method createAxiomRequest. An axiom type must be passed to this method, virtually all subclasses of Axiom are admissable. The sample code below creates a request for axioms of type FClassMember, in other words, for axioms carrying the information on what objects are instances of what concepts.

Request<FClassMember> request = geographyOnto.createAxiomRequest(FClassMember.class);

Setting Conditions

Depending on the type of object being requested, different conditions can be set. Axioms pertaining to ObjectLogic concepts, instances and properties are concentrated in the class hierarchy below FAtom, each of these classes defines string constants for the applicable conditions (see the javadoc). The conditions are self-explanatory and follow from what information a particular FAtom subclass carries.

For example, the FClassMember binds an instance (called 'object') to a concept (called 'class object'). Since we intend to request the instances of a particular concept, we set a condition on the concept ('class object'), that should be equal to the particular concept name.




Multiple values for a condition can also be specified using the method setConditionMultipleValues. Any one of the specified values will then qualify a record for inclusion. Consider the following variation of the previous condition; in addition to instances of City, instances of Village would also be included in the result.




Accessing Results

The Request class provides several methods for accessing the results, being interested in all matching axioms from the current ontology, we call the plain get() variant. This returns the complete result set at once as a typed Set of FClassMember. In line with our expectations, the type of the result elements corresponds to the type requested, we can therefore directly make use of the three accessor methods.

Set<FPropertyMember> result = request.get();

for (FPropertyMember ax : result) {


 String cityLocal = ((IRIHolder) (((Constant) ax.getObject()).getValue())).getLocal();

 String stateLocal = ((IRIHolder) (((Constant) ax.getValue()).getValue())).getLocal();

 String propLocal = ((IRIHolder) (((Constant) ax.getProperty()).getValue())).getLocal();

 System.out.printf("%-20s [ %20s -> %-20s ]%n", cityLocal, propLocal, stateLocal);


Knowing the Right Axiom Type

When unsure about how a particular ObjectLogic construct is represented in the Axiom form (which is necessary for correctly setting the request condition), there is an alternative to a lengthy trial-and-error brain exercise. The KAON2Factory class provides a method for creating axioms from an ObjectLogic expression.

Inspecting the result of a code snippet like the one below should quickly get you back on the right track. (A similar check can obviously be done in the debugger.)

List<Axiom> axioms = KAON2Manager.factory().axioms(

         "Offenburg:City[hasName->\"Offenburg\", "

        + "hasPopulation->59171, partOfFederalState->BW].",

         namespaces, geographyOnto.getModule());

for (Axiom ax : axioms) {

 String className = "";

 if (ax instanceof FClassMember)

         className = "FClassMember";

 else if (ax instanceof FPropertyMember)

         className = "FPropertyMember";

 else if ...