Package net.sf.tweety.logics.fol.parser
Class FolParser
- java.lang.Object
-
- net.sf.tweety.commons.Parser<FolBeliefSet,FolFormula>
-
- net.sf.tweety.logics.fol.parser.FolParser
-
public class FolParser extends net.sf.tweety.commons.Parser<FolBeliefSet,FolFormula>
This class implements a parser for first-order logic. The BNF for a first-order knowledge base is given by (starting symbol is KB)
KB ::== SORTSDEC DECLAR FORMULAS
DECLAR ::== (FUNCTORDEC | PREDDEC)*
SORTSDEC ::== ( SORTNAME "=" "{" (CONSTANTNAME ("," CONSTANTNAME)*)? "}" "\n" )*
PREDDEC ::== "type" "(" PREDICATENAME ("(" SORTNAME ("," SORTNAME)* ")")? ")" "\n"
FUNCTORDEC ::== "type" "(" SORTNAME "=" FUNCTORNAME "(" (SORTNAME ("," SORTNAME)*)? ")" ")" "\n"
FORMULAS ::== ( "\n" FORMULA)*
FORMULA ::== ATOM | "forall" VARIABLENAME ":" "(" FORMULA ")" | "exists" VARIABLENAME ":" "(" FORMULA ")" |
"(" FORMULA ")" | FORMULA "&&" FORMULA | FORMULA "||" FORMULA | "!" FORMULA | "+" | "-" |
FORMULA "=>" FORMULA | FORMULA "<=>" FORMULA | FORMULA "==" FORMULA | FORMULA "/==" FORMULA |
FORMULA "^^" FORMULA
ATOM ::== PREDICATENAME ("(" TERM ("," TERM)* ")")?
TERM ::== VARIABLENAME | CONSTANTNAME | FUNCTORNAME "(" (TERM ("," TERM)*)? ")"
where SORTNAME, PREDICATENAME, CONSTANTNAME and FUNCTORNAME are sequences of
symbols from {a,...,z,A,...,Z,0,...,9} with a letter at the beginning and VARIABLENAME
is a sequence of symbols from {a,...,z,A,...,Z,0,...,9} with an uppercase letter at the beginning.
Note: Equality/Inequality predicates (== and /==) can only be parsed if the parser is given a FolSignature
with equality (which is not the case by default).- Author:
- Matthias Thimm, Anna Gessler
-
-
Method Summary
Modifier and Type Method Description FolSignaturegetSignature()Returns the signature of this parser.Map<String,net.sf.tweety.logics.commons.syntax.Variable>getVariables()FolBeliefSetparseBeliefBase(Reader reader)FolFormulaparseFormula(Reader reader)FolSignatureparseSignature(String s)This function parses only the sorts declaration and type declaration parts of a belief base.voidparseSortDeclaration(String s, FolSignature sig)Parses a sort declaration of the form "SORTNAME "=" "{" (CONSTANTNAME ("," CONSTANTNAME)*)? "}"" and modifies the given signature accordingly.voidparseTypeDeclaration(String s, FolSignature sig)Parses a predicate declaration of the form "type" "(" PREDICATENAME "(" (SORTNAME ("," SORTNAME)*)? ")" ")" or a functor declaration of the form "type" "(" SORTNAME "=" FUNCTORNAME "(" (SORTNAME ("," SORTNAME)*)? ")" ")" and modifies the given signature accordingly.voidsetSignature(FolSignature signature)Sets the signature for this parser.voidsetVariables(Map<String,net.sf.tweety.logics.commons.syntax.Variable> variables)
-
-
-
Method Detail
-
parseBeliefBase
public FolBeliefSet parseBeliefBase(Reader reader) throws IOException, net.sf.tweety.commons.ParserException
- Specified by:
parseBeliefBasein classnet.sf.tweety.commons.Parser<FolBeliefSet,FolFormula>- Throws:
IOExceptionnet.sf.tweety.commons.ParserException
-
parseSortDeclaration
public void parseSortDeclaration(String s, FolSignature sig) throws net.sf.tweety.commons.ParserException
Parses a sort declaration of the form "SORTNAME "=" "{" (CONSTANTNAME ("," CONSTANTNAME)*)? "}"" and modifies the given signature accordingly.- Parameters:
s- a stringsig- a signature- Throws:
net.sf.tweety.commons.ParserException- if parsing fails
-
parseTypeDeclaration
public void parseTypeDeclaration(String s, FolSignature sig) throws net.sf.tweety.commons.ParserException
Parses a predicate declaration of the form "type" "(" PREDICATENAME "(" (SORTNAME ("," SORTNAME)*)? ")" ")" or a functor declaration of the form "type" "(" SORTNAME "=" FUNCTORNAME "(" (SORTNAME ("," SORTNAME)*)? ")" ")" and modifies the given signature accordingly.- Parameters:
s- a stringsig- a signature- Throws:
net.sf.tweety.commons.ParserException- if parsing fails
-
parseFormula
public FolFormula parseFormula(Reader reader) throws IOException, net.sf.tweety.commons.ParserException
- Specified by:
parseFormulain classnet.sf.tweety.commons.Parser<FolBeliefSet,FolFormula>- Throws:
IOExceptionnet.sf.tweety.commons.ParserException
-
parseSignature
public FolSignature parseSignature(String s)
This function parses only the sorts declaration and type declaration parts of a belief base.- Parameters:
s- the signature as a string- Returns:
- the parsed fol signature
-
setSignature
public void setSignature(FolSignature signature)
Sets the signature for this parser.- Parameters:
signature- a fol signature.
-
getSignature
public FolSignature getSignature()
Returns the signature of this parser.- Returns:
- the signature of this parser.
-
-