public static Class lookupAnnotationKeyWithClassname(Env env, String name) { Class annotationKey = lookupAnnotationKey(env, name); if (annotationKey == null) { try { Class clazz = Class.forName(name); return clazz; } catch (ClassNotFoundException ex) { } return null; } else { return annotationKey; } }
@Override public Value apply(Env env, List<Value> in) { if (in.get(0) == null || in.get(0).get() == null ) return null; // Allow for null Map map = (Map) in.get(0).get(); Object key = in.get(1).get(); if (in.size() >= 3) { Value fieldValue = in.get(2); if (fieldValue != null) { map.put(key, fieldValue.get()); } else { map.remove(key); } } Object obj = map.get(key); if (in.size() == 2 && obj == null && key instanceof String) { Class annotationFieldClass = null; annotationFieldClass = EnvLookup.lookupAnnotationKey(env, (String) key); if (annotationFieldClass != null) { obj = map.get(annotationFieldClass); } } return Expressions.asValue(env, obj); // return Expressions.PrimitiveValue.create(null, obj); } };
Class annotationFieldClass = null; if (field instanceof String) { annotationFieldClass = EnvLookup.lookupAnnotationKey(env, (String) field); if (annotationFieldClass == null) { throw new IllegalArgumentException("Cannot get annotation field " + field);
@Override public Value evaluate(Env env, Object... args) { Expression exp = null; String varName = value; if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; if (VAR_SELF.equals(varName)) { return createValue(varName, cm); } Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { return createValue(varName, cm.get(annotationKey)); } } } if (VAR_SELF.equals(varName)) { return createValue(varName, env.peek(varName)); } Object obj = env.get(varName); if (obj != null) { exp = asExpression(env, obj); } Value v = exp != null? exp.evaluate(env, args): null; if (v == null) { log.info("Unknown variable: " + varName); } return v; } public Expression assign(Expression expr) {
public Value evaluate(Env env, Object... args) { Value value = valueExpr.evaluate(env, args); if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { cm.set(annotationKey, (value != null)? value.get():null); return value; } } } if (bindAsValue) { env.bind(varName, value); } else { env.bind(varName, (value != null)? value.get():null); if (TYPE_REGEX == value.getType()) { try { Object vobj = value.get(); if (vobj instanceof String) { env.bindStringRegex(varName, (String) vobj); } else if (vobj instanceof Pattern) { env.bindStringRegex(varName, ((Pattern) vobj).pattern()); } } catch (Exception ex) {} } } return value; }
public static Class lookupAnnotationKeyWithClassname(Env env, String name) { Class annotationKey = lookupAnnotationKey(env, name); if (annotationKey == null) { try { Class clazz = Class.forName(name); return clazz; } catch (ClassNotFoundException ex) { } return null; } else { return annotationKey; } }
public static Class lookupAnnotationKeyWithClassname(Env env, String name) { Class annotationKey = lookupAnnotationKey(env, name); if (annotationKey == null) { try { Class clazz = Class.forName(name); return clazz; } catch (ClassNotFoundException ex) { } return null; } else { return annotationKey; } }
@Override public Value apply(Env env, List<Value> in) { if (in.get(0) == null || in.get(0).get() == null ) return null; // Allow for null Map map = (Map) in.get(0).get(); Object key = in.get(1).get(); if (in.size() >= 3) { Value fieldValue = in.get(2); if (fieldValue != null) { map.put(key, fieldValue.get()); } else { map.remove(key); } } Object obj = map.get(key); if (in.size() == 2 && obj == null && key instanceof String) { Class annotationFieldClass = null; annotationFieldClass = EnvLookup.lookupAnnotationKey(env, (String) key); if (annotationFieldClass != null) { obj = map.get(annotationFieldClass); } } return Expressions.asValue(env, obj); // return Expressions.PrimitiveValue.create(null, obj); } };
@Override public Value apply(Env env, List<Value> in) { if (in.get(0) == null || in.get(0).get() == null ) return null; // Allow for null Map map = (Map) in.get(0).get(); Object key = in.get(1).get(); if (in.size() >= 3) { Value fieldValue = in.get(2); if (fieldValue != null) { map.put(key, fieldValue.get()); } else { map.remove(key); } } Object obj = map.get(key); if (in.size() == 2 && obj == null && key instanceof String) { Class annotationFieldClass = null; annotationFieldClass = EnvLookup.lookupAnnotationKey(env, (String) key); if (annotationFieldClass != null) { obj = map.get(annotationFieldClass); } } return Expressions.asValue(env, obj); // return Expressions.PrimitiveValue.create(null, obj); } };
@Override public Value apply(Env env, List<Value> in) { if (in.get(0) == null || in.get(0).get() == null ) return null; // Allow for null Map map = (Map) in.get(0).get(); Object key = in.get(1).get(); if (in.size() >= 3) { Value fieldValue = in.get(2); if (fieldValue != null) { map.put(key, fieldValue.get()); } else { map.remove(key); } } Object obj = map.get(key); if (in.size() == 2 && obj == null && key instanceof String) { Class annotationFieldClass = null; annotationFieldClass = EnvLookup.lookupAnnotationKey(env, (String) key); if (annotationFieldClass != null) { obj = map.get(annotationFieldClass); } } return Expressions.asValue(env, obj); // return Expressions.PrimitiveValue.create(null, obj); } };
private void addAnnotationPatterns(CollectionValuedMap<Class, Pair<Pattern,Pattern>> annotationPatterns, String conf, boolean attrOnly) { String[] annoPatternStrings = conf == null ? new String[0] : conf.trim().split("\\s*,\\s*"); for (String annoPatternString:annoPatternStrings) { String[] annoPattern = annoPatternString.split("\\s*=\\s*", 2); if (annoPattern.length != 2) { throw new IllegalArgumentException("Invalid annotation to tag pattern: " + annoPatternString); } String annoKeyString = annoPattern[0]; String pattern = annoPattern[1]; Class annoKey = EnvLookup.lookupAnnotationKey(null, annoKeyString); if (annoKey == null) { throw new IllegalArgumentException("Cannot resolve annotation key " + annoKeyString); } Matcher m = TAG_ATTR_PATTERN.matcher(pattern); if (m.matches()) { Pattern tagPattern = toCaseInsensitivePattern(m.group(1)); Pattern attrPattern = toCaseInsensitivePattern(m.group(2)); annotationPatterns.add(annoKey, Pair.makePair(tagPattern, attrPattern)); } else { if (attrOnly) { // attribute is require throw new IllegalArgumentException("Invalid tag pattern: " + pattern + " for annotation key " + annoKeyString); } else { Pattern tagPattern = toCaseInsensitivePattern(pattern); annotationPatterns.add(annoKey, Pair.makePair(tagPattern, (Pattern) null)); } } } }
annotationField = (Class) annoKey; } else if (annoKey instanceof String) { annotationField = EnvLookup.lookupAnnotationKey(env, (String) annoKey); } else if (annotationField == null) { annotationField = CoreMap.class;
Class annotationFieldClass = null; if (field instanceof String) { annotationFieldClass = EnvLookup.lookupAnnotationKey(env, (String) field); if (annotationFieldClass == null) { throw new IllegalArgumentException("Cannot get annotation field " + field);
public TokensRegexAnnotator(String name, Properties props) { String prefix = (name == null)? "":name + "."; String[] files = PropertiesUtils.getStringArray(props, prefix + "rules"); if (files == null || files.length == 0) { throw new RuntimeException("No rules specified for TokensRegexAnnotator " + name + ", check " + prefix + "rules property"); } env = TokenSequencePattern.getNewEnv(); env.bind("options", options); extractor = CoreMapExpressionExtractor.createExtractorFromFiles(env, files); verbose = PropertiesUtils.getBool(props, prefix + "verbose", verbose); options.setTokenOffsets = PropertiesUtils.getBool(props, prefix + "setTokenOffsets", options.setTokenOffsets); options.extractWithTokens = PropertiesUtils.getBool(props, prefix + "extractWithTokens", options.extractWithTokens); options.flatten = PropertiesUtils.getBool(props, prefix + "flatten", options.flatten); String matchedExpressionsAnnotationKeyName = props.getProperty(prefix + "matchedExpressionsAnnotationKey"); if (matchedExpressionsAnnotationKeyName != null) { options.matchedExpressionsAnnotationKey = EnvLookup.lookupAnnotationKey(env, matchedExpressionsAnnotationKeyName); if (options.matchedExpressionsAnnotationKey == null) { String propName = prefix + "matchedExpressionsAnnotationKey"; throw new RuntimeException("Cannot determine annotation key for " + propName + "=" + matchedExpressionsAnnotationKeyName); } } }
public Value evaluate(Env env, Object... args) { Expression exp = null; String varName = value; if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; if (VAR_SELF.equals(varName)) { return createValue(varName, cm); } Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { return createValue(varName, cm.get(annotationKey)); } } } if (VAR_SELF.equals(varName)) { return createValue(varName, env.peek(varName)); } Object obj = env.get(varName); if (obj != null) { exp = asExpression(env, obj); } Value v = exp != null? exp.evaluate(env, args): null; if (v == null) { System.err.println("Unknown variable: " + varName); } return v; } public Expression assign(Expression expr) {
@Override public Value evaluate(Env env, Object... args) { Expression exp = null; String varName = value; if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; if (VAR_SELF.equals(varName)) { return createValue(varName, cm); } Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { return createValue(varName, cm.get(annotationKey)); } } } if (VAR_SELF.equals(varName)) { return createValue(varName, env.peek(varName)); } Object obj = env.get(varName); if (obj != null) { exp = asExpression(env, obj); } Value v = exp != null? exp.evaluate(env, args): null; if (v == null) { log.info("Unknown variable: " + varName); } return v; } public Expression assign(Expression expr) {
@Override public Value evaluate(Env env, Object... args) { Expression exp = null; String varName = value; if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; if (VAR_SELF.equals(varName)) { return createValue(varName, cm); } Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { return createValue(varName, cm.get(annotationKey)); } } } if (VAR_SELF.equals(varName)) { return createValue(varName, env.peek(varName)); } Object obj = env.get(varName); if (obj != null) { exp = asExpression(env, obj); } Value v = exp != null? exp.evaluate(env, args): null; if (v == null) { log.info("Unknown variable: " + varName); } return v; } public Expression assign(Expression expr) {
public Value evaluate(Env env, Object... args) { Value value = valueExpr.evaluate(env, args); if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { cm.set(annotationKey, (value != null)? value.get():null); return value; } } } if (bindAsValue) { env.bind(varName, value); } else { env.bind(varName, (value != null)? value.get():null); if (TYPE_REGEX == value.getType()) { try { Object vobj = value.get(); if (vobj instanceof String) { env.bindStringRegex(varName, (String) vobj); } else if (vobj instanceof Pattern) { env.bindStringRegex(varName, ((Pattern) vobj).pattern()); } } catch (Exception ex) {} } } return value; }
public Value evaluate(Env env, Object... args) { Value value = valueExpr.evaluate(env, args); if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { cm.set(annotationKey, (value != null)? value.get():null); return value; } } } if (bindAsValue) { env.bind(varName, value); } else { env.bind(varName, (value != null)? value.get():null); if (TYPE_REGEX == value.getType()) { try { Object vobj = value.get(); if (vobj instanceof String) { env.bindStringRegex(varName, (String) vobj); } else if (vobj instanceof Pattern) { env.bindStringRegex(varName, ((Pattern) vobj).pattern()); } } catch (Exception ex) {} } } return value; }
public Value evaluate(Env env, Object... args) { Value value = valueExpr.evaluate(env, args); if (args != null) { if (args.length == 1 && args[0] instanceof CoreMap) { CoreMap cm = (CoreMap) args[0]; Class annotationKey = EnvLookup.lookupAnnotationKey(env, varName); if (annotationKey != null) { cm.set(annotationKey, (value != null)? value.get():null); return value; } } } if (bindAsValue) { env.bind(varName, value); } else { env.bind(varName, (value != null)? value.get():null); if (TYPE_REGEX == value.getType()) { try { Object vobj = value.get(); if (vobj instanceof String) { env.bindStringRegex(varName, (String) vobj); } else if (vobj instanceof Pattern) { env.bindStringRegex(varName, ((Pattern) vobj).pattern()); } } catch (Exception ex) {} } } return value; }