TimeoutMatcher - apache/ctakes GitHub Wiki
Class that can / should be used to find text spans using regular expressions. It runs Matcher find {@link Matcher#find()} in a separate thread so that it may be interrupted at a set timeout. This prevents infinite loop problems that can be caused by poorly-built expressions or unexpected text contents. The timeout can be specified in milliseconds between 100 and 10,000. Large timeouts are unadvised. If a large amount of text needs to be parsed then it is better to split up the text logically and use smaller timeouts. The default timeout is 1000 milliseconds. Extending Matcher would be better, but it is final.
Proper usage is:
try ( TimeoutMatcher finder = new TimeoutMatcher( "\\s+", "Hello World !" ) ) {
Matcher matcher = finder.find();
while ( matcher != null ) {
... <do something with the match> ...
matcher = finder.find();
}
} catch ( IllegalArgumentException iaE ) {
... <do something with the exception> ...
}
- Author: SPF , chip-nlp
- Version: %I%
-
Since: 11/5/2016
Uses the default timeout of 1000 milliseconds
-
Parameters:
-
regexregular expression -
texttext to parse
-
-
Exceptions:
-
IllegalArgumentExceptionif the regular expression is null or malformed
-
public TimeoutMatcher( final String regex, final String text, final int timeoutMillis ) throws IllegalArgumentException
-
Parameters:
-
regexregular expression -
texttext to parse -
timeoutMillismilliseconds at which the regex match should abort, between 100 and 10000
-
-
Exceptions:
-
IllegalArgumentExceptionif the regular expression is null or malformed
-
Uses the default timeout of 1000 milliseconds
-
Parameters:
-
patternPattern compiled from a regular expression -
texttext to parse
-
-
Exceptions:
-
IllegalArgumentExceptionif the pattern is null or malformed
-
public TimeoutMatcher( final Pattern pattern, final String text, final int timeoutMillis ) throws IllegalArgumentException
Uses the default timeout of 1000 milliseconds
-
Parameters:
-
patternPattern compiled from a regular expression -
texttext to parse -
timeoutMillismilliseconds at which the regex match should abort, between 100 and 10000
-
-
Exceptions:
-
IllegalArgumentExceptionif the pattern is null or malformed
-
-
Returns: a matcher representing the next call to {@link Matcher#find()}
shut down the executor {@inheritDoc}
Simple Callable that runs a {@link Matcher} on text
{@inheritDoc}
- Returns: matcher if there is another find, else null