예제 #1
0
 // TODO: For additional keys, read map of name to Class from file???
 public static Class lookupAnnotationKey(Env env, String name) {
   if (env != null) {
     Object obj = env.get(name);
     if (obj != null) {
       if (obj instanceof Class) {
         return (Class) obj;
       } else if (obj instanceof Value) {
         obj = ((Value) obj).get();
         if (obj instanceof Class) {
           return (Class) obj;
         }
       }
     }
   }
   AnnotationLookup.KeyLookup lookup = AnnotationLookup.getCoreKey(name);
   if (lookup != null) {
     return lookup.coreKey;
   } else {
     try {
       Class clazz = Class.forName(name);
       return clazz;
     } catch (ClassNotFoundException ex) {
     }
     return null;
   }
 }
예제 #2
0
 public static Class getDefaultTextAnnotationKey(Env env) {
   if (env != null) {
     Class obj = env.getDefaultTextAnnotationKey();
     if (obj != null) {
       return obj;
     }
   }
   return CoreAnnotations.TextAnnotation.class;
 }
예제 #3
0
 public static Class getDefaultNestedResultsAnnotationKey(Env env) {
   if (env != null) {
     Class obj = env.getDefaultNestedResultsAnnotationKey();
     if (obj != null) {
       return obj;
     }
   }
   return null;
 }
예제 #4
0
 public static Function<MatchedExpression, ?> getDefaultResultAnnotationExtractor(Env env) {
   if (env != null) {
     Function<MatchedExpression, ?> obj = env.getDefaultResultsAnnotationExtractor();
     if (obj != null) {
       return obj;
     }
   }
   return null;
 }
예제 #5
0
 public static List<Class> getDefaultResultAnnotationKey(Env env) {
   if (env != null) {
     List<Class> obj = env.getDefaultResultAnnotationKey();
     if (obj != null) {
       return obj;
     }
   }
   return null;
 }
예제 #6
0
 public static Map<Class, CoreMapAttributeAggregator> getDefaultTokensAggregators(Env env) {
   if (env != null) {
     Map<Class, CoreMapAttributeAggregator> obj = env.getDefaultTokensAggregators();
     if (obj != null) {
       return obj;
     }
   }
   return CoreMapAttributeAggregator.DEFAULT_NUMERIC_TOKENS_AGGREGATORS;
 }
 private MultiPatternMatcher<CoreMap> createPatternMatcher(
     Map<SequencePattern<CoreMap>, Entry> patternToEntry) {
   // Convert to tokensregex pattern
   int patternFlags = ignoreCase ? Pattern.CASE_INSENSITIVE : 0;
   int stringMatchFlags = ignoreCase ? NodePattern.CASE_INSENSITIVE : 0;
   Env env = TokenSequencePattern.getNewEnv();
   env.setDefaultStringPatternFlags(patternFlags);
   env.setDefaultStringMatchFlags(stringMatchFlags);
   NodePattern<String> posTagPattern =
       (validPosPattern != null && PosMatchType.MATCH_ALL_TOKENS.equals(posMatchType))
           ? new CoreMapNodePattern.StringAnnotationRegexPattern(validPosPattern)
           : null;
   List<TokenSequencePattern> patterns = new ArrayList<>(entries.size());
   for (Entry entry : entries) {
     TokenSequencePattern pattern;
     if (entry.tokensRegex != null) {
       // TODO: posTagPatterns...
       pattern = TokenSequencePattern.compile(env, entry.tokensRegex);
     } else {
       List<SequencePattern.PatternExpr> nodePatterns = new ArrayList<>();
       for (String p : entry.regex) {
         CoreMapNodePattern c = CoreMapNodePattern.valueOf(p, patternFlags);
         if (posTagPattern != null) {
           c.add(CoreAnnotations.PartOfSpeechAnnotation.class, posTagPattern);
         }
         nodePatterns.add(new SequencePattern.NodePatternExpr(c));
       }
       pattern =
           TokenSequencePattern.compile(new SequencePattern.SequencePatternExpr(nodePatterns));
     }
     if (entry.annotateGroup < 0 || entry.annotateGroup > pattern.getTotalGroups()) {
       throw new RuntimeException("Invalid match group for entry " + entry);
     }
     pattern.setPriority(entry.priority);
     patterns.add(pattern);
     patternToEntry.put(pattern, entry);
   }
   return TokenSequencePattern.getMultiPatternMatcher(patterns);
 }