Class ADNameSampleStream

java.lang.Object
opennlp.tools.formats.ad.ADNameSampleStream
All Implemented Interfaces:
AutoCloseable, ObjectStream<NameSample>

@Internal public class ADNameSampleStream extends Object implements ObjectStream<NameSample>
Parser for Floresta Sita(c)tica Arvores Deitadas corpus, output to for the Portuguese NER training.

The data contains four named entity types: Person, Organization, Group, Place, Event, ArtProd, Abstract, Thing, Time and Numeric.

Data can be found on this web site.

Information about the format:
Susana Afonso. "Árvores deitadas: Descrição do formato e das opções de análise na Floresta Sintáctica".
12 de Fevereiro de 2006.

Detailed info about the NER tagset.

Whitespace inside the tags of a leaf and in a contraction is the Unicode White_Space property, see StringUtil.isUnicodeWhitespace(char), independent of the whitespace mode.

Note: Do not use this class, internal use only!

  • Field Details

    • HAREM

      private static final Map<String,String> HAREM
    • NER_PREFIX

      private static final String NER_PREFIX
      See Also:
    • HYPHEN

      private static final char HYPHEN
      See Also:
    • UNDERSCORE_SEPARATOR

      private static final char[] UNDERSCORE_SEPARATOR
    • TAG_OPEN

      private static final char TAG_OPEN
      See Also:
    • TAG_CLOSE

      private static final char TAG_CLOSE
      See Also:
    • LITERARY_PREFIX

      private static final String LITERARY_PREFIX
      See Also:
    • SCIENTIFIC_PREFIX

      private static final String SCIENTIFIC_PREFIX
      See Also:
    • adSentenceStream

      private final ObjectStream<ADSentenceStream.Sentence> adSentenceStream
    • leftContractionPart

      private String leftContractionPart
    • splitHyphenatedTokens

      private final boolean splitHyphenatedTokens
    • textID

      private int textID
    • textIdMeta2

      private int textIdMeta2
      The number of distinct LIT or CIE texts read so far, minus one.
    • textMeta2

      private String textMeta2
      The LIT or CIE text name of the sentence read last.
  • Constructor Details

    • ADNameSampleStream

      public ADNameSampleStream(ObjectStream<String> lineStream, boolean splitHyphenatedTokens)
      Initializes a new ADNameSampleStream stream from a ObjectStream<String>, that could be a PlainTextByLineStream object.
      Parameters:
      lineStream - An ObjectStream<String> as input.
      splitHyphenatedTokens - If true hyphenated tokens will be separated: "carros-monstro" > "carros" "-" "monstro". Combining marks remain attached to their letters. If false, hyphenated words remain single tokens.
    • ADNameSampleStream

      @Deprecated(forRemoval=true) public ADNameSampleStream(InputStreamFactory in, String charsetName, boolean splitHyphenatedTokens) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Initializes a new ADNameSampleStream from an InputStreamFactory
      Parameters:
      in - The Corpus InputStreamFactory.
      charsetName - The charset to use for reading of the corpus.
      splitHyphenatedTokens - If true hyphenated tokens will be separated: "carros-monstro" > "carros" "-" "monstro". Combining marks remain attached to their letters. If false, hyphenated words remain single tokens.
      Throws:
      IOException
  • Method Details

    • read

      public NameSample read() throws IOException
      Description copied from interface: ObjectStream
      Returns the next ObjectStream object. Calling this method repeatedly until it returns null will return each object from the underlying source exactly once.
      Specified by:
      read in interface ObjectStream<NameSample>
      Returns:
      The next object or null to signal that the stream is exhausted.
      Throws:
      IOException - Thrown if there is an error during reading.
    • process

      private void process(ADSentenceStream.SentenceParser.Node node, List<String> sentence, List<Span> names)
      Recursive method to process a ADSentenceStream.SentenceParser.Node in Arvores Deitadas format.
      Parameters:
      node - The ADSentenceStream.SentenceParser.Node to be processed.
      sentence - The sentence tokens processed so far.
      names - The names processed so far.
    • processLeaf

      private void processLeaf(ADSentenceStream.SentenceParser.Leaf leaf, List<String> sentence, List<Span> names)
      Processes a ADSentenceStream.SentenceParser.Leaf of Arvores Detaitadas format
      Parameters:
      leaf - The ADSentenceStream.SentenceParser.Leaf to be processed
      sentence - The sentence tokens processed so far.
      names - The names processed so far.
    • processLexeme

      private List<String> processLexeme(String lexemeStr)
    • processTok

      private List<String> processTok(String tok)
    • addIfNotEmpty

      private void addIfNotEmpty(String firstTok, List<String> out)
    • splitOnUnderscores

      String[] splitOnUnderscores(String s)
      Splits a lexeme on underscores into its non-empty parts, so a lexeme such as Rio_de_Janeiro yields its three words. Runs of underscores count as one separator, and leading or trailing underscores add no part.
      Parameters:
      s - The lexeme.
      Returns:
      The parts in order; empty when the lexeme has no character other than underscores.
    • isAlphaNumeric

      boolean isAlphaNumeric(String tok)
      Tests whether a token consists of letters and decimal digits only, by code point.
      Parameters:
      tok - The token.
      Returns:
      true if the token is non-empty and every code point is a letter or a decimal digit.
    • matchHyphenatedToken

      String[] matchHyphenatedToken(String tok)
      Splits a hyphenated token into the letters before the hyphen, the letters after it, and the rest. Three shapes match: letters followed by a final hyphen, a leading hyphen followed by letters and anything, and letters, a hyphen, letters, and anything. Each letter run includes its combining marks without normalizing the original text.
      Parameters:
      tok - The token, at least two characters long.
      Returns:
      The first token, second token, and rest, each null when absent, or null if the token has none of the three shapes.
    • lettersEnd

      private int lettersEnd(String s, int from)
      Finds the end of a run starting with a letter and continuing with letters or combining marks. A mark cannot start a run; marks following a letter stay attached to it.
      Parameters:
      s - The text.
      from - The start offset.
      Returns:
      The offset after the run, or from if no letter starts there.
    • tagContent

      String tagContent(String t)
      Extracts the content of a NER tag in Arvores Deitadas format, between the optional NER: prefix and the closing angle bracket.
      Parameters:
      t - The tag.
      Returns:
      The content, or null if t is not enclosed in angle brackets.
    • getNER

      private String getNER(String tags)
      Parses a NER tag in Arvores Deitadas format.
      Parameters:
      tags - The NER tag in Arvores Deitadas format.
      Returns:
      The NER tag, or null if not a NER tag in Arvores Deitadas format.
    • reset

      public void reset() throws IOException, UnsupportedOperationException
      Repositions the stream at the beginning and the previously seen object sequence will be repeated exactly. This method can be used to re-read the stream if multiple passes over the objects are required.

      The implementation of this method is optional. Starts a new pass with no preceding text, so its first sample clears adaptive data.

      Specified by:
      reset in interface ObjectStream<NameSample>
      Throws:
      IOException - Thrown if there is an error during resetting the stream.
      UnsupportedOperationException - Thrown if the reset() is not supported. By default, this is the case.
    • close

      public void close() throws IOException
      Description copied from interface: ObjectStream
      Closes the ObjectStream and releases all allocated resources. After close was called, it's not allowed to call ObjectStream.read() or ObjectStream.reset().
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ObjectStream<NameSample>
      Throws:
      IOException - Thrown if there is an error during closing the stream.
    • getTextID

      private int getTextID(ADSentenceStream.Sentence paragraph) throws InvalidFormatException
      Reads the id of the text a sentence belongs to; adaptive data is cleared when it changes. In the Amazonia corpus it is the text id of the metadata. In the literary and scientific corpora the text is named by its reference prefix or its source attribute instead, and the id counts the distinct names seen so far, so it changes when a new text starts.
      Parameters:
      paragraph - The sentence.
      Returns:
      The id.
      Throws:
      InvalidFormatException - Thrown if the metadata has no id or one that does not fit into an int.