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


Java SyntaxTreeNode类代码示例

本文整理汇总了Java中edu.uw.easysrl.syntax.grammar.SyntaxTreeNode的典型用法代码示例。如果您正苦于以下问题:Java SyntaxTreeNode类的具体用法?Java SyntaxTreeNode怎么用?Java SyntaxTreeNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SyntaxTreeNode类属于edu.uw.easysrl.syntax.grammar包,在下文中一共展示了SyntaxTreeNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: predictedDependencyStream

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的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()));
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:24,代码来源:DependencyEvaluator.java

示例2: updateStats

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的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());
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:21,代码来源:EvaluationStatistics.java

示例3: TrainableAgendaItem

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
public TrainableAgendaItem(final SyntaxTreeNode node,
                           final double insideScore,
                           final double outsideScoreUpperbound,
                           final int startIndex,
                           final int length,
                           final boolean includeDeps,
                           final boolean isGold,
                           final double loss,
                           final boolean isTight) {
    super(node, insideScore, outsideScoreUpperbound, startIndex, length, includeDeps);
    this.isGold = isGold;
    this.includeDeps = includeDeps;
    this.isTight = isTight;
    this.tightened = Optional.empty();
    this.loss = loss;
    this.index = counter.getAndIncrement();
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:18,代码来源:TrainableAgendaItem.java

示例4: scoreAndBuildRepresentation

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
private double scoreAndBuildRepresentation(final SyntaxTreeNode node) {
    final ParseProto parse = SyntaxUtil.toProto(node, chartIndexes).build();
    Preconditions.checkState(chartIndexes.put(node, chartIndexes.size()) == null, node);
    final double score;
    if (factory.keepGates) {
        try {
            final GatesProto currentGates = GatesProto
                    .parseFrom(scoreAndBuildRepresentationWithGates(parse.toByteArray()));
            gates.add(currentGates);
            score = currentGates.getScore();
        } catch (InvalidProtocolBufferException e) {
            throw new RuntimeException(e);
        }
    } else {
        score = scoreAndBuildRepresentation(parse.toByteArray());
    }
    Preconditions.checkState(score <= 0.0, score);
    factory.stats.ifPresent(s -> s.addNeuralScore(score));
    factory.neuralCount.incrementAndGet();
    return score;
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:22,代码来源:TreeFactoredModel.java

示例5: combineNodes

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
@Override
public AgendaItem combineNodes(final AgendaItem leftChild, final AgendaItem rightChild, final SyntaxTreeNode node) {
    final int length = leftChild.getSpanLength() + rightChild.getSpanLength();

    final TrainableAgendaItem item = new TrainableAgendaItem(
            node,
            leftChild.getInsideScore() + rightChild.getInsideScore(),
            getOutsideUpperBound(leftChild.getStartOfSpan(), leftChild.getStartOfSpan() + length),
            leftChild.getStartOfSpan(),
            length,
            AGENDA_DEPS,
            isGold(node, leftChild, rightChild),
            computeLoss(node, leftChild, rightChild));

    if (factory.useLazyAgenda) {
        return item;
    } else {
        return this.tighten(item);
    }
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:21,代码来源:TreeFactoredModel.java

示例6: unary

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
@Override
public AgendaItem unary(final AgendaItem child, final SyntaxTreeNode node, final AbstractParser.UnaryRule rule) {
    final TrainableAgendaItem item = new TrainableAgendaItem(
            node,
            child.getInsideScore(),
            child.getOutsideScoreUpperbound(),
            child.getStartOfSpan(),
            child.getSpanLength(),
            AGENDA_DEPS,
            isGold(node, child),
            computeLoss(node, child));

    if (factory.useLazyAgenda) {
        return item;
    } else {
        return this.tighten(item);
    }
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:19,代码来源:TreeFactoredModel.java

示例7: getRows

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
private int getRows(final SyntaxTreeNode node, final List<List<SyntaxTreeNode>> rows,
                    final int minIndentation) {
    int maxChildLevel = 0;
    int i = minIndentation;
    for (final SyntaxTreeNode child : node.getChildren()) {
        maxChildLevel = Math.max(getRows(child, rows, i), maxChildLevel);
        i = i + getWidth(child);
    }

    int level;
    if (node.getChildren().size() > 0) {
        level = maxChildLevel + 1;
    } else {
        level = 0;
    }

    while (rows.size() < level + 1) {
        rows.add(new ArrayList<>());
    }
    while (rows.get(level).size() < minIndentation + 1) {
        rows.get(level).add(null);
    }

    rows.get(level).set(minIndentation, node);
    return level;
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:27,代码来源:GatedHtmlPrinter.java

示例8: getRows

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
private static int getRows(SyntaxTreeNode node,
                           List<List<SyntaxTreeNode>> result, int minIndentation) {
    if (node.getDependenciesLabelledAtThisNode().size() > 0) {
        return getRows(node.getChild(0), result, minIndentation);
    }
    int maxChildLevel = 0;
    int i = minIndentation;
    for (final SyntaxTreeNode child : node.getChildren()) {
        maxChildLevel = Math.max(getRows(child, result, i), maxChildLevel);
        i = i + getWidth(child);
    }

    final int level = node.getChildren().isEmpty() ? 0 : maxChildLevel + 1;

    while (result.size() < level + 1) {
        result.add(new ArrayList<SyntaxTreeNode>());
    }
    while (result.get(level).size() < minIndentation + 1) {
        result.get(level).add(null);
    }

    result.get(level).set(minIndentation, node);
    return level;
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:25,代码来源:LatexPrinter.java

示例9: getFromParse

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
public static Adverb getFromParse(Integer headIndex, PredicateCache preds, Parse parse) {
    final SyntaxTreeNode tree = parse.syntaxTree;
    final SyntaxTreeNodeLeaf headLeaf = tree.getLeaves().get(headIndex);

    final String predicate = TextGenerationHelper.renderString(TextGenerationHelper.getNodeWords(headLeaf));
    final Category predicateCategory = parse.categories.get(headIndex);

    final ImmutableMap<Integer, ImmutableList<Argument>> args = IntStream
        .range(1, predicateCategory.getNumberOfArguments() + 1)
        .boxed()
        .collect(toImmutableMap(argNum -> argNum, argNum -> parse.dependencies.stream()
        .filter(dep -> dep.getHead() == headIndex && dep.getArgument() != headIndex && argNum == dep.getArgNumber())
        .flatMap(argDep -> Stream.of(Predication.Type.getTypeForArgCategory(predicateCategory.getArgument(argDep.getArgNumber())))
        .filter(Optional::isPresent).map(Optional::get)
        .map(predType -> new Argument(Optional.of(argDep), preds.getPredication(argDep.getArgument(), predType))))
        .collect(toImmutableList())));

    if(!adverbCategories.contains(predicateCategory)) {
        // System.err.println(String.format("new adverb category: %s (e.g., %s)",
        //                                  predicateCategory, predicate));
        adverbCategories.add(predicateCategory);
    }

    return new Adverb(predicate, predicateCategory, args);
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:26,代码来源:Adverb.java

示例10: getFromParse

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
public static Preposition getFromParse(Integer headIndex, PredicateCache preds, Parse parse) {
    final SyntaxTreeNode tree = parse.syntaxTree;
    final SyntaxTreeNodeLeaf headLeaf = tree.getLeaves().get(headIndex);

    final String predicate = TextGenerationHelper.renderString(TextGenerationHelper.getNodeWords(headLeaf));
    final Category predicateCategory = parse.categories.get(headIndex);
    final ImmutableMap<Integer, ImmutableList<Argument>> args = IntStream
        .range(1, predicateCategory.getNumberOfArguments() + 1)
        .boxed()
        .collect(toImmutableMap(argNum -> argNum, argNum -> parse.dependencies.stream()
        .filter(dep -> dep.getHead() == headIndex && dep.getArgument() != headIndex && argNum == dep.getArgNumber())
        .flatMap(argDep -> Stream.of(Predication.Type.getTypeForArgCategory(predicateCategory.getArgument(argDep.getArgNumber())))
        .filter(Optional::isPresent).map(Optional::get)
        .map(predType -> new Argument(Optional.of(argDep), preds.getPredication(argDep.getArgument(), predType))))
        .collect(toImmutableList())));

    if(!prepositionCategories.contains(predicateCategory)) {
        // System.err.println(String.format("new preposition category: %s (e.g., %s)",
        //                                  predicateCategory, predicate));
        prepositionCategories.add(predicateCategory);
    }

    return new Preposition(predicate, predicateCategory, args);
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:25,代码来源:Preposition.java

示例11: 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;
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:21,代码来源:TextGenerationHelper.java

示例12: parse

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
@Override
protected List<Scored<SyntaxTreeNode>> parse(final InputToParser input) {
	final List<Scored<SyntaxTreeNode>> candidates = baseParser.doParsing(input);

	if (candidates == null) {
		// Base parser failed. Fail here too.
		return null;
	} else if (candidates.size() == 1) {
		// Base parser only provided a single parse. Nothing to rerank.
		return candidates;
	}

	// Add all partial parses to a set which constrains the search.
	candidateSteps.clear();
	candidates.stream()
			.map(Scored::getObject)
			.flatMap(SyntaxUtil::subtreeStream)
			.map(ParserReranking::wrapParse)
			.forEach(candidateSteps::add);

	// Do standard A* parsing with the constraints from the n-best list.
	return super.parse(input);
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:24,代码来源:ParserReranking.java

示例13: compareParses

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
private static void compareParses(final DependencyParse bestParse, final SyntaxTreeNode syntaxTreeNode) {
	final List<String> words = bestParse.getLeaves().stream().map(x -> x.getWord()).collect(Collectors.toList());
	final List<Category> predictedTags = bestParse.getLeaves().stream().map(x -> x.getCategory())
			.collect(Collectors.toList());
	final List<Category> goldTags = syntaxTreeNode.getLeaves().stream().map(x -> x.getCategory())
			.collect(Collectors.toList());
	for (int i = 0; i < predictedTags.size(); i++) {
		System.out.print(words.get(i));
		if (!predictedTags.get(i).equals(goldTags.get(i))) {
			System.out.print("|" + goldTags.get(i) + "|" + predictedTags.get(i));
		}

		System.out.print(" ");
	}
	System.out.println();
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:17,代码来源:CCGBankEvaluation.java

示例14: parseFile

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的package包/类
private static int parseFile(final Parser astar, final InputReader reader, final Stopwatch parsingTime,
		final File file, final ByteBuffer wrBuf) throws IOException {
	int sentences = 0;
	for (final InputToParser input : reader.readFile(file)) {
		parsingTime.start();
		final List<Scored<SyntaxTreeNode>> parses = astar.doParsing(input);
		parsingTime.stop();

		if (parses != null) {
			wrBuf.put(parses.get(0).getObject().toString().getBytes());
		}

		sentences++;
	}
	return sentences;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:17,代码来源:GPUEvaluation.java

示例15: combineNodes

import edu.uw.easysrl.syntax.grammar.SyntaxTreeNode; //导入依赖的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);
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:21,代码来源:OracleDependenciesModel.java


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