Class KIF

java.lang.Object
com.articulate.sigma.KIF

public class KIF extends Object
A class designed to read a file in SUO-KIF format into memory. See invalid input: '<'http://sigmakee.cvs.sourceforge.net/viewvc/sigmakee/sigma/suo-kif.pdf> for a language specification. readFile() and writeFile() are the primary entry points and parse() does all the real work.
Author:
Adam Pease
  • Field Details

    • NORMAL_PARSE_MODE

      public static final int NORMAL_PARSE_MODE
      A numeric constant denoting normal parse mode, in which syntax constraints are enforced.
      See Also:
    • count

      public static int count
    • RELAXED_PARSE_MODE

      public static final int RELAXED_PARSE_MODE
      A numeric constant denoting relaxed parse mode, in which fewer syntax constraints are enforced than in NORMAL_PARSE_MODE.
      See Also:
    • terms

      public Set<String> terms
      The set of all terms in the knowledge base. This is a set of Strings.
    • termFrequency

      public Map<String,Integer> termFrequency
      A hashMap to store term frequencies for each term in knowledge base
    • formulas

      public Map<String,List<String>> formulas
      A HashMap of ArrayLists of Formulas. Each String key points to a list of String formulas that correspond to that key. For example, "arg-1-Foo" would be one of several keys for "(instance Foo Bar)".
      See Also:
    • formulaMap

      public Map<String,Formula> formulaMap
      A HashMap of String keys representing the formula, and Formula values. For example, "(instance Foo Bar)" is a String key that might point to a Formula that is that string, along with information about at what line number and in what file it appears.
    • formulasOrdered

      public Map<Integer,Formula> formulasOrdered
    • filename

      public String filename
    • warningSet

      public Set<String> warningSet
      warnings generated during parsing
    • errorSet

      public Set<String> errorSet
      errors generated during parsing
  • Constructor Details

    • KIF

      public KIF()
    • KIF

      public KIF(String fname)
      Pre-allocate space for hashes, based on file size
  • Method Details

    • getKIFFileSize

      public long getKIFFileSize(String filename)
      Returns:
      long file size in bytes handling any errors
    • getParseMode

      public int getParseMode()
      Returns:
      int Returns an integer value denoting the current parse mode.
    • setParseMode

      public void setParseMode(int mode)
      Sets the current parse mode to the input value mode.
      Parameters:
      mode - An integer value denoting a parsing mode.
    • setupStreamTokenizer

      public static void setupStreamTokenizer(StreamTokenizer_s st)
      This routine sets up the StreamTokenizer_s so that it parses SUO-KIF. = invalid input: '<' > are treated as word characters, as are normal alphanumerics. ; is the line comment character and " is the quote character.
    • parse

      public Set<String> parse(Reader r)
      This method has the side effect of setting the contents of formulaMap and formulas as it parses the file. It throws a ParseException with file line numbers if fatal errors are encountered during parsing. Keys in variable "formulas" include the string representation of the formula.
      Parameters:
      r - the Reader containing SUO-KIF text
      Returns:
      a Set of warnings that may indicate syntax errors, but not fatal parse errors.
    • createKey

      public static String createKey(String sval, boolean inAntecedent, boolean inConsequent, int argumentNum, int parenLevel)
      This routine creates a key that relates a token in a logical statement to the entire statement. It prepends to the token a string indicating its position in the statement. The key is of the form type-[num]-term, where [num] is only present when the type is "arg", meaning a statement in which the term is nested only within one pair of parentheses. The other possible types are "ant" for rule antecedent, "cons" for rule consequent, and "stmt" for cases where the term is nested inside multiple levels of parentheses. An example key would be arg-0-instance for a appearance of the term "instance" in a statement in the predicate position.
      Parameters:
      sval - - the token such as "instance", "Human" etc.
      inAntecedent - - whether the term appears in the antecedent of a rule.
      inConsequent - - whether the term appears in the consequent of a rule.
      argumentNum - - the argument position in which the term appears. The predicate position is argument 0. The first argument is 1 etc.
      parenLevel - - if the paren level is > 1 then the term appears nested in a statement and the argument number is ignored.
    • readFile

      public void readFile(String fname) throws Exception
      Read a KIF file.
      Parameters:
      fname - - the full pathname of the file.
      Throws:
      Exception
    • writeFile

      public void writeFile(String fname)
      Write a KIF file.
      Parameters:
      fname - - the name of the file to write, including full path.
    • lexicalOrder

      public List<Formula> lexicalOrder()
      Return an ArrayList of Formula in the same lexical order as their source file
    • parseStatement

      public String parseStatement(String formula)
      Parse a single formula.
    • tptpOutputTest

      public static void tptpOutputTest(String filename) throws IOException
      Writes the TPTP output to a file.
      Throws:
      IOException
    • test

      public static void test()
      Test method for this class.
    • showHelp

      public static void showHelp()
    • main

      public static void main(String[] args) throws IOException
      Throws:
      IOException