Class Parser

java.lang.Object
opennlp.tools.parser.AbstractBottomUpParser
opennlp.tools.parser.treeinsert.Parser
All Implemented Interfaces:
Parser

public class Parser extends AbstractBottomUpParser
A built-attach Parser implementation.

Nodes are built when their left-most child is encountered. Subsequent children are attached as daughters. Attachment is based on node in the right-frontier of the tree. After each attachment or building, nodes are assessed as either complete or incomplete. Complete nodes are no longer eligible for daughter attachment.

Complex modifiers which produce additional node levels of the same type are attached with sister-adjunction. Attachment can not take place higher in the right-frontier than an incomplete node.

See Also:
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
    • DONE

      public static final String DONE
      Outcome used when a constituent needs an no additional parent node/building.
      See Also:
    • ATTACH_SISTER

      public static final String ATTACH_SISTER
      Outcome used when a node should be attached as a sister to another node.
      See Also:
    • ATTACH_DAUGHTER

      public static final String ATTACH_DAUGHTER
      Outcome used when a node should be attached as a daughter to another node.
      See Also:
    • NON_ATTACH

      public static final String NON_ATTACH
      Outcome used when a node should not be attached to another node.
      See Also:
    • BUILT

      public static final String BUILT
      Label used to distinguish build nodes from non-built nodes.
      See Also:
    • buildModel

      private final MaxentModel buildModel
    • attachModel

      private final MaxentModel attachModel
    • checkModel

      private final MaxentModel checkModel
    • checkComplete

      static boolean checkComplete
    • buildContextGenerator

      private final BuildContextGenerator buildContextGenerator
    • attachContextGenerator

      private final AttachContextGenerator attachContextGenerator
    • checkContextGenerator

      private final CheckContextGenerator checkContextGenerator
    • bprobs

      private final double[] bprobs
    • aprobs

      private final double[] aprobs
    • cprobs

      private double[] cprobs
    • doneIndex

      private final int doneIndex
    • sisterAttachIndex

      private final int sisterAttachIndex
    • daughterAttachIndex

      private final int daughterAttachIndex
    • nonAttachIndex

      private final int nonAttachIndex
    • completeIndex

      private final int completeIndex
    • attachments

      private final int[] attachments
  • Constructor Details

    • Parser

      public Parser(ParserModel model, int beamSize, double advancePercentage)
      Instantiates a Parser via a given model and other configuration parameters. Uses the default implementations of POSTaggerME and ChunkerME.
      Parameters:
      model - The ParserModel to use.
      beamSize - The number of different parses kept during parsing.
      advancePercentage - The minimal amount of probability mass which advanced outcomes must represent. Only outcomes which contribute to the top advancePercentage will be explored.
      Throws:
      IllegalStateException - Thrown if the ParserType is not supported.
      See Also:
    • Parser

      public Parser(ParserModel model)
      Instantiates a Parser via a given model. Uses the default implementations of POSTaggerME and ChunkerME and default values for beamSize and advancePercentage.
      Parameters:
      model - The ParserModel to use.
      Throws:
      IllegalStateException - Thrown if the ParserType is not supported.
      See Also:
    • Parser

      private Parser(MaxentModel buildModel, MaxentModel attachModel, MaxentModel checkModel, POSTagger tagger, Chunker chunker, HeadRules headRules, int beamSize, double advancePercentage)
      Instantiates a Parser via a given model and other configuration parameters.
      Parameters:
      buildModel - A valid MaxentModel used to build.
      checkModel - A valid MaxentModel used to check.
      tagger - A valid POSModel used to tag.
      chunker - A valid ChunkerModel used to chunk.
      headRules - The HeadRules for head word percolation.
      beamSize - The number of different parses kept during parsing.
      advancePercentage - The minimal amount of probability mass which advanced outcomes must represent. Only outcomes which contribute to the top advancePercentage will be explored.
      See Also:
  • Method Details

    • getRightFrontier

      public static List<Parse> getRightFrontier(Parse root, Set<String> punctSet)
      Returns the right frontier of the specified tree with nodes ordered from deepest to shallowest.
      Parameters:
      root - The root of the parse tree.
      punctSet - A set of punctuation symbols to be used.
      Returns:
      The right frontier of the specified parse tree.
    • setBuilt

      private void setBuilt(Parse p)
    • setComplete

      private void setComplete(Parse p)
    • setIncomplete

      private void setIncomplete(Parse p)
    • isBuilt

      private boolean isBuilt(Parse p)
    • isComplete

      private boolean isComplete(Parse p)
    • advanceChunks

      protected Parse[] advanceChunks(Parse p, double minChunkScore)
      Description copied from class: AbstractBottomUpParser
      Returns the top chunk sequences for the specified Parse.
      Overrides:
      advanceChunks in class AbstractBottomUpParser
      Parameters:
      p - A pos-tag assigned Parse.
      minChunkScore - A minimum score below which chunks should not be advanced.
      Returns:
      The top chunk assignments to the specified Parse.
    • advanceParses

      protected Parse[] advanceParses(Parse p, double probMass)
      Description copied from class: AbstractBottomUpParser
      Advances the specified Parse and returns the an array advanced parses whose probability accounts for more than the specified amount of probability mass.
      Specified by:
      advanceParses in class AbstractBottomUpParser
      Parameters:
      p - The Parse to advance.
      probMass - The amount of probability mass that should be accounted for by the advanced parses.
    • advanceTop

      protected void advanceTop(Parse p)
      Description copied from class: AbstractBottomUpParser
      Adds the AbstractBottomUpParser.TOP_NODE to the specified parse.
      Specified by:
      advanceTop in class AbstractBottomUpParser
      Parameters:
      p - The complete Parse.
    • train

      public static ParserModel train(String languageCode, ObjectStream<Parse> parseSamples, HeadRules rules, TrainingParameters mlParams) throws IOException
      Starts a training of a ParserModel.
      Parameters:
      languageCode - An ISO conform language code.
      parseSamples - The samples as input.
      rules - The HeadRules to use.
      mlParams - The parameters for training.
      Returns:
      A valid ParserModel.
      Throws:
      IOException - Thrown if IO errors occurred during training.
    • train

      public static ParserModel train(String languageCode, ObjectStream<Parse> parseSamples, HeadRules rules, int iterations, int cutoff) throws IOException
      Starts a training of a ParserModel.
      Parameters:
      languageCode - An ISO conform language code.
      parseSamples - The samples as input.
      rules - The HeadRules to use.
      iterations - The number of iterations to be conducted.
      cutoff - The cut-off parameter to be used.
      Returns:
      A valid ParserModel.
      Throws:
      IOException - Thrown if IO errors occurred during training.