@Override public void clear() { if (this.bidirectionalMap!=null) { this.bidirectionalMap = null; this.valueSetMap = new SimpleValueSetMap<K, V>(); } else { this.valueSetMap.clear(); } }
/** * @see #mapFromTwoColumnsText(String) */ public static ValueSetMap<String,String> mapFromTwoColumnsText(Iterable<String> lines, String separatorPattern) { ValueSetMap<String,String> theMap = new SimpleValueSetMap<String,String>(); for (String line: lines) { line = line.replaceAll(commentPattern.pattern(), ""); line = line.trim(); String[] fields = line.split(separatorPattern); if (fields.length<2) continue; // ignore empty lines theMap.put(fields[0], fields[1]); } return theMap; }
@Override protected void generateMapOriginalToGenerated() throws OperationException { if (null==mapGeneratedToOrig) throw new OperationException("internal bug"); this.mapOriginalToGenerated = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); for (ExtendedNode generatedNode : mapGeneratedToOrig.keySet()) { ExtendedNode originalNode = mapGeneratedToOrig.get(generatedNode); mapOriginalToGenerated.put(originalNode, generatedNode); } }
/** * @see #mapOfMapsFromText(String) */ public static Map<String, ValueSetMap<String, String>> mapOfMapsFromText(List<String> lines, String separatorPattern) { Map<String,ValueSetMap<String,String>> theMapOfMaps = new TreeMap<String,ValueSetMap<String,String>>(); String currentTitle = null; Matcher matcher = null; for (String line: lines) { line = line.replaceAll(commentPattern.pattern(), ""); line = line.trim(); if ((matcher = headingMatcher(line))!=null) { currentTitle = matcher.group(1).trim(); } else if ((matcher = listItemMatcher(line))!=null && currentTitle!=null) { String pair = matcher.group(3); String[] fields = pair.split(separatorPattern); if (fields.length<2) // skip empty lines continue; if (!theMapOfMaps.containsKey(currentTitle)) theMapOfMaps.put(currentTitle, new SimpleValueSetMap<String,String>()); theMapOfMaps.get(currentTitle).put(fields[0].trim(), fields[1].trim()); } } return theMapOfMaps; }
private static <T extends Info, S extends AbstractNode<T,S>> ValueSetMap<S, List<S>> mapNamedEntitiesFromTree(S tree) { ValueSetMap<S, List<S>> ret = new SimpleValueSetMap<S, List<S>>(); List<List<S>> listOfLists = listsNamedEntitiesFromTree(tree); for (List<S> neList : listOfLists) { for (S node : neList) { ret.put(node,neList); } } return ret; }
protected void flipToValueSetMap() { this.valueSetMap = new SimpleValueSetMap<K, V>(); for (K key : this.bidirectionalMap.leftSet()) { V value = this.bidirectionalMap.leftGet(key); this.valueSetMap.put(key, value); } this.bidirectionalMap = null; }
private static <T> ValueSetMap<T, T> generateMapWithMappedValues(BidirectionalMap<T, T> bidiMap, ValueSetMap<T, T> originalValueSetMap) { ValueSetMap<T, T> ret = new SimpleValueSetMap<T, T>(); for (T element : originalValueSetMap.keySet()) { for (T mappedInOriginal : originalValueSetMap.get(element)) { ret.put(element, bidiMap.leftGet(mappedInOriginal)); } } return ret; }
private void createMapSimilarNodesAndMissingSimilarNodes() { mapSimilarNodesFromHypothesisToText = new SimpleValueSetMap<S, S>(); missingSimilarNodes = new LinkedHashSet<S>(); Set<S> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); Set<S> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (S hypothesisNode : hypothesisNodes) { boolean foundSimilar = false; for (S textNode : textNodes) { if (alignmentCriteria.nodesSimilar(textTree, hypothesisTree, textNode, hypothesisNode)) { foundSimilar = true; mapSimilarNodesFromHypothesisToText.put(hypothesisNode, textNode); } } if (!foundSimilar) { missingSimilarNodes.add(hypothesisNode); } } }
private void createMapAlignedTriplesAndMissingTriples() { mapAlignedTriplesFromHypothesisToText = new SimpleValueSetMap<S, S>(); missingTriples = new LinkedHashSet<S>(); Set<S> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); Set<S> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (S hypothesisNode : hypothesisNodes) { boolean foundAligned = false; for (S textNode : textNodes) { if (alignmentCriteria.triplesAligned(textTree, hypothesisTree, textNode, hypothesisNode)) { foundAligned = true; mapAlignedTriplesFromHypothesisToText.put(hypothesisNode, textNode); } } if (!foundAligned) { missingTriples.add(hypothesisNode); } } }
private void buildArgumentMap() { mapArgumentsHypothesisToText = new SimpleValueSetMap<>(); hypothesisArguments = listOfArguments(hypothesisStructures); textArguments = listOfArguments(textStructures); if (surroundingStructures!=null) { for (Set<PredicateArgumentStructure<I, S>> structures : surroundingStructures) { textArguments.addAll(listOfArguments(structures)); } } for (PredicateAndArgument<I, S> hypothesisArgument : hypothesisArguments) { for (PredicateAndArgument<I, S> textArgument : textArguments) { if (argumentsMatch(textArgument,hypothesisArgument)) { mapArgumentsHypothesisToText.put(hypothesisArgument, textArgument); } } } }
private void createMapAlignedNodesAndMissingAlignedNodes() { mapAlignedNodesFromHypothesisToText = new SimpleValueSetMap<S, S>(); missingAlignedNodes = new LinkedHashSet<S>(); Set<S> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); Set<S> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (S hypothesisNode : hypothesisNodes) { boolean foundSimilar = false; for (S textNode : textNodes) { if (alignmentCriteria.nodesAligned(textTree, hypothesisTree, textNode, hypothesisNode)) { foundSimilar = true; mapAlignedNodesFromHypothesisToText.put(hypothesisNode, textNode); } } if (!foundSimilar) { missingAlignedNodes.add(hypothesisNode); } } }
/** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { ValueSetMap<String,String> theMap = new SimpleValueSetMap<String,String>(); theMap.put("bird", "animal"); theMap.put("cow", "animal"); theMap.put("bird", "flyable"); nounOcean = new ValueSetMapLexicalResource( theMap, SimplerCanonicalPosTag.NOUN, "DemoResource", "DemoRelation"); }
@Deprecated public static ValueSetMap<ExtendedNode, ExtendedNode> findSimilarContentNodes(ExtendedNode textTree, ExtendedNode hypothesisTree) { ValueSetMap<ExtendedNode, ExtendedNode> ret = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree); Set<ExtendedNode> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree); for (ExtendedNode hypothesisNode : hypothesisNodes) { for (ExtendedNode textNode : textNodes) { if (nodesSimilarContents(textNode.getInfo(),hypothesisNode.getInfo())) { ret.put(hypothesisNode,textNode); } } } return ret; }
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); } } } }
@Deprecated public static ValueSetMap<ExtendedNode, ExtendedNode> findMatchingNodes(ExtendedNode textTree, ExtendedNode hypothesisTree) { ValueSetMap<ExtendedNode, ExtendedNode> ret = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> hypothesisNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree); Set<ExtendedNode> textNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree); for (ExtendedNode hypothesisNode : hypothesisNodes) { for (ExtendedNode textNode : textNodes) { if (nodesEqual(textNode.getInfo(),hypothesisNode.getInfo())) { ret.put(hypothesisNode,textNode); } } } return ret; }
/** * Creates the rules. <code>depth</code> indicates the maximum chain-length. * * @param depth the maximum chain-length * @throws LexicalResourceException * @throws TeEngineMlException */ public void createRuleBase(int depth) throws LexicalResourceException, TeEngineMlException { generatedRules = new SimpleValueSetMap<CanonicalLemmaAndPos, ChainOfLexicalRules>(); List<ChainOrWord> currentRules = createOriginalListOfHypothesis(); for (int index=0;index<depth;++index) { logger.debug("expanding..."); currentRules = expand(currentRules); logger.debug("expanding done."); for (ChainOrWord chain : currentRules) { CanonicalLemmaAndPos lemmaAndPos = new CanonicalLemmaAndPos(chain.getChain().getLhsLemma(),chain.getChain().getLhsPos()); generatedRules.put(lemmaAndPos, chain.getChain()); } } }
public static ValueSetMap<ExtendedNode, ExtendedNode> findAllMatchingNodes(ExtendedNode fromTree, ExtendedNode toTree) { ValueSetMap<ExtendedNode, ExtendedNode> ret = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> fromTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(fromTree); Set<ExtendedNode> toTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(toTree); for (ExtendedNode fromNode : fromTreeNodes) { for (ExtendedNode toNode : toTreeNodes) { if (Equalities.areEqualNodes(fromNode.getInfo(), toNode.getInfo())) { ret.put(fromNode, toNode); } } } return ret; }
private void buildMapPredicatesHypothesisToText() { mapPredicatesHypothesisToText = new SimpleValueSetMap<>(); for (PredicateArgumentStructure<I, S> hypothesisStructure : hypothesisStructures) { for(PredicateArgumentStructure<I, S> textStructure : textStructures) { if (samePredicate(hypothesisStructure.getPredicate(), textStructure.getPredicate())) { mapPredicatesHypothesisToText.put( hypothesisStructure, new FlaggedPredicateArgumentStructure<>( predicateTruthValueMatch(hypothesisStructure,textStructure), textStructure) ); } } } }
public void generate() { TreeCopier<I, S, I, S> copier = new TreeCopier<I, S, I, S>( originalTree, new TreeCopier.InfoConverter<S, I>() { @Override public I convert(S os) { return os.getInfo(); } }, nodeConstructor ); copier.copy(); generatedTree = copier.getGeneratedTree(); generatedTree.addChild(treeToPatch); BidirectionalMap<S, S> copierMap = copier.getNodesMap(); mapOriginalToGenerated = new SimpleValueSetMap<>(); for (S node : copierMap.leftSet()) { mapOriginalToGenerated.put(node, copierMap.leftGet(node)); } }
@Override protected void generateTheTree() throws OperationException { affectedNodes = new LinkedHashSet<ExtendedNode>(); //BidirectionalMap<AbstractNode<Info,?>, EnglishNode> copyMap = AbstractNodeUtils.copyTreeReturnMap(textTree.getTree(), new EnglishNodeConstructor()); BidirectionalMap<ExtendedNode, ExtendedNode> copyMap = AbstractNodeUtils.strictTypeCopyTree(textTree.getTree(), new ExtendedNodeConstructor()); ExtendedNode duplicatedNode = new ExtendedNode(new ExtendedInfo(new DefaultInfo(nodeToMove.getInfo().getId(), nodeToMove.getInfo().getNodeInfo(), this.newEdgeInfo), nodeToMove.getInfo().getAdditionalNodeInformation()) ); ExtendedNode parentInGeneratedTree = copyMap.leftGet(newParent); parentInGeneratedTree.addChild(duplicatedNode); if (nodeToMove.getAntecedent()!=null) { ExtendedNode antecedentInOriginal = nodeToMove.getAntecedent(); ExtendedNode antecedentInGenerated = copyMap.leftGet(antecedentInOriginal); duplicatedNode.setAntecedent(antecedentInGenerated); } affectedNodes.add(duplicatedNode); this.generatedTree = copyMap.leftGet(textTree.getTree()); this.mapOriginalToGenerated = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); for (ExtendedNode originalNode : copyMap.leftSet()) { mapOriginalToGenerated.put(originalNode,copyMap.leftGet(originalNode)); } mapOriginalToGenerated.put(nodeToMove,duplicatedNode); }