use of edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser in project CoreNLP by stanfordnlp.
the class CoreMapExpressionExtractor method createExtractorFromFiles.
/**
* Creates an extractor using the specified environment, and reading the rules from the given filenames.
* @param env
* @param filenames
* @throws RuntimeException
*/
public static <M extends MatchedExpression> CoreMapExpressionExtractor<M> createExtractorFromFiles(Env env, List<String> filenames) throws RuntimeException {
CoreMapExpressionExtractor<M> extractor = new CoreMapExpressionExtractor<>(env);
for (String filename : filenames) {
try {
if (verbose)
log.info("Reading TokensRegex rules from " + filename);
BufferedReader br = IOUtils.readerFromString(filename);
TokenSequenceParser parser = new TokenSequenceParser();
parser.updateExpressionExtractor(extractor, br);
IOUtils.closeIgnoringExceptions(br);
} catch (Exception ex) {
throw new RuntimeException("Error parsing file: " + filename, ex);
}
}
return extractor;
}
use of edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser in project CoreNLP by stanfordnlp.
the class TokenSequencePattern method getNewEnv.
public static Env getNewEnv() {
Env env = new Env(new TokenSequenceParser());
env.initDefaultBindings();
return env;
}
use of edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser in project CoreNLP by stanfordnlp.
the class CoreMapExpressionExtractor method createExtractorFromString.
/**
* Creates an extractor using the specified environment, and reading the rules from the given string
* @param env
* @param str
* @throws IOException, ParseException
*/
public static CoreMapExpressionExtractor createExtractorFromString(Env env, String str) throws IOException, ParseException, TokenSequenceParseException {
TokenSequenceParser parser = new TokenSequenceParser();
CoreMapExpressionExtractor extractor = parser.getExpressionExtractor(env, new StringReader(str));
return extractor;
}
Aggregations