本文整理匯總了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;
}
示例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);
}
示例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;
}