Package opennlp.tools.formats.ad
Class ADNameSampleStream
java.lang.Object
opennlp.tools.formats.ad.ADNameSampleStream
- All Implemented Interfaces:
AutoCloseable,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 Summary
FieldsModifier and TypeFieldDescriptionprivate final ObjectStream<ADSentenceStream.Sentence> private static final charprivate Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate final booleanprivate static final charprivate static final charprivate intprivate intThe number of distinct LIT or CIE texts read so far, minus one.private StringThe LIT or CIE text name of the sentence read last.private static final char[] -
Constructor Summary
ConstructorsConstructorDescriptionADNameSampleStream(InputStreamFactory in, String charsetName, boolean splitHyphenatedTokens) Deprecated, for removal: This API element is subject to removal in a future version.ADNameSampleStream(ObjectStream<String> lineStream, boolean splitHyphenatedTokens) Initializes a newADNameSampleStreamstream from aObjectStream<String>, that could be aPlainTextByLineStreamobject. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddIfNotEmpty(String firstTok, List<String> out) voidclose()Closes theObjectStreamand releases all allocated resources.private StringParses a NER tag in Arvores Deitadas format.private intgetTextID(ADSentenceStream.Sentence paragraph) Reads the id of the text a sentence belongs to; adaptive data is cleared when it changes.(package private) booleanisAlphaNumeric(String tok) Tests whether a token consists of letters and decimal digits only, by code point.private intlettersEnd(String s, int from) Finds the end of a run starting with a letter and continuing with letters or combining marks.(package private) String[]Splits a hyphenated token into the letters before the hyphen, the letters after it, and the rest.private voidRecursive method to process aADSentenceStream.SentenceParser.Nodein Arvores Deitadas format.private voidprocessLeaf(ADSentenceStream.SentenceParser.Leaf leaf, List<String> sentence, List<Span> names) Processes aADSentenceStream.SentenceParser.Leafof Arvores Detaitadas formatprocessLexeme(String lexemeStr) processTok(String tok) read()Returns the nextObjectStreamobject.voidreset()Repositions the stream at the beginning and the previously seen object sequence will be repeated exactly.(package private) String[]Splits a lexeme on underscores into its non-empty parts, so a lexeme such asRio_de_Janeiroyields its three words.(package private) StringtagContent(String t) Extracts the content of a NER tag in Arvores Deitadas format, between the optionalNER:prefix and the closing angle bracket.
-
Field Details
-
HAREM
-
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
- See Also:
-
SCIENTIFIC_PREFIX
- See Also:
-
adSentenceStream
-
leftContractionPart
-
splitHyphenatedTokens
private final boolean splitHyphenatedTokens -
textID
private int textID -
textIdMeta2
private int textIdMeta2The number of distinct LIT or CIE texts read so far, minus one. -
textMeta2
The LIT or CIE text name of the sentence read last.
-
-
Constructor Details
-
ADNameSampleStream
Initializes a newADNameSampleStreamstream from aObjectStream<String>, that could be aPlainTextByLineStreamobject.- Parameters:
lineStream- AnObjectStream<String>as input.splitHyphenatedTokens- Iftruehyphenated tokens will be separated: "carros-monstro" > "carros" "-" "monstro". Combining marks remain attached to their letters. Iffalse, 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 newADNameSampleStreamfrom anInputStreamFactory- Parameters:
in- The CorpusInputStreamFactory.charsetName- Thecharsetto use for reading of the corpus.splitHyphenatedTokens- Iftruehyphenated tokens will be separated: "carros-monstro" > "carros" "-" "monstro". Combining marks remain attached to their letters. Iffalse, hyphenated words remain single tokens.- Throws:
IOException
-
-
Method Details
-
read
Description copied from interface:ObjectStreamReturns the nextObjectStreamobject. Calling this method repeatedly until it returnsnullwill return each object from the underlying source exactly once.- Specified by:
readin interfaceObjectStream<NameSample>- Returns:
- The next object or
nullto 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 aADSentenceStream.SentenceParser.Nodein Arvores Deitadas format.- Parameters:
node- TheADSentenceStream.SentenceParser.Nodeto be processed.sentence- Thesentence tokensprocessed so far.names- Thenamesprocessed so far.
-
processLeaf
private void processLeaf(ADSentenceStream.SentenceParser.Leaf leaf, List<String> sentence, List<Span> names) Processes aADSentenceStream.SentenceParser.Leafof Arvores Detaitadas format- Parameters:
leaf- TheADSentenceStream.SentenceParser.Leafto be processedsentence- Thesentence tokensprocessed so far.names- Thenamesprocessed so far.
-
processLexeme
-
processTok
-
addIfNotEmpty
-
splitOnUnderscores
Splits a lexeme on underscores into its non-empty parts, so a lexeme such asRio_de_Janeiroyields 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
Tests whether a token consists of letters and decimal digits only, by code point.- Parameters:
tok- The token.- Returns:
trueif the token is non-empty and every code point is a letter or a decimal digit.
-
matchHyphenatedToken
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
nullwhen absent, ornullif the token has none of the three shapes.
-
lettersEnd
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
fromif no letter starts there.
-
tagContent
Extracts the content of a NER tag in Arvores Deitadas format, between the optionalNER:prefix and the closing angle bracket.- Parameters:
t- The tag.- Returns:
- The content, or
nulliftis not enclosed in angle brackets.
-
getNER
Parses a NER tag in Arvores Deitadas format.- Parameters:
tags- The NER tag in Arvores Deitadas format.- Returns:
- The NER tag, or
nullif not a NER tag in Arvores Deitadas format.
-
reset
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:
resetin interfaceObjectStream<NameSample>- Throws:
IOException- Thrown if there is an error during resetting the stream.UnsupportedOperationException- Thrown if thereset()is not supported. By default, this is the case.
-
close
Description copied from interface:ObjectStreamCloses theObjectStreamand releases all allocated resources. After close was called, it's not allowed to callObjectStream.read()orObjectStream.reset().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceObjectStream<NameSample>- Throws:
IOException- Thrown if there is an error during closing the stream.
-
getTextID
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 anint.
-