I have been looking for a solution to extract email addresses, phone numbers, ... from a text using Stanford CoreNLP (RegexNERAnnotator). Can anyone please provide any example?
UPDATE : 04/11/2015: Actually i should asked instead if there is a way Stanford RegexNERAnnotator can supports Java Regular expression.
Example Usage:
final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
List<CoreLabel> tokens = ...;
TokenSequencePattern pattern = TokenSequencePattern.compile(EMAIL_PATTERN);
TokenSequenceMatcher matcher = pattern.getMatcher(tokens);
while (matcher.find()) {
String matchedString = matcher.group();
List<CoreMap> matchedTokens = matcher.groupNodes();
...
}
It seems that it doesn't support Java Regular expression:
Exception in thread "main" edu.stanford.nlp.ling.tokensregex.parser.TokenMgrError: Lexical error at line 1, column 1. Encountered: "^" (94), after : ""
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParserTokenManager.getNextToken(TokenSequenceParserTokenManager.java:1029)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.jj_ntk(TokenSequenceParser.java:3228)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexBasic(TokenSequenceParser.java:784)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexDisjConj(TokenSequenceParser.java:973)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegex(TokenSequenceParser.java:743)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexWithAction(TokenSequenceParser.java:1596)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.parseSequenceWithAction(TokenSequenceParser.java:37)
at edu.stanford.nlp.ling.tokensregex.TokenSequencePattern.compile(TokenSequencePattern.java:186)
at edu.stanford.nlp.ling.tokensregex.TokenSequencePattern.compile(TokenSequencePattern.java:169)