private static Class lookupAnnotationKey(SequencePattern.Env env, String name) { if (env != null) { Object obj = env.get(name); if (obj != null && obj instanceof Class) { return (Class) obj; } } AnnotationLookup.KeyLookup lookup = AnnotationLookup.getCoreKey(name); if (lookup != null) { return lookup.coreKey; } else { return null; } }
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; } }
public static void annotateChunk(CoreMap chunk, Map<String,String> attributes) { for (String attr:attributes.keySet()) { String value = attributes.get(attr); AnnotationLookup.KeyLookup lookup = AnnotationLookup.getCoreKey(attr); if (attr != null) { if (value != null) { try { Class valueClass = AnnotationLookup.getValueType(lookup.coreKey); if (valueClass == String.class) { chunk.set((Class<? extends CoreAnnotation>) lookup.coreKey, value); } else { Method valueOfMethod = valueClass.getMethod("valueOf", String.class); if (valueOfMethod != null) { chunk.set((Class<? extends CoreAnnotation>) lookup.coreKey, valueOfMethod.invoke(valueClass, value)); } } } catch (Exception ex) { throw new RuntimeException("Unable to annotate attribute " + attr, ex); } } else { chunk.set((Class<? extends CoreAnnotation>) lookup.coreKey, null); } } else { throw new UnsupportedOperationException("Unknown attributes: " + attr); } } }
public static void annotateChunk(CoreMap chunk, Map<String,String> attributes) { for (String attr:attributes.keySet()) { String value = attributes.get(attr); AnnotationLookup.KeyLookup lookup = AnnotationLookup.getCoreKey(attr); if (attr != null) { if (value != null) { try { Class valueClass = AnnotationLookup.getValueType(lookup.coreKey); if (valueClass == String.class) { chunk.set(lookup.coreKey, value); } else { Method valueOfMethod = valueClass.getMethod("valueOf", String.class); if (valueOfMethod != null) { chunk.set(lookup.coreKey, valueOfMethod.invoke(valueClass, value)); } } } catch (Exception ex) { throw new RuntimeException("Unable to annotate attribute " + attr, ex); } } else { chunk.set(lookup.coreKey, null); } } else { throw new UnsupportedOperationException("Unknown attributes: " + attr); } } }
String key = keys[i]; String value = values[i]; KeyLookup lookup = AnnotationLookup.getCoreKey(key);
String key = keys[i]; String value = values[i]; KeyLookup lookup = AnnotationLookup.getCoreKey(key);