當前位置: 首頁>>代碼示例>>Java>>正文


Java Chunk類代碼示例

本文整理匯總了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;
        }
    }
}
 
開發者ID:westei,項目名稱:stanbol-talismane,代碼行數:71,代碼來源:TestTalismaneAnalyser.java

示例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;
        }
    }
}
 
開發者ID:insideout10,項目名稱:stanbol-freeling,代碼行數:71,代碼來源:TestFreelingAnalysis.java


注:本文中的org.apache.stanbol.enhancer.nlp.model.Chunk類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。