@Override public void clear() { if (this.bidirectionalMap!=null) { this.bidirectionalMap = null; this.valueSetMap = new SimpleValueSetMap<K, V>(); } else { this.valueSetMap.clear(); } }
@Override protected void setCanonicalPosTag() { setTextProPos(posTagString); if (null==_textproPos) this.canonicalPosTag = CanonicalPosTag.OTHER; else { // look it up in the TextPro to Canonicals map this.canonicalPosTag = TEXTPRO_TO_CANONICAL_MAP.containsValue(_textproPos) ? TEXTPRO_TO_CANONICAL_MAP.getKeysOf(_textproPos).iterator().next() : CanonicalPosTag.OTHER; // default } }
/** * 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); }
/** * get the canonical Pos corresponding to the given TextPro pos * * @param textproPos * @return */ public static CanonicalPosTag textproPosToCannonical(TextProPosTag textproPos) { return TEXTPRO_TO_CANONICAL_MAP.getKeysOf(textproPos).iterator().next(); }
/** * @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 void parseToSetAndMap(String[] components) throws TeEngineMlException { datasetNames = new LinkedHashSet<String>(); mapDatasetNameToFileName = new SimpleValueSetMap<String, String>(); for (String component : components) { if (!component.contains(NAME_AND_FILENAME_SEPARATOR)) // then it is only dataset name, no file name. { datasetNames.add(component.trim()); } else { String[] dsNameAndFileName = component.split(NAME_AND_FILENAME_SEPARATOR); if (dsNameAndFileName.length!=(1+1)) throw new TeEngineMlException("Illegal parameter value of dataset(s): "+parameterValue); else { String datasetNameComponent = dsNameAndFileName[0].trim(); String fileNameComponent = dsNameAndFileName[1].trim(); datasetNames.add(datasetNameComponent); mapDatasetNameToFileName.put(datasetNameComponent,fileNameComponent); } } } }
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; }
mapAllRules = new SimpleValueSetMap<Integer, IdAndScore>();
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; }
ValueSetMap<String,String> theMap = new SimpleValueSetMap<String,String>(); String currentTitle = null; Matcher matcher = null;
private void buildMatchingMap() matchingPredicates = new SimpleValueSetMap<PredicateArgumentStructure<I, S>, PredicateArgumentStructure<I, S>>(); for (PredicateArgumentStructure<I, S> hypothesisStructure : hypothesisStructures)
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 void find() throws OperationException { specs = new LinkedHashSet<SubstitutionSubtreeSpecification>(); nodesAndTheirAntecedent = new LinkedHashMap<ExtendedNode, ExtendedNode>(); mapNodeToThoseWhoHaveItAsAntecedent = new SimpleValueSetMap<ExtendedNode, ExtendedNode>(); Set<ExtendedNode> nodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); for (ExtendedNode node : nodes) { if (node.getAntecedent()!=null) { ExtendedNode antecedent = AbstractNodeUtils.getDeepAntecedentOf(node); nodesAndTheirAntecedent.put(node,antecedent); mapNodeToThoseWhoHaveItAsAntecedent.put(antecedent, node); } } for (ExtendedNode nodeThatHasAntecedent : nodesAndTheirAntecedent.keySet()) { specs.add(new SubstitutionSubtreeSpecification(nodeThatHasAntecedent, nodesAndTheirAntecedent.get(nodeThatHasAntecedent))); } if (parser.equals(PARSER.EASYFIRST)) { addCopyForRefRelation(); } }
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"); }