Example usage for com.google.common.collect TreeMultimap get

List of usage examples for com.google.common.collect TreeMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect TreeMultimap get.

Prototype

@Override
@GwtIncompatible("NavigableSet")
public NavigableSet<V> get(@Nullable K key) 

Source Link

Usage

From source file:eus.ixa.ixa.pipe.nerc.dict.MFSResource.java

/**
 * Get the MFS from a lemma#posClass entry, e.g., house#n.
 * @param mfsMap map to get the MFS from
 * @return the most frequent sense//from   w w w  .jav a 2s . c o  m
 */
public String getMFS(TreeMultimap<Integer, String> mfsMap) {
    SortedSet<String> mfs = mfsMap.get(mfsMap.keySet().first());
    return mfs.first();
}

From source file:com.tuplejump.stargate.cassandra.RowFetcher.java

private List<Row> fetchIOOptimized() throws IOException {
    List<Row> rows = new ArrayList<>();
    TreeMultimap<DecoratedKey, IndexEntryCollector.IndexEntry> docs = resultMapper.docsByRowKey();

    for (DecoratedKey dk : docs.keySet()) {
        NavigableSet<IndexEntryCollector.IndexEntry> entries = docs.get(dk);

        if (!resultMapper.filter.dataRange.contains(dk)) {
            if (logger.isTraceEnabled()) {
                logger.trace("Skipping entry {} outside of assigned scan range", dk.getToken());
            }//from  w  w w  .j  a v  a2 s.c o m
            continue;
        }
        final Map<CellName, ColumnFamily> fullSlice = resultMapper.fetchPagedRangeSlice(entries, dk, limit);

        for (IndexEntryCollector.IndexEntry input : entries) {
            CellName cellName = input.clusteringKey;
            if (!resultMapper.filter.columnFilter(dk.getKey()).maySelectPrefix(table.getComparator(),
                    cellName.start())) {
                continue;
            }
            ColumnFamily data = fullSlice.get(cellName);
            if (data == null || resultMapper.searchSupport.deleteIfNotLatest(dk, data.maxTimestamp(),
                    input.pkName, data))
                continue;
            float score = input.score;
            ColumnFamily cleanColumnFamily = resultMapper.showScore ? scored(score, data) : data;
            rows.add(new Row(dk, cleanColumnFamily));
            columnsCount++;
            if (columnsCount > limit)
                break;
        }
        if (columnsCount > limit)
            break;
    }

    return rows;
}

From source file:com.tuplejump.stargate.lucene.query.function.MatchPartition.java

private List<Tuple> getAllMatches(ResultMapper resultMapper, Map<String, Integer> positions) {
    List<Tuple> allMatches = new ArrayList<>();

    TreeMultimap<DecoratedKey, IndexEntryCollector.IndexEntry> docs = resultMapper.docsByRowKey();
    for (final DecoratedKey dk : docs.keySet()) {
        List<IndexEntryCollector.IndexEntry> entries = new ArrayList<>(docs.get(dk));
        final Map<CellName, ColumnFamily> fullSlice = resultMapper.fetchRangeSlice(entries, dk);
        List<Tuple> tuples = new ArrayList<>(fullSlice.size());
        for (IndexEntryCollector.IndexEntry entry : entries) {
            CellName cellName = entry.clusteringKey;
            ColumnFamily cf = fullSlice.get(cellName);
            if (cf != null) {
                Tuple tuple = aggregateFunction.createTuple(options);
                resultMapper.tableMapper.load(positions, tuple, new Row(dk, cf));
                tuples.add(tuple);/*  w w  w  . j  a  va  2s.c o m*/
            }
        }
        int splice = Math.min(tuples.size(), maxMatches);

        allMatches.addAll(matchPartition(tuples.subList(0, splice)));
    }
    return allMatches;
}

From source file:org.artifactory.repo.cleanup.IntegrationCleanupServiceImpl.java

private Map<String, TreeMultimap<Calendar, ItemInfo>> forkByClassifier(
        TreeMultimap<Calendar, ItemInfo> cleanupCandidates) {
    Map<String, TreeMultimap<Calendar, ItemInfo>> result = Maps.newHashMap();
    for (Calendar calendar : cleanupCandidates.keySet()) {
        NavigableSet<ItemInfo> itemInfos = cleanupCandidates.get(calendar);
        for (ItemInfo itemInfo : itemInfos) {
            String classifier = resolveClassifier(itemInfo);
            TreeMultimap<Calendar, ItemInfo> classifierMap = result.get(classifier);
            if (classifierMap == null) {
                //classifierMap= TreeMultimap.create(Ordering.natural().reverse(), Ordering.natural().reverse());
                classifierMap = TreeMultimap.create(Ordering.natural(), Ordering.natural());
                ;//from   w ww.j  a  v  a  2 s.co m
                result.put(classifier, classifierMap);
            }
            classifierMap.put(calendar, itemInfo);
        }
    }
    return result;
}

From source file:com.progressiveaccess.cmlspeech.analysis.StructuralAnalysis.java

/**
 * Makes shared connections (sprio, shared, bridge atoms or shared bonds) for
 * an atom set./*w ww. j  a va2  s  . c  o  m*/
 *
 * @param atomSet
 *          The atom set.
 * @param connectionsSet
 *          A multi map specifying connections. That is, elements from the
 *          atom set and the chemical structure it connects to. An element can
 *          be represented multiple times. For example, an atom can be shared
 *          between three sub-rings.
 */
private void makeConnections(final RichAtomSet atomSet, final TreeMultimap<String, String> connectionsSet) {
    for (final String key : connectionsSet.keySet()) {
        final NavigableSet<String> allConnections = connectionsSet.get(key);
        final SortedSet<String> sharedAtoms = new TreeSet<String>(new CmlNameComparator());
        for (final String bond : allConnections.descendingSet()) {
            if (!RichStructureHelper.isBond(bond)) {
                break;
            }
            atomSet.getConnections().add(new SharedBond(bond, key));
            sharedAtoms.addAll(RichStructureHelper.getRichBond(bond).getComponents());
        }
        for (final String shared : sharedAtoms) {
            atomSet.getConnections().add(new BridgeAtom(shared, key));
        }
        for (final String connection : Sets.difference(allConnections, sharedAtoms)) {
            if (!RichStructureHelper.isAtom(connection)) {
                break;
            }
            if (atomSet.isRing() && RichStructureHelper.getRichAtomSet(key).isRing()) {
                atomSet.getConnections().add(new SpiroAtom(connection, key));
            } else {
                atomSet.getConnections().add(new SharedAtom(connection, key));
            }
        }
    }
}

From source file:org.cloudsmith.geppetto.catalog.util.CatalogRspecGenerator.java

public void generateAll(Catalog catalog, Appendable out) throws IOException {
    TreeMultimap<String, CatalogResource> sorted = TreeMultimap.create(new TypeComparator(),
            new TitleComparator());
    for (CatalogResource r : catalog.getResources()) {
        // transform these per type (sorted on type)
        sorted.put(r.getType(), r);//from  w w  w  .  j a  v a2  s .c o  m
    }
    // classes are processed separately
    SortedSet<CatalogResource> classes = sorted.get("Class");
    generateClasses(classes, out);
    sorted.removeAll("Class");
    generateResources(sorted, out);

}

From source file:com.streamsets.pipeline.stage.processor.fuzzy.FuzzyFieldProcessor.java

private TreeMultimap<String, MatchCandidate> findCandidatesFor(Map<String, Field> fields)
        throws StageException {
    TreeMultimap<String, MatchCandidate> candidates = TreeMultimap.create();

    for (String outputField : outputFieldNames) {
        for (Map.Entry<String, Field> entry : fields.entrySet()) {
            String fieldPath = entry.getKey();
            Field field = entry.getValue();
            int score = FuzzyMatch.getRatio(outputField, fieldPath, true);
            if (score >= matchThreshold) {
                if (greaterScore(candidates.get(outputField), score) || allCandidates) {
                    if (!allCandidates) {
                        // If not storing all candidates we must clear any existing candidates for this key
                        // since a Multimap won't replace multiple values for a key.
                        candidates.get(outputField).clear();
                    }/* w  w  w  .  j  a v a2  s .c  o  m*/
                    candidates.put(outputField, new MatchCandidate(outputField, score, fieldPath, field));
                }
            }
        }
    }

    return candidates;
}

From source file:com.data2semantics.yasgui.client.tab.optionbar.LinkCreator.java

private String getLink(TreeMultimap<String, String> args) {
    String url = JsMethods.getLocation();

    //remove these, as we will be adding these again
    url = Helper.removeArgumentsFromUrl(url, args.keySet());
    boolean firstItem = true;
    if (url.contains("?")) {
        firstItem = false;// w ww.  j  a v a 2  s. com
    }
    Iterator<String> iterator = args.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        for (String value : args.get(key)) {
            value = URL.encodeQueryString(value);
            if (firstItem) {
                url += "?";
                firstItem = false;
            } else {
                url += "&";
            }
            url += key + "=" + value;
        }
    }
    return url;

}

From source file:org.cloudsmith.geppetto.catalog.util.CatalogRspecGenerator.java

/**
 * @param sorted/*from  w w w  . jav  a 2  s .  c  o  m*/
 * @param out
 */
private void generateResources(TreeMultimap<String, CatalogResource> sorted, Appendable out)
        throws IOException {
    out.append(indent(1)).append("# Resources per type and title (alphabetically)\n");

    boolean first = true;
    for (String type : sorted.keySet()) {
        if (!first) {
            out.append("\n");
            first = false;
        }
        String matcherName = typeToMatcherName(type);
        String matcher = "contain_" + matcherName;
        for (CatalogResource r : sorted.get(type)) {
            out.append(indent(1)).append("it ");
            GeneratorUtil.emitRubyStringLiteral(out, "resource " + matcherName + " " + r.getTitle());
            out.append(" do\n");
            out.append(indent(2)).append("should ").append(matcher).append("(");
            GeneratorUtil.emitRubyStringLiteral(out, r.getTitle());
            out.append(")");

            if (r.getParameters().size() < 1) {
                // TODO: There is no way to check that there are no additional parameters set
                // without explicitly listing all that should not be set
                out.append("\n");
            } else {
                // prepare data, a cluster for padding calculation, and a treemap for sorting parameters
                IntegerCluster cluster = new IntegerCluster(20);
                TreeMap<String, List<String>> sortedParameters = Maps.newTreeMap();
                for (CatalogResourceParameter p : r.getParameters()) {
                    cluster.add(p.getName().length());
                    sortedParameters.put(p.getName(), p.getValue());
                }
                out.append(".with(\n");
                boolean firstItem = true;

                for (Entry<String, List<String>> entry : sortedParameters.entrySet()) {

                    if (firstItem)
                        firstItem = false;
                    else
                        out.append(",\n");

                    String name = entry.getKey();
                    out.append(indent(3));
                    GeneratorUtil.emitRubyStringLiteral(out, name);
                    out.append(padding(name, cluster)).append("=> ");
                    List<String> values = entry.getValue();
                    if (values.size() == 1) {
                        out.append(fJavaStrToRubyStr.apply(values.get(0))).append("");
                    } else {
                        // values is an array
                        // TODO: It can also be a hash - need to see how that is encoded
                        out.append("[");
                        Joiner.on(',').appendTo(out, Iterables.transform(values, fJavaStrToRubyStr));
                        out.append("]");
                    }

                }

                out.append('\n').append(indent(2)).append(")\n");
            }

            out.append(indent(1)).append("end\n");
        }
    }
}

From source file:org.apache.ctakes.ytex.kernel.wsd.WordSenseDisambiguatorImpl.java

@Override
public String disambiguate(List<Set<String>> sentenceConcepts, int index, Set<String> contextConcepts,
        int windowSize, SimilarityMetricEnum metric, Map<String, Double> scoreMap, boolean weighted) {
    // get the candidate concepts that we want to disambiguate
    Set<String> candidateConcepts = sentenceConcepts.get(index);
    if (candidateConcepts.size() == 1)
        return candidateConcepts.iterator().next();
    // allocate set to hold all the concepts to compare to
    Map<String, Integer> windowContextConcepts = new HashMap<String, Integer>();
    // add context concepts (e.g. title concepts)
    if (contextConcepts != null) {
        addConcepts(windowContextConcepts, contextConcepts);
    }/*from w  ww  .j a  va2 s .c  om*/
    // add windowSize concepts from the sentence
    // get left, then right concepts
    // case 1 - enough tokens on both sides
    int indexLeftStart = index - windowSize - 1;
    int indexRightStart = index + windowSize + 1;
    if (indexLeftStart < 0) {
        // case 2 - not enough tokens on left
        indexRightStart += (-1 * indexLeftStart);
        indexLeftStart = 0;
    } else if (indexRightStart >= sentenceConcepts.size()) {
        // case 3 - not enough tokens on right
        indexLeftStart -= indexRightStart - sentenceConcepts.size() - 1;
        indexRightStart = sentenceConcepts.size() - 1;
    }
    // make sure the range is in bounds
    if (indexLeftStart < 0)
        indexLeftStart = 0;
    if (indexRightStart >= sentenceConcepts.size())
        indexRightStart = sentenceConcepts.size() - 1;
    // add the concepts in the ranges
    if (indexLeftStart < index) {
        for (Set<String> cs : sentenceConcepts.subList(indexLeftStart, index)) {
            addConcepts(windowContextConcepts, cs);
        }
    }
    if (indexRightStart > index) {
        for (Set<String> cs : sentenceConcepts.subList(index + 1, indexRightStart + 1)) {
            addConcepts(windowContextConcepts, cs);
        }
    }
    // allocate map to hold scores
    TreeMultimap<Double, String> scoreConceptMap = TreeMultimap.create();
    for (String c : candidateConcepts) {
        scoreConceptMap.put(scoreConcept(c, windowContextConcepts, metric, weighted), c);
    }
    // if scoreMap is not null, fill it in with the concept scores - invert
    // scoreConceptMap
    boolean bNonZero = false;
    if (scoreMap != null) {
        for (Map.Entry<Double, String> scoreConcept : scoreConceptMap.entries()) {
            scoreMap.put(scoreConcept.getValue(), scoreConcept.getKey());
        }
    }
    SortedSet<String> bestConcepts = scoreConceptMap.get(scoreConceptMap.keySet().last());
    String bestConcept = null;
    if (bestConcepts.size() == 1) {
        // only 1 concept with high score
        bestConcept = bestConcepts.iterator().next();
    } else if (bestConcepts.size() == candidateConcepts.size()) {
        // all concepts have same score
        bestConcept = null;
    } else {
        // multiple best candidates - pick concept with lowest ic - most
        // general concept
        double ic = 1e6;
        Map<String, ConcRel> conceptMap = this.getConceptSimilarityService().getConceptGraph().getConceptMap();
        for (String c : bestConcepts) {
            ConcRel cr = conceptMap.get(c);
            if (cr != null && cr.getIntrinsicInfoContent() < ic) {
                ic = cr.getIntrinsicInfoContent();
                bestConcept = c;
            }
        }
    }
    // get the best scoring concept
    return bestConcept;
}