Package com.articulate.sigma
Class KIF
java.lang.Object
com.articulate.sigma.KIF
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 Summary
FieldsModifier and TypeFieldDescriptionstatic interrors generated during parsingA HashMap of String keys representing the formula, and Formula values.A HashMap of ArrayLists of Formulas.static final intA numeric constant denoting normal parse mode, in which syntax constraints are enforced.static final intA numeric constant denoting relaxed parse mode, in which fewer syntax constraints are enforced than in NORMAL_PARSE_MODE.A hashMap to store term frequencies for each term in knowledge baseThe set of all terms in the knowledge base.warnings generated during parsing -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringThis routine creates a key that relates a token in a logical statement to the entire statement.longgetKIFFileSize(String filename) intReturn an ArrayList of Formula in the same lexical order as their source filestatic voidThis method has the side effect of setting the contents of formulaMap and formulas as it parses the file.parseStatement(String formula) Parse a single formula.voidRead a KIF file.voidsetParseMode(int mode) Sets the current parse mode to the input value mode.static voidThis routine sets up the StreamTokenizer_s so that it parses SUO-KIF.static voidshowHelp()static voidtest()Test method for this class.static voidtptpOutputTest(String filename) Writes the TPTP output to a file.voidWrite a KIF file.
-
Field Details
-
NORMAL_PARSE_MODE
public static final int NORMAL_PARSE_MODEA 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_MODEA numeric constant denoting relaxed parse mode, in which fewer syntax constraints are enforced than in NORMAL_PARSE_MODE.- See Also:
-
terms
The set of all terms in the knowledge base. This is a set of Strings. -
termFrequency
A hashMap to store term frequencies for each term in knowledge base -
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
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
-
filename
-
warningSet
warnings generated during parsing -
errorSet
errors generated during parsing
-
-
Constructor Details
-
KIF
public KIF() -
KIF
Pre-allocate space for hashes, based on file size
-
-
Method Details
-
getKIFFileSize
- 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
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
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
Read a KIF file.- Parameters:
fname- - the full pathname of the file.- Throws:
Exception
-
writeFile
Write a KIF file.- Parameters:
fname- - the name of the file to write, including full path.
-
lexicalOrder
Return an ArrayList of Formula in the same lexical order as their source file -
parseStatement
Parse a single formula. -
tptpOutputTest
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
- Throws:
IOException
-