/** * Returns all sources for a target. * * @param target * the target * @return all sources */ public Set<T> getSources(R target) { return sources.get(target).uniqueSet(); }
@SuppressWarnings("deprecation") protected Map<String,Float> calculateWordScores( List<List<String>> phrases) { Bag<String> wordFreq = new HashBag<String>(); Bag<String> wordDegree = new HashBag<String>(); for (List<String> phrase : phrases) { int degree = -1; for (String word : phrase) { if (NumberUtils.isNumber(word)) continue; else degree++; } for (String word : phrase) { wordFreq.add(word); wordDegree.add(word, degree); // other words } } for (String word : wordFreq.uniqueSet()) { wordDegree.add(word, wordFreq.getCount(word)); // itself } Map<String,Float> wordScores = new HashMap<String,Float>(); for (String word : wordFreq.uniqueSet()) { float score = (float) wordDegree.getCount(word) / (float) wordFreq.getCount(word); wordScores.put(word, score); } return wordScores; }
@Override public Bag<String> transform(AbstractNode<? extends Info,? extends AbstractNode> parseTree) { Bag<String> words = new HashBag<String> (); if (parseTree.getChildren()==null) { words.add(InfoGetFields.getWord(parseTree.getInfo())); } else { for (AbstractNode child: parseTree.getChildren()) { words.addAll(mapNodeToBagOfWords.get(child)); } } return words; } }
/** * Adds a mapping. * * @param mapping * the mapping to be added */ public void add(Mapping<T, R> mapping) { mappings.add(mapping); T source = mapping.getSource(); R target = mapping.getTarget(); Set<Mapping<T, R>> s0 = taskMappings.get(source); Set<Mapping<T, R>> s1 = resourceMappings.get(target); s0.add(mapping); s1.add(mapping); Bag<R> ts = targets.get(source); Bag<T> ss = sources.get(target); ts.add(target); ss.add(source); }
/** * Removes a mapping * * @param mapping * the mapping to be removed * @return {@code true} if the mapping was removed */ public boolean remove(Mapping<T, R> mapping) { boolean exist = mappings.remove(mapping); if (exist) { T source = mapping.getSource(); R target = mapping.getTarget(); Set<Mapping<T, R>> s0 = taskMappings.get(source); Set<Mapping<T, R>> s1 = resourceMappings.get(target); s0.remove(mapping); s1.remove(mapping); Bag<R> ts = targets.get(source); Bag<T> ss = sources.get(target); ts.remove(target); ss.remove(source); } return exist; }
/** * Returns all targets for a source. * * @param source * the source * @return all targets */ public Set<R> getTargets(T source) { return targets.get(source).uniqueSet(); }