本文整理匯總了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);
}
}
}