本文整理匯總了Java中org.maltparser.concurrent.graph.ConcurrentDependencyNode.hasHead方法的典型用法代碼示例。如果您正苦於以下問題:Java ConcurrentDependencyNode.hasHead方法的具體用法?Java ConcurrentDependencyNode.hasHead怎麽用?Java ConcurrentDependencyNode.hasHead使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.maltparser.concurrent.graph.ConcurrentDependencyNode
的用法示例。
在下文中一共展示了ConcurrentDependencyNode.hasHead方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doProcess
import org.maltparser.concurrent.graph.ConcurrentDependencyNode; //導入方法依賴的package包/類
@Override
protected void doProcess(final JCas jCas) throws AnalysisEngineProcessException {
for (final Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
final List<WordToken> wordTokens = JCasUtil.selectCovered(jCas, WordToken.class, sentence);
final String[] tokens = new String[wordTokens.size()];
int i = 0;
for (final WordToken wt : wordTokens) {
// TODO: Can include the lemma too
final String pos = wt.getPartOfSpeech();
final String lemma = getLemma(wt);
final String tag = udTags ? convertPennToUniversal(pos) : pos;
tokens[i] = String.format("%d\t%s\t%s\t%s\t%s\t_", i + 1, wt.getCoveredText(), lemma, tag, pos);
// System.out.println(tokens[i]);
i++;
}
try {
final ConcurrentDependencyGraph graph = model.parse(tokens);
for (int j = 0; j < graph.nDependencyNodes(); j++) {
final ConcurrentDependencyNode node = graph.getDependencyNode(j);
if (node.hasHead()) {
final Dependency dep = new Dependency(jCas);
// System.out.println(node.getIndex() + " : " + node.isRoot() + ": " +
// node.getHeadIndex());
if (node.getHeadIndex() != 0) {
dep.setGovernor(wordTokens.get(node.getHeadIndex() - 1));
final String label = node.getLabel(7);
dep.setDependencyType(label);
} else {
dep.setGovernor(wordTokens.get(node.getIndex() - 1));
dep.setDependencyType("ROOT");
}
dep.setDependent(wordTokens.get(node.getIndex() - 1));
dep.setBegin(dep.getDependent().getBegin());
dep.setEnd(dep.getDependent().getEnd());
addToJCasIndex(dep);
}
}
} catch (final Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
}
示例2: doProcess
import org.maltparser.concurrent.graph.ConcurrentDependencyNode; //導入方法依賴的package包/類
@Override
protected void doProcess(final JCas jCas) throws AnalysisEngineProcessException {
for (final Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
final List<WordToken> wordTokens = JCasUtil.selectCovered(jCas, WordToken.class, sentence);
final String[] tokens = new String[wordTokens.size()];
int i = 0;
for (final WordToken wt : wordTokens) {
final String pos = wt.getPartOfSpeech();
final String lemma = getLemma(wt);
final String tag = udTags ? convertPennToUniversal(pos) : pos;
tokens[i] = String.format("%d\t%s\t%s\t%s\t%s\t_", i + 1, wt.getCoveredText(), lemma, tag, pos);
i++;
}
try {
final ConcurrentDependencyGraph graph = model.parse(tokens);
for (int j = 0; j < graph.nDependencyNodes(); j++) {
final ConcurrentDependencyNode node = graph.getDependencyNode(j);
if (node.hasHead()) {
final Dependency dep = new Dependency(jCas);
if (node.getHeadIndex() != 0) {
dep.setGovernor(wordTokens.get(node.getHeadIndex() - 1));
final String label = node.getLabel(7);
dep.setDependencyType(label);
} else {
dep.setGovernor(wordTokens.get(node.getIndex() - 1));
dep.setDependencyType("ROOT");
}
dep.setDependent(wordTokens.get(node.getIndex() - 1));
dep.setBegin(dep.getDependent().getBegin());
dep.setEnd(dep.getDependent().getEnd());
addToJCasIndex(dep);
}
}
} catch (final Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
}