Class RpclProbabilityDistributionParser
- All Implemented Interfaces:
RpclProbabilityDistributionParserConstants
This parser can read from various inputs and convert them into a
RpclProbabilityDistribution.
The parser uses semantics from RpclSemantics and a signature from
FolSignature.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic TokenNext token.static TokenCurrent token.Generated Token Manager.Fields inherited from interface org.tweetyproject.logics.rpcl.parser.rpclprobabilitydistributionparser.RpclProbabilityDistributionParserConstants
DEFAULT, EOF, PROBABILITY, STRUCTURENAME, tokenImage -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Constructor for parsing withInputStream.RpclProbabilityDistributionParser(InputStream stream, String encoding) Constructor for parsing withInputStreamand specified encoding.Constructor for parsing with aReader.Constructor for the parser with a generated Token Manager.RpclProbabilityDistributionParser(RpclSemantics semantics) Constructor that initializes the parser with the given semantics.RpclProbabilityDistributionParser(RpclSemantics semantics, FolSignature signature) Constructor that initializes the parser with the given semantics and signature. -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidDisable tracing.static final RpclProbabilityDistributionDistribution(RpclSemantics semantics, FolSignature signature) Constructorstatic final voidEnable tracing.static ParseExceptionGenerate aParseExceptionwhen an error occurs during parsing.static final TokenRetrieve the next token from the token stream.static final TokengetToken(int index) Retrieve the next token from the token stream.static final FolAtomGroundAtom(FolSignature signature) Parses and returns a ground atom (an atom where all terms are constants) from the input stream.parseProbabilityDistribution(Reader reader) Parses the probability distribution from the provided reader.static final Pair<HerbrandInterpretation, Probability> ProbabilityAssignment(FolSignature signature) Parses and returns a pair consisting of aHerbrandInterpretationand its associatedProbability.static voidReInit(InputStream stream) Reinitialises the parser with a new input stream.static voidReInit(InputStream stream, String encoding) Reinitialises the parser with a new input stream and specified encoding.static voidReinitialises the parser with a newReaderinput stream.voidReinitialises the parser with a newRpclProbabilityDistributionParserTokenManager.voidsetSemantics(RpclSemantics semantics) Sets the semantics to be used for parsing the probability distribution.voidsetSignature(FolSignature signature) Sets the signature to be used for interpreting the parsed terms.
-
Field Details
-
token_source
Generated Token Manager. -
token
Current token. -
jj_nt
Next token.
-
-
Constructor Details
-
RpclProbabilityDistributionParser
public RpclProbabilityDistributionParser()Default constructor. -
RpclProbabilityDistributionParser
Constructor that initializes the parser with the given semantics.- Parameters:
semantics- TheRpclSemanticsto use for parsing.
-
RpclProbabilityDistributionParser
Constructor that initializes the parser with the given semantics and signature.- Parameters:
semantics- TheRpclSemanticsto use for parsing.signature- TheFolSignatureto use for interpreting terms.
-
RpclProbabilityDistributionParser
Constructor for parsing withInputStream.- Parameters:
stream- The input stream to be parsed.
-
RpclProbabilityDistributionParser
Constructor for parsing withInputStreamand specified encoding.- Parameters:
stream- The input stream to be parsed.encoding- The character encoding to be used, ornullfor the platform's default encoding.- Throws:
RuntimeException- If an unsupported encoding is provided.Error- If the constructor is called more than once when the parser is set to be static.
-
RpclProbabilityDistributionParser
Constructor for parsing with aReader. This constructor initializes the parser using a character-based input reader.The parser should only be initialized once if it is static. If this constructor is called more than once when the parser is static, it throws an error. For subsequent uses, the parser should be reinitialized using the
ReInit()method. -
RpclProbabilityDistributionParser
Constructor for the parser with a generated Token Manager.This constructor initializes the `RpclProbabilityDistributionParser` with a custom
RpclProbabilityDistributionParserTokenManager. The token manager is responsible for generating tokens from the input source.This constructor should only be called once if the parser is static. If this constructor is called more than once when the parser is static, it throws an error. To reinitialize the parser, the
ReInit()method should be used instead.- Parameters:
tm- TheRpclProbabilityDistributionParserTokenManagerresponsible for token generation.- Throws:
Error- If the constructor is called more than once when the parser is static.
-
-
Method Details
-
setSemantics
Sets the semantics to be used for parsing the probability distribution.- Parameters:
semantics- TheRpclSemanticsto set.
-
setSignature
Sets the signature to be used for interpreting the parsed terms.- Parameters:
signature- TheFolSignatureto set.
-
parseProbabilityDistribution
public RpclProbabilityDistribution parseProbabilityDistribution(Reader reader) throws ParserException Parses the probability distribution from the provided reader.This method reads from the
Readerand parses the input into anRpclProbabilityDistribution. It uses the currently set semantics and signature to interpret the data.- Parameters:
reader- TheReaderto read the input from.- Returns:
- The parsed
RpclProbabilityDistribution. - Throws:
ParserException- If a parsing error occurs.
-
Distribution
public static final RpclProbabilityDistribution Distribution(RpclSemantics semantics, FolSignature signature) throws ParseException Constructor- Parameters:
semantics- the semanticsignature- the signature- Returns:
- a RpclProbabilityDistribution
- Throws:
ParseException- error
-
ProbabilityAssignment
public static final Pair<HerbrandInterpretation, Probability> ProbabilityAssignment(FolSignature signature) throws ParseException Parses and returns a pair consisting of aHerbrandInterpretationand its associatedProbability.This method parses a set of ground atoms and their associated probability from the input stream. The ground atoms are parsed and added to a
HerbrandInterpretation. The associated probability is then parsed and the pair is returned.- Parameters:
signature- theFolSignatureto which the constants and predicates belong. If a constant or predicate is not found in the signature, it is added to it.- Returns:
- a
Pairconsisting of aHerbrandInterpretationcontaining the parsed ground atoms, and aProbabilityrepresenting the parsed probability. - Throws:
ParseException- if there is an error during parsing, such as unexpected tokens in the input stream.
-
GroundAtom
Parses and returns a ground atom (an atom where all terms are constants) from the input stream.A ground atom consists of a predicate symbol and zero or more constant arguments. This method reads the predicate and its corresponding constants (if any), checks if they already exist in the given
FolSignature, and adds them if they do not.- Parameters:
signature- theFolSignatureto which the constants and predicate belong. If a constant or predicate is not found in the signature, it is added to it.- Returns:
- a
FolAtomrepresenting the parsed ground atom. - Throws:
ParseException- if there is an error during parsing, such as unexpected tokens in the input stream.
-
ReInit
Reinitialises the parser with a new input stream. This method resets the input stream to the new one provided, along with all associated parser states such as tokens and lookahead variables.- Parameters:
stream- the new input stream to be parsed.
-
ReInit
Reinitialises the parser with a new input stream and specified encoding. This method resets the input stream to the new one provided and reinitializes the parser with the specified character encoding.If the encoding is not supported, a
RuntimeExceptionis thrown. This method also resets tokens, lookahead variables, and the token source.- Parameters:
stream- the new input stream to be parsed.encoding- the character encoding used for reading the input stream, ornullfor the platform default encoding.- Throws:
RuntimeException- if the specified encoding is not supported.
-
ReInit
Reinitialises the parser with a newReaderinput stream. This method resets the input stream to the new one provided, along with all associated parser states such as tokens, lookahead variables, and the token source.The method assumes the input starts at the first line and first column.
- Parameters:
stream- the newReaderinput stream to be parsed.
-
ReInit
Reinitialises the parser with a newRpclProbabilityDistributionParserTokenManager. This method resets the parser's internal state and prepares it to process new tokens provided by the given token manager.The token manager is responsible for providing tokens to the parser during parsing. The method also resets all lookahead variables, ensuring that the parser starts fresh with no leftover state from previous parsing.
- Parameters:
tm- the newRpclProbabilityDistributionParserTokenManagerthat provides tokens for parsing.
-
getNextToken
Retrieve the next token from the token stream.This method moves the parser to the next token in the input stream. If the next token has already been generated and is available, it is returned immediately. Otherwise, the next token is fetched from the token source.
- Returns:
- the next
Tokenin the input stream.
-
getToken
Retrieve the next token from the token stream.This method moves the parser to the next token in the input stream. If the next token has already been generated and is available, it is returned immediately. Otherwise, the next token is fetched from the token source.
- Parameters:
index- the index- Returns:
- the next
Tokenin the input stream.
-
generateParseException
Generate aParseExceptionwhen an error occurs during parsing.This method collects information about the tokens that were expected but not found during parsing, and generates a
ParseExceptioncontaining details about the error. It is used to report errors and provide feedback about what was expected at the point of failure in the parsing process.- Returns:
- a
ParseExceptionthat contains details about the parsing error, including the unexpected token and the expected token sequences.
-
enable_tracing
public static final void enable_tracing()Enable tracing.This method is used to enable tracing during the parsing process. Tracing can be helpful for debugging purposes, allowing the parser to output detailed information about its internal state and the parsing steps it is performing.
In the current implementation, this method does not perform any actions, but it can be overridden or modified to include tracing functionality.
-
disable_tracing
public static final void disable_tracing()Disable tracing.This method is used to disable tracing during the parsing process. Disabling tracing stops the parser from outputting detailed information about its internal state and the parsing steps.
In the current implementation, this method does not perform any actions, but it can be overridden or modified to include tracing functionality.
-