org.jscience.linguistics.kif
Class KB

java.lang.Object
  extended by org.jscience.linguistics.kif.KB

public class KB
extends java.lang.Object

**************************************************************** Contains methods for reading, writing knowledge bases and their configurations. Also contains the inference engine process for the knowledge base.


Field Summary
 CELT celt
          The instance of the CELT process.
 java.util.HashMap children
          A HashMap of ArrayLists, which contain all the child classes of a given class.
 java.util.ArrayList constituents
          An ArrayList of Strings which are the full path file names of the files which comprise the KB.
 java.util.HashMap disjoint
          A HashMap of ArrayLists, which contain all the disjoint classes of a given class.
 Vampire inferenceEngine
          The inference engine process for this KB.
 java.lang.String kbDir
          The location of preprocessed KIF files, suitable for loading into Vampire.
 java.lang.String language
          The natural language in which axiom paraphrases should be presented.
 java.lang.String name
          The name of the knowledge base.
 java.util.HashMap parents
          A HashMap of ArrayLists, which contain all the parent classes of a given class.
 java.util.TreeSet terms
          A Set of Strings, which are all the terms in the KB.
 
Constructor Summary
KB(java.lang.String n, java.lang.String dir)
          ************************************************************ Constructor which takes the name of the KB and the location where KBs preprocessed for Vampire should be placed.
 
Method Summary
 void addConstituent(java.lang.String filename)
          ************************************************************ Add a new KB constituent by reading in the file, and then merging the formulas with the existing set of formulas.
 java.util.ArrayList ask(java.lang.String kind, int argnum, java.lang.String term)
          ************************************************************ Get an ArrayList which are the Formulas the match the request.
 java.util.ArrayList askWithRestriction(int argnum1, java.lang.String term1, int argnum2, java.lang.String term2)
          ************************************************************ Get an ArrayList of Formulas in which the two terms provided appear in the indicated argument positions.
 java.util.ArrayList availableLanguages()
          ************************************************************ Get an ArrayList of Strings containing the language identifiers of available natural language formatting templates.
 void cache()
          ************************************************************ Cache subclass and instance statements in the knowledge base.
 boolean containsTerm(java.lang.String term)
          ************************************************************** Take a term and return whether the term exists in the knowledge base.
 void deleteUserAssertions()
          ************************************************************** Delete the user assertions file.
 java.lang.String formatDocumentation(java.lang.String href, java.lang.String documentation)
          ************************************************************ Hyperlink terms identified with '&%' to the URL that brings up that term in the browser.
 int getCountAxioms()
          ************************************************************** Count the number of formulas in the knowledge base in order to present statistics to the user.
 int getCountRules()
          ************************************************************** Count the number of rules in the knowledge base in order to present statistics to the user.
 int getCountTerms()
          ************************************************************** Count the number of terms in the knowledge base in order to present statistics to the user.
 java.util.HashMap getFormatMap(java.lang.String lang)
          ************************************************************** This method creates an association list (Map) of the natural language format string and the relation name for which that format string applies.
 java.util.TreeSet getFormulas()
          ************************************************************** an accessor providing a TreeSet of un-preProcess-ed Formula.
 java.util.ArrayList getNearestNonRelations(java.lang.String term)
          ************************************************************** Get the neighbors of this initial lowercase term (relation).
 java.util.ArrayList getNearestRelations(java.lang.String term)
          ************************************************************** Get the neighbors of this initial uppercase term (class or function).
 java.util.HashMap getTermFormatMap(java.lang.String lang)
          ************************************************************** This method creates an association list (Map) of the natural language string and the term for which that format string applies.
static void main(java.lang.String[] args)
          ************************************************************ A test method.
 java.util.TreeSet preProcess(java.util.TreeSet forms)
          ************************************************************** Preprocess a the knowledge base to work with Vampire.
 void reload()
          ************************************************************** Reload all the KB constituents.
 java.lang.String tell(java.lang.String formula)
          ************************************************************ Add a formula to the knowledge base.
 void writeConfiguration(java.io.PrintWriter pw)
          ************************************************************ Write the XML configuration file.
 void writeFile(java.lang.String fname)
          ************************************************************** Write a KIF file.
 java.lang.String writeInferenceEngineFormulas(java.util.TreeSet forms)
          ************************************************************ Save the contents of the current KB to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inferenceEngine

public Vampire inferenceEngine
The inference engine process for this KB.


name

public java.lang.String name
The name of the knowledge base.


constituents

public java.util.ArrayList constituents
An ArrayList of Strings which are the full path file names of the files which comprise the KB.


language

public java.lang.String language
The natural language in which axiom paraphrases should be presented.


kbDir

public java.lang.String kbDir
The location of preprocessed KIF files, suitable for loading into Vampire.


parents

public java.util.HashMap parents
A HashMap of ArrayLists, which contain all the parent classes of a given class.


children

public java.util.HashMap children
A HashMap of ArrayLists, which contain all the child classes of a given class.


disjoint

public java.util.HashMap disjoint
A HashMap of ArrayLists, which contain all the disjoint classes of a given class.


celt

public CELT celt
The instance of the CELT process.


terms

public java.util.TreeSet terms
A Set of Strings, which are all the terms in the KB.

Constructor Detail

KB

public KB(java.lang.String n,
          java.lang.String dir)
************************************************************ Constructor which takes the name of the KB and the location where KBs preprocessed for Vampire should be placed.

Method Detail

availableLanguages

public java.util.ArrayList availableLanguages()
************************************************************ Get an ArrayList of Strings containing the language identifiers of available natural language formatting templates.

Returns:
an ArrayList of Strings containing the language identifiers

cache

public void cache()
************************************************************ Cache subclass and instance statements in the knowledge base.


askWithRestriction

public java.util.ArrayList askWithRestriction(int argnum1,
                                              java.lang.String term1,
                                              int argnum2,
                                              java.lang.String term2)
************************************************************ Get an ArrayList of Formulas in which the two terms provided appear in the indicated argument positions.


ask

public java.util.ArrayList ask(java.lang.String kind,
                               int argnum,
                               java.lang.String term)
************************************************************ Get an ArrayList which are the Formulas the match the request.

Parameters:
kind - - May be one of "ant", "cons", "stmt", or "arg", @see KIF.createKey()
term - - The term that appears in the statements being requested.
argnum - - The argument position of the term being asked for. The first argument after the predicate is "1". This parameter is ignored if the kind is "ant", "cons" or "stmt".
Returns:
an ArrayList of Formula(s), or null if no match found.

tell

public java.lang.String tell(java.lang.String formula)
************************************************************ Add a formula to the knowledge base. Returns an XML formatted String that contains the response of the inference engine. It should be in the form "..." where the body should be " Formula has been added to the session database" if all went well.


containsTerm

public boolean containsTerm(java.lang.String term)
************************************************************** Take a term and return whether the term exists in the knowledge base.


getCountTerms

public int getCountTerms()
************************************************************** Count the number of terms in the knowledge base in order to present statistics to the user.

Returns:
The int(eger) number of terms in the knowledge base.

getCountAxioms

public int getCountAxioms()
************************************************************** Count the number of formulas in the knowledge base in order to present statistics to the user.

Returns:
The int(eger) number of formulas in the knowledge base.

getFormulas

public java.util.TreeSet getFormulas()
************************************************************** an accessor providing a TreeSet of un-preProcess-ed Formula.

Returns:
A Treeset of un-preProcess(ed) formulas.

getCountRules

public int getCountRules()
************************************************************** Count the number of rules in the knowledge base in order to present statistics to the user. Note that the number of rules is a subset of the number of formulas.

Returns:
The int(eger) number of rules in the knowledge base.

getNearestRelations

public java.util.ArrayList getNearestRelations(java.lang.String term)
************************************************************** Get the neighbors of this initial uppercase term (class or function).


getNearestNonRelations

public java.util.ArrayList getNearestNonRelations(java.lang.String term)
************************************************************** Get the neighbors of this initial lowercase term (relation).


getFormatMap

public java.util.HashMap getFormatMap(java.lang.String lang)
************************************************************** This method creates an association list (Map) of the natural language format string and the relation name for which that format string applies. If the map has already been built and the language hasn't changed, just return the existing map. This is a case of "lazy evaluation".

Returns:
An instance of Map where the keys are relation names and the values are format strings.

deleteUserAssertions

public void deleteUserAssertions()
************************************************************** Delete the user assertions file.


getTermFormatMap

public java.util.HashMap getTermFormatMap(java.lang.String lang)
************************************************************** This method creates an association list (Map) of the natural language string and the term for which that format string applies. If the map has already been built and the language hasn't changed, just return the existing map. This is a case of "lazy evaluation".

Returns:
An instance of Map where the keys are terms and the values are format strings.

addConstituent

public void addConstituent(java.lang.String filename)
                    throws java.io.IOException,
                           java.text.ParseException
************************************************************ Add a new KB constituent by reading in the file, and then merging the formulas with the existing set of formulas.

Parameters:
filename - - the full path of the file being added.
Throws:
java.io.IOException
java.text.ParseException

reload

public void reload()
************************************************************** Reload all the KB constituents.


writeFile

public void writeFile(java.lang.String fname)
               throws java.io.IOException
************************************************************** Write a KIF file.

Parameters:
fname - - the name of the file to write, including full path.
Throws:
java.io.IOException

writeConfiguration

public void writeConfiguration(java.io.PrintWriter pw)
************************************************************ Write the XML configuration file.


formatDocumentation

public java.lang.String formatDocumentation(java.lang.String href,
                                            java.lang.String documentation)
************************************************************ Hyperlink terms identified with '&%' to the URL that brings up that term in the browser. Handle (and ignore) suffixes on the term. For example "&%Processes" would get properly linked to the term "Process", if present in the knowledge base.


writeInferenceEngineFormulas

public java.lang.String writeInferenceEngineFormulas(java.util.TreeSet forms)
                                              throws java.io.IOException
************************************************************ Save the contents of the current KB to a file.

Throws:
java.io.IOException

preProcess

public java.util.TreeSet preProcess(java.util.TreeSet forms)
************************************************************** Preprocess a the knowledge base to work with Vampire. This includes "holds" prefixing, ticking nested formulas, expanding row variables, and translating mathematical relation operators.

Returns:
a TreeSet of Strings.

main

public static void main(java.lang.String[] args)
************************************************************ A test method.