'
;; 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."))
;; 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)
))
(tell ((:USE-KB :KB-1 Protege ".../mykbs/kb.pprj")
(:USE-KB :KB-2 Google "com.google.soap.search" "***-insert-your-Google-access-key-here-***")))
((connected ?a ?b) <- (slot1 ?a ?x) (connected ?x ?b) ) ((connected ?a ?b) <- (slot2 ?a ?x) (connected ?x ?b) ) ... one rule for every slot.
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.")
)
Ask: ((color Tour_De_Eiffel ?color)
(height Great_Pyramid ?height)
(age Stonehenge ?age)
(neighbor Switzerland ?neighbor)
)
// 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)
)
: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
// 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))");
;; count new neighbors
((neighbor ?thing ?neighbor)
->
(counter1 Counter ?value)
(:BIND ?new-value (:LISP (+ ?value 1)))
(:CLEAR-RELATION Counter counter1)
(counter1 Counter ?new-value)
)
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."))
)
)