Search in sources :

Example 1 with TokenSequenceParser

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;
}
Also used : BufferedReader(java.io.BufferedReader) TokenSequenceParser(edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser) ParseException(edu.stanford.nlp.ling.tokensregex.parser.ParseException) IOException(java.io.IOException) TokenSequenceParseException(edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParseException)

Example 2 with TokenSequenceParser

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;
}
Also used : TokenSequenceParser(edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser)

Example 3 with TokenSequenceParser

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;
}
Also used : TokenSequenceParser(edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser) StringReader(java.io.StringReader)

Aggregations

TokenSequenceParser (edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser)3 ParseException (edu.stanford.nlp.ling.tokensregex.parser.ParseException)1 TokenSequenceParseException (edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParseException)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1