当前位置: 首页>>代码示例>>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;未经允许,请勿转载。