Class MascSentence

java.lang.Object
opennlp.tools.util.Span
opennlp.tools.formats.masc.MascSentence
All Implemented Interfaces:
Serializable, Comparable<Span>

public class MascSentence extends Span
See Also:
  • Field Details

  • Constructor Details

    • MascSentence

      public MascSentence(int s, int e, String text, List<MascWord> sentenceQuarks, List<MascWord> allQuarks)
      Initializes a MascSentence containing its associated text and quarks
      Parameters:
      s - Start of the sentence within the corpus file
      e - End of the sentence within the corpus file
      text - The reference to text of the corpus file
      sentenceQuarks - The quarks found in that sentence
      allQuarks - The reference to a list of all quarks in the file
  • Method Details

    • tokenizePenn

      boolean tokenizePenn(Map<Integer,int[]> tokenToQuarks, Map<Integer,int[]> quarkToTokens, Map<Integer,String> tokenToBase, Map<Integer,String> tokenToTag) throws IOException
      Add the Penn tokenization and POS tagging to the sentence.
      Parameters:
      tokenToQuarks - A map from token ID to quarks in that token.
      quarkToTokens - A map of quark IDs and the token IDs containing that quark.
      tokenToBase - Token ID to the token base.
      tokenToTag - Token ID to the POS tag.
      Returns:
      true if no issue encountered, false if tokens cross sentence boundaries.
      Throws:
      IOException - Thrown if IO errors occurred.
    • addNamedEntities

      boolean addNamedEntities(Map<Integer,String> entityIDtoEntityType, Map<Integer, List<Integer>> entityIDsToTokens) throws IOException
      Add the named entity annotation to the tokenized sentence
      Parameters:
      entityIDtoEntityType - Maps the named entity ID to its type
      entityIDsToTokens - A list of tokens covered by each named entity
      Returns:
      true if all went well, false if named entities overlap.
      Throws:
      IOException - Thrown if IO errors occurred.
    • getNamedEntities

      public List<Span> getNamedEntities()
      Returns:
      Retrieves the named entities, e.g. Span(1,3, "org") for tokens [1,3).
    • getSentDetectText

      public String getSentDetectText()
      Returns:
      Retrieves text of the sentence as defined by the sentence segmentation annotation.
    • getTokenText

      public String getTokenText()
      Returns:
      Retrieves text of the sentence as defined by the tokens in it.
    • getTokenStrings

      public List<String> getTokenStrings()
      Returns:
      The texts of the individual tokens in the sentence
    • getTokensSpans

      public List<Span> getTokensSpans()
      Retrieves the boundaries of individual tokens.
      Returns:
      The spans representing the tokens of the sentence, according to Penn tokenization.
    • getTags

      public List<String> getTags() throws IOException
      Returns:
      Get the (individual) tags of tokens in the sentence.
      Throws:
      IOException - Thrown if used on an un-tokenized sentence.