Class RpclProbabilityDistributionParser

java.lang.Object
org.tweetyproject.logics.rpcl.parser.rpclprobabilitydistributionparser.RpclProbabilityDistributionParser
All Implemented Interfaces:
RpclProbabilityDistributionParserConstants

public class RpclProbabilityDistributionParser extends Object implements RpclProbabilityDistributionParserConstants
Parser for reading and parsing RPCL (Relational Probabilistic Conditional Logic) probability distributions.

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 Details

  • Constructor Details

    • RpclProbabilityDistributionParser

      public RpclProbabilityDistributionParser()
      Default constructor.
    • RpclProbabilityDistributionParser

      public RpclProbabilityDistributionParser(RpclSemantics semantics)
      Constructor that initializes the parser with the given semantics.
      Parameters:
      semantics - The RpclSemantics to use for parsing.
    • RpclProbabilityDistributionParser

      public RpclProbabilityDistributionParser(RpclSemantics semantics, FolSignature signature)
      Constructor that initializes the parser with the given semantics and signature.
      Parameters:
      semantics - The RpclSemantics to use for parsing.
      signature - The FolSignature to use for interpreting terms.
    • RpclProbabilityDistributionParser

      public RpclProbabilityDistributionParser(InputStream stream)
      Constructor for parsing with InputStream.
      Parameters:
      stream - The input stream to be parsed.
    • RpclProbabilityDistributionParser

      public RpclProbabilityDistributionParser(InputStream stream, String encoding)
      Constructor for parsing with InputStream and specified encoding.
      Parameters:
      stream - The input stream to be parsed.
      encoding - The character encoding to be used, or null 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

      public RpclProbabilityDistributionParser(Reader stream)
      Constructor for parsing with a Reader. 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.

      Parameters:
      stream - The Reader providing the input to be parsed.
      Throws:
      Error - If the constructor is called more than once when the parser is static.
    • RpclProbabilityDistributionParser

      public RpclProbabilityDistributionParser(RpclProbabilityDistributionParserTokenManager tm)
      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 - The RpclProbabilityDistributionParserTokenManager responsible for token generation.
      Throws:
      Error - If the constructor is called more than once when the parser is static.
  • Method Details

    • setSemantics

      public void setSemantics(RpclSemantics semantics)
      Sets the semantics to be used for parsing the probability distribution.
      Parameters:
      semantics - The RpclSemantics to set.
    • setSignature

      public void setSignature(FolSignature signature)
      Sets the signature to be used for interpreting the parsed terms.
      Parameters:
      signature - The FolSignature 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 an RpclProbabilityDistribution. It uses the currently set semantics and signature to interpret the data.

      Parameters:
      reader - The Reader 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 semantic
      signature - 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 a HerbrandInterpretation and its associated Probability.

      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 - the FolSignature 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 a HerbrandInterpretation containing the parsed ground atoms, and a Probability representing the parsed probability.
      Throws:
      ParseException - if there is an error during parsing, such as unexpected tokens in the input stream.
    • GroundAtom

      public static final FolAtom GroundAtom(FolSignature signature) throws ParseException
      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 - the FolSignature 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

      public static void ReInit(InputStream stream)
      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

      public static void ReInit(InputStream stream, String encoding)
      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, or null for the platform default encoding.
      Throws:
      RuntimeException - if the specified encoding is not supported.
    • ReInit

      public static void ReInit(Reader stream)
      Reinitialises the parser with a new Reader 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 new Reader input stream to be parsed.
    • ReInit

      Reinitialises the parser with a new RpclProbabilityDistributionParserTokenManager. 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 new RpclProbabilityDistributionParserTokenManager that provides tokens for parsing.
    • getNextToken

      public static final Token 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

      public static final Token getToken(int index)
      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

      public static ParseException generateParseException()
      Generate a ParseException 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.