Package opennlp.tools.namefind
Class RegexNameFinder
- java.lang.Object
-
- opennlp.tools.namefind.RegexNameFinder
-
- All Implemented Interfaces:
TokenNameFinder
public final class RegexNameFinder extends Object implements TokenNameFinder
ATokenNameFinder
implementation based on a series of regular expressions.
-
-
Constructor Summary
Constructors Constructor Description RegexNameFinder(Map<String,Pattern[]> regexMap)
Initializes aRegexNameFinder
instance.RegexNameFinder(Pattern[] patterns)
Deprecated.Use constructorRegexNameFinder(Pattern[], String)
for single types, and/or constructorRegexNameFinder(Map)
instead.RegexNameFinder(Pattern[] patterns, String type)
Initializes aRegexNameFinder
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearAdaptiveData()
Forgets all adaptive data which was collected during previous calls to one of the find methods.Span[]
find(String text)
Findsspans
with character indices, rather than word.Span[]
find(String[] tokens)
Generates name tags for the given sequence, typically a sentence, returningtoken spans
for any identified names.Pattern[]
getMatchingPatterns()
String
getSpanType()
void
setMatchingPatterns(Pattern[] mPatterns)
void
setSpanType(String sType)
-
-
-
Constructor Detail
-
RegexNameFinder
public RegexNameFinder(Map<String,Pattern[]> regexMap)
Initializes aRegexNameFinder
instance.
-
RegexNameFinder
public RegexNameFinder(Pattern[] patterns, String type)
Initializes aRegexNameFinder
instance.- Parameters:
patterns
- Thepatterns
to use. Must not benull
and not be empty.type
- The type to use.- Throws:
IllegalArgumentException
- Thrown ifpatterns
werenull
or empty.
-
RegexNameFinder
@Deprecated public RegexNameFinder(Pattern[] patterns)
Deprecated.Use constructorRegexNameFinder(Pattern[], String)
for single types, and/or constructorRegexNameFinder(Map)
instead.Initializes aRegexNameFinder
instance.- Parameters:
patterns
- Thepatterns
to use. Must not benull
and not be empty.- Throws:
IllegalArgumentException
- Thrown ifpatterns
werenull
or empty.
-
-
Method Detail
-
find
public Span[] find(String[] tokens)
Description copied from interface:TokenNameFinder
Generates name tags for the given sequence, typically a sentence, returningtoken spans
for any identified names.- Specified by:
find
in interfaceTokenNameFinder
- Parameters:
tokens
- An array of the tokens or words of the sequence, typically a sentence.- Returns:
- An array of
spans
for each of the names identified.
-
find
public Span[] find(String text)
Findsspans
with character indices, rather than word.- Parameters:
text
- The text to use.- Returns:
- A
Span
representing the annotations.
-
clearAdaptiveData
public void clearAdaptiveData()
Description copied from interface:TokenNameFinder
Forgets all adaptive data which was collected during previous calls to one of the find methods.Note: This method should typically be called at the end of the processing of a document.
- Specified by:
clearAdaptiveData
in interfaceTokenNameFinder
-
getMatchingPatterns
public Pattern[] getMatchingPatterns()
- Returns:
- Retrieves the
matching patterns
used.
-
setMatchingPatterns
public void setMatchingPatterns(Pattern[] mPatterns)
- Parameters:
mPatterns
- Thematching patterns
to be set.
-
-