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; }
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; }
@Override public void clear() { if (this.bidirectionalMap!=null) { this.bidirectionalMap = null; this.valueSetMap = new SimpleValueSetMap<K, V>(); } else { this.valueSetMap.clear(); } }
/** * Adds all (L,R) keys-values from <code>mapToAdd</code> to <code>map</code> * @param <L> * @param <R> * @param map * @param mapToAdd */ public static <L,R> void BidiMapAddAll(BidirectionalMap<L, R> map, BidirectionalMap<L, R> mapToAdd) { for (L l : mapToAdd.leftSet()) { if (!map.leftContains(l)) { map.put(l, mapToAdd.leftGet(l)); } } }
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; }
public void annotate() throws AnnotatorException { mapOriginalToAnnotated = new SimpleBidirectionalMap<ExtendedNode, ExtendedNode>(); for (ExtendedNode node : TreeIterator.iterableTree(this.tree)) { mapOriginalToAnnotated.put(node, node); } annotated=true; }
@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; }
@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 Set<T> getSpecs() throws OperationException { return new DummySet<T>(); } }
/** * get the set of TextPro POSs corresponding to the given canonical Pos * * @param canonPos * @return */ public static ImmutableSet<TextProPosTag> canonicalPosToTextPro(CanonicalPosTag canonPos) { return TEXTPRO_TO_CANONICAL_MAP.get(canonPos); }
@Override public ValueSetMap<K, V> deepCopy() { if (this.bidirectionalMap!=null) { flipToValueSetMap(); } return valueSetMap.deepCopy(); }
public static <L, R, M> BidirectionalMap<L, R> concatenateBidiMaps(BidirectionalMap<L, M> map1,BidirectionalMap<M, R> map2) throws TeEngineMlException { boolean failed = false; BidirectionalMap<L, R> ret = new SimpleBidirectionalMap<L, R>(); for (L l : map1.leftSet()) { M m = map1.leftGet(l); if (!map2.leftContains(m)) failed=true; ret.put(l, map2.leftGet(m) ); } if (failed) throw new TeEngineMlException("Concatenation failed."); else return ret; } }
/** * @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"); }
@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); } }