Algernon Software

org.algernon.kb.okbc.protege
Class AlgernonProtegeKB

java.lang.Object
  extended byorg.jatha.dynatype.StandardLispValue
      extended byorg.algernon.kb.okbc.protege.AlgernonProtegeObject
          extended byorg.algernon.kb.okbc.protege.AlgernonProtegeKB
All Implemented Interfaces:
AlgernonKB, AlgernonObject, Comparable, LispValue

public class AlgernonProtegeKB
extends AlgernonProtegeObject
implements AlgernonKB

Implements a Protege KB for Algernon. This interface adds just a few functions on top of the existing Protege interface.


Field Summary
protected  AlgernonProtegeRelation f_displayNameRelation
           
protected  String f_displayNameRelationName
           
protected  KnowledgeBase f_kb
           
protected  URI f_projectURI
           
protected  HashMap localCache
           
protected  HashMap localDisplayNameCache
           
 
Fields inherited from class org.algernon.kb.okbc.protege.AlgernonProtegeObject
f_algy
 
Fields inherited from class org.jatha.dynatype.StandardLispValue
f_lisp
 
Constructor Summary
AlgernonProtegeKB(Algernon algy)
          Creates a new in-memory Protege project.
AlgernonProtegeKB(Algernon algy, KnowledgeBase kb)
          Adds a kb that is already open.
AlgernonProtegeKB(Algernon algy, String projectFileName)
          Opens the given Protege project file.
 
Method Summary
 void addToCache(Object frameImplementation, Object algernonFrame)
          Adds a pairing of frames to the frame cache.
 void addToDisplayNameCache(String displayName, AlgernonFrame frame)
          Adds a mapping from a DisplayName to an AlgernonFrame to the display name frame cache.
 boolean canAssignToValueType(Object o, LispValue vt)
          Check if you can assign a Java Object o to a Protege slot having a ValueType vt
 void close()
          Closes a KB.
 boolean containsClause(Clause clause, int state)
          State is Algernon.NEGATED or something else.
 Collection convertFromAlgernon(Collection coll)
          Converts a collection of Algernon objects to a collection of Protege objects, if possible.
 Object convertFromAlgernon(Object obj)
          Converts an Algernon object to a Protege object, if possible.
 Collection convertToAlgernon(Collection coll)
          Converts a collection of Protege objects to a collection of Algernon objects, if possible.
 Object convertToAlgernon(Object obj)
          Converts a Protege object to a ProtegeAlgernon object, if possible.
 AlgernonClass createClass(String frameName, AlgernonClass superclass)
          Creates a new frame in the storage.
 AlgernonClass createClass(String frameName, AlgernonClass superclass, AlgernonClass metaClass)
          Creates a new frame in the storage.
 AlgernonFacet createFacet(String facetName)
          Creates a new facet in the storage.
 AlgernonInstance createInstance(String frameName, AlgernonClass theClass)
          Creates a new instance in the storage.
 AlgernonRelation createRelation(String relationName, LispValue domain, LispValue range, Integer minCardinality, Integer maxCardinality, Object defaultValue, AlgernonRelation inverseRelation)
          Helper method that creates a set around single domain and range to pass into the actual createRelation method.
 AlgernonRelation createRelation(String relationName, Set domains, Set ranges, Integer minCardinality, Integer maxCardinality, Object defaultValue, AlgernonRelation inverseRelation)
          Creates a new relation in this KB.
 void deleteClass(AlgernonClass frame)
          Deletes a frame and all of its relations from storage.
 void deleteClauses(Clause clause)
          Deletes one or more clauses from the storage.
 void deleteClauses(Clause clause, AlgernonFacet facet)
          Deletes one or more clauses from the storage.
 void deleteFacet(AlgernonFacet frame)
          Deletes a frame and all of its relations from storage.
 void deleteFrame(AlgernonFrame frame)
          Deletes a frame and all of its relations from storage.
 void deleteInstance(AlgernonInstance frame)
          Deletes a frame and all of its relations from storage.
 void deleteRelation(AlgernonRelation frame)
          Deletes a relation from storage.
 Collection frameSearch(String searchString)
          Performs a string search within the KB for frames whose name contains the given string.
 Collection frameSearch(String searchString, String nameSlot)
          Performs a string search within the KB for frames whose name contains the given string.
 Collection frameSearch(String searchString, String nameSlot, int limit)
          Performs a string search within the KB for frames whose name contains the given string.
 boolean generalIsa(String child, String parent)
          Returns true if the first argument is an instance or subclass of the second argument in this KB.
 boolean generalNotIsa(String child, String parent)
          Returns true if the first argument is not an instance or subclass of the second argument this KB.
 LispValue getAllFrames()
          Returns a collection of all frames in the KB.
 AlgernonRelation getDisplayNameRelation()
          Get the actual DisplayName slot.
 String getDisplayNameRelationName()
          Get the name of the DisplayName slot.
 AlgernonFrame getFrame(String name)
          Returns a frame with the given name, if any exists.
 AlgernonProtegeObject getFromCache(Object frameImplementation)
          Retrieves a Algernon-level frame or other value given a KBMS-level object as the key.
 AlgernonFrame getFromDisplayNameCache(String displayName)
          Retrieves an Algernon frame from its display name.
 Object getImplementation()
          Returns the KBMS-specific object implementing this interface.
 KnowledgeBase getKb()
           
 String getName()
          Returns the name of this KB as a string.
 AlgernonClass getRootClass()
          Returns a the "first" root class in the KB.
 Collection getRootClasses()
          Returns a Collection of the root classes of the KB.
 String getUserName()
          Returns a String containing the name of the current user of this KB.
 LispValue getValueType(Object o)
          Get the data type of the Java object passed in; we expect this to be Integer, Float, Boolean, Frame, etc., etc
 Collection getValueTypes()
          Returns a collection of AlgernonValueTypes, listing all the value types the kb knows about
 boolean isClass(String frameName)
          Returns the Class if the String is the name of a frame that is a class in the KB.
 boolean isClassToInstanceRelation(String relationName)
          Returns true if the given string is the name of the relation/slot linking a class to its instance in this KB.
 boolean isDisjointRelation(String relationName)
          Always returns false - Protege has no default disjoint relation.
 boolean isFacet(String frameName)
          Returns true if the String is the name of a frame that is a facet in the KB.
 boolean isFrame(String frameName)
          Returns the Frame if the String is the name of a frame in the KB.
 boolean isInstance(String frameName)
          Returns the Instance if the String is the name of a frame that is an instance in the KB.
 boolean isInstanceToClassRelation(String relationName)
          Returns true if the given string is the name of the relation/slot linking an instance to its class in this KB.
 boolean isNameRelation(String relationName)
          Returns true if the string is the name of a NAME relation in this KB.
 boolean isRelation(String frameName)
          Returns the Relation if the String is the name of a frame that is a relation in the KB.
 boolean isSimpleType(AlgernonFrame frame, AlgernonRelation slot)
          Determines if this slot takes an atomic data type value.
 boolean isSimpleType(AlgernonRelation relation)
          Determines if this slot takes an atomic data type value
static boolean isSimpleType(Frame frame, Slot slot)
          Checks the ValueType of slot AT THE CLASS--returns true if it's simple
static boolean isSimpleType(Slot slot)
           
 boolean isSubclassToSuperclassRelation(String relationName)
          Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.
 boolean isSuperclassToSubclassRelation(String relationName)
          Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.
 AlgernonFrame leastCommonSuperclass(AlgernonFrame frame1, AlgernonFrame frame2)
          Returns the most specialized common superclass of the two classes or instances.
 AlgernonClass lookupClass(String name)
          Returns a class with the given name if it can find one in this KB.
 AlgernonFacet lookupFacet(String name)
          Returns a frame with the given name if it can find one in this KB.
 AlgernonFrame lookupFrame(String name)
          Returns a frame with the given name if it can find one in this KB.
 AlgernonInstance lookupInstance(String name)
          Returns a frame with the given name if it can find one in this KB.
 AlgernonInstance lookupInstance(String javaClassName, String name)
          Returns a frame with the given name if it can find one in this KB.
 AlgernonInstance lookupInstance(String javaClassName, String name, String field)
          Returns a frame with the given name if it can find one in this KB.
 AlgernonRelation lookupRelation(String name)
          Returns a relation with the given name if it can find one in this KB.
 AlgernonRelation lookupRelation(String name, Set classes)
          Returns a relation with the given name, if any.
private  boolean myContains(Collection values, LispValue value)
          Needed because ArrayList.contains calls Object.equals() for some bizarre reason rather than LispValue.equals.
protected  KnowledgeBase openKB(String projectFile)
           
 LispValue query(Clause clause)
          Returns all of the values that match the given clause.
 LispValue query(Clause clause, AlgernonFacet facet)
          See the simpler form getValues.
 void removeFromCache(Object frameImplementation)
          Removes a frame from the cache.
 void removeFromDisplayNameCache(String objectName)
          Removes it from the display name cache.
 void reset()
          Resets a KB.
 void save()
          Saves the kb to a file.
 void setDisplayNameRelationName(String relationName)
          Sets the name of the relation (slot) used for "pretty names", "common names", "display names" or whatever you want to call it.
 void setName(String newName)
          Sets the name of the KB.
 LispValue store(Clause clause)
          Asserts the given clause into the storage.
 LispValue store(Clause clause, AlgernonFacet facet)
          Asserts the given clause into the storage.
 boolean supportsNegatedClauses()
          Returns true if this KB supports negated clauses.
 ValueType toValueType(Object range)
          Range should be one of the ranges specified in the Algernon class, such as BOOLEAN_TYPE, STRING_TYPE, etc.
 ValueType valueOf(LispValue typeName)
          Returns the Protege value type for the given named type
 Collection valueSearch(String searchString)
          Performs a string search within the KB for slot values that contain the given string.
 Collection valueSearch(String searchString, Collection frames, Collection slots)
          Performs a string search within the KB for slot values that contain the given string.
 Collection valueSearch(String searchString, Collection frames, Collection slots, int limit)
          Performs a string search within the KB for slot values that contain the given string.
 LispValue verify(Clause clause)
          Verifies that the clause is in the KB.
 
Methods inherited from class org.algernon.kb.okbc.protege.AlgernonProtegeObject
getAlgernon, toString
 
Methods inherited from class org.jatha.dynatype.StandardLispValue
abs, acos, add, adjustSpecialCount, append, apply, apropos_print, asin, assoc, atan, atan2, atom, basic_atom, basic_bignump, basic_consp, basic_constantp, basic_floatp, basic_foreignp, basic_functionp, basic_integerp, basic_keywordp, basic_length, basic_listp, basic_macrop, basic_null, basic_numberp, basic_stringp, basic_symbolp, bignump, boundp, butlast, car, cdr, ceiling, characterp, clrhash, compareTo, concatenate, consp, constantp, contains, copy_list, copy, cos, cot, csc, degreesToRadians, divide, eighth, elt, elt, eq, eql, equal, equalNumeric, factorial, fboundp, fifth, first, floatp, floor, fourth, funcall, functionp, get_specialCount, gethash, gethash, getLisp, greaterThan, greaterThanOrEqual, hash_table_count, hash_table_rehash_size, hash_table_rehash_threshold, hash_table_size, hash_table_test, hashtablep, integerp, internal_getName, internal_prin1_as_cdr, internal_prin1, internal_princ_as_cdr, internal_princ, internal_print_as_cdr, internal_print, iterator, keywordp, last, length, lessThan, lessThanOrEqual, lisp_null, list, listp, max, member, min, multiply, nconc, negate, neql, ninth, nreverse, nstringCapitalize, nstringDowncase, nstringUpcase, numberp, pop, position, prin1, princ, print, push, radiansToDegrees, rassoc, reciprocal, remhash, remove, rest, reverse, rplaca, rplacd, sec, second, set_special, setf_gethash, setf_symbol_function, setf_symbol_plist, setf_symbol_value, setLisp, setPackage, setq, seventh, sin, sixth, specialP, sqrt, string, stringCapitalize, stringDowncase, stringEndsWith, stringEq, stringEqual, stringGreaterP, stringGreaterThan, stringGreaterThanOrEqual, stringLeftTrim, stringLeftTrim, stringLessP, stringLessThan, stringLessThanOrEqual, stringNeq, stringNotGreaterP, stringNotLessP, stringp, stringRightTrim, stringRightTrim, stringStartsWith, stringTrim, stringTrim, stringUpcase, subst, substring, substring, subtract, symbol_function, symbol_name, symbol_package, symbol_plist, symbol_value, symbolp, tan, tenth, third, toCollection, toJava, toJava, toString, toStringAsCdr_internal, toStringAsCdr, toStringShort, toStringShort, toStringSimple, type_of, typep, zerop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

f_kb

protected KnowledgeBase f_kb

f_projectURI

protected URI f_projectURI

f_displayNameRelationName

protected String f_displayNameRelationName

f_displayNameRelation

protected AlgernonProtegeRelation f_displayNameRelation

localCache

protected HashMap localCache

localDisplayNameCache

protected HashMap localDisplayNameCache
Constructor Detail

AlgernonProtegeKB

public AlgernonProtegeKB(Algernon algy)
Creates a new in-memory Protege project. Call setName() after creating one to set the name.


AlgernonProtegeKB

public AlgernonProtegeKB(Algernon algy,
                         String projectFileName)
                  throws AlgernonStorageException
Opens the given Protege project file.


AlgernonProtegeKB

public AlgernonProtegeKB(Algernon algy,
                         KnowledgeBase kb)
Adds a kb that is already open. Useful when running as a Protege tab.

Method Detail

getImplementation

public Object getImplementation()
Returns the KBMS-specific object implementing this interface. Returns a Protege KnowledgeBase object.

Specified by:
getImplementation in interface AlgernonKB

openKB

protected KnowledgeBase openKB(String projectFile)
                        throws AlgernonStorageException
Throws:
AlgernonStorageException

close

public void close()
Closes a KB. The KB should not be readable or writeable after closing.

Specified by:
close in interface AlgernonKB

reset

public void reset()
           throws AlgernonStorageException
Resets a KB. This normally restores it to its initial configuration at the time it was last opened, but is not required to.

Specified by:
reset in interface AlgernonKB
Throws:
AlgernonStorageException

getAllFrames

public LispValue getAllFrames()
Returns a collection of all frames in the KB.

Specified by:
getAllFrames in interface AlgernonKB

getKb

public KnowledgeBase getKb()

getName

public String getName()
Returns the name of this KB as a string.

Specified by:
getName in interface AlgernonKB
Overrides:
getName in class AlgernonProtegeObject

setName

public void setName(String newName)
Sets the name of the KB.

Specified by:
setName in interface AlgernonKB

query

public LispValue query(Clause clause)
                throws AlgernonStorageException,
                       AlgernonException
Returns all of the values that match the given clause. The clause is typically non-ground when this method is called, but it may be ground. If non-ground, it will contains variables. Any parameter may be a variable. If the storage system cannot handle a variable in some position, it should throw an AlgernonUnhandledDataForm exception. For example, Algernon requires that the first two parameters be ground. In a frame system, the first parameter of the clause corresponds to the Slot and the second parameter corresponds to the Frame. The second form of this method specifies a facet to use. This may only be valid for some storage systems.

Specified by:
query in interface AlgernonKB
Returns:
a LISP list of Clauses from storage that match the input clause. If none match, return LispValue.NIL.
Throws:
AlgernonStorageException
AlgernonException
See Also:
Clause

query

public LispValue query(Clause clause,
                       AlgernonFacet facet)
                throws AlgernonStorageException,
                       AlgernonDataException
See the simpler form getValues. This extends it to indicate a facet to be used in retrieval. NOT YET IMPLEMENTED.

Specified by:
query in interface AlgernonKB
Returns:
a LISP list of Clauses from storage that match the input clause. If none match, return LispValue.NIL.
Throws:
AlgernonStorageException
AlgernonDataException

frameSearch

public Collection frameSearch(String searchString)
                       throws AlgernonStorageException
Performs a string search within the KB for frames whose name contains the given string. If the backend KB is case sensitive, this search is case sensitive. If nameSlot is null, the KB can choose which slot to search. Otherwise, provide the name of a slot whose value should be compared with the search string. Note that this method can actually be used to search on any slot - it doesn't have to be a name slot. The return value is a Collection of frames whose name contains the given string. Returns null if the KB implementation does not support string search of frame names.

Specified by:
frameSearch in interface AlgernonKB
Parameters:
searchString - a string that must be contained in the value
Returns:
A Collection of AlgernonFrame instances, or null if the KB doesn't support search.
Throws:
AlgernonStorageException
See Also:
valueSearch(java.lang.String)

frameSearch

public Collection frameSearch(String searchString,
                              String nameSlot)
                       throws AlgernonStorageException
Performs a string search within the KB for frames whose name contains the given string. If the backend KB is case sensitive, this search is case sensitive. If nameSlot is null, the KB can choose which slot to search. Otherwise, provide the name of a slot whose value should be compared with the search string. Note that this method can actually be used to search on any slot - it doesn't have to be a name slot. The return value is a Collection of frames whose name contains the given string. Returns null if the KB implementation does not support string search of frame names.

Specified by:
frameSearch in interface AlgernonKB
Parameters:
searchString - a string that must be contained in the value
nameSlot - an optional slot to be used as the search value. Enter null to use the default slot.
Returns:
A Collection of AlgernonFrame instances, or null if the KB doesn't support search.
Throws:
AlgernonStorageException
See Also:
valueSearch(java.lang.String)

frameSearch

public Collection frameSearch(String searchString,
                              String nameSlot,
                              int limit)
                       throws AlgernonStorageException
Performs a string search within the KB for frames whose name contains the given string. If the backend KB is case sensitive, this search is case sensitive. If nameSlot is null, the KB can choose which slot to search. Otherwise, provide the name of a slot whose value should be compared with the search string. Note that this method can actually be used to search on any slot - it doesn't have to be a name slot. The return value is a Collection of frames whose name contains the given string. Returns null if the KB implementation does not support string search of frame names.

Specified by:
frameSearch in interface AlgernonKB
Parameters:
searchString - a string that must be contained in the value
nameSlot - an optional slot to be used as the search value. Enter null to use the default slot.
limit - a limit on the number of frames to return. Use -1 for unlimited.
Returns:
A Collection of AlgernonFrame instances, or null if the KB doesn't support search.
Throws:
AlgernonStorageException
See Also:
valueSearch(java.lang.String)

valueSearch

public Collection valueSearch(String searchString)
                       throws AlgernonStorageException
Performs a string search within the KB for slot values that contain the given string. If the backend KB is case sensitive, this search is case sensitive. When the value is a frame, its name is compared to the search string. If the slots and frames arguments are null, all slots on all frames are searched. Slots may be a collection of strings (slot names) or instances of AlgernonSlot. If it is not null, only those slots are searched. If it is null, all slots are searched. Frames may be a collection of strings (frame names) or instances of AlgernonFrame. If it is not null, only those frames are searched. If it is null, all frames are searched. The return value is a Collection of frames that have a slot whose value satisfies the given string. Each frame occurs only once in the returned collection. Returns null if the KB implementation does not support string search of slot values.

Specified by:
valueSearch in interface AlgernonKB
Parameters:
searchString - a string that must be contained in the value
Returns:
a Collection of AlgernonFrame instances, or null if the KB doesn't support the search.
Throws:
AlgernonStorageException
See Also:
frameSearch(java.lang.String)

valueSearch

public Collection valueSearch(String searchString,
                              Collection frames,
                              Collection slots)
                       throws AlgernonStorageException
Performs a string search within the KB for slot values that contain the given string. If the backend KB is case sensitive, this search is case sensitive. When the value is a frame, its name is compared to the search string. If the slots and frames arguments are null, all slots on all frames are searched. Slots may be a collection of strings (slot names) or instances of AlgernonSlot. If it is not null, only those slots are searched. If it is null, all slots are searched. Frames may be a collection of strings (frame names) or instances of AlgernonFrame. If it is not null, only those frames are searched. If it is null, all frames are searched. The return value is a Collection of frames that have a slot whose value satisfies the given string. Each frame occurs only once in the returned collection. Returns null if the KB implementation does not support string search of slot values.

Specified by:
valueSearch in interface AlgernonKB
Parameters:
searchString - a string that must be contained in the value
frames - an optional Collection of frames or frame names to be searched
slots - an optional Collection of slots or slot names to be searched
Returns:
a Collection of AlgernonFrame instances, or null if the KB doesn't support the search.
Throws:
AlgernonStorageException
See Also:
frameSearch(java.lang.String)

valueSearch

public Collection valueSearch(String searchString,
                              Collection frames,
                              Collection slots,
                              int limit)
                       throws AlgernonStorageException
Performs a string search within the KB for slot values that contain the given string. If the backend KB is case sensitive, this search is case sensitive. When the value is a frame, its name is compared to the search string. If the slots and frames arguments are null, all slots on all frames are searched. Slots may be a collection of strings (slot names) or instances of AlgernonSlot. If it is not null, only those slots are searched. If it is null, all slots are searched. Frames may be a collection of strings (frame names) or instances of AlgernonFrame. If it is not null, only those frames are searched. If it is null, all frames are searched. The return value is a Collection of frames that have a slot whose value satisfies the given string. Each frame occurs only once in the returned collection. Returns null if the KB implementation does not support string search of slot values.

Specified by:
valueSearch in interface AlgernonKB
Parameters:
searchString - a string that must be contained in the value
frames - an optional Collection of frames or frame names to be searched
slots - an optional Collection of slots or slot names to be searched
limit - a limit on the number of frames to return. Use -1 for unlimited.
Returns:
a Collection of AlgernonFrame instances, or null if the KB doesn't support the search.
Throws:
AlgernonStorageException
See Also:
frameSearch(java.lang.String)

verify

public LispValue verify(Clause clause)
                 throws AlgernonStorageException,
                        AlgernonDataException
Verifies that the clause is in the KB. Returns null if the relation is not in this KB. Otherwise returns AlgernonKB.SUCCESS or AlgernonKb.FAIL.

Specified by:
verify in interface AlgernonKB
Throws:
AlgernonStorageException
AlgernonDataException

myContains

private boolean myContains(Collection values,
                           LispValue value)
Needed because ArrayList.contains calls Object.equals() for some bizarre reason rather than LispValue.equals.


getRootClass

public AlgernonClass getRootClass()
Returns a the "first" root class in the KB. This may not correspond to the order in which they were added. This is most useful for a frame-based storage system. If it is not meaningful for the given storage system, it may be useful to return null or a list of all concepts.

Specified by:
getRootClass in interface AlgernonKB

getRootClasses

public Collection getRootClasses()
Returns a Collection of the root classes of the KB. This is most useful for a frame-based storage system. If it is not meaningful for the given storage system, it may be useful to return NIL or a list of all concepts.

Specified by:
getRootClasses in interface AlgernonKB

getUserName

public String getUserName()
Returns a String containing the name of the current user of this KB. If not meaningful, return "guest" or a similar string.

Specified by:
getUserName in interface AlgernonKB

store

public LispValue store(Clause clause)
                throws AlgernonStorageException,
                       AlgernonDataException
Asserts the given clause into the storage. The clause is typically ground. Most storage systems will throw an exception if it is not. Returns either AlgernonKB.SUCCESS, AlgernonKB.KNOWN or AlgernonKB.FAIL Return KNOWN if it was already in storage.

Specified by:
store in interface AlgernonKB
Throws:
AlgernonStorageException
AlgernonDataException

store

public LispValue store(Clause clause,
                       AlgernonFacet facet)
                throws AlgernonStorageException,
                       AlgernonDataException
Asserts the given clause into the storage. The clause is typically ground. Most storage systems will throw an exception if it is not. Returns either AlgernonKB.SUCCESS, AlgernonKB.KNOWN or AlgernonKB.FAIL Return KNOWN if it was already in storage.

NOT YET IMPLEMENTED.

Specified by:
store in interface AlgernonKB
Throws:
AlgernonStorageException
AlgernonDataException

createClass

public AlgernonClass createClass(String frameName,
                                 AlgernonClass superclass)
                          throws AlgernonRuntimeException
Creates a new frame in the storage. Non frame-based systems must implement some mechanism for handling this method intelligently. For example, a concept in the KB could be created.

Specified by:
createClass in interface AlgernonKB
Returns:
the frame that was created.
Throws:
AlgernonRuntimeException

createClass

public AlgernonClass createClass(String frameName,
                                 AlgernonClass superclass,
                                 AlgernonClass metaClass)
                          throws AlgernonRuntimeException
Creates a new frame in the storage. Non frame-based systems must implement some mechanism for handling this method intelligently. For example, a concept in the KB could be created. Throws an AlgernonRuntimeException if any exception occurs.

Specified by:
createClass in interface AlgernonKB
Returns:
the frame that was created.
Throws:
AlgernonRuntimeException

createFacet

public AlgernonFacet createFacet(String facetName)
Creates a new facet in the storage. Systems that don't normally contain facets must implement some mechanism for handling them intelligently. For example, a separate storage area could be opened for each facet. If the given name is in use by another facet, do not do anything, just return the existing facet.

Specified by:
createFacet in interface AlgernonKB
Returns:
the facet that was created.

createInstance

public AlgernonInstance createInstance(String frameName,
                                       AlgernonClass theClass)
Creates a new instance in the storage. Non frame-based systems must implement some mechanism for handling this method intelligently. For example, a concept in the KB could be created.

Specified by:
createInstance in interface AlgernonKB
Returns:
the frame that was created.

createRelation

public AlgernonRelation createRelation(String relationName,
                                       LispValue domain,
                                       LispValue range,
                                       Integer minCardinality,
                                       Integer maxCardinality,
                                       Object defaultValue,
                                       AlgernonRelation inverseRelation)
                                throws AlgernonDataException
Helper method that creates a set around single domain and range to pass into the actual createRelation method.

Specified by:
createRelation in interface AlgernonKB
Throws:
AlgernonDataException

createRelation

public AlgernonRelation createRelation(String relationName,
                                       Set domains,
                                       Set ranges,
                                       Integer minCardinality,
                                       Integer maxCardinality,
                                       Object defaultValue,
                                       AlgernonRelation inverseRelation)
                                throws AlgernonDataException
Creates a new relation in this KB. The set of domains must contain one or more AlgernonClass instances. The set of ranges can contain AlgernonValueType instances or AlgernonClass instances. This backend has minimal support for multiple domains and relations as of yet. It creates a slot for every domain, but returns only the last one created.

Specified by:
createRelation in interface AlgernonKB
Returns:
the relation that was created.
Throws:
AlgernonDataException

deleteClass

public void deleteClass(AlgernonClass frame)
                 throws AlgernonException
Deletes a frame and all of its relations from storage.

Specified by:
deleteClass in interface AlgernonKB
Throws:
AlgernonException

deleteFacet

public void deleteFacet(AlgernonFacet frame)
                 throws AlgernonException
Deletes a frame and all of its relations from storage.

Specified by:
deleteFacet in interface AlgernonKB
Throws:
AlgernonException

deleteFrame

public void deleteFrame(AlgernonFrame frame)
                 throws AlgernonException
Deletes a frame and all of its relations from storage.

Specified by:
deleteFrame in interface AlgernonKB
Throws:
AlgernonException

deleteInstance

public void deleteInstance(AlgernonInstance frame)
                    throws AlgernonException
Deletes a frame and all of its relations from storage.

Specified by:
deleteInstance in interface AlgernonKB
Throws:
AlgernonException

deleteRelation

public void deleteRelation(AlgernonRelation frame)
                    throws AlgernonException
Deletes a relation from storage.

Specified by:
deleteRelation in interface AlgernonKB
Throws:
AlgernonException

deleteClauses

public void deleteClauses(Clause clause)
Deletes one or more clauses from the storage. If the clause is unground, the storage system should do a query to ground it, then delete all the clauses that match the query clause. If the clause is ground, just delete that clause. Another form of this method takes a facet argument.

Specified by:
deleteClauses in interface AlgernonKB

deleteClauses

public void deleteClauses(Clause clause,
                          AlgernonFacet facet)
Deletes one or more clauses from the storage. If the clause is unground, the storage system should do a query to ground it, then delete all the clauses that match the query clause. If the clause is ground, just delete that clause. Another form of this method takes a facet argument.

Specified by:
deleteClauses in interface AlgernonKB

isClass

public boolean isClass(String frameName)
                throws AlgernonDataException
Returns the Class if the String is the name of a frame that is a class in the KB.

Specified by:
isClass in interface AlgernonKB
Throws:
AlgernonDataException

isFacet

public boolean isFacet(String frameName)
                throws AlgernonDataException
Returns true if the String is the name of a frame that is a facet in the KB.

Specified by:
isFacet in interface AlgernonKB
Throws:
AlgernonDataException

isInstance

public boolean isInstance(String frameName)
                   throws AlgernonDataException
Returns the Instance if the String is the name of a frame that is an instance in the KB.

Specified by:
isInstance in interface AlgernonKB
Throws:
AlgernonDataException

isFrame

public boolean isFrame(String frameName)
                throws AlgernonDataException
Returns the Frame if the String is the name of a frame in the KB.

Specified by:
isFrame in interface AlgernonKB
Throws:
AlgernonDataException

isRelation

public boolean isRelation(String frameName)
                   throws AlgernonDataException
Returns the Relation if the String is the name of a frame that is a relation in the KB.

Specified by:
isRelation in interface AlgernonKB
Throws:
AlgernonDataException

convertToAlgernon

public Collection convertToAlgernon(Collection coll)
Converts a collection of Protege objects to a collection of Algernon objects, if possible.

Specified by:
convertToAlgernon in interface AlgernonKB

convertToAlgernon

public Object convertToAlgernon(Object obj)
Converts a Protege object to a ProtegeAlgernon object, if possible.

Specified by:
convertToAlgernon in interface AlgernonKB

convertFromAlgernon

public Collection convertFromAlgernon(Collection coll)
Converts a collection of Algernon objects to a collection of Protege objects, if possible.

Specified by:
convertFromAlgernon in interface AlgernonKB

convertFromAlgernon

public Object convertFromAlgernon(Object obj)
Converts an Algernon object to a Protege object, if possible.

Specified by:
convertFromAlgernon in interface AlgernonKB

getValueTypes

public Collection getValueTypes()
Returns a collection of AlgernonValueTypes, listing all the value types the kb knows about


valueOf

public ValueType valueOf(LispValue typeName)
Returns the Protege value type for the given named type

Specified by:
valueOf in interface AlgernonKB

getValueType

public LispValue getValueType(Object o)
Get the data type of the Java object passed in; we expect this to be Integer, Float, Boolean, Frame, etc., etc

Specified by:
getValueType in interface AlgernonKB

canAssignToValueType

public boolean canAssignToValueType(Object o,
                                    LispValue vt)
Check if you can assign a Java Object o to a Protege slot having a ValueType vt

Specified by:
canAssignToValueType in interface AlgernonKB

isSimpleType

public static boolean isSimpleType(Slot slot)

isSimpleType

public boolean isSimpleType(AlgernonRelation relation)
Determines if this slot takes an atomic data type value

Specified by:
isSimpleType in interface AlgernonKB

isSimpleType

public static boolean isSimpleType(Frame frame,
                                   Slot slot)
Checks the ValueType of slot AT THE CLASS--returns true if it's simple


isSimpleType

public boolean isSimpleType(AlgernonFrame frame,
                            AlgernonRelation slot)
Determines if this slot takes an atomic data type value. Frame is ignored

Specified by:
isSimpleType in interface AlgernonKB
Parameters:
frame - ignored
slot - its implementation's value type is checked.

addToCache

public void addToCache(Object frameImplementation,
                       Object algernonFrame)
Adds a pairing of frames to the frame cache. The key is the KBMS-level frame instance, such as a Protege frame. The value is the Algernon-level frame instance. KBMS-level frame instances should hash to the same value and should be equal() if they represent the same frame. This cache saves memory allocation at the Algernon level. Since the parameters are Objects, this can be used to cache other things (such as value types) rather than just frames.

Parameters:
frameImplementation - The KBMS-level (e.g. Protege) instance
algernonFrame - The Algernon equivalent.

getFromCache

public AlgernonProtegeObject getFromCache(Object frameImplementation)
Retrieves a Algernon-level frame or other value given a KBMS-level object as the key. See the documentation on putInCache. Returns null if the object is not in the cache or if the cache is not in use.

Parameters:
frameImplementation - The KBMS-level (e.g. Protege) instance

removeFromCache

public void removeFromCache(Object frameImplementation)
Removes a frame from the cache. Call this after deleting a frame.


removeFromDisplayNameCache

public void removeFromDisplayNameCache(String objectName)
Removes it from the display name cache.

Parameters:
objectName -

isNameRelation

public boolean isNameRelation(String relationName)
Returns true if the string is the name of a NAME relation in this KB.

Specified by:
isNameRelation in interface AlgernonKB

isInstanceToClassRelation

public boolean isInstanceToClassRelation(String relationName)
Returns true if the given string is the name of the relation/slot linking an instance to its class in this KB.

Specified by:
isInstanceToClassRelation in interface AlgernonKB

isClassToInstanceRelation

public boolean isClassToInstanceRelation(String relationName)
Returns true if the given string is the name of the relation/slot linking a class to its instance in this KB.

Specified by:
isClassToInstanceRelation in interface AlgernonKB

isSubclassToSuperclassRelation

public boolean isSubclassToSuperclassRelation(String relationName)
Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.

Specified by:
isSubclassToSuperclassRelation in interface AlgernonKB

isSuperclassToSubclassRelation

public boolean isSuperclassToSubclassRelation(String relationName)
Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.

Specified by:
isSuperclassToSubclassRelation in interface AlgernonKB

isDisjointRelation

public boolean isDisjointRelation(String relationName)
Always returns false - Protege has no default disjoint relation.

Specified by:
isDisjointRelation in interface AlgernonKB

generalIsa

public boolean generalIsa(String child,
                          String parent)
                   throws AlgernonDataException
Returns true if the first argument is an instance or subclass of the second argument in this KB. Both arguments must be frames.

Specified by:
generalIsa in interface AlgernonKB
Throws:
AlgernonDataException

generalNotIsa

public boolean generalNotIsa(String child,
                             String parent)
Returns true if the first argument is not an instance or subclass of the second argument this KB. Both arguments must be frames.

Specified by:
generalNotIsa in interface AlgernonKB

lookupClass

public AlgernonClass lookupClass(String name)
                          throws AlgernonDataException
Returns a class with the given name if it can find one in this KB. Otherwise returns null.

Specified by:
lookupClass in interface AlgernonKB
Throws:
AlgernonDataException

lookupFacet

public AlgernonFacet lookupFacet(String name)
                          throws AlgernonDataException
Returns a frame with the given name if it can find one in this KB. Otherwise returns null.

Specified by:
lookupFacet in interface AlgernonKB
Throws:
AlgernonDataException

lookupFrame

public AlgernonFrame lookupFrame(String name)
                          throws AlgernonDataException
Returns a frame with the given name if it can find one in this KB. Otherwise returns null.

Specified by:
lookupFrame in interface AlgernonKB
Throws:
AlgernonDataException

lookupInstance

public AlgernonInstance lookupInstance(String name)
                                throws AlgernonDataException
Returns a frame with the given name if it can find one in this KB. Otherwise returns null.

Specified by:
lookupInstance in interface AlgernonKB
Throws:
AlgernonDataException

lookupInstance

public AlgernonInstance lookupInstance(String javaClassName,
                                       String name)
                                throws AlgernonDataException
Returns a frame with the given name if it can find one in this KB. Otherwise returns null.

Specified by:
lookupInstance in interface AlgernonKB
Throws:
AlgernonDataException

lookupInstance

public AlgernonInstance lookupInstance(String javaClassName,
                                       String name,
                                       String field)
                                throws AlgernonDataException
Returns a frame with the given name if it can find one in this KB. Otherwise returns null.

Specified by:
lookupInstance in interface AlgernonKB
Throws:
AlgernonDataException

lookupRelation

public AlgernonRelation lookupRelation(String name)
                                throws AlgernonDataException
Returns a relation with the given name if it can find one in this KB. Otherwise returns null.

Specified by:
lookupRelation in interface AlgernonKB
Throws:
AlgernonDataException

lookupRelation

public AlgernonRelation lookupRelation(String name,
                                       Set classes)
                                throws AlgernonDataException
Description copied from interface: AlgernonKB
Returns a relation with the given name, if any. The set is a list of classes to look on for the relation, before looking at the KB in general. This is because some KBMS, such as Protege, allow slots to be redefined at a specific class.

Specified by:
lookupRelation in interface AlgernonKB
Throws:
AlgernonDataException

getFrame

public AlgernonFrame getFrame(String name)
                       throws AlgernonDataException
Returns a frame with the given name, if any exists. Searches both the standard Protege name and the DisplayName slot, if given. Searches the KB for a frame matching the displayName string passed in. If none found, returns null. There should never be more than one matching frame. If more than one is found, returns null. If one frame found, it returns that frame.

Specified by:
getFrame in interface AlgernonKB
Throws:
AlgernonDataException

getFromDisplayNameCache

public AlgernonFrame getFromDisplayNameCache(String displayName)
Retrieves an Algernon frame from its display name. See the documentation on addToDisplayNameCache. Returns null if the object is not in the cache or if the cache is not in use.

Parameters:
displayName - The display name of a frame.
See Also:
AlgernonFrame, AlgernonKB

addToDisplayNameCache

public void addToDisplayNameCache(String displayName,
                                  AlgernonFrame frame)
Adds a mapping from a DisplayName to an AlgernonFrame to the display name frame cache. The key is a string. The value is the Algernon-level frame instance. This cache saves KB references. If a frame's display name is modified, the entry in this cache should be removed.

Parameters:
displayName - The display name of the frame.
frame - The Algernon frame.
See Also:
AlgernonFrame, AlgernonKB

getDisplayNameRelationName

public String getDisplayNameRelationName()
Get the name of the DisplayName slot.

Specified by:
getDisplayNameRelationName in interface AlgernonKB

getDisplayNameRelation

public AlgernonRelation getDisplayNameRelation()
                                        throws AlgernonDataException
Get the actual DisplayName slot.

Specified by:
getDisplayNameRelation in interface AlgernonKB
Throws:
AlgernonDataException

setDisplayNameRelationName

public void setDisplayNameRelationName(String relationName)
Sets the name of the relation (slot) used for "pretty names", "common names", "display names" or whatever you want to call it. The :NAME slot in Protege often has an ugly name in it. If you set this, Algernon will be able to look up frames by their pretty name.

Specified by:
setDisplayNameRelationName in interface AlgernonKB

save

public void save()
          throws AlgernonStorageException
Saves the kb to a file.

Specified by:
save in interface AlgernonKB
Throws:
AlgernonStorageException

supportsNegatedClauses

public boolean supportsNegatedClauses()
Description copied from interface: AlgernonKB
Returns true if this KB supports negated clauses.

Specified by:
supportsNegatedClauses in interface AlgernonKB

leastCommonSuperclass

public AlgernonFrame leastCommonSuperclass(AlgernonFrame frame1,
                                           AlgernonFrame frame2)
Returns the most specialized common superclass of the two classes or instances. Returns null if there is none.

Specified by:
leastCommonSuperclass in interface AlgernonKB

containsClause

public boolean containsClause(Clause clause,
                              int state)
                       throws AlgernonDataException
State is Algernon.NEGATED or something else.

Specified by:
containsClause in interface AlgernonKB
Parameters:
clause -
state - is Algernon.NEGATED or something else.
Throws:
AlgernonDataException

toValueType

public ValueType toValueType(Object range)
Range should be one of the ranges specified in the Algernon class, such as BOOLEAN_TYPE, STRING_TYPE, etc.

Parameters:
range -

Algernon Software