'
100 Things You Can Do With Algernon
15 (so far) Things You Can Do With Algernon
- Traverse the entire KB with one line of code.
- Perform Google searches.
- Use Google to search for web pages related to your KB contents.
- Find connectivity between two frames using alternate paths.
- Write queries that follow paths in the KB.
- Write queries that don't follow paths in the KB.
- Trigger KB operations from external events.
- Build an entire KB from information in a file.
- Act as a server for remote rule processing.
- Count KB events.
- Delete unneeded frames from the KB.
- Generate robot navigation plans.
- Compute reachability in a Petri Net.
- Perform qualitative reasoning.
- Verify the consistency of a knowledge base.
 
1. Traverse the entire KB with one line of code.
The :CHILD command
in Algernon will retrieve all children (subclasses and instances) of a class. Thus,
the following command will retrieve every frame in the KB:
;; Retrieve all KB objects
((:CHILD :THING ?x))
;; Retrieve all KB objects and do something with them
((:CHILD :THING ?x)
(:PRINTLN ?x " is in the KB."))
 
2. Perform Google searches
Algernon provides a Google backend that intercepts
queries to a slot called "Search" and redirects them
to query Google. Results are stored in an in-memory
KB. See also item 3.
;; Put this in a text file, insert your own
;; Google search key in the :USE-KB clause,
;; and have Algernon execute the file:
;;
;; java -classpath algernon.jar:protege.jar:googleapi.jar org.algernon.Algernon this-file.txt
;;
;; This will run inside Protege if you put googleapi.jar
;; in the Protege plugins directory. googleapi.jar is
;; available at http://www.google.com/apis/
;; You must also register with Google and put the correct
;; key in the :USE-KB clause below.
(tell ((:trace :silent)
(:USE-KB :google-1 Google "com.google.soap.search" "***-insert-your-Google-access-key-here-***")
)) ;; 32 characters in key
(ask ((:println "Google Search")
(:add-instance (?query GoogleSearch) (QueryString ?query "NFL Football"))
(doSearch ?query ?result)
(SearchTime ?result ?searchtime)
(:println " Search took " ?searchtime " seconds.")
(ResultElements ?result ?resultElement)
(URL ?resultElement ?url)
(Title ?resultElement ?title)
(:println " " ?url + ": " + ?title)
))
 
3. Use Google to search for web pages related to your KB contents
Using the Google backend described in item 2 above,
you can create search queries related to information in your KB
and then store the query results in your KB. Algernon lets you
access multiple KBs at the same time.
(tell ((:USE-KB :KB-1 Protege ".../mykbs/kb.pprj")
(:USE-KB :KB-2 Google "com.google.soap.search" "***-insert-your-Google-access-key-here-***")))
 
4. Find connectivity between two frames using alternate paths
Are instances A and B connected by one or more paths?
((connected ?a ?b)
<-
(slot1 ?a ?x)
(connected ?x ?b)
)
((connected ?a ?b)
<-
(slot2 ?a ?x)
(connected ?x ?b)
)
... one rule for every slot.
 
5. Write queries that follow paths in the KB.
A path in a KB (frame1 -> slot -> frame2 -> slot -> frame3 ...
)
maps directly into Algernon syntax. For example, to find
a person's cousins on their mother's side:
Ask: ((mother person1 ?mother)
(sibling ?mother ?sib)
(child ?sib ?cousin)
(:PRINTLN ?cousin " is a cousin of person1 on his or her mother's side.")
)
 
6. Write queries that don't follow paths in the KB.
Although Algernon's syntax is path-oriented, you can easily
retrieve information scattered throughout the KB.
Ask: ((color Tour_De_Eiffel ?color)
(height Great_Pyramid ?height)
(age Stonehenge ?age)
(neighbor Switzerland ?neighbor)
)
 
7. Trigger KB operations from external events
By calling Algernon from Java, you can perform KB
operations and fire rules inside the KB based on
external events.
// in Java
Algernon algy = new Algernon();
algy.addKB(...);
if (..whatever...)
algy.tell("(color object1 " + newColor + ")");
;; in Algernon
((color ?something ?newcolor)
->
(:println ?something " is now " ?newcolor)
)
 
8. Build an entire KB from information in a file.
Algernon's :TAXONOMY
command allows you
to quickly create an ontology in a KB using a tree
syntax.
(tell ((:USE-KB :KB-1 Protege ".../kb.pprj")))
(tell ((:TAXONOMY
(:THING
(Vehicles
(Automobiles)
(Airplanes)
(Trains)
)
(Colors Red Green Blue) ;; R, G, B are instances
(Animals
(Vertebrates
(Insects))
(Bacteria)
)
)
)))
(tell ((:RELATION Color (:THING Colors)))) ;; and so on
(tell ((Color Bacteria Green))) ;; and so on
 
9. Act as a server for remote rule processing
Algernon has a built-in server that accepts
paths that are asserted.
// in Java on the server
Algernon algy = new Algernon();
algy.addKB("...");
algy.startServer(8111); // The port number
...
algy.shutdownServer();
// The client program
Socket socket = new Socket("localhost", 8111);
PrintWriter writer = new PrintWriter(socket.getOutputStream());
writer.println("((color Bacteria Green))");
 
10. Count KB events
You can create forward chaining rules that fire whenever
a certain slot is modified. They would increment a counter
stored somewhere.
;; count new neighbors
((neighbor ?thing ?neighbor)
->
(counter1 Counter ?value)
(:BIND ?new-value (:LISP (+ ?value 1)))
(:CLEAR-RELATION Counter counter1)
(counter1 Counter ?new-value)
)
 
11. Delete unneeded frames from the KB.
Algernon contains :DELETE-CLASS, :DELETE-INSTANCE
and :DELETE-SLOT commands. Use them to clean
up old information from a KB.
 
12. Generate robot navigation plans
At the
University of Texas Robotics Lab, they used Algernon to
create high-level plans for robot movement. These plans
were grounded to an actual robot or optionally to a robot simulator
using a system much like RAPS (by Firby). This work was done
by Emilio Remolina and Micheal Hewett.
 
13. Compute reachability in a Petri Net
Mor Peleg
at Stanford has used Algernon rules to compute reachability in a Petri
Net. She represented the Petri Net in a Protege KB and
developed a set of rules to do the computation.
 
14. Perform qualitative reasoning
The Qualitative Process Compiler
was implemented in Algernon.
 
15. Verify the consistency of a knowledge base
For example, every instance of class A must have
slots containing at least one instance of classes B and C.
Ask: ((:instance A ?instance)
(:OR ((slot1 ?instance ?slot1-value)
(slot2 ?instance ?slot2-value)
(:instance B ?slot1-value)
(:instance C ?slot2-value)
(:println ?instance " is okay.")
)
((:println "*** " ?instance " does not link to instances of B and C."))
)
)
Author: Micheal Hewett