本文整理匯總了Java中org.apache.stanbol.enhancer.nlp.model.Chunk類的典型用法代碼示例。如果您正苦於以下問題:Java Chunk類的具體用法?Java Chunk怎麽用?Java Chunk使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Chunk類屬於org.apache.stanbol.enhancer.nlp.model包,在下文中一共展示了Chunk類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateAnalysedText
import org.apache.stanbol.enhancer.nlp.model.Chunk; //導入依賴的package包/類
private void validateAnalysedText(String text, AnalysedText at){
Assert.assertNotNull(text);
Assert.assertNotNull(at);
//Assert the AnalysedText
Assert.assertEquals(0, at.getStart());
Assert.assertEquals(text.length(), at.getEnd());
Iterator<Span> it = at.getEnclosed(EnumSet.allOf(SpanTypeEnum.class));
while(it.hasNext()){
//validate that the span|start|end corresponds with the Text
Span span = it.next();
Assert.assertNotNull(span);
Assert.assertEquals(text.substring(span.getStart(), span.getEnd()),
span.getSpan());
switch (span.getType()) {
case Token:
double prevProb = -1;
List<Value<PosTag>> posTags = span.getAnnotations(POS_ANNOTATION);
Assert.assertTrue("All Tokens need to have a PosTag (missing for "
+ span+ ")", posTags != null && !posTags.isEmpty());
for(Value<PosTag> posTag : posTags){
//assert Mapped PosTags
Assert.assertTrue("PosTag "+posTag+" used by "+span+" is not present in the PosTagSet",
TAG_SET.getTag(posTag.value().getTag()) != null);
//assert declining probabilities
Assert.assertTrue("Wrong order in "+posTags+" of "+span+"!",
prevProb < 0 || posTag.probability() <= prevProb);
prevProb = posTag.probability();
}
Assert.assertNull("Tokens MUST NOT have Phrase annotations!",
span.getAnnotation(PHRASE_ANNOTATION));
Assert.assertNull("Tokens MUST NOT have NER annotations!",
span.getAnnotation(NER_ANNOTATION));
break;
case Chunk:
Assert.assertNull("Chunks MUST NOT have POS annotations!",
span.getAnnotation(POS_ANNOTATION));
List<Token> tokens = AnalysedTextUtils.asList(((Chunk)span).getTokens());
prevProb = -1;
List<Value<PhraseTag>> phraseTags = span.getAnnotations(PHRASE_ANNOTATION);
boolean hasPhraseTag = (phraseTags != null && !phraseTags.isEmpty());
List<Value<NerTag>> nerTags = span.getAnnotations(NER_ANNOTATION);
boolean hasNerTag = (nerTags != null && !nerTags.isEmpty());
Assert.assertTrue("All Chunks with several words need to have a PhraseTag (missing for "
+ span+ ")", hasPhraseTag || tokens.size() < 2);
Assert.assertTrue("All Chunks with a single word need to have a NerTag (missing for"
+ span +")", hasNerTag || tokens.size() > 1);
for(Value<PhraseTag> phraseTag : phraseTags){
//assert Mapped PosTags
Assert.assertNotNull("PhraseTag "+phraseTag+" is not mapped",
phraseTag.value().getCategory());
//assert declining probabilities
Assert.assertTrue(prevProb < 0 || phraseTag.probability() < prevProb);
prevProb = phraseTag.probability();
}
for(Value<NerTag> nerTag : nerTags){
Assert.assertTrue("NER Tags need to have a probability",
nerTag.probability() > 0);
}
break;
default:
Assert.assertNull(span.getType()+" type Spans MUST NOT have POS annotations!",
span.getAnnotation(POS_ANNOTATION));
Assert.assertNull(span.getType()+" type Spans MUST NOT have Phrase annotations!",
span.getAnnotation(PHRASE_ANNOTATION));
Assert.assertNull(span.getType()+" type Spans MUST NOT have NER annotations!",
span.getAnnotation(NER_ANNOTATION));
break;
}
}
}
示例2: validateAnalysedText
import org.apache.stanbol.enhancer.nlp.model.Chunk; //導入依賴的package包/類
private void validateAnalysedText(String text, AnalysedText at){
Assert.assertNotNull(text);
Assert.assertNotNull(at);
//Assert the AnalysedText
Assert.assertEquals(0, at.getStart());
Assert.assertEquals(text.length(), at.getEnd());
Iterator<Span> it = at.getEnclosed(EnumSet.allOf(SpanTypeEnum.class));
while(it.hasNext()){
//validate that the span|start|end corresponds with the Text
Span span = it.next();
Assert.assertNotNull(span);
Assert.assertEquals(text.substring(span.getStart(), span.getEnd()),
span.getSpan());
switch (span.getType()) {
case Token:
double prevProb = -1;
List<Value<PosTag>> posTags = span.getAnnotations(POS_ANNOTATION);
Assert.assertTrue("All Tokens need to have a PosTag (missing for "
+ span+ ")", posTags != null && !posTags.isEmpty());
for(Value<PosTag> posTag : posTags){
//assert Mapped PosTags
Assert.assertTrue("PosTag "+posTag+" used by "+span+" is not mapped",
posTag.value().isMapped());
//assert declining probabilities
Assert.assertTrue("Wrong order in "+posTags+" of "+span+"!",
prevProb < 0 || posTag.probability() <= prevProb);
prevProb = posTag.probability();
}
Assert.assertNull("Tokens MUST NOT have Phrase annotations!",
span.getAnnotation(PHRASE_ANNOTATION));
Assert.assertNull("Tokens MUST NOT have NER annotations!",
span.getAnnotation(NER_ANNOTATION));
break;
case Chunk:
Assert.assertNull("Chunks MUST NOT have POS annotations!",
span.getAnnotation(POS_ANNOTATION));
List<Token> tokens = AnalysedTextUtils.asList(((Chunk)span).getTokens());
prevProb = -1;
List<Value<PhraseTag>> phraseTags = span.getAnnotations(PHRASE_ANNOTATION);
boolean hasPhraseTag = (phraseTags != null && !phraseTags.isEmpty());
List<Value<NerTag>> nerTags = span.getAnnotations(NER_ANNOTATION);
boolean hasNerTag = (nerTags != null && !nerTags.isEmpty());
Assert.assertTrue("All Chunks with several words need to have a PhraseTag (missing for "
+ span+ ")", hasPhraseTag || tokens.size() < 2);
Assert.assertTrue("All Chunks with a single word need to have a NerTag (missing for"
+ span +")", hasNerTag || tokens.size() > 1);
for(Value<PhraseTag> phraseTag : phraseTags){
//assert Mapped PosTags
Assert.assertNotNull("PhraseTag "+phraseTag+" is not mapped",
phraseTag.value().getCategory());
//assert declining probabilities
Assert.assertTrue(prevProb < 0 || phraseTag.probability() < prevProb);
prevProb = phraseTag.probability();
}
for(Value<NerTag> nerTag : nerTags){
Assert.assertTrue("NER Tags need to have a probability",
nerTag.probability() > 0);
}
break;
default:
Assert.assertNull(span.getType()+" type Spans MUST NOT have POS annotations!",
span.getAnnotation(POS_ANNOTATION));
Assert.assertNull(span.getType()+" type Spans MUST NOT have Phrase annotations!",
span.getAnnotation(PHRASE_ANNOTATION));
Assert.assertNull(span.getType()+" type Spans MUST NOT have NER annotations!",
span.getAnnotation(NER_ANNOTATION));
break;
}
}
}