Algernon in Java Documentation

Quick Links


FAQ and How to...

How do I access Algernon query results from a Java program?

The Algernon.ask() and Algernon.tell() methods return an object of class Result, or else null. If there was a serious error, null is returned and the Error object contains relevant error messages.

Otherwise, you can pull result sets out of the Result object using an iterator similar to the one below.

  // Example that retrieves all bindings of the variable ?X.
  // Note that the variable names are case-sensitive:

  Result result = algy.ask("...");
  if (result == null)
    ...
  else
    for (Iterator iterator = result.iterator(); 
         iterator.hasNext();)
    {
       // Result contains some BindingList objects.
       BindingList bl = (BindingList) iterator.next();
       Object value = algy.getBinding("?X", bl);

       // Object will either be a Java Object (Integer, Float, etc.)
       // or a KB object (typically a Protege Instance).
       // If you want Algernon objects, use algy.getAlgernonBinding().
     }
If for some reason you don't know the names of the variables in the Binding Lists, you can iterate on the BindingList to retrieve variable names and values. See the JavaDoc documentation for the BindingList api.

How to store rules in the KB


How to use the Algernon Server


Why can't Algernon find my frames?

Algernon uses the :NAME slot in Protege to lookup frames. However, many Protege KBs use a "browser key" to display the contents of another frame as the "name". Algernon can't figure out which frame you want if you use the "browser key" value.
Protege now prints the value of the :NAME slot in the title bar of an instance display if the browser key is not :NAME. A programmatic way to find it is the following Algernon code, which works in the (old) newspaper example project:
  ((:forc-instance (?x Author) (byname ?x "Michael Jordan")))
Note: FORC-INSTANCE appears to be broken in v3.3.0
Author: Micheal Hewett