本文整理汇总了Java中edu.uw.easysrl.syntax.grammar.SyntaxTreeNode.getStartIndex方法的典型用法代码示例。如果您正苦于以下问题:Java SyntaxTreeNode.getStartIndex方法的具体用法?Java SyntaxTreeNode.getStartIndex怎么用?Java SyntaxTreeNode.getStartIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.uw.easysrl.syntax.grammar.SyntaxTreeNode
的用法示例。
在下文中一共展示了SyntaxTreeNode.getStartIndex方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParent
import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入方法依赖的package包/类
/**
* Tries to get the parent of a node in a tree.
* Assumes the given node is in the given tree. If not, it will probably return empty, maybe... but maybe not.
* Returns empty if the node is just the whole tree.
*/
public static Optional<SyntaxTreeNode> getParent(SyntaxTreeNode node, SyntaxTreeNode wholeTree) {
int nodeStart = node.getStartIndex();
int nodeEnd = node.getEndIndex();
Optional<SyntaxTreeNode> curCandidate = Optional.of(wholeTree);
Optional<SyntaxTreeNode> lastCandidate = Optional.empty();
while(curCandidate.isPresent() && curCandidate.get() != node) {
lastCandidate = curCandidate;
curCandidate = curCandidate.get().getChildren().stream().filter(child -> {
int childStart = child.getStartIndex();
int childEnd = child.getEndIndex();
return (childStart <= nodeStart) && (childEnd >= nodeEnd);
}).findFirst();
}
return lastCandidate;
}
示例2: getArgumentConstituent
import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入方法依赖的package包/类
private SyntaxTreeNode getArgumentConstituent(final SyntaxTreeNode node, final int head, final int excludeIndex) {
final boolean exclude = excludeIndex >= node.getStartIndex() && excludeIndex < node.getEndIndex();
if (!exclude && node.getDependencyStructure().getArbitraryHead() == head) {
return node;
}
for (final SyntaxTreeNode child : node.getChildren()) {
final SyntaxTreeNode result = getArgumentConstituent(child, head, excludeIndex);
if (result != null) {
return result;
}
}
return null;
}
示例3: parsesEqual
import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入方法依赖的package包/类
public static boolean parsesEqual(final SyntaxTreeNode parse1, final SyntaxTreeNode parse2) {
return parse1.getStartIndex() == parse2.getStartIndex()
&& parse1.getEndIndex() == parse2.getEndIndex()
&& parse1.getCategory() == parse2.getCategory()
&& parse1.getRuleType().ordinal() == parse2.getRuleType().ordinal()
&& parse1.getChildren().size() == parse2.getChildren().size()
&& CollectionUtil.zip(parse1.getChildren().stream(), parse2.getChildren().stream(), SyntaxUtil::parsesEqual).allMatch(Boolean::booleanValue);
}
示例4: getNodeWords
import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入方法依赖的package包/类
public static List<String> getNodeWords(SyntaxTreeNode node, Optional<Integer> replaceIndexOpt, Optional<String> replacementWord) {
List<String> words = node.getLeaves()
.stream()
.map(leaf -> leaf.getWord())
.collect(Collectors.toList());
if(node.getStartIndex() == 0) {
SyntaxTreeNodeLeaf firstLeaf = node.getLeaves().stream().findFirst().get(); // this should always be present
String firstWord = firstLeaf.getWord();
String firstPos = firstLeaf.getPos();
boolean isProper = firstPos.equals("NNP") || firstPos.equals("NNPS");
boolean isAllCaps = firstWord.matches("[A-Z]{2,}");
if(!isProper && !isAllCaps) {
words.set(0, Character.toLowerCase(words.get(0).charAt(0)) + words.get(0).substring(1));
}
}
if(replacementWord.isPresent() && replaceIndexOpt.isPresent()) {
int indexInWords = replaceIndexOpt.get() - node.getStartIndex();
String word = replacementWord.get();
if(indexInWords >= 0 && indexInWords < words.size()) {
// if we replace with empty string, just remove the word
if(word.length() > 0) {
words.set(indexInWords, replacementWord.get());
} else {
words.remove(indexInWords);
}
}
}
return words;
}
示例5: getContainedDependencies
import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入方法依赖的package包/类
/**
* Gets all of the dependencies that start and end inside the syntax tree rooted at the given node
*/
public static ImmutableSet<ResolvedDependency> getContainedDependencies(SyntaxTreeNode node, Parse parse) {
final int minIndex = node.getStartIndex();
final int maxIndex = node.getEndIndex();
return parse.dependencies.stream()
.filter(dep -> dep.getHead() >= minIndex && dep.getHead() < maxIndex &&
dep.getArgument() >= minIndex && dep.getArgument() <= maxIndex)
.collect(toImmutableSet());
}
示例6: parsesEqual
import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入方法依赖的package包/类
public static boolean parsesEqual(final SyntaxTreeNode parse1, final SyntaxTreeNode parse2) {
return parse1.getStartIndex() == parse2.getStartIndex()
&& parse1.getEndIndex() == parse2.getEndIndex()
&& parse1.getCategory() == parse2.getCategory()
&& parse1.getRuleType().ordinal() == parse2.getRuleType().ordinal()
&& parse1.getChildren().size() == parse2.getChildren().size()
&& Util.zip(parse1.getChildren().stream(), parse2.getChildren().stream(), SyntaxUtil::parsesEqual)
.allMatch(Boolean::booleanValue);
}
示例7: isIndexInSpan
import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入方法依赖的package包/类
public static boolean isIndexInSpan(final int i, final SyntaxTreeNode node) {
return i >= node.getStartIndex() && i < node.getEndIndex();
}