本文整理汇总了Java中edu.uw.easysrl.dependencies.ResolvedDependency类的典型用法代码示例。如果您正苦于以下问题:Java ResolvedDependency类的具体用法?Java ResolvedDependency怎么用?Java ResolvedDependency使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResolvedDependency类属于edu.uw.easysrl.dependencies包,在下文中一共展示了ResolvedDependency类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: predictedDependencyStream
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
public Stream<ResolvedDependency> predictedDependencyStream(final SyntaxTreeNode parse,
final boolean generateDependencies,
final List<InputWord> leaves,
final boolean local) {
if (parse == null) {
return Stream.empty();
}
final Set<UnlabelledDependency> unlabeledDependencies = new HashSet<>();
if (generateDependencies) {
dependencyGenerator.generateDependencies(parse, unlabeledDependencies);
} else {
if (local) {
unlabeledDependencies.addAll(parse.getResolvedUnlabelledDependencies());
} else {
SyntaxUtil.subtreeStream(parse).forEach(subtree -> unlabeledDependencies.addAll(subtree.getResolvedUnlabelledDependencies()));
}
}
return CCGBankEvaluation
.convertDeps(leaves, unlabeledDependencies)
.stream()
.filter(x -> x.getHead() != x.getArgument())
.filter(x -> validDependencies.contains(x.getCategory().toString() + x.getArgNumber()));
}
示例2: updateStats
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
public void updateStats(final Set<ResolvedDependency> goldDependencies,
final List<Category> goldCategories,
final List<Util.Scored<SyntaxTreeNode>> predictedParses,
final DependencyEvaluator evaluator) {
sentenceCount.incrementAndGet();
if (predictedParses != null) {
parsableSentenceCount.incrementAndGet();
} else {
evaluator.evaluate(goldDependencies, null, overallStats);
return;
}
final SyntaxTreeNode topParse = predictedParses.get(0).getObject();
evaluator.evaluate(goldDependencies, topParse, overallStats);
final int numCorrect = (int) CollectionUtil.zip(
topParse.getLeaves().stream().map(SyntaxTreeNode::getCategory),
goldCategories.stream(), Object::equals).filter(Boolean::booleanValue).count();
correctlySupertaggedWords.addAndGet(numCorrect);
totalWords.addAndGet(goldCategories.size());
}
示例3: filter
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
/**
* Return all the dependencies that's relevant to this structure.
* @param dependencies
* @return
*/
public ImmutableSet<ResolvedDependency> filter(Collection<ResolvedDependency> dependencies) {
if (!singleHeaded) {
return dependencies.stream()
.collect(Collectors.groupingBy(ResolvedDependency::getHead))
.values().stream()
.filter(deps -> {
ImmutableList<Integer> argList = deps.stream()
.map(ResolvedDependency::getArgument)
.distinct()
.collect(GuavaCollectors.toImmutableList());
return argList.size() == argumentIndices.size() &&
argList.containsAll(argumentIndices) && argumentIndices.containsAll(argList);
})
.flatMap(Collection::stream)
.collect(GuavaCollectors.toImmutableSet());
}
if (!headIsVP) {
return dependencies.stream()
.filter(d -> d.getArgument() == argumentIndices.get(0))
.collect(GuavaCollectors.toImmutableSet());
}
return dependencies.stream()
.filter(d -> d.getHead() == argumentIndices.get(0))
.collect(GuavaCollectors.toImmutableSet());
}
示例4: BasicQuestionAnswerPair
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
public BasicQuestionAnswerPair(int sentenceId, int parseId, Parse parse,
int predicateIndex, Category predicateCategory, int argumentNumber,
int questionMainIndex, QuestionType questionType,
Set<ResolvedDependency> questionDeps, List<String> question,
ResolvedDependency targetDep, TextWithDependencies answer) {
this.predicateIndex = predicateIndex;
this.predicateCategory = predicateCategory;
this.argumentNumber = argumentNumber;
this.questionMainIndex = questionMainIndex;
this.questionType = questionType;
this.questionDeps = questionDeps;
this.question = question;
this.targetDep = targetDep;
this.answer = answer.tokens;
this.answerDeps = answer.dependencies;
this.parseId = parseId;
this.sentenceId = sentenceId;
this.parse = parse;
}
示例5: getArgumentIdsForDependency
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
public static Set<Integer> getArgumentIdsForDependency(final List<String> words, Parse parse,
ResolvedDependency dependency) {
Set<Integer> answers = new HashSet<>();
Category answerCategory = dependency.getCategory().getArgument(dependency.getArgNumber());
int argumentId = dependency.getArgument();
if (answerCategory.equals(Category.PP) || words.get(argumentId).equals("to")) {
parse.dependencies.stream()
.filter(d -> d.getHead() == argumentId)
.forEach(d2 -> answers.add(d2.getArgument()));
if (answers.size() == 0) {
answers.add(argumentId);
}
} else {
answers.add(argumentId);
}
return answers;
}
示例6: combineNodes
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
@Override
public AgendaItem combineNodes(final AgendaItem leftChild, final AgendaItem rightChild, final SyntaxTreeNode node) {
final int score = scoreNode(node);
if (rightChild.getParse().getHead().getWord().equals("around")) {
Util.debugHook();
}
int expectedDeps = 0;
for (final ResolvedDependency dep : gold) {
if (expected(leftChild, rightChild, dep) || expected(rightChild, leftChild, dep)) {
expectedDeps++;
}
}
final double insideScore = leftChild.getInsideScore() + rightChild.getInsideScore() + score;
return new AgendaItem(node, insideScore, leftChild.outsideScoreUpperbound + rightChild.outsideScoreUpperbound
- globalUpperBound - expectedDeps, leftChild.getStartOfSpan(), leftChild.getSpanLength()
+ rightChild.getSpanLength(), true);
}
示例7: scoreNode
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
private int scoreNode(final SyntaxTreeNode node) {
int score = 0;
for (final UnlabelledDependency dep : node.getResolvedUnlabelledDependencies()) {
if (!CCGBankEvaluation.filter(words.get(dep.getHead()), dep.getCategory(), dep.getArgNumber())) {
for (final int arg : dep.getArguments()) {
if (gold.contains(new ResolvedDependency(dep.getHead(), dep.getCategory(), dep.getArgNumber(), arg,
SRLFrame.NONE, null))) {
score++;
} else {
score--;
}
}
}
}
return score;
}
示例8: parseDisjunctive
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
private DisjunctiveNode parseDisjunctive(final Key key, final Map<Key, DisjunctiveNode> disjuctiveNodeCache,
final Map<ResolvedDependency, DisjunctiveNode> dependencyNodeCache,
final Map<Value, ConjunctiveNode> conjuctiveNodeCache) {
DisjunctiveTreeNode result = (DisjunctiveTreeNode) disjuctiveNodeCache.get(key);
if (result == null) {
result = new DisjunctiveTreeNode(key.category, key.startIndex, key.lastIndex, key.ruleClass);
for (final Value child : key.getChildren()) {
result.addChild(parseConjunctive(child, disjuctiveNodeCache, conjuctiveNodeCache, dependencyNodeCache,
result));
}
disjuctiveNodeCache.put(key, result);
}
return result;
}
示例9: getAllDependencies
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
private void getAllDependencies(final Key key, final Set<ResolvedDependency> result, final Set<Key> visited) {
if (visited.contains(key)) {
return;
}
visited.add(key);
for (final Value value : key.getChildren()) {
for (final ResolvedDependency dep : value.getDependencies()) {
result.add(dep);
}
for (final Key child : value.getChildren()) {
getAllDependencies(child, result, visited);
}
}
}
示例10: 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;
}
}
示例11: printParse
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
@Override
protected void printParse(final SyntaxTreeNode parse, final int sentenceNumber, final StringBuilder result) {
final List<List<ResolvedDependency>> labels = new ArrayList<>();
for (final SyntaxTreeNodeLeaf leaf : parse.getLeaves()) {
labels.add(new ArrayList<>(leaf.getCategory().getNumberOfArguments()));
for (int i = 0; i < leaf.getCategory().getNumberOfArguments(); i++) {
labels.get(labels.size() - 1).add(null); // TODO
}
}
for (final ResolvedDependency dep : parse.getAllLabelledDependencies()) {
final List<ResolvedDependency> labelsForWord = labels.get(dep.getHead());
if (dep.getArgumentIndex() > -1) {
labelsForWord.set(dep.getArgNumber() - 1, dep);
}
}
Preconditions.checkState(parse.getSemantics().isPresent());
result.append(parse.getSemantics().get());
Util.debugHook();
}
示例12: getLemma
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
/**
* Gets a lemma for a phrase. Multiword phrases are collapsed into a single token. If a parse is provided, it will
* collapse verb-particle constructions.
*/
public String getLemma(final String word, final String pos, final Optional<CCGandSRLparse> parse, final int wordIndex) {
String lemma = word == null ? null : MorphaStemmer.stemToken(word.toLowerCase().replaceAll(" ", "_"), pos);
if (parse.isPresent()) {
final List<ResolvedDependency> deps = parse.get().getOrderedDependenciesAtPredicateIndex(wordIndex);
for (final ResolvedDependency dep : deps) {
if (dep != null && dep.getCategory().getArgument(dep.getArgNumber()) == Category.PR) {
// Merge predicates in verb-particle constructions, e.g. pick_up
lemma = lemma + "_" + parse.get().getLeaf(dep.getArgumentIndex()).getWord();
}
}
}
return lemma;
}
示例13: makeCopulaVerb
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
/**
* Special-case semantics for copular verbs:
*
* TODO verbs with expletive arguments and 'other' prepositions
*/
private Logic makeCopulaVerb(final List<ResolvedDependency> deps, final List<Variable> vars, final Variable head,
final CCGandSRLparse parse) {
Logic statement;
if (deps.get(1) != null && deps.get(1).getPreposition() != Preposition.NONE) {
// S\NP/PP_on --> on(x,y,e)
statement = new AtomicSentence(getPrepositionPredicate(deps, 1, parse), vars.get(1), vars.get(0), head);
} else {
if (deps.get(0) != null && deps.get(0).getPreposition() != Preposition.NONE) {
// Can happen in questions: S[q]/PP/NP Is the ball on the table?
statement = new AtomicSentence(getPrepositionPredicate(deps, 0, parse), vars.get(0), vars.get(1), head);
} else {
// S\NP/NP
SemanticType type = SemanticType.T;
type = SemanticType.make(head.getType(), type);
type = SemanticType.make(vars.get(1).getType(), type);
type = SemanticType.make(vars.get(0).getType(), type);
Constant pred = new Constant("eq", type);
statement = new AtomicSentence(pred, vars.get(0), vars.get(1), head);
}
}
return LambdaExpression.make(statement, vars);
}
示例14: getPrepositionPredicate
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
private String getPrepositionPredicate(final List<ResolvedDependency> deps, final int arg,
final CCGandSRLparse parse) {
final Preposition preposition = deps.get(arg).getPreposition();
String result = preposition.toString();
if (preposition == Preposition.OTHER) {
// Hack to fill in the prepositions the parse didn't track. Look for PP/NP nodes whose argument is the same
// as the PP arg of the verb.
for (final ResolvedDependency dep : parse.getCcgParse().getAllLabelledDependencies()) {
if (dep.getCategory().equals(Category.valueOf("PP/NP"))
&& dep.getArgumentIndex() == deps.get(arg).getArgumentIndex()) {
result = parse.getCcgParse().getLeaves().get(dep.getHead()).getWord();
}
}
}
return result.toLowerCase();
}
示例15: evaluateStep
import edu.uw.easysrl.dependencies.ResolvedDependency; //导入依赖的package包/类
public RetrievalStatistics evaluateStep(final Set<ResolvedDependency> goldDependencies,
final SyntaxTreeNode predictedParse,
final boolean generateDependencies,
final List<InputWord> leaves) {
final RetrievalStatistics stats = new RetrievalStatistics();
stats.update(goldDependencies.stream()
.filter(dep -> SyntaxUtil.isDependencyAtStep(dep, predictedParse)),
predictedDependencyStream(predictedParse, generateDependencies, leaves, true));
return stats;
}