当前位置: 首页>>代码示例>>Java>>正文


Java ResolvedDependency.getHead方法代码示例

本文整理汇总了Java中edu.uw.easysrl.dependencies.ResolvedDependency.getHead方法的典型用法代码示例。如果您正苦于以下问题:Java ResolvedDependency.getHead方法的具体用法?Java ResolvedDependency.getHead怎么用?Java ResolvedDependency.getHead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.uw.easysrl.dependencies.ResolvedDependency的用法示例。


在下文中一共展示了ResolvedDependency.getHead方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showDependency

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
/**
 * Decide which dependencies are worth showing.
 */
private boolean showDependency(final ResolvedDependency dep, final SyntaxTreeNode parse) {
	final SyntaxTreeNodeLeaf predicateNode = parse.getLeaves().get(dep.getHead());
	if (dep.getHead() == dep.getArgumentIndex()) {
		return false;
	} else if (dep.getSemanticRole() != SRLFrame.NONE) {
		return true;
	} else if (predicateNode.getPos().startsWith("JJ") && dep.getCategory() != Category.valueOf("NP/N")) {
		// Adjectives, excluding determiners
		return true;
	} else if (Category.valueOf("(S\\NP)/(S\\NP)") == dep.getCategory()) {
		// Exclude auxiliary verbs. Hopefully the SRL will have already identified the times this category isn't
		// an auxiliary.
		return false;
	} else if (predicateNode.getPos().startsWith("NN") && dep.getCategory().isFunctionInto(Category.N)) {
		// Checking category to avoid annoying getting a "subject" dep on yesterday|NN|(S\NP)\(S\NP)
		return true;
	} else if (predicateNode.getPos().startsWith("VB")) {
		// Other verb arguments, e.g. particles
		return true;
	} else {
		return false;
	}
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:27,代码来源:ParsePrinter.java

示例2: getMatchedDeps

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
/**
 * Finds the set of SRL dependencies that match dependencies resolved at this node
 */
private Set<SRLDependency> getMatchedDeps(final Set<SRLDependency> goldDeps,
		final Collection<ResolvedDependency> dependencies, final CutoffsDictionaryInterface cutoffs,
		final Collection<ResolvedDependency> newDeps) {
	final Set<SRLDependency> matchedDeps = new HashSet<>(dependencies.size());
	for (final ResolvedDependency dep : dependencies) {
		final int predicateIndex = dep.getHead();
		final int argumentIndex = predicateIndex + dep.getOffset();
		boolean isSRL = false;

		for (final SRLDependency srl : goldDeps) {
			if (!matchedDeps.contains(srl)
					&& cutoffs.isFrequent(dep.getCategory(), dep.getArgNumber(), srl.getLabel())
					&& cutoffs.getRoles(completeChart.getWords().get(dep.getHead()).word, dep.getCategory(),
							dep.getPreposition(), dep.getArgNumber()).contains(srl.getLabel())
					&& matches(predicateIndex, argumentIndex, srl, dep.getPreposition())) {

				matchedDeps.add(srl);
				newDeps.add(dep.overwriteLabel(srl.getLabel()));
				isSRL = true;
				break;
			}
		}

		if (!isSRL) {
			// Dependencies that aren't in the gold training data.
			// For SRL, these should get 'NONE', for CCG they should get ARG_n
			if (usingCCGbankDepenencies) {
				newDeps.add(dep.overwriteLabel(SRLLabel.fromString("ARG" + (dep.getArgNumber() - 1))));
			} else {
				newDeps.add(dep.overwriteLabel(SRLFrame.NONE));
			}
		}

	}
	return matchedDeps;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:40,代码来源:GoldChartFinder.java

示例3: getPredicate

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
private String getPredicate(final SyntaxTreeNode parse, final int index) {
	final SyntaxTreeNodeLeaf node = parse.getLeaves().get(index);
	final StringBuilder result = new StringBuilder();
	result.append(MorphaStemmer.stemToken(node.getWord()));
	final Category category = node.getCategory();
	final List<Integer> indices = new ArrayList<>();
	indices.add(index);

	// Add particles if necessary. e.g. give_up, take_off
	for (int i = 1; i <= category.getNumberOfArguments(); i++) {
		if (category.getArgument(i) == Category.PR) {
			for (final ResolvedDependency dep : parse.getAllLabelledDependencies()) {
				if (dep.getHead() == index && dep.getArgNumber() == i) {
					final String particle = parse.getLeaves().get(dep.getArgumentIndex()).getWord();
					indices.add(dep.getArgumentIndex());
					result.append("_");
					result.append(particle);
					break;
				}
			}
		}
	}

	if (includeWordIndices) {
		result.append("@");
		for (int i = 0; i < indices.size(); i++) {
			if (i > 0) {
				result.append(",");
			}
			result.append(indices.get(i));
		}
	}
	return result.toString();
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:35,代码来源:ParsePrinter.java

示例4: unlabeledMatch

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
public static boolean unlabeledMatch(final ResolvedDependency dep1, final ResolvedDependency dep2) {
    return dep1.getHead() == dep2.getHead() && dep1.getArgument() == dep2.getArgument();
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:4,代码来源:CcgEvaluation.java

示例5: dependencyToString

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
public static String dependencyToString(final ResolvedDependency dep) {
    return dep.getHead() + "_" + dep.getArgument() + "_" + dep.getCategory() + "." + dep.getArgNumber();
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:4,代码来源:CcgEvaluation.java

示例6: evaluate

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
private static Results evaluate(final SRLParse gold, final CCGandSRLparse parse) {
	final Collection<ResolvedDependency> predictedDeps = new HashSet<>(parse.getDependencyParse());

	final Set<SRLDependency> goldDeps = new HashSet<>(gold.getDependencies());
	final Iterator<ResolvedDependency> depsIt = predictedDeps.iterator();
	// Remove non-SRL dependencies.
	predictedDeps.removeIf(dep -> (dep.getSemanticRole() == SRLFrame.NONE) || dep.getOffset() == 0);

	int correctCount = 0;
	final int predictedCount = predictedDeps.size();
	final int goldCount = goldDeps.size();
	for (final SRLDependency goldDep : goldDeps) {
		if (goldDep.getArgumentPositions().size() == 0) {
			continue;
		}

		// boolean found = false;
		for (final ResolvedDependency predictedDep : predictedDeps) {
			int predictedPropbankPredicate;
			int predictedPropbankArgument;
			if (goldDep.isCoreArgument()) {
				predictedPropbankPredicate = predictedDep.getHead();
				predictedPropbankArgument = predictedDep.getArgumentIndex();
			} else {
				predictedPropbankPredicate = predictedDep.getArgumentIndex();
				predictedPropbankArgument = predictedDep.getHead();
			}
			// For adjuncts, the CCG functor is the Propbank argument

			if (goldDep.getPredicateIndex() == predictedPropbankPredicate
					&& (goldDep.getLabel() == predictedDep.getSemanticRole())
					&& goldDep.getArgumentPositions().contains(predictedPropbankArgument)) {

				predictedDeps.remove(predictedDep);
				correctCount++;
				// found = true;
				break;
			}
		}
	}

	return new Results(predictedCount, correctCount, goldCount);
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:44,代码来源:SRLEvaluation.java

示例7: expected

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
private boolean expected(final AgendaItem leftChild, final AgendaItem rightChild, final ResolvedDependency dep) {
	return dep.getHead() >= rightChild.getStartOfSpan()
			&& dep.getHead() < rightChild.getStartOfSpan() + rightChild.getSpanLength()
			&& dep.getArgumentIndex() >= leftChild.getStartOfSpan()
			&& dep.getArgumentIndex() < leftChild.getStartOfSpan() + leftChild.getSpanLength();
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:7,代码来源:OracleDependenciesModel.java

示例8: printParse

import edu.uw.easysrl.dependencies.ResolvedDependency; //导入方法依赖的package包/类
@Override
protected void printParse(final SyntaxTreeNode parse, final int sentenceNumber, final StringBuilder result) {
	final int numWords = parse.getLeaves().size();
	final int id = parseID.getAndIncrement();

	final int betweenWordSpace = 5;
	int parseWidth = 0;

	for (final SyntaxTreeNodeLeaf word : parse.getLeaves()) {
		parseWidth += Math.max(guessWidth(word.getWord().toString()), guessWidth(word.getCategory().toString())
				+ (word.getSemantics().isPresent() ? guessWidth(word.getSemantics().get().toString()) : 0));
		parseWidth += betweenWordSpace;
	}

	result.append("<table>");
	result.append("<tr><td colspan=" + (numWords + 1) + " style=\"padding-left:0px;padding-right:0px;\">\n"
			+ "<canvas id=\"myCanvas" + id + "\" width=" + (parseWidth)
			+ " height=200 display:block vertical-align:bottom></canvas></td></tr>");

	int wordIndex = 0;
	for (final List<SyntaxTreeNode> row : getRows(parse)) {
		result.append("<tr>");
		int indent = 0;
		while (indent < row.size()) {
			final SyntaxTreeNode cell = row.get(indent);

			if (cell == null) {
				result.append("<td></td>");
				indent = indent + 1;
			} else if (cell.isLeaf()) {
				result.append(makeCell(((SyntaxTreeNodeLeaf) cell).getWord(), cell.getCategory(),
						cell.getSemantics(), wordIndex, id));
				indent = indent + 1;
				wordIndex++;
			} else {
				final int width = getWidth(cell);
				result.append(makeCell(cell.getCategory(), cell.getSemantics(), width));
				indent = indent + width;
			}
		}
		result.append("<td width=" + "0" + " /></tr>\n");
	}
	result.append("</table>");

	result.append("<script>");
	result.append("      var canvas = document.getElementById('myCanvas" + id + "');\n");
	result.append("      var context = canvas.getContext('2d');\n");
	for (final ResolvedDependency dep : parse.getAllLabelledDependencies()) {
		if (showDependency(dep, parse)) {

			final String label;
			final int from;
			final int to;
			if (dep.getSemanticRole() != SRLFrame.NONE) {
				// Draw adjuncts PropBank-style, from the predicate to the modifier.
				label = dep.getSemanticRole().toString();
				from = dep.getPropbankPredicateIndex();
				to = dep.getPropbankArgumentIndex();
			} else {
				// Draw in some extra CCG dependencies for nouns and adjectives.
				label = "";
				from = dep.getHead();
				to = dep.getArgumentIndex();
			}

			result.append("draw(context, " + from + ", " + to + ", '" + label + "', " + id + ");");
		}

	}
	result.append("</script>");
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:72,代码来源:ParsePrinter.java


注:本文中的edu.uw.easysrl.dependencies.ResolvedDependency.getHead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。