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; }
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)); } } }
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); }
public static double missingRelationsPortion(TreeAndParentMap<ExtendedInfo,ExtendedNode> text, TreeAndParentMap<ExtendedInfo,ExtendedNode> hypothesis) { int totalNumberOfRelations = AbstractNodeUtils.treeToLinkedHashSet(hypothesis.getTree()).size()-1; if (0==totalNumberOfRelations) return 0; else { int numberOfMissingRelations = findRelationsNoMatch(text, hypothesis).size(); return ((double)numberOfMissingRelations)/((double)totalNumberOfRelations); } }
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; }
public static Set<String> constructSetLemmasLowerCase(TreeAndParentMap<ExtendedInfo, ExtendedNode> tree) { Set<String> ret = new LinkedHashSet<String>(); for (ExtendedNode node : TreeIterator.iterableTree(tree.getTree())) { String lemma = InfoGetFields.getLemma(node.getInfo()); if (lemma.length()>0) { ret.add(lemma.toLowerCase()); } } return ret; }
@Override protected void generateTheTree() throws OperationException { if (textTree.getTree()==nodeToMove) throw new OperationException("Moving the root is illegal."); affectedNodes = new LinkedHashSet<ExtendedNode>(); mapOrigToCopy = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); this.generatedTree = recursiveGenerate(textTree.getTree(),null,false); updateAntecedentInformation(); this.nodeToMoveNotExistInGeneratedTree = !nodeHasAlreadyBeenMoved; }
@Override protected void generateTheTree() throws OperationException { affectedNodes = new LinkedHashSet<ExtendedNode>(); mapOrigToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); mapGeneratedToOrig = new LinkedHashMap<ExtendedNode, ExtendedNode>(); substitutionNodeEncountered = false; this.generatedTree = copySubTree(textTree.getTree(),null,null,false); updateAntecedents(); }
public void annotateTheTree() throws AnnotationOperationException { treeWasAltered = false; // cross the tree-to-LHS map with the LHS-to-RHS-annotations map Map<ExtendedConstructionNode, BasicRuleAnnotations> mapTreeNodesToAnnotations = new LinkedHashMap<ExtendedConstructionNode, BasicRuleAnnotations>(); for (ExtendedNode lhsNode : mapLhsToAnnotations.keySet()) { if (!mapLhsToTree.leftContains(lhsNode)) throw new AnnotationOperationException("Matching bug! This node is mapped in the rule but not matched against the text tree: " + lhsNode); mapTreeNodesToAnnotations.put(mapLhsToTree.leftGet(lhsNode), mapLhsToAnnotations.get(lhsNode)); } // replace annotations in the tree replaceAnnotationsOfTree(treeAndParentMap.getTree(), mapTreeNodesToAnnotations); affectedNodes = mapTreeNodesToAnnotations.keySet(); }
private void buildLemmasOfText() { lemmasOfText_lowerCase = new LinkedHashSet<>(); addLemmasOfTextFromTree(textTree.getTree()); addLemmasOfTextFromStructures(textStructures); if (surroundingStructures!=null) { for (Set<PredicateArgumentStructure<I, S>> structures : surroundingStructures) { addLemmasOfTextFromStructures(structures); } } lemmasOfText_lowerCase.addAll(wholeTextLemmas); }
@Override protected void generateTheTree() throws OperationException { mapOrigToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); affectedNodes = new LinkedHashSet<ExtendedNode>(); this.generatedTree = copySubTree(this.textTree.getTree()); updateAntecedents(); }
private void extractGivenTreeCharacteristics() { ParseTreeCharacteristicsCollector<ExtendedInfo,ExtendedNode> collector = new ParseTreeCharacteristicsCollector<ExtendedInfo,ExtendedNode>(textTree.getTree()); collector.extract(); posRelPosTree = collector.getPosRelPosSet(); lemmaAndPosTree = collector.getLemmaAndPosSet(); if (logger.isDebugEnabled()) { logger.debug("Given tree characteristics:"); logger.debug("posRelPosTree = "+printSet(posRelPosTree)); logger.debug("lemmaAndPosTree = "+printSet(lemmaAndPosTree)); } }
private void buildMap() { mapHypothesisNodesToText = new SimpleValueSetMap<>(); for (ExtendedNode hypothesisNode : TreeIterator.iterableTree(HypothesisTree.getTree())) { for (ExtendedNode textNode : TreeIterator.iterableTree(textTree.getTree())) { if (lemmaOfNode_lowerCase(hypothesisNode).equals(lemmaOfNode_lowerCase(textNode))) { mapHypothesisNodesToText.put(hypothesisNode, textNode); } } } }
@Override protected void generateTheTree() throws OperationException { this.affectedNodes = new LinkedHashSet<ExtendedNode>(); mapOrigToGenerated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); this.generatedTree = copyTree(this.textTree.getTree()); updateAntecedents(); ExtendedNode parent = mapOrigToGenerated.leftGet(whereToInsert); ExtendedNode insertedNode = new ExtendedNode(nodeToInsert); // ExtendedNode insertedNode = new ExtendedNode(new ExtendedInfo(nodeToInsert.getId(),nodeToInsert.getNodeInfo(),nodeToInsert.getEdgeInfo(),AdditionalInformationServices.emptyInformation())); affectedNodes.add(insertedNode); parent.addChild(insertedNode); }
private void buildContentLemmasOfHypothesis() { Set<S> hypothesisPredicateNodes = getPredicateNodes(hypothesisStructures); contentLemmasOfHypothesisNonPredicates_lowerCase = contentLemmasOfNodes_lowerCase(TreeIterator.iterableTree(hypothesisTree.getTree()),hypothesisPredicateNodes); contentLemmasOfHypothesisPredicates_lowerCase = contentLemmasOfNodes_lowerCase(hypothesisPredicateNodes); }
@Override public void init() throws TeEngineMlException, OperationException, TreeAndParentMapException, AnnotatorException { super.init(); hypothesisTotalNumberOfNodes = (double)AbstractNodeUtils.treeToLinkedHashSet(operationsEnvironment.getHypothesis().getTree()).size(); hypothesisLemmasLowerCase = TreeUtilities.constructSetLemmasLowerCase(operationsEnvironment.getHypothesis()); this.initialized=true; initialFeatureVector = initialFeatureVector(); }
private void constructSetOfLemmas() throws TeEngineMlException { lemmas = new LinkedHashSet<LemmaAndPos>(); for (ExtendedNode node : AbstractNodeUtils.treeToSet(treeAndParentMap.getTree())) { if (InfoObservations.infoHasLemma(node.getInfo())) { String lemma = InfoGetFields.getLemma(node.getInfo()); PartOfSpeech pos = InfoGetFields.getPartOfSpeechObject(node.getInfo()); LemmaAndPos lemmaAndPos = new LemmaAndPos(lemma, pos); lemmas.add(lemmaAndPos); } } }
private void findForSingleNodeRule(RuleWithConfidenceAndDescription<Info, BasicNode> rule) { BasicNode lhs = rule.getRule().getLeftHandSide(); for (ExtendedNode node : TreeIterator.iterableTree(textTree.getTree())) { if (matchCriteria.nodesMatch(node, lhs)) { specs.add(new RuleSpecification(this.ruleBaseName,rule, new SingleItemBidirectionalMap<BasicNode, ExtendedNode>(lhs, node) ,false)); } } }
private void updateAntecedents() { Set<ExtendedNode> originalTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (ExtendedNode originalTreeNode : originalTreeNodes) { if (originalTreeNode.getAntecedent()!=null) { ExtendedNode originalTreeNodeAntecedent = originalTreeNode.getAntecedent(); mapOrigToGenerated.leftGet(originalTreeNode).setAntecedent(mapOrigToGenerated.leftGet(originalTreeNodeAntecedent)); } } }