public class TPTPParser extends Parser<FolBeliefSet>
TPTP files consist of any of the following in any order and separated by newlines:
The syntax for first-order logic formulas is 'fof(name,role,formula,source,[useful_info]).':
Supported operators and pre-defined predicates in formulas:
Negation: ~ formula
Conjunction: formula & formula
Disjunction: formula | formula
Implication: formula => formula
formula <= formula
Equivalence: formula <=> formula
Universal quantifier: ! [Variable1,Variable2,...] : (formula)
Existential quantifier: ? [Variable1,Variable2,...] : (formula)
Tautology: $true
Contradiction: $false
Equality: = (TODO soon to be added)
Inequality: != (TODO soon to be added)
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
formulaNames
Regular expression that restricts which formulas will be parsed.
|
private java.lang.String |
formulaRoles
Regular expression that restricts which formulas will be parsed.
|
private java.lang.String |
includePath
Location of included files (optional).
|
private FolSignature |
signature
Keeps track of the signature.
|
private java.util.Map<java.lang.String,Variable> |
variables
Keeps track of variables defined.
|
Constructor and Description |
---|
TPTPParser() |
Modifier and Type | Method and Description |
---|---|
private void |
consumeToken(java.util.Stack<java.lang.Object> stack,
int c)
This method reads one token from the given reader and appropriately
constructs a fol formula from the stream.
|
FolSignature |
getSignature()
Returns the signature of this parser.
|
private FolFormula |
parseAtomic(java.util.List<java.lang.Object> l) |
FolBeliefSet |
parseBeliefBase(java.io.Reader reader)
Parses the given reader into a belief base of the given type.
|
private FolFormula |
parseConjunction(java.util.List<java.lang.Object> l)
Parses a conjunction as a list of String tokens or formulas into a fol formula.
|
private FolFormula |
parseDisjunction(java.util.List<java.lang.Object> l)
Parses a disjunction as a list of String tokens or formulas into a fol formula.
|
private FolFormula |
parseEquivalence(java.util.List<java.lang.Object> l)
Parses an equivalence as a list of String tokens or formulas into a fol formula.
|
Formula |
parseFormula(java.io.Reader reader)
Parses the given reader into a formula of the given type.
|
private FolFormula |
parseImplication(java.util.List<java.lang.Object> l)
Parses an implication as a list of String tokens or formulas into a fol formula.
|
private FolBeliefSet |
parseIncludedFiles(java.lang.String s)
Parses formulas of an included TPTP problem file.
|
private FolFormula |
parseNegation(java.util.List<java.lang.Object> l) |
private FolFormula |
parseQuantification(java.util.List<java.lang.Object> l)
Parses a quantified formula as a list of String tokens or formulas.
|
private java.util.List<Term<?>> |
parseTermlist(java.util.List<java.lang.Object> l)
Parses a term list as a list of String tokens or terms into a list of terms.
|
private void |
parseTypes(java.lang.String formula)
Parse signature of a problem file.
|
void |
resetFormulaNames()
Reset the regular expression that restricts which formulas will be parsed to the default value,
meaning formulas of all names will be parsed.
|
void |
resetFormulaRoles()
Reset the regular expression that restricts which formulas will be parsed to the default value,
meaning formulas of any TPTP roles will be parsed.
|
void |
setFormulaNames(java.lang.String formulaNames)
Set the regular expression that restricts which formulas will be parsed.
|
void |
setFormulaRoles(java.lang.String formulaRoles)
Set the regular expression that restricts which formulas will be parsed.
|
void |
setIncludePath(java.lang.String includePath)
Set the location of included files.
|
void |
setSignature(FolSignature signature)
Sets the signature for this parser.
|
isNumeric, parseBeliefBase, parseBeliefBaseFromFile, parseFormula, parseFormulaFromFile
private FolSignature signature
private java.util.Map<java.lang.String,Variable> variables
private java.lang.String includePath
private java.lang.String formulaNames
private java.lang.String formulaRoles
public FolBeliefSet parseBeliefBase(java.io.Reader reader) throws java.io.IOException, ParserException
Parser
parseBeliefBase
in class Parser<FolBeliefSet>
reader
- a readerjava.io.IOException
ParserException
private FolBeliefSet parseIncludedFiles(java.lang.String s) throws java.io.FileNotFoundException, ParserException, java.io.IOException
s
- String of format "include('path/to/file')." or "include('path/to/file',[formula,names,separated,by,commata])."java.io.FileNotFoundException
ParserException
java.io.IOException
public Formula parseFormula(java.io.Reader reader) throws java.io.IOException, ParserException
Parser
parseFormula
in class Parser<FolBeliefSet>
reader
- a readerjava.io.IOException
ParserException
private void parseTypes(java.lang.String formula)
a
- String of a formulaprivate void consumeToken(java.util.Stack<java.lang.Object> stack, int c)
stack
- a stack used for monitoring the read items.c
- a token from a stream.ParserException
- in case of parser errors.private java.util.List<Term<?>> parseTermlist(java.util.List<java.lang.Object> l)
l
- a list of objects, either String tokens or objects of type List.ParserException
- if the list could not be parsed.private FolFormula parseQuantification(java.util.List<java.lang.Object> l)
l
- a list objects, either String tokens or objects of type FolFormula.ParserException
- if the list could not be parsed.private FolFormula parseEquivalence(java.util.List<java.lang.Object> l)
l
- a list objects, either String tokens or objects of type FolFormula.ParserException
- if the list could not be parsed.private FolFormula parseImplication(java.util.List<java.lang.Object> l)
l
- a list objects, either String tokens or objects of type FolFormula.ParserException
- if the list could not be parsed.private FolFormula parseDisjunction(java.util.List<java.lang.Object> l)
l
- a list objects, either String tokens or objects of type FolFormula.ParserException
- if the list could not be parsed.private FolFormula parseConjunction(java.util.List<java.lang.Object> l)
l
- a list objects, either String tokens or objects of type FolFormula.ParserException
- if the list could not be parsed.private FolFormula parseNegation(java.util.List<java.lang.Object> l)
private FolFormula parseAtomic(java.util.List<java.lang.Object> l)
public void setSignature(FolSignature signature)
signature
- a fol signature.public FolSignature getSignature()
public void setFormulaNames(java.lang.String formulaNames)
public void setFormulaRoles(java.lang.String formulaRoles)
public void resetFormulaRoles()
public void resetFormulaNames()
public void setIncludePath(java.lang.String includePath)
path
- that will be prepended to the paths of all included problem files.