本文整理汇总了Java中edu.stanford.nlp.ling.AnnotationLookup类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationLookup类的具体用法?Java AnnotationLookup怎么用?Java AnnotationLookup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationLookup类属于edu.stanford.nlp.ling包,在下文中一共展示了AnnotationLookup类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupAnnotationKey
import edu.stanford.nlp.ling.AnnotationLookup; //导入依赖的package包/类
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: annotateChunk
import edu.stanford.nlp.ling.AnnotationLookup; //导入依赖的package包/类
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);
}
}
}