本文整理汇总了Java中com.hankcs.hanlp.corpus.dependency.CoNll.CoNLLWord.ROOT属性的典型用法代码示例。如果您正苦于以下问题:Java CoNLLWord.ROOT属性的具体用法?Java CoNLLWord.ROOT怎么用?Java CoNLLWord.ROOT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.hankcs.hanlp.corpus.dependency.CoNll.CoNLLWord
的用法示例。
在下文中一共展示了CoNLLWord.ROOT属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWordsInPath
/**
* 获得词语依存路径中的词语
* @param word 词语
* @param maxReturn 最大路径长度
* @return 依存路径词语列表
*/
public static List<Term> getWordsInPath(CoNLLWord word, int maxReturn) {
List<Term> words = new ArrayList<Term>();
if (word == CoNLLWord.ROOT || maxReturn < 1) return words;
while (word != CoNLLWord.ROOT) {
words.add(new Term(word.LEMMA, Nature.fromString(word.POSTAG)));
word = word.HEAD;
if (--maxReturn < 1) break;
}
return words;
}
示例2: calWordDepth
/**
* 获得词语的深度
* @param word 词语
* @return 词语在句法树中的深度
*/
public static int calWordDepth(CoNLLWord word) {
if (word == CoNLLWord.ROOT) return -1;
int depth = 0;
while(word.HEAD != CoNLLWord.ROOT) {
depth++;
word = word.HEAD;
}
return depth;
}
示例3: parse
@Override
public CoNLLSentence parse(List<Term> termList)
{
List<String> posTagList = PosTagUtil.to863(termList);
List<String> wordList = new ArrayList<String>(termList.size());
for (Term term : termList)
{
wordList.add(term.word);
}
List<Integer> heads = new ArrayList<Integer>(termList.size());
List<String> deprels = new ArrayList<String>(termList.size());
parser_dll.parse(wordList, posTagList, heads, deprels);
CoNLLWord[] wordArray = new CoNLLWord[termList.size()];
for (int i = 0; i < wordArray.length; ++i)
{
wordArray[i] = new CoNLLWord(i + 1, wordList.get(i), posTagList.get(i), termList.get(i).nature.toString());
wordArray[i].DEPREL = deprels.get(i);
}
for (int i = 0; i < wordArray.length; ++i)
{
int index = heads.get(i) - 1;
if (index < 0)
{
wordArray[i].HEAD = CoNLLWord.ROOT;
continue;
}
wordArray[i].HEAD = wordArray[index];
}
return new CoNLLSentence(wordArray);
}