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
Modifier and TypeFieldDescriptionstatic Token
Next token.static Token
Current token.Generated Token Manager.Fields inherited from interface org.tweetyproject.logics.rpcl.parser.rpclprobabilitydistributionparser.RpclProbabilityDistributionParserConstants
DEFAULT, EOF, PROBABILITY, STRUCTURENAME, tokenImage
-
Constructor Summary
ConstructorDescriptionDefault constructor.Constructor for parsing withInputStream
.RpclProbabilityDistributionParser
(InputStream stream, String encoding) Constructor for parsing withInputStream
and 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 void
Disable tracing.static final RpclProbabilityDistribution
Distribution
(RpclSemantics semantics, FolSignature signature) Constructorstatic final void
Enable tracing.static ParseException
Generate aParseException
when an error occurs during parsing.static final Token
Retrieve the next token from the token stream.static final Token
getToken
(int index) Retrieve the next token from the token stream.static final FolAtom
GroundAtom
(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 aHerbrandInterpretation
and its associatedProbability
.static void
ReInit
(InputStream stream) Reinitialises the parser with a new input stream.static void
ReInit
(InputStream stream, String encoding) Reinitialises the parser with a new input stream and specified encoding.static void
Reinitialises the parser with a newReader
input stream.void
Reinitialises the parser with a newRpclProbabilityDistributionParserTokenManager
.void
setSemantics
(RpclSemantics semantics) Sets the semantics to be used for parsing the probability distribution.void
setSignature
(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
- TheRpclSemantics
to use for parsing.
-
RpclProbabilityDistributionParser
Constructor that initializes the parser with the given semantics and signature.- Parameters:
semantics
- TheRpclSemantics
to use for parsing.signature
- TheFolSignature
to use for interpreting terms.
-
RpclProbabilityDistributionParser
Constructor for parsing withInputStream
.- Parameters:
stream
- The input stream to be parsed.
-
RpclProbabilityDistributionParser
Constructor for parsing withInputStream
and specified encoding.- Parameters:
stream
- The input stream to be parsed.encoding
- The character encoding to be used, ornull
for 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
- TheRpclProbabilityDistributionParserTokenManager
responsible 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
- TheRpclSemantics
to set.
-
setSignature
Sets the signature to be used for interpreting the parsed terms.- Parameters:
signature
- TheFolSignature
to set.
-
parseProbabilityDistribution
public RpclProbabilityDistribution parseProbabilityDistribution(Reader reader) throws ParserException Parses the probability distribution from the provided reader.This method reads from the
Reader
and parses the input into anRpclProbabilityDistribution
. It uses the currently set semantics and signature to interpret the data.- Parameters:
reader
- TheReader
to 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 aHerbrandInterpretation
and 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
- theFolSignature
to which the constants and predicates belong. If a constant or predicate is not found in the signature, it is added to it.- Returns:
- a
Pair
consisting of aHerbrandInterpretation
containing the parsed ground atoms, and aProbability
representing 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
- theFolSignature
to which the constants and predicate belong. If a constant or predicate is not found in the signature, it is added to it.- Returns:
- a
FolAtom
representing 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
RuntimeException
is 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, ornull
for the platform default encoding.- Throws:
RuntimeException
- if the specified encoding is not supported.
-
ReInit
Reinitialises the parser with a newReader
input 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 newReader
input 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 newRpclProbabilityDistributionParserTokenManager
that 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
Token
in 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
Token
in the input stream.
-
generateParseException
Generate aParseException
when an error occurs during parsing.This method collects information about the tokens that were expected but not found during parsing, and generates a
ParseException
containing 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
ParseException
that 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.
-