Class Parser<T>

java.lang.Object
org.lifstools.jgoslin.parser.Parser<T>
Type Parameters:
T - the type of a successful parse result.
Direct Known Subclasses:
FattyAcidParser, GoslinParser, HmdbParser, LipidMapsParser, ShorthandParser, SumFormulaParser, SwissLipidsParser

public abstract class Parser<T> extends Object
Abstract base class for parsers producing a parse result of type T. Uses a re-implementation of Cocke-Younger-Kasami (CYK) algorithm for context free grammars.
Author:
Dominik Kopczynski, Nils Hoffmann
  • Field Details

  • Constructor Details

    • Parser

      public Parser(String grammarContent)
    • Parser

      public Parser(String grammarContent, char _quote)
  • Method Details

    • newEventHandler

      public abstract BaseParserEventHandler<T> newEventHandler()
    • get_next_free_rule_index

      protected long get_next_free_rule_index()
    • readGrammar

      protected final void readGrammar(String grammar)
    • extract_text_based_rules

      protected ArrayList<String> extract_text_based_rules(String grammar, char _quote)
    • compute_rule_key

      protected long compute_rule_key(long rule_index_1, long rule_index_2)
    • is_terminal

      protected boolean is_terminal(String product_token, char _quote)
    • de_escape

      protected String de_escape(String text, char _quote)
    • add_terminal

      protected long add_terminal(String text)
    • top_nodes

      protected ArrayList<Long> top_nodes(long rule_index)
    • collect_one_backwards

      protected ArrayList<Long> collect_one_backwards(Long rule_index)
    • collect_backwards

      protected ArrayList<ArrayList<Long>> collect_backwards(Long child_rule_index, Long parent_rule_index)
    • collect_backwards

      protected ArrayList<ArrayList<Long>> collect_backwards(long child_rule_index, long parent_rule_index, HashSet<Long> visited, ArrayList<Long> path, ArrayList<ArrayList<Long>> collection)
    • raise_events

      protected void raise_events(TreeNode node, BaseParserEventHandler parserEventHandler)
    • fill_tree

      protected void fill_tree(TreeNode node, Parser<T>.DPNode dp_node)
    • parse

      public T parse(String textToParse, BaseParserEventHandler<T> parserEventHandler)
      Parse the given text, constructing the output object of type T using the provided parser event handler.
      Parameters:
      textToParse - the text to parse.
      parserEventHandler - the parser event handler to process events created by the parser.
      Returns:
      the parsed object of type T if successful, otherwise an exception will be thrown.
      Throws:
      LipidParsingException
    • parse

      public T parse(String textToParse, BaseParserEventHandler<T> parserEventHandler, boolean throwError)
      Parse the given text, constructing the output object of type T using the provided parser event handler.Allows the user to specify, if exceptions should be thrown on errors.
      Parameters:
      textToParse - the text to parse.
      parserEventHandler - the parser event handler to process events created by the parser.
      throwError - if true, throws exception if parsing was not successful.
      Returns:
      the parsed object of type T if successful, otherwise null, if throwError is false.
    • parse_regular

      protected Optional<Parser<T>.ParsingErrors> parse_regular(String text_to_parse, BaseParserEventHandler<T> parserEventHandler)