本文整理匯總了Java中edu.stanford.nlp.util.CoreMap.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java CoreMap.containsKey方法的具體用法?Java CoreMap.containsKey怎麽用?Java CoreMap.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.stanford.nlp.util.CoreMap
的用法示例。
在下文中一共展示了CoreMap.containsKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addEntityMentions
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
static void addEntityMentions(Map<String,Object> sent_info, CoreMap sentence) {
List<CoreMap> coreMentions = sentence.get(MentionsAnnotation.class);
List<Map> jsonMentions = new ArrayList<>();
/* trying to figure out the keys in each mention. here's a printout from one.
MENTION August 2014
class edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation August 2014
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetBeginAnnotation 3
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetEndAnnotation 14
class edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation [August-2, 2014-3]
class edu.stanford.nlp.ling.CoreAnnotations$TokenBeginAnnotation 1
class edu.stanford.nlp.ling.CoreAnnotations$TokenEndAnnotation 3
class edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation DATE
class edu.stanford.nlp.ling.CoreAnnotations$NormalizedNamedEntityTagAnnotation 2014-08
class edu.stanford.nlp.ling.CoreAnnotations$EntityTypeAnnotation DATE
class edu.stanford.nlp.ling.CoreAnnotations$SentenceIndexAnnotation 0
class edu.stanford.nlp.time.TimeAnnotations$TimexAnnotation <TIMEX3 tid="t1" type="DATE" value="2014-08">August 2014</TIMEX3>
MENTION Barack Obama
class edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation Barack Obama
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetBeginAnnotation 17
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetEndAnnotation 29
class edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation [Barack-5, Obama-6]
class edu.stanford.nlp.ling.CoreAnnotations$TokenBeginAnnotation 4
class edu.stanford.nlp.ling.CoreAnnotations$TokenEndAnnotation 6
class edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation PERSON
class edu.stanford.nlp.ling.CoreAnnotations$EntityTypeAnnotation PERSON
class edu.stanford.nlp.ling.CoreAnnotations$SentenceIndexAnnotation 0
MENTION Paris
class edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation Paris
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetBeginAnnotation 66
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetEndAnnotation 71
class edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation [Paris-5]
class edu.stanford.nlp.ling.CoreAnnotations$TokenBeginAnnotation 14
class edu.stanford.nlp.ling.CoreAnnotations$TokenEndAnnotation 15
class edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation LOCATION
class edu.stanford.nlp.ling.CoreAnnotations$EntityTypeAnnotation LOCATION
class edu.stanford.nlp.ling.CoreAnnotations$SentenceIndexAnnotation 1
*/
for (CoreMap mention : coreMentions) {
// U.p("MENTION " + mention);
// for (Class k : mention.keySet()) {
// U.pf("%s\t%s\n", k, mention.get(k));
// }
Map m = new HashMap<String, Object>();
m.put("tokspan", Lists.newArrayList(
mention.get(TokenBeginAnnotation.class).intValue(),
mention.get(TokenEndAnnotation.class).intValue()));
m.put("charspan", Lists.newArrayList(
mention.get(CharacterOffsetBeginAnnotation.class).intValue(),
mention.get(CharacterOffsetEndAnnotation.class).intValue()));
m.put("sentence", mention.get(SentenceIndexAnnotation.class).intValue());
String entityType = mention.get(EntityTypeAnnotation.class);
m.put("type", entityType);
if (mention.containsKey(NormalizedNamedEntityTagAnnotation.class)) {
m.put("normalized", mention.get(NormalizedNamedEntityTagAnnotation.class));
}
if (mention.containsKey(TimexAnnotation.class)) {
m.put("timex_xml", mention.get(TimexAnnotation.class).toString());
}
jsonMentions.add(m);
}
sent_info.put("entitymentions", jsonMentions);
}