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; }
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; }
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; }
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); }
private void initializeQueue() throws ClassifierException, TreeAndParentMapException, TeEngineMlException { queue = new PriorityQueue<AStarTreeElement>(); for (ExtendedNode tree : originalTextTrees) { Map<Integer,Double> featureVector = initialFeatureVector(); String sentence = originalMapTreesToSentences.get(tree); if (sentence==null)throw new TeEngineMlException("Could not find a sentence to a given original tree"); AStarTreeElement element = AStarUtilities.createElement(new TreeAndFeatureVector(tree, featureVector), new TreeAndParentMap<ExtendedInfo, ExtendedNode>(tree), this.operationsEnvironment.getHypothesis(), this.classifier, new TreeHistory(TreeHistoryComponent.onlyFeatureVector(initialFeatureVector())), sentence, 0, null, 0); queue.offer(element); } }
private Set<TreeAndFeatureVector> findMatchingTextTrees(Set<TreeAndFeatureVector> textTrees) throws TeEngineMlException, TreeAndParentMapException { Set<TreeAndFeatureVector> matchingTrees = new LinkedHashSet<TreeAndFeatureVector>(); for (TreeAndFeatureVector textTree : textTrees) { TreeAndParentMap<ExtendedInfo,ExtendedNode> textTreeAndParentMap = new TreeAndParentMap<ExtendedInfo,ExtendedNode>(textTree.getTree()); if (AdvancedEqualities.USE_ADVANCED_EQUALITIES) { if (AdvancedEqualities.findMissingRelations(textTreeAndParentMap, operationsEnvironment.getHypothesis()).size()==0) matchingTrees.add(textTree); } else { boolean nodesOk = (TreeUtilities.findNodesNoMatch(textTreeAndParentMap,operationsEnvironment.getHypothesis()).size()==0); if (nodesOk) { boolean relationsOk = (TreeUtilities.findRelationsNoMatch(textTreeAndParentMap, operationsEnvironment.getHypothesis()).size()==0); if (relationsOk) { matchingTrees.add(textTree); } } } } return matchingTrees; }
TreeAndParentMap<ExtendedInfo, ExtendedNode> tree = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(element.getTree());
private Set<TreeAndFeatureVector> generateTrees(TreeAndFeatureVector textTree, ImmutableList<SingleOperationItem> operations) throws TeEngineMlException, OperationException, ScriptException, RuleBaseException, TreeAndParentMapException { ++this.numberOfExpandedElements; TreesGeneratorByOperations generator = new TreesGeneratorByOperations(textTree, operations, script, historyMap.get(textTree),this.operationsEnvironment); if (USE_CACHE_OF_GENERATED_TREES) generator.setCache(cache); generator.generateTrees(); if (USE_CACHE_OF_GENERATED_TREES) this.generatedSingleIteration.putAll(generator.getGeneratedTreesAsMap()); if (USE_CACHE_OF_GENERATED_TREES) this.debugFoundInCacheCount += generator.getDebugFoundInCacheCount(); if (USE_CACHE_OF_GENERATED_TREES) this.debugGeneratedFoundInCacheCount += generator.getDebugGeneratedFoundInCacheCount(); // new code, after changing the generator working method. String originalSentence = mapTreeToSentence.get(textTree); for (TreeAndFeatureVector generatedTree: generator.getGeneratedTrees()) { mapTreeToSentence.put(generatedTree, originalSentence); // Asher 10-June-2011 TreeAndParentMap<ExtendedInfo, ExtendedNode> treeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(generatedTree.getTree()); evaluationHistoryMap.put(generatedTree, new TreeEvaluationsHistory(evaluationHistoryMap.get(textTree),createEvaluationForTree(treeAndParentMap))); } this.historyMap.putAll(generator.getHistoryMap()); Set<TreeAndFeatureVector> generator_generatedTrees = generator.getGeneratedTrees(); this.numberOfGeneratedElements += generator_generatedTrees.size(); return generator_generatedTrees; }
@Override protected void postGlobalLoop(LocalCreativeTreeElement bestElement) throws TeEngineMlException, TreeAndParentMapException { if (bestElement!=null) { updateLocalHistory(this.localIterationsArray, bestElement); // For GUI if (this.progressFire!=null) { double currentProgress = progressSoFar+progressSingleTree*((initialHeuristicGap-getHeuristicGap(new TreeAndParentMap<ExtendedInfo,ExtendedNode>(bestElement.getTree()),bestElement.getFeatureVector()))/initialHeuristicGap); progressFire.fire(currentProgress); } } }
private double getHeuristicGap(TreeInProcess treeInProcess) throws GapException, TreeAndParentMapException { return getHeuristicGap(new TreeAndParentMap<ExtendedInfo,ExtendedNode>(treeInProcess.getTree().getTree(),treeInProcess.getParentMap()),treeInProcess.getTree().getFeatureVector()); }
@Override public GapDescription getGapDescription() throws TeEngineMlException { if (hybridGapMode) { try { return gapTools.getGapDescriptionGenerator().describeGap( new TreeAndParentMap<ExtendedInfo, ExtendedNode>(getBestTree().getTree()) , gapEnvironment); } catch(TreeAndParentMapException e){throw new TeEngineMlException("Failed to describe gap.",e);} } else { return null; } }
protected List<KStagedElement> createInitialStates() throws ClassifierException, TreeAndParentMapException, TeEngineMlException { List<KStagedElement> initialStates = new ArrayList<KStagedElement>(originalTextTrees.size()); for (ExtendedNode tree : originalTextTrees) { Map<Integer,Double> featureVector = initialFeatureVector(); double cost = -this.classifier.getProduct(featureVector); TreeAndParentMap<ExtendedInfo, ExtendedNode> treeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(tree); // SingleTreeEvaluations evaluations = SingleTreeEvaluations.create(treeAndParentMap, operationsEnvironment.getHypothesis(), this.operationsEnvironment.getHypothesisLemmasLowerCase(), this.operationsEnvironment.getHypothesisNumberOfNodes()); SingleTreeEvaluations evaluations = new AlignmentCalculator(operationsEnvironment.getAlignmentCriteria(), treeAndParentMap, operationsEnvironment.getHypothesis()).getEvaluations(operationsEnvironment.getHypothesisLemmasLowerCase(), operationsEnvironment.getHypothesisNumberOfNodes()); KStagedElement element = new KStagedElement( tree, new TreeHistory(TreeHistoryComponent.onlyFeatureVector(initialFeatureVector())), featureVector, originalMapTreesToSentences.get(tree), cost, evaluations, 0, evaluations, cost ); initialStates.add(element); } return initialStates; }
private boolean alreadyExamined(AStarTreeElement element) throws TreeAndParentMapException, ClassifierException { boolean ret = false; TreeAndParentMap<ExtendedInfo, ExtendedNode> elementTreeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(element.getTree(),element.getParentMap()); AStarTreeElement olderElement = element.getGeneratedFrom(); while ((false==ret)&&(olderElement!=null)) { TreeAndParentMap<ExtendedInfo, ExtendedNode> olderElementTreeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(olderElement.getTree(),olderElement.getParentMap()); if (TreeUtilities.areEqualTrees(elementTreeAndParentMap, olderElementTreeAndParentMap)) { double classificationScoreOfElement = classifier.classify(element.getFeatureVector()); double classificationScoreOfOlderElement = classifier.classify(olderElement.getFeatureVector()); if (classificationScoreOfOlderElement>=classificationScoreOfElement) // the old is no worse than the new { ret = true; } } olderElement = olderElement.getGeneratedFrom(); } 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();
private double gapOf(ExtendedNode textTree) throws TreeAndParentMapException { TreeAndParentMap<ExtendedInfo, ExtendedNode> tapm = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(textTree); // SingleTreeEvaluations evaluations = SingleTreeEvaluations.create(tapm, this.operationsEnvironment.getHypothesis(), this.operationsEnvironment.getHypothesisLemmasLowerCase(),this.operationsEnvironment.getHypothesisNumberOfNodes()); SingleTreeEvaluations evaluations = new AlignmentCalculator(operationsEnvironment.getAlignmentCriteria(), tapm, operationsEnvironment.getHypothesis()).getEvaluations(operationsEnvironment.getHypothesisLemmasLowerCase(), operationsEnvironment.getHypothesisNumberOfNodes()); return (double) evaluations.getMissingLemmas()+evaluations.getMissingNodes()+evaluations.getMissingRelations(); }
new TreeAndParentMap<ExtendedInfo, ExtendedNode>(tree);
new TreeAndParentMap<ExtendedInfo, ExtendedNode>(generatedTree.getTree()); TreeHistory history = generatedTreesHistory.get(generatedTree); Specification lastSpec = history.getSpecifications().get(history.getSpecifications().size()-1);
new TreeAndParentMap<ExtendedInfo, ExtendedNode>(textTree);
double gap = getHeuristicGap(new TreeAndParentMap<ExtendedInfo, ExtendedNode>(generatedTree.getTree()));
public static KStagedElement create( LocalCreativeTreeElement element, String originalSentence, SingleTreeEvaluations evaluationsOfOriginalTree, double costOfOriginalTree, OperationsEnvironment environment ) throws TreeAndParentMapException { TreeAndParentMap<ExtendedInfo, ExtendedNode> textTreeAndParentMap = new TreeAndParentMap<ExtendedInfo, ExtendedNode>(element.getTree()); // SingleTreeEvaluations evaluations = SingleTreeEvaluations.create(textTreeAndParentMap,environment.getHypothesis(),environment.getHypothesisLemmasLowerCase(),environment.getHypothesisNumberOfNodes()); SingleTreeEvaluations evaluations = new AlignmentCalculator(environment.getAlignmentCriteria(), textTreeAndParentMap, environment.getHypothesis()).getEvaluations(environment.getHypothesisLemmasLowerCase(), environment.getHypothesisNumberOfNodes()); KStagedElement createdElement = new KStagedElement( element.getTree(), element.getHistory(), element.getFeatureVector(), originalSentence, element.getCost(), evaluations, element.getGlobalIteration(), evaluationsOfOriginalTree, costOfOriginalTree ); return createdElement; }