public OriginalTreesAfterInitialization( List<ExtendedNode> originalTextTrees, ExtendedNode hypothesisTree, Map<ExtendedNode, String> originalMapTreesToSentences, TreeCoreferenceInformation<ExtendedNode> coreferenceInformation) throws TreeAndParentMapException { super(); this.originalTextTrees = originalTextTrees; this.hypothesisTree = hypothesisTree; this.originalMapTreesToSentences = originalMapTreesToSentences; hypothesisTreeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(this.hypothesisTree); this.coreferenceInformation = coreferenceInformation; }
public static <I, S extends AbstractNode<I, S>> LinkedHashSet<S> findAllowedRootsByAffectedNodes(TreeAndParentMap<I, S> tree, Set<S> affectedNodes) { final S treeRoot = tree.getTree(); final Map<S, S> parentMap = tree.getParentMap(); LinkedHashSet<S> ret = new LinkedHashSet<>(); for (S affectedNode : affectedNodes) { S node = affectedNode; while (node != treeRoot) { ret.add(node); node = parentMap.get(node); } ret.add(node); } return ret; }
private List<Set<PredicateArgumentStructure<I, S>>> buildStructuresForSurrounding(List<S> surrounding, TreeAndParentMap<I, S> exclude) throws PredicateArgumentIdentificationException, TreeAndParentMapException { if (null==surrounding) return null; if (surrounding.size()==0) return null; List<Set<PredicateArgumentStructure<I, S>>> ret = new ArrayList<>(surrounding.size()-1); for (S surroundingTree : surrounding) { if (exclude.getTree()!=surroundingTree) { ret.add(buildStructuresForTree(new TreeAndParentMap<I, S>(surroundingTree))); } } return ret; }
private List<ExtendedNode> findUpNodes(ExtendedNode textNodeToMove, ExtendedNode textNodeToBeParent, ExtendedNode leastCommonAncestor) { List<ExtendedNode> ret = new LinkedList<ExtendedNode>(); if (leastCommonAncestor==textNodeToMove) { // do nothing - empty list } else { ExtendedNode current = tree.getParentMap().get(textNodeToMove); while(current != leastCommonAncestor) { ret.add(current); current = tree.getParentMap().get(current); } } return ret; }
protected void offerAllLastDfsIterations(AStarTreeElement startingElementInRecursion) throws TreeAndParentMapException, ClassifierException, TeEngineMlException new TreeAndParentMap<ExtendedInfo, ExtendedNode>(startingElementInRecursion.getTree(),startingElementInRecursion.getParentMap()); new TreeAndParentMap<ExtendedInfo, ExtendedNode>(generatedTree.getTree()); mapToTreeAndParentMap.put(generatedTree, treeAndParentMap); AStarTreeElement newElement = new AStarTreeElement(generatedTree.getTree(), mapToTreeAndParentMap.get(generatedTree).getParentMap(), generator.getHistoryMap().get(generatedTree), generatedTree.getFeatureVector(), startingElementInRecursion.getOriginalSentence(), previousElement.getDistance()+1, estimation, previousElement);
public MoveNodeOperation(TreeAndParentMap<ExtendedInfo,ExtendedNode> textTree, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesisTree, ExtendedNode nodeToMove, ExtendedNode newParent, EdgeInfo newEdgeInfo) throws OperationException { super(textTree, hypothesisTree); if (hypothesisTree.getTree()==nodeToMove) throw new OperationException("Moving the root is illegal."); this.nodeToMove = nodeToMove; this.newParent = newParent; this.newEdgeInfo = newEdgeInfo; }
this.numberOfHypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(operationsEnvironment.getHypothesis().getTree()).size(); Set<TreeAndFeatureVector> treesSet = new LinkedHashSet<TreeAndFeatureVector>(); this.mapTreeToSentence = new LinkedHashMap<TreeAndFeatureVector, String>(); new TreeAndParentMap<ExtendedInfo, ExtendedNode>(textTree); Map<Integer,Double> initialFeatureVector = initialFeatureVector(); TreeAndFeatureVector treeAndFeatureVector = new TreeAndFeatureVector(textTree, initialFeatureVector);
private List<ExtendedNode> findDownNodes(ExtendedNode textNodeToMove, ExtendedNode textNodeToBeParent, ExtendedNode leastCommonAncestor) { List<ExtendedNode> ret = new LinkedList<ExtendedNode>(); if (leastCommonAncestor==textNodeToBeParent) { // do nothing } else { ExtendedNode current = tree.getParentMap().get(textNodeToBeParent); while (current!=leastCommonAncestor) { ret.add(current); current=tree.getParentMap().get(current); } } Collections.reverse(ret); return ret; }
if (null==element)throw new TeEngineMlException("empty queue"); TreeAndParentMap<ExtendedInfo, ExtendedNode> tree = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(element.getTree()); new TreeAndParentMap<ExtendedInfo, ExtendedNode>(generatedTree.getTree()); mapToTreeAndParentMap.put(generatedTree, treeAndParentMap); new TreeAndParentMap<ExtendedInfo, ExtendedNode>(generatedTree.getTree()); double aStarEstimation = AStarUtilities.aStarEstimation(generatedTree, generatedTreeAndParentMap, operationsEnvironment.getHypothesis(), classifier, futureEstimationPerNode); generatedTree.getTree(), generatedTreeAndParentMap.getParentMap(), generatedTreesHistory.get(generatedTree), generatedTree.getFeatureVector(), element.getOriginalSentence(),
private void buildMissingLemmasInText() { Map<String,S> hypothesisLemmasAndNodes = getLemmasOfTree(hypothesisTree.getTree()); Set<String> hypothesisLemmas = hypothesisLemmasAndNodes.keySet(); Set<String> textLemmas = getLemmasOfTree(textTree.getTree()).keySet(); missingLemmasInText = setMinus(hypothesisLemmas,textLemmas); missingNodes = new ArrayList<S>(missingLemmasInText.size()); { for (String lemma : missingLemmasInText) { missingNodes.add(hypothesisLemmasAndNodes.get(lemma)); } } }
protected <T extends LexicalRule> Set<RuleWithConfidenceAndDescription<Info, BasicNode>> createSetOfRulesForMultiWord(String ruleBaseName, ByLemmaPosLexicalRuleBase<T> ruleBase , BasicNode hypothesisTreeAsBasicNode) throws TreeAndParentMapException, TeEngineMlException, OperationException { Set<RuleWithConfidenceAndDescription<Info, BasicNode>> setRules = new LinkedHashSet<RuleWithConfidenceAndDescription<Info, BasicNode>>(); if (logger.isDebugEnabled()){logger.debug("Finding rules for "+originalTextTrees.size()+" trees.");} int iterationIndex=0; for (ExtendedNode textTree : originalTextTrees) { if (logger.isDebugEnabled()){logger.debug("Finding rules for tree: #"+iterationIndex);} TreeAndParentMap<ExtendedInfo, ExtendedNode> treeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(textTree); MultiWordRuleBaseCreator<T> creator = new MultiWordRuleBaseCreator<T>(hypothesisTreeAsBasicNode, treeAndParentMap, ruleBase, ruleBaseName, teSystemEnvironment.getStopWords()); creator.create(); setRules.addAll(creator.getSetRules()); ++iterationIndex; } if (logger.isDebugEnabled()){if (0==setRules.size())logger.debug("No rules were created for rule base \""+ruleBaseName+"\"");} return setRules; }
public static Set<ExtendedNode> findRelationsNoMatch(TreeAndParentMap<ExtendedInfo,ExtendedNode> text, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesis) { Set<ExtendedNode> ret = new LinkedHashSet<ExtendedNode>(); Set<ExtendedNode> textNodes = AbstractNodeUtils.treeToLinkedHashSet(text.getTree()); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesis.getTree()); for (ExtendedNode hypothesisNode : hypothesisNodes) { boolean found = false; for (ExtendedNode textNode : textNodes) { if (Equalities.areEqualRelations(hypothesisNode, textNode, hypothesis.getParentMap(),text.getParentMap())) { found = true; break; } } if (!found) ret.add(hypothesisNode); } return ret; }
BasicNode englishTree = parser.getParseTree(); ExtendedNode tree = englishToExtendedNode(englishTree); TreeAndParentMap<ExtendedInfo, ExtendedNode> textTreeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(tree); new TreeAndParentMap<ExtendedInfo, ExtendedNode>(tree), rule, mapLhsToTree); operation.generate(); ExtendedNode generatedTree = operation.getGeneratedTree(); printDotFiles(textTreeAndParentMap.getTree(), generatedTree, text, ruleWithCD.getDescription(), dotDir, appNdx++); matchedRules.add(new RuleWithConfidenceAndDescription<Info, BasicNode>(rule, ruleWithCD.getConfidence(), ruleWithCD.getDescription()));
ExtendedNode current = textNodeToMove; nodes_from_root.add(current); while(tree.getParentMap().containsKey(current)) ExtendedNode parent = tree.getParentMap().get(current); nodes_from_root.add(parent); current = parent; while ( (current!=null) && (!nodes_from_root.contains(current)) ) current = tree.getParentMap().get(current);
new TreeAndParentMap<ExtendedInfo, ExtendedNode>(generatedTree.getTree()); double aStarEstimation = AStarUtilities.aStarEstimation(generatedTree, generatedTreeAndParentMap, this.operationsEnvironment.getHypothesis(), this.classifier, this.futureEstimationPerNode); AStarTreeElement generatedElement = new AStarTreeElement(generatedTree.getTree(), generatedTreeAndParentMap.getParentMap(), generatedTreesHistory.get(generatedTree), generatedTree.getFeatureVector(), element.getOriginalSentence(), element.getDistance()+1, aStarEstimation, element);
public static double missingNodesPortion(TreeAndParentMap<ExtendedInfo,ExtendedNode> text, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesis) { int totalNumberOfNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesis.getTree()).size(); int numberOfMissingNodes = findNodesNoMatch(text, hypothesis).size(); return ((double)numberOfMissingNodes)/((double)totalNumberOfNodes); }
private Map<Integer, Double> getFeatureVectorOfTransformationsPlusGap(ExtendedNode tree, Map<Integer,Double> featureVector) throws TreeAndParentMapException, TeEngineMlException { if (!hybridGapMode) throw new TeEngineMlException("Internal bug! This method should be called only in hybrid-gap mode."); TreeAndParentMap<ExtendedInfo, ExtendedNode> tapm = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(tree); return gapTools.getGapFeaturesUpdate().updateForGap(tapm, featureVector,gapEnvironment); }
ValueSetMap<ExtendedNode, ExtendedNode> matchingNodesMap = findAllMatchingNodes(hypothesisTree.getTree(), textTree.getTree()); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); for (ExtendedNode hypothesisNode : hypothesisNodes) (hypothesisTree.getParentMap().get(hypothesisNode)!=null) // not root && for (ExtendedNode matchingTextNode : matchingNodesMap.get(hypothesisNode)) if (Equalities.areEqualRelations(hypothesisNode, matchingTextNode, hypothesisTree.getParentMap(), textTree.getParentMap()))
try { textTreeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedConstructionNode>(tree); } catch ( TreeAndParentMapException e) { throw new AnnotatorException("see nested", e); } } catch (OperationException e) { logger.error("Error applying the following rule to the following tree"); try { TREE_VIEWER.printTree(textTreeAndParentMap.getTree(), false); } catch (TreeStringGeneratorException e1) { } try { RULE_VIEWER.viewRule(rule); } catch (TreeStringGeneratorException e1) { } throw new AnnotatorException("see nested", e );