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


Java CoreLabel.endPosition方法代碼示例

本文整理匯總了Java中edu.stanford.nlp.ling.CoreLabel.endPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java CoreLabel.endPosition方法的具體用法?Java CoreLabel.endPosition怎麽用?Java CoreLabel.endPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在edu.stanford.nlp.ling.CoreLabel的用法示例。


在下文中一共展示了CoreLabel.endPosition方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tokenizeBySentence

import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public LinkedList<LinkedList<String>> tokenizeBySentence(String text, LinkedList<int[]> boundaries) {
    LinkedList<LinkedList<String>> res = new LinkedList<>();
    if (text != null) {
        Annotation qaTokens = new Annotation(text);
        pipelineTokens.annotate(qaTokens);
        List<CoreMap> qssTokens = qaTokens.get(CoreAnnotations.SentencesAnnotation.class);
        for (CoreMap sentenceTokens : qssTokens) {
            ArrayList<CoreLabel> tokens = (ArrayList<CoreLabel>) sentenceTokens.get(CoreAnnotations.TokensAnnotation.class);
            LinkedList<String> sentence=new LinkedList<>();
            boolean first=true;
            int[] bounds=new int[2];
            CoreLabel last=null;
            for (CoreLabel t : tokens) {
                if (first) {
                    bounds[0]=t.beginPosition();
                    first=false;
                }
                last=t;
                String lemma = t.lemma();
                String pos = t.tag();
                if (!stopwords.contains(lemma)) {
                    String rep = representativeProvider.getRepresentative(lemma, pos);
                    if (!stopwords.contains(rep)) {
                        sentence.add(rep);
                    }
                }
            }
            bounds[1]=last.endPosition();
            if (sentence.size()>0) {
                res.add(sentence);
                boundaries.add(bounds);
            }
        }
    }
    return res;
}
 
開發者ID:UCLA-BD2K,項目名稱:aztec-text-analysis-tools,代碼行數:37,代碼來源:Tokenizer.java

示例2: addWord

import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public void addWord(CoreLabel token) {
        token.set(ReadabilityAnnotations.ContentWord.class, false);
        token.set(ReadabilityAnnotations.LiteralWord.class, false);

        String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
//        String lemma = token.get(CoreAnnotations.LemmaAnnotation.class);
        String word = token.word();

        addingToken(token);

        if (isWordPos(pos)) {
            addingWord(token);
            wordCount++;
            docLenLettersOnly += token.endPosition() - token.beginPosition();

            word = flattenToAscii(word);
            Hyphenation hyphenation = hyphenator.hyphenate(word);

            boolean done = false;
            if (hyphenation != null) {
                try {
                    String h = hyphenation.toString();
                    incrementHyphenCount(hyphenation.length() + 1);
                    token.set(ReadabilityAnnotations.HyphenationAnnotation.class, h);
                    done = true;
                    hyphenWordCount++;
                } catch (Exception e) {
                    // ignored
                }
            }

            if (!done && word.length() < 5) {
                incrementHyphenCount(1);
                hyphenWordCount++;
            }

            if (isContentPos(pos)) {
                contentWordSize++;
                addingContentWord(token);
            }
            if (isEasyPos(pos)) {
                contentEasyWordSize++;
                addingEasyWord(token);
            }
        }
        if (token.get(ReadabilityAnnotations.HyphenationAnnotation.class) == null) {
            token.set(ReadabilityAnnotations.HyphenationAnnotation.class, token.originalText());
        }

        String genericPos = getGenericPos(pos);
        posStats.add(pos);
        genericPosStats.add(genericPos);
    }
 
開發者ID:dhfbk,項目名稱:tint,代碼行數:54,代碼來源:Readability.java

示例3: parse

import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
@Override
public ParseResult parse(String text, Set<Pair<Integer,Integer>> entities) {
    
    ParseResult result = new ParseResult();

    Annotation document = new Annotation(text);
    pipeline.annotate(document);
    
    int i = 0;
    List<CoreMap> annotations = document.get(SentencesAnnotation.class);
    for (CoreMap s: annotations) {
        i++;
        
        // Sentence string
        result.addSentence(i,s.toString());

        // Tokens and POS tags
        for (CoreLabel token: s.get(TokensAnnotation.class)) {
        result.addToken(i,token.index(),token.originalText());
        result.addPOS(i,token.index(),token.getString(PartOfSpeechAnnotation.class));
        // Mark named entities
        if (entities == null) {
            // Use Stanford NEs
            if (!token.get(NamedEntityTagAnnotation.class).equals("O")) {
                result.addPOS(i,token.index(),"NE");
            }
        } else {
            // Use NEs provided in input
            for (Pair<Integer,Integer> entity : entities) {
                if (entity.getLeft()  <= token.beginPosition() 
                 && entity.getRight() >= token.endPosition())
                    result.addPOS(i,token.index(),"NE");
            }
        }}
        
        // Dependency parse
        SemanticGraph dependencies = s.get(BasicDependenciesAnnotation.class);
        result.addParse(i,dependencies.toList().trim());
    }
    
    return result;
}
 
開發者ID:okbqa,項目名稱:rocknrole,代碼行數:43,代碼來源:Stanford.java


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