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; }
@Override public ImmutableSet<K> getKeysOf(V value) { ImmutableSet<K> ret = null; if (this.bidirectionalMap!=null) { LinkedHashSet<K> set = new LinkedHashSet<K>(); if (this.bidirectionalMap.rightContains(value)) { K key = this.bidirectionalMap.rightGet(value); set.add(key); } ret = new ImmutableSetWrapper<K>(set); } else { ret = this.valueSetMap.getKeysOf(value); } return ret; }
/** * Convert the given ValueSetMap to a string of the form: * <p>key1 => value1</p> * <p>key2 => value2</p> * <p>...</p> */ public static <K,V> String mapToString(ValueSetMap<K,V> theMap) { StringBuilder sb = new StringBuilder(); for (K key: theMap.keySet()) sb.append(key).append(" => ").append(theMap.get(key)).append("\n"); return sb.toString(); }
private boolean hasMapped(ExtendedNode hypothesisNode) { boolean ret = false; if (mapHypothesisNodesToText.containsKey(hypothesisNode)) { ImmutableSet<ExtendedNode> mapped = mapHypothesisNodesToText.get(hypothesisNode); if (mapped!=null) { if (mapped.size()>0) { ret = true; } } } return ret; }
@Override public void put(K key, V value) { if (this.bidirectionalMap!=null) { flipToValueSetMap(); } this.valueSetMap.put(key, value); }
if (processed.containsKey(node)) if (processed.get(node).contains(successorNode)) alreadyDone = true; else processed.put(node, successorNode);
@Override public ImmutableSet<K> keySet() { ImmutableSet<K> ret = null; if (this.bidirectionalMap!=null) { ret = this.bidirectionalMap.leftSet(); } else { ret = this.valueSetMap.keySet(); } return ret; }
@Override public boolean containsKey(K key) { boolean ret = false; if (this.bidirectionalMap!=null) { ret = this.bidirectionalMap.leftContains(key); } else { ret = this.valueSetMap.containsKey(key); } return ret; }
if (mapOriginalToGenerated.containsValue(oi)) ImmutableSet<ExtendedNode> fromWhich = mapOriginalToGenerated.getKeysOf(oi); if (fromWhich.size()!=1) exception = new TeEngineMlException("Wrong mapping. fromWhich.size() = "+fromWhich.size()+
@Override public void clear() { if (this.bidirectionalMap!=null) { this.bidirectionalMap = null; this.valueSetMap = new SimpleValueSetMap<K, V>(); } else { this.valueSetMap.clear(); } }
@Override public boolean containsValue(V value) { boolean ret = false; if (this.bidirectionalMap!=null) { ret = this.bidirectionalMap.rightContains(value); } else { ret = this.valueSetMap.containsValue(value); } return ret; }
public static <T, S extends AbstractNode<T,S>> void addItself(S tree, ValueSetMap<S, S> mapOriginalToGenerated) { for (S node : TreeIterator.iterableTree(tree)) { mapOriginalToGenerated.put(node, node); } }
private void buildSpecifications() { specs = new LinkedHashSet<RuleSpecification>(); for (BasicNode lhs : matchedLeftHandSides.keySet()) { for (RuleWithConfidenceAndDescription<Info, BasicNode> rule : allMatchedRules.get(lhs)) { for (BidirectionalMap<BasicNode,ExtendedNode> mapLhsToTree : matchedLeftHandSides.get(lhs)) { specs.add(new RuleSpecification(ruleBaseName,rule,mapLhsToTree,this.introduction)); } } } }
private static <T> boolean keyHasValue(ValueSetMap<T, ?> map, T key) { boolean ret = false; if (map.containsKey(key)) { ImmutableSet<?> values = map.get(key); if (values!=null) { if (values.size()>0) { ret = true; } } } return ret; }
private void calculatePredicateNoMatch() { calculatedPredicatesNoMatch = new LinkedList<FlaggedPredicateArgumentStructure<I, S>>(); for (PredicateArgumentStructure<I, S> hypothesisStructure : hypothesisStructures) { if (!(keyHasValue(mapPredicatesHypothesisToText, hypothesisStructure))) { calculatedPredicatesNoMatch.add(new FlaggedPredicateArgumentStructure<>(false, hypothesisStructure)); } else { boolean matchFound = false; for (FlaggedPredicateArgumentStructure<I, S> textStructure : mapPredicatesHypothesisToText.get(hypothesisStructure)) { if (textStructure.isFlag()) { matchFound=true; break; } } if (!matchFound) { calculatedPredicatesNoMatch.add(new FlaggedPredicateArgumentStructure<>(true, hypothesisStructure)); } } } }
private void extractMatchedRules() throws OperationException { try { allMatchedRules = new LinkedHashMap<BasicNode, ImmutableSet<RuleWithConfidenceAndDescription<Info,BasicNode>>>(); for (BasicNode lhs : matchedLeftHandSides.keySet()) { if (!allMatchedRules.containsKey(lhs)) { ImmutableSet<RuleWithConfidenceAndDescription<Info, BasicNode>> rules = ruleBase.getRulesByLeftHandSide(lhs); if (null==rules)throw new OperationException("DynamicRuleBase returned null for a certain left hand side, that was earlier returned by getLeftHandSidesByLemmaAndPos()"); allMatchedRules.put(lhs, rules); } } } catch (RuleBaseException e) { throw new OperationException("error",e); } }
/** * @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"); }