public V remove(K1 key1, K2 key2) { return get(key1).remove(key2); }
public boolean contains(K1 key1, K2 key2, K3 key3) { if (!map.containsKey(key1)) return false; if (!map.get(key1).containsKey(key2)) return false; if (!map.get(key1).get(key2).containsKey(key3)) return false; else return true; }
public Set<K2> secondKeySet() { Set<K2> keys = Generics.newHashSet(); for (K1 k1 : map.keySet()) { keys.addAll(get(k1).keySet()); } return keys; }
public V get(K1 key1, K2 key2, K3 key3) { return getTwoDimensionalMap(key1).get(key2, key3); }
public Map<K3, V> get(K1 key1, K2 key2) { return get(key1).get(key2); }
public Map<K4, V> get(K1 key1, K2 key2, K3 key3) { return get(key1, key2).get(key3); }
public Map<K5, V> get(K1 key1, K2 key2, K3 key3, K4 key4) { return get(key1, key2, key3).get(key4); }
public Set<K3> thirdKeySet() { Set<K3> keys = Generics.newHashSet(); for (K1 k1 : map.keySet()) { TwoDimensionalMap<K2, K3, V> m = map.get(k1); for (K2 k2 : m.firstKeySet()) { keys.addAll(m.get(k2).keySet()); } } return keys; }
public SimpleMatrix getBinaryClassification(String left, String right) { if (op.combineClassification) { return unaryClassification.get(""); } else { left = basicCategory(left); right = basicCategory(right); return binaryClassification.get(left, right); } }
public SimpleTensor getBinaryTensor(String left, String right) { left = basicCategory(left); right = basicCategory(right); return binaryTensors.get(left, right); }
public SimpleMatrix getBinaryTransform(String left, String right) { left = basicCategory(left); right = basicCategory(right); return binaryTransform.get(left, right); }
public Set<K4> fourthKeySet() { Set<K4> keys = Generics.newHashSet(); for (K1 k1 : map.keySet()) { ThreeDimensionalMap<K2,K3,K4,V> m3 = map.get(k1); for (K2 k2 : m3.firstKeySet()) { TwoDimensionalMap<K3,K4,V> m2 = m3.get(k2); for (K3 k3 : m2.firstKeySet()) { keys.addAll(m2.get(k3).keySet()); } } } return keys; }
public static boolean entityIsAcronym(Document document, CorefCluster mentionCluster, CorefCluster potentialAntecedent) { int minId = Math.min(mentionCluster.clusterID, potentialAntecedent.clusterID); int maxId = Math.max(mentionCluster.clusterID, potentialAntecedent.clusterID); if(!document.acronymCache.contains(minId, maxId)) { boolean isAcronym = false; for(Mention m : mentionCluster.corefMentions){ if(m.isPronominal()) continue; for(Mention ant : potentialAntecedent.corefMentions){ if(isAcronym(m.originalSpan, ant.originalSpan)) isAcronym = true; } } document.acronymCache.put(minId, maxId, isAcronym); } return document.acronymCache.get(minId, maxId); }
public Set<K5> fifthKeySet() { Set<K5> keys = Generics.newHashSet(); for (K1 k1 : map.keySet()) { FourDimensionalMap<K2,K3,K4,K5,V> m4 = map.get(k1); for (K2 k2 : m4.firstKeySet()) { ThreeDimensionalMap<K3,K4,K5,V> m3 = m4.get(k2); for (K3 k3 : m3.firstKeySet()) { TwoDimensionalMap<K4,K5,V> m2 = m3.get(k3); for (K4 k4 : m2.firstKeySet()) { keys.addAll(m2.get(k4).keySet()); } } } } return keys; }
public SimpleTensor getTensorForNode(Tree node) { if (!op.useTensors) { throw new AssertionError("Not using tensors"); } if (node.children().length == 2) { String leftLabel = node.children()[0].value(); String leftBasic = basicCategory(leftLabel); String rightLabel = node.children()[1].value(); String rightBasic = basicCategory(rightLabel); return binaryTensors.get(leftBasic, rightBasic); } else if (node.children().length == 1) { throw new AssertionError("No unary transform matrices, only unary classification"); } else { throw new AssertionError("Unexpected tree children size of " + node.children().length); } }
public SimpleMatrix getWForNode(Tree node) { if (node.children().length == 2) { String leftLabel = node.children()[0].value(); String leftBasic = basicCategory(leftLabel); String rightLabel = node.children()[1].value(); String rightBasic = basicCategory(rightLabel); return binaryTransform.get(leftBasic, rightBasic); } else if (node.children().length == 1) { throw new AssertionError("No unary transform matrices, only unary classification"); } else { throw new AssertionError("Unexpected tree children size of " + node.children().length); } }
public SimpleMatrix getWForNode(Tree node) { if (node.children().length == 1) { String childLabel = node.children()[0].value(); String childBasic = basicCategory(childLabel); return unaryTransform.get(childBasic); } else if (node.children().length == 2) { String leftLabel = node.children()[0].value(); String leftBasic = basicCategory(leftLabel); String rightLabel = node.children()[1].value(); String rightBasic = basicCategory(rightLabel); return binaryTransform.get(leftBasic, rightBasic); } throw new AssertionError("Should only have unary or binary nodes"); }
public SimpleMatrix getScoreWForNode(Tree node) { if (node.children().length == 1) { String childLabel = node.children()[0].value(); String childBasic = basicCategory(childLabel); return unaryScore.get(childBasic); } else if (node.children().length == 2) { String leftLabel = node.children()[0].value(); String leftBasic = basicCategory(leftLabel); String rightLabel = node.children()[1].value(); String rightBasic = basicCategory(rightLabel); return binaryScore.get(leftBasic, rightBasic); } throw new AssertionError("Should only have unary or binary nodes"); }
private static double scaleAndRegularizeTensor(TwoDimensionalMap<String, String, SimpleTensor> derivatives, TwoDimensionalMap<String, String, SimpleTensor> currentMatrices, double scale, double regCost) { double cost = 0.0; // the regularization cost for (TwoDimensionalMap.Entry<String, String, SimpleTensor> entry : currentMatrices) { SimpleTensor D = derivatives.get(entry.getFirstKey(), entry.getSecondKey()); D = D.scale(scale).plus(entry.getValue().scale(regCost)); derivatives.put(entry.getFirstKey(), entry.getSecondKey(), D); cost += entry.getValue().elementMult(entry.getValue()).elementSum() * regCost / 2.0; } return cost; }
/** * Add tensors from the second map to the first map, in place. */ public static void addTensors(TwoDimensionalMap<String, String, SimpleTensor> first, TwoDimensionalMap<String, String, SimpleTensor> second) { for (TwoDimensionalMap.Entry<String, String, SimpleTensor> entry : first) { if (second.contains(entry.getFirstKey(), entry.getSecondKey())) { first.put(entry.getFirstKey(), entry.getSecondKey(), entry.getValue().plus(second.get(entry.getFirstKey(), entry.getSecondKey()))); } } for (TwoDimensionalMap.Entry<String, String, SimpleTensor> entry : second) { if (!first.contains(entry.getFirstKey(), entry.getSecondKey())) { first.put(entry.getFirstKey(), entry.getSecondKey(), entry.getValue()); } } }