Class CLawParser
- java.lang.Object
-
- net.sf.tweety.commons.Parser<CActionDescription,Formula>
-
- net.sf.tweety.action.description.parser.CLawParser
-
public class CLawParser extends Parser<CActionDescription,Formula>
This class implements a parser for causal laws in C. The BNF of such rules is given by: (starting symbol is DESC)
DESC ::== LAW ("\n" LAW)*
LAW ::== STATICLAW | DYNAMICLAW
STATICLAW ::== "caused" FOLFORMULA ("if" FOLFORMULA)? ("requires" REQUIREMENTS)?
DYNAMICLAW ::== "caused" FOLFORMULA ("if" FOLFORMULA)? "after" FOLFORMULA ("requires" REQUIREMENTS)?
REQUIREMENTS ::== REQUIREMENT ("," REQUIREMENT)*
REQUIREMENT ::== (VARIABLENAME "<>" VARIABLENAME | VARIABLENAME "<>" CONSTANTNAME)*
where FOLFORMULA is an unquantified first-order formula without functors,
and VARIABLENAME, CONSTANTNAME are sequences of symbols
from {a,...,z,A,...,Z,0,...,9} with a letter at the beginning.- Author:
- Sebastian Homann
-
-
Field Summary
Fields Modifier and Type Field Description protected ActionSignaturesignature
-
Constructor Summary
Constructors Constructor Description CLawParser(ActionSignature signature)This parser needs a valid action signature to parse causal laws.
-
Method Summary
Modifier and Type Method Description protected java.util.Set<java.lang.String>containedKeywords(java.lang.String s)Returns the set of forbidden keywords, that are contained in a string.private FormulaparseAlwaysFormula(java.lang.String s, java.lang.String reqString)Parses a string containing a single causal law of the form always A which is converted to caused - if !ACActionDescriptionparseBeliefBase(java.io.Reader reader)Parses the given reader into a belief base of the given type.private FormulaparseCausedFormula(java.lang.String s, java.lang.String reqString)Parses a string containing a single causal law of the form caused A (if B)? (after C)?private FormulaparseCausesFormula(java.lang.String s, java.lang.String reqString)Parses a string containing a single causal law of the form A causes B if C which is converted to caused B if + after A && Cprivate FormulaparseDefaultFormula(java.lang.String s, java.lang.String reqString)Parses a string containing a single causal law of the form default A (if B)? which is converted to the causal law caused A if A && Bprotected FolFormulaparseFolFormula(java.lang.String s)Parses a FolFormula from a string using the FolParser classFormulaparseFormula(java.io.Reader reader)Parses the given reader into a formula of the given type.FormulaparseFormula(java.lang.String s)Parses the given text into a formula of the given type.private FormulaparseInertialFormula(java.lang.String s, java.lang.String reqString)Parses a string containing a single causal law of the form inertial A which is converted to the causal law caused A if A after Aprivate FormulaparseMayCauseFormula(java.lang.String s, java.lang.String reqString)Parses a string containing a single causal law of the form A may cause B if C which is converted to caused B if B after A && Cprivate FormulaparseNonexecutableFormula(java.lang.String s, java.lang.String reqString)Parses a string containing a single causal law of the form nonexecutable A if B which is converted to caused - after A && B-
Methods inherited from class net.sf.tweety.commons.Parser
isNumeric, parseBeliefBase, parseBeliefBaseFromFile, parseFormulaFromFile
-
-
-
-
Field Detail
-
signature
protected ActionSignature signature
-
-
Constructor Detail
-
CLawParser
public CLawParser(ActionSignature signature)
This parser needs a valid action signature to parse causal laws.- Parameters:
signature- some signature
-
-
Method Detail
-
parseBeliefBase
public CActionDescription parseBeliefBase(java.io.Reader reader) throws ParserException
Description copied from class:ParserParses the given reader into a belief base of the given type.- Specified by:
parseBeliefBasein classParser<CActionDescription,Formula>- Parameters:
reader- a reader- Returns:
- a belief base
- Throws:
ParserException- some parsing exceptions may be added here.
-
parseFormula
public Formula parseFormula(java.io.Reader reader) throws java.io.IOException, ParserException
Description copied from class:ParserParses the given reader into a formula of the given type.- Specified by:
parseFormulain classParser<CActionDescription,Formula>- Parameters:
reader- a reader- Returns:
- a formula
- Throws:
java.io.IOException- if some IO issue occurred.ParserException- some parsing exceptions may be added here.
-
parseFolFormula
protected FolFormula parseFolFormula(java.lang.String s) throws ParserException, java.io.IOException
Parses a FolFormula from a string using the FolParser class- Parameters:
s- a string- Returns:
- A first order formula
- Throws:
ParserException- if parsing failsjava.io.IOException- if an IO issue occurs.
-
parseFormula
public Formula parseFormula(java.lang.String s) throws ParserException, java.io.IOException
Description copied from class:ParserParses the given text into a formula of the given type.- Overrides:
parseFormulain classParser<CActionDescription,Formula>- Parameters:
s- a string- Returns:
- a formula
- Throws:
ParserException- some parsing exceptions may be added here.java.io.IOException- if some IO issue occurred.
-
parseCausedFormula
private Formula parseCausedFormula(java.lang.String s, java.lang.String reqString) throws ParserException, java.io.IOException
Parses a string containing a single causal law of the form caused A (if B)? (after C)?- Parameters:
s- a string containing a single causal law.reqString- the grounding requirements of this law.- Returns:
- the corresponding causal law
- Throws:
ParserException- if parsing failesjava.io.IOException- if io failes
-
parseInertialFormula
private Formula parseInertialFormula(java.lang.String s, java.lang.String reqString) throws ParserException, java.io.IOException
Parses a string containing a single causal law of the form inertial A which is converted to the causal law caused A if A after A- Parameters:
s- a string containing a single inertial law.reqString- the grounding requirements of this law.- Returns:
- the corresponding causal law
- Throws:
ParserException- if parsing failesjava.io.IOException- if io failes
-
parseDefaultFormula
private Formula parseDefaultFormula(java.lang.String s, java.lang.String reqString) throws ParserException, java.io.IOException
Parses a string containing a single causal law of the form default A (if B)? which is converted to the causal law caused A if A && B- Parameters:
s- a string containing a single causal law.reqString- the grounding requirements of this law.- Returns:
- the corresponding causal law
- Throws:
ParserException- if parsing failesjava.io.IOException- if io failes
-
parseCausesFormula
private Formula parseCausesFormula(java.lang.String s, java.lang.String reqString) throws ParserException, java.io.IOException
Parses a string containing a single causal law of the form A causes B if C which is converted to caused B if + after A && C- Parameters:
s- a string containing a single causal law.reqString- the grounding requirements of this law.- Returns:
- the corresponding causal law
- Throws:
ParserException- if parsing failesjava.io.IOException- if io failes
-
parseAlwaysFormula
private Formula parseAlwaysFormula(java.lang.String s, java.lang.String reqString) throws ParserException, java.io.IOException
Parses a string containing a single causal law of the form always A which is converted to caused - if !A- Parameters:
s- a string containing a single causal law.reqString- the grounding requirements of this law.- Returns:
- the corresponding causal law
- Throws:
ParserException- if parsing failesjava.io.IOException- if io failes
-
parseNonexecutableFormula
private Formula parseNonexecutableFormula(java.lang.String s, java.lang.String reqString) throws ParserException, java.io.IOException
Parses a string containing a single causal law of the form nonexecutable A if B which is converted to caused - after A && B- Parameters:
s- a string containing a single causal law.reqString- the grounding requirements of this law.- Returns:
- the corresponding causal law
- Throws:
ParserException- if parsing failesjava.io.IOException- if io failes
-
parseMayCauseFormula
private Formula parseMayCauseFormula(java.lang.String s, java.lang.String reqString) throws ParserException, java.io.IOException
Parses a string containing a single causal law of the form A may cause B if C which is converted to caused B if B after A && C- Parameters:
s- a string containing a single causal law.reqString- the grounding requirements of this law.- Returns:
- the corresponding causal law
- Throws:
ParserException- if parsing failesjava.io.IOException- if io failes
-
containedKeywords
protected java.util.Set<java.lang.String> containedKeywords(java.lang.String s)
Returns the set of forbidden keywords, that are contained in a string. This is used for error recognition in input strings.- Parameters:
s- some string- Returns:
- the set of forbidden keywords
-
-