本文整理汇总了Java中edu.stanford.nlp.ling.Sentence.size方法的典型用法代码示例。如果您正苦于以下问题:Java Sentence.size方法的具体用法?Java Sentence.size怎么用?Java Sentence.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.ling.Sentence
的用法示例。
在下文中一共展示了Sentence.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tagPos
import edu.stanford.nlp.ling.Sentence; //导入方法依赖的package包/类
/**
* Tags the tokens with part of speech
*
* @param tokens Array of token strings
* @return Part of speech tags
*/
public static String[] tagPos(String[] tokens) {
Sentence untagged = createSentence(tokens);
Sentence tagged = MaxentTagger.tagSentence(untagged);
String[] pos = new String[tagged.size()];
for (int i = 0; i < tagged.size(); i++) {
HasWord w = (HasWord) tagged.get(i);
String[] s = w.toString().split("/");
if (s.length > 1)
pos[i] = s[s.length - 1];
else
pos[i] = "";
}
return pos;
}
示例2: evaluate
import edu.stanford.nlp.ling.Sentence; //导入方法依赖的package包/类
@Override
public void evaluate(Tree guess, Tree gold, PrintWriter pw) {
Sentence<TaggedWord> sGold = gold.taggedYield();
Sentence<TaggedWord> sGuess;
if (useTag) {
sGuess = myExtractor(guess);
} else {
sGuess = guess.taggedYield();
}
if (sGuess.size() != sGold.size()) {
pw.println("Warning: yield length differs:");
pw.println("Guess: " + sGuess);
pw.println("Gold: " + sGold);
} else {
if (DEBUG) {
for (Iterator<TaggedWord> goldIt = sGold.iterator(), guessIt = sGuess.iterator(); goldIt.hasNext();) {
TaggedWord goldNext = goldIt.next();
TaggedWord guessNext = guessIt.next();
if (!goldNext.tag().equals(guessNext.tag())) {
pw.print("TaggingError ");
if (lex != null && lex.isKnown(goldNext.word())) {
pw.print("seen ");
} else {
pw.print("unseen ");
}
pw.println(goldNext.word() + " correct " + goldNext.tag() + " chose " + guessNext.tag());
}
}
}
}
super.evaluate(guess, gold, pw);
}