Class KBmanager

java.lang.Object
com.articulate.sigma.KBmanager
All Implemented Interfaces:
Serializable

public class KBmanager extends Object implements Serializable
This is a class that manages a group of knowledge bases. It should only have one instance, contained in its own static member variable.
See Also:
  • Field Details

    • CONFIG_KEYS

      public static final List<String> CONFIG_KEYS
      Master key cache for the config
    • FILE_KEYS

      public static final List<String> FILE_KEYS
      Master file key cache for the config
    • CONFIG_FILE

      protected static final String CONFIG_FILE
      See Also:
    • KB_MANAGER_SER

      protected static final String KB_MANAGER_SER
      See Also:
    • prefOverride

      public static Map<String,String> prefOverride
    • initialized

      public static boolean initialized
    • initializing

      public static boolean initializing
    • debug

      public static boolean debug
    • prover

      public KBmanager.Prover prover
    • kbs

      public Map<String,KB> kbs
  • Constructor Details

    • KBmanager

      public KBmanager()
  • Method Details

    • setError

      public void setError(String er)
      Set an error string for file loading.
    • getError

      public String getError()
      Get the error string for file loading.
    • serializedExists

      public static boolean serializedExists()
      Check whether sources are newer than serialized version.
    • serializedOld

      public static boolean serializedOld(SimpleElement configuration)
      Check whether sources are newer than serialized version.
    • infFileOld

      public boolean infFileOld(String lang)
      Check whether config file or any .kif constituent is newer than its corresponding TPTP/TFF/THF file
    • infBaseFileOldIgnoringUserAssertions

      public boolean infBaseFileOldIgnoringUserAssertions(String lang)
    • infFileOld

      public boolean infFileOld()
      Check whether config file or any .kif constituent is newer than its corresponding TPTP/TFF/THF file
    • loadSerialized

      public static boolean loadSerialized()
      Load the most recently saved serialized version.
    • encoder

      public static void encoder(Object object)
    • decoder

      public static <T> T decoder()
    • serialize

      public static void serialize()
      save serialized version.
    • setDefaultAttributes

      public void setDefaultAttributes()
      Set default attribute values if not in the configuration file.
    • initiateCCheck

      public static CCheckManager.CCheckStatus initiateCCheck(KB kb, String chosenEngine, String systemChosen, String location, String language, int timeout)
    • ccheckResults

      public static String ccheckResults(String kbName)
    • ccheckStatus

      public static CCheckManager.CCheckStatus ccheckStatus(String kbName)
    • loadKBforInference

      public void loadKBforInference(KB kb)
    • loadKB

      public boolean loadKB(String kbName, List<String> constituents)
      Loads the constituents of the KB from ~/.sigmakee/config.xml
      Parameters:
      kbName - the name of the KB
      constituents - a list of constituents to load
      Returns:
      true if the loading was successful
    • copyFile

      public static void copyFile(File in, File out)
      Copies an XML configuration file to the File out location.
      Parameters:
      in - the file to copy
      out - the location to copy the in param to
    • readConfiguration

      public SimpleElement readConfiguration(String configDirPath)
      Reads an XML configuration file from the directory configDirPath, and tries to find a configuration file elsewhere if configDirPath is null. The method initializeOnce() sets the preferences based on the contents of the configuration file. This routine has the side effect of setting the variable called "configuration". It also creates the KBs directory and an empty configuration file if none exists.
    • initializeOnce

      public void initializeOnce()
      Reads in the KBs and other parameters defined in the XML configuration file, or uses the default parameters. Entry point for the web app (Prelude.jsp).
    • initializeOnce

      public void initializeOnce(String configFileDir)
      Reads in the KBs and other parameters defined in the XML configuration file, or uses the default parameters. If configFileDir is not null and a configuration file can be read from the directory, reinitialization is forced.
      Parameters:
      configFileDir - the directory where the config.xml resides, typically ~/.sigmakee/KBs
    • setConfiguration

      public void setConfiguration(SimpleElement configuration)
      Sets instance fields by reading the xml found in the configuration file.
      Parameters:
      configuration -
    • escapeFilename

      public static String escapeFilename(String fname)
      Double the backslash in a filename so that it can be saved to a text file and read back properly.
    • addKB

      public void addKB(String name)
      Create a new empty KB with a name.
      Parameters:
      name - - the name of the KB
    • addKB

      public void addKB(String name, boolean isVisible)
    • removeKB

      public String removeKB(String name)
      Remove a knowledge base.
      Parameters:
      name - - the name of the KB
      Returns:
      indication of KB removal
    • writeConfiguration

      public void writeConfiguration() throws IOException
      Write the current configuration of the system. Call writeConfiguration() on each KB object to write its manifest.
      Throws:
      IOException
    • getKB

      public KB getKB(String name)
      Get the KB that has the given name.
    • existsKB

      public boolean existsKB(String name)
      Returns true if a KB with the given name exists.
    • remove

      public void remove(String name)
      Remove the KB that has the given name.
    • getMgr

      public static KBmanager getMgr()
      Get the one instance of KBmanager from its class variable.
    • getKBnames

      public Set<String> getKBnames()
      Get the Set of KB names in this manager.
    • allAvailableLanguages

      public List<String> allAvailableLanguages()
      Get the the complete list of languages available in all KBs
    • printPrefs

      public void printPrefs()
      Print all preferences to stdout
    • getPref

      public String getPref(String key)
      Get the preference corresponding to the given key
    • prefEquals

      public boolean prefEquals(String key, String value)
      Safer than getPref().equals() since it can check for null
    • setPref

      public void setPref(String key, String value)
      Set the preference to the given value.
    • pythonServer

      public static void pythonServer()
      Create an server-based interface for Python to call the KB object. https://pypi.python.org from py4j.java_gateway import JavaGateway gateway = JavaGateway() # connect to the JVM sigma_app = gateway.entry_point # get the KB instance print(sigma_app.getTerms()) # call a method
    • printHelp

      public static void printHelp()
    • main

      public static void main(String[] args)