/** * 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 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)); } } } }
/** * The inverse of {@link #mapFromWikiText(String, boolean, boolean)}. * <p>Convert the given ValueSetMap to a string in wiki format: * * <pre> * == key 1 == * * value 1-1 * * value 1-2 * ... * == key 2 == * * value 2-1 * * value 2-2 * ... * ... * </pre> */ public static <K,V> String mapToWikiText(ValueSetMap<K,V> theMap) { StringBuilder sb = new StringBuilder(); for (K key: theMap.keySet()) { sb.append("== ").append(key).append(" ==\n"); for (V value: theMap.get(key)) { sb.append("* ").append(value).append("\n"); } } return sb.toString(); }
/** * @param mapPredToType * @param map2ndPredToType * @param expandedPropertiesFile * @throws IOException */ private static void printWNExpandedPredicateTypePropertiesFile(HashMap<String, PredicateSignature> mapPredToType, HashMap<String, PredicateSignature> map2ndPredToType, File expandedPropertiesFile) throws IOException { // join maps mapPredToType.putAll(map2ndPredToType); // build reversed map ValueSetMap<PredicateSignature, String> mapTypeToPred = Utils.reverseMapIntoValueSetMap(mapPredToType); StringBuilder buf = new StringBuilder(); for (PredicateSignature predType : mapTypeToPred.keySet()) buf.append(predType.name()).append(" = ").append(mapTypeToPred.get(predType)).append("\n\n"); String contents = buf.toString().replaceAll("[\\[\\]]", ""); // remove Java's parenthesis FileUtils.writeFile(expandedPropertiesFile, contents); }
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; }
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)); } } } }
@SuppressWarnings("unchecked") @Override public List<LexicalRule<? extends RuleInfo>> getRulesForLeft(String leftLemma, PartOfSpeech leftPos) throws LexicalResourceException { if (leftPos==null || simplerPos(leftPos.getCanonicalPosTag())==this.canonicalPartOfSpeech) { PartOfSpeech posForRule = (leftPos==null? this.partOfSpeech: leftPos); List<LexicalRule<? extends RuleInfo>> theRules = new ArrayList<LexicalRule<? extends RuleInfo>>(); for (String rightLemma: getMap().get(leftLemma)) { // NOTE: getMap() is used instead of this.map, to allow overriding in OnlineFileBasedLexicalResource. theRules.add(new LexicalRule<RuleInfo>( leftLemma, posForRule, rightLemma, posForRule, relationName, resourceName, EmptyRuleInfo.getInstance())); } return theRules; } else { return Collections.EMPTY_LIST; } }
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>(); try { findCoreferringNodes(); for (ExtendedNode nodeInTree : this.getMapNodeToCoreferringNodes().keySet()) { for (ExtendedNode coreferringNode : this.getMapNodeToCoreferringNodes().get(nodeInTree)) { specs.add(new SubstitutionSubtreeSpecification("Coreference substitution", nodeInTree, coreferringNode)); } } } catch (TreeCoreferenceInformationException e) { throw new OperationException("Coreference problem. See nested exception.",e); } }
@SuppressWarnings("unchecked") @Override public List<LexicalRule<? extends RuleInfo>> getRules(String leftLemma, PartOfSpeech leftPos, String rightLemma, PartOfSpeech rightPos) throws LexicalResourceException { if (rightPos==null || simplerPos(rightPos.getCanonicalPosTag())==this.canonicalPartOfSpeech) { if (leftPos==null || simplerPos(leftPos.getCanonicalPosTag())==this.canonicalPartOfSpeech) { ImmutableSet<String> rightLemmas = getMap().get(leftLemma); // NOTE: getMap() is used instead of this.map, to allow overriding in OnlineFileBasedLexicalResource. if (rightLemmas.contains(rightLemma)) { List<LexicalRule<? extends RuleInfo>> theRules = new ArrayList<LexicalRule<? extends RuleInfo>>(); theRules.add(new LexicalRule<RuleInfo>( leftLemma, (leftPos==null? this.partOfSpeech: leftPos), rightLemma, (rightPos==null? this.partOfSpeech: rightPos), relationName, resourceName, EmptyRuleInfo.getInstance())); return theRules; } } } return Collections.EMPTY_LIST; }
@Override public void find() throws OperationException { try { fillMapTextNodesToHypothesisNodes(); this.specs = new LinkedHashSet<SubstituteNodeSpecification>(); for (ExtendedNode textNode : mapTextNodesToHypothesisNodes.keySet()) { for (ExtendedNode hypothesisNode : mapTextNodesToHypothesisNodes.get(textNode)) { SubstituteNodeSpecification spec = new SubstituteNodeSpecification(textNode, hypothesisNode.getInfo().getNodeInfo(),textNode.getInfo().getAdditionalNodeInformation()); specs.add(spec); } } } catch(LemmatizerException e) { throw new OperationException("Lemmatizer failed. See nested Exception",e); } }
@Override public ImmutableSet<V> get(K key) { ImmutableSet<V> ret = null; if (this.bidirectionalMap!=null) { Set<V> set = null; if (this.bidirectionalMap.leftContains(key)) { V value = this.bidirectionalMap.leftGet(key); set = new SingleItemSet<V>(value); } else { set = new DummySet<V>(); } ret = new ImmutableSetWrapper<V>(set); } else { ret = this.valueSetMap.get(key); } return ret; }
ImmutableSet<ExtendedNode> mappedOfMovedNode = operation.getMapOriginalToGenerated().get(specification.getTextNodeToMove()); if (mappedOfMovedNode.size()==0)
for (ExtendedNode textNode : matchIgnoreAnnotationHypothesisToText.get(hypothesisNode))