Example usage for java.util HashMap containsKey

List of usage examples for java.util HashMap containsKey

Introduction

In this page you can find the example usage for java.util HashMap containsKey.

Prototype

public boolean containsKey(Object key) 

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:com.almarsoft.GroundhogReader.lib.MessageTextProcessor.java

public static String getCharsetFromHeader(HashMap<String, String> header) {
    String[] tmpContentArr = null;
    String[] contentTypeParts = null;
    String tmpFirstToken;//from  ww w.  j  a v a2s .c o m

    String charset = "iso-8859-1";

    if (header.containsKey("Content-Type")) {
        tmpContentArr = header.get("Content-Type").split(";");

        for (String content : tmpContentArr) {

            contentTypeParts = content.split("=", 2);
            tmpFirstToken = contentTypeParts[0].trim();

            if (contentTypeParts.length > 1 && tmpFirstToken.equalsIgnoreCase("charset")) {
                // Found
                return contentTypeParts[1].replace("\"", "").trim();

            }
        }
    }
    return charset;
}

From source file:edu.illinois.cs.cogcomp.transliteration.CSPTransliteration.java

/**
 * Gets counts for productions by (conceptually) summing over all the possible alignments
 * and weighing each alignment (and its constituent productions) by the given probability table.
 * probSum is important (and memoized for input word pairs)--it keeps track and returns the sum of the probabilities of all possible alignments for the word pair
 *
 * @param position         ?/*from ww  w.  j av a2 s .co  m*/
 * @param originalWord1    ?
 * @param word1            ?
 * @param word2            ?
 * @param model            ?
 * @param memoizationTable ?
 * @return ?
 */
public static Pair<SparseDoubleVector<Triple<Integer, String, String>>, Double> LearnModel(int position,
        String originalWord1, String word1, String word2, CSPModel model,
        HashMap<Triple<Double, String, String>, Pair<SparseDoubleVector<Triple<Integer, String, String>>, Double>> memoizationTable) {
    Pair<SparseDoubleVector<Triple<Integer, String, String>>, Double> memoization;

    Triple check = new Triple<>(position, word1, word2);
    if (memoizationTable.containsKey(check)) {
        return memoizationTable.get(check);
    }

    Pair<SparseDoubleVector<Triple<Integer, String, String>>, Double> result = new Pair<>(
            new SparseDoubleVector<Triple<Integer, String, String>>(), 0.0);

    if (word1.length() == 0 && word2.length() == 0) //record probabilities
    {
        result.setSecond(1.0); //null -> null is always a perfect alignment
        return result; //end of the line
    }

    int maxSubstringLength1f = Math.min(word1.length(), model.maxSubstringLength);
    int maxSubstringLength2f = Math.min(word2.length(), model.maxSubstringLength);

    String[] leftContexts = WikiTransliteration.GetLeftFallbackContexts(originalWord1, position,
            Math.max(model.segContextSize, model.productionContextSize));

    int firstVowel = -1;
    int secondVowel = -1;
    if (model.syllabic) {
        for (int i = 0; i < word1.length(); i++) {

            if (Arrays.asList(vowels).contains(word1.charAt(i))) {
                firstVowel = i;
            } else if (firstVowel >= 0) {
                break;
            }
        }

        if (firstVowel == -1)
            firstVowel = word1.length() - 1; //no vowels!

        for (int i = firstVowel + 1; i < word1.length(); i++) {
            if (Arrays.asList(vowels).contains(word1.charAt(i))) {
                secondVowel = i;
                break;
            }
        }

        if (secondVowel == -1 || (secondVowel == word1.length() - 1 && word1.charAt(secondVowel) == 'e')) //if only one vowel, only consider the entire thing; note consideration of silent 'e' at end of words
        {
            firstVowel = maxSubstringLength1f - 1;
            secondVowel = maxSubstringLength1f;
        }
    } else {
        firstVowel = 0;
        secondVowel = maxSubstringLength1f;
    }

    for (int i = firstVowel + 1; i <= secondVowel; i++)
    //for (int i = 1; i <= maxSubstringLength1f; i++) //for each possible substring in the first word...
    {
        String substring1 = word1.substring(0, i);
        String[] rightContexts = WikiTransliteration.GetRightFallbackContexts(originalWord1, position + i,
                Math.max(model.segContextSize, model.productionContextSize));

        double segProb;
        if (model.segProbs.size() == 0)
            segProb = 1;
        else {
            segProb = 0;
            int minK = model.fallbackStrategy == FallbackStrategy.NotDuringTraining ? model.segContextSize : 0;
            for (int k = model.segContextSize; k >= minK; k--) {
                if (model.segProbs.containsKey(new Triple<>(leftContexts[k], substring1, rightContexts[k]))) {
                    segProb = model.segProbs.get(new Triple<>(leftContexts[k], substring1, rightContexts[k]));
                    break;
                }
            }
        }

        for (int j = 1; j <= maxSubstringLength2f; j++) //foreach possible substring in the second
        {
            if ((word1.length() - i) * model.maxSubstringLength >= word2.length() - j
                    && (word2.length() - j) * model.maxSubstringLength >= word1.length() - i) //if we get rid of these characters, can we still cover the remainder of word2?
            {
                String substring2 = word2.substring(0, j);
                //Pair<Triple<String, String, String>, String> production = new Pair<Triple<String, String, String>, String>(new Triple<String, String, String>(leftProductionContext, substring1, rightProductionContext), substring2);

                double prob;
                if (model.productionProbs.size() == 0)
                    prob = 1;
                else {
                    prob = 0;
                    int minK = model.fallbackStrategy == FallbackStrategy.NotDuringTraining
                            ? model.productionContextSize
                            : 0;
                    for (int k = model.productionContextSize; k >= minK; k--) {
                        Pair<Triple<String, String, String>, String> v = new Pair<>(
                                new Triple<>(leftContexts[k], substring1, rightContexts[k]), substring2);
                        if (model.productionProbs.containsKey(v)) {
                            prob = model.productionProbs.get(v);
                            break;
                        }
                    }

                    if (model.emMode == CSPModel.EMMode.Smoothed)
                        prob = Math.max(model.minProductionProbability, prob);
                }

                Pair<SparseDoubleVector<Triple<Integer, String, String>>, Double> remainder = LearnModel(
                        position + i, originalWord1, word1.substring(i), word2.substring(j), model,
                        memoizationTable);

                double cProb = prob * segProb;

                //record this production in our results

                result.getFirst().put(cProb, remainder.getFirst());
                result.setSecond(result.getSecond() + remainder.getSecond() * cProb);

                Triple<Integer, String, String> pp = new Triple<>(position, substring1, substring2);
                result.getFirst().put(pp, result.getFirst().get(pp) + cProb * remainder.getSecond());
            }
        }
    }

    memoizationTable.put(new Triple<>((double) position, word1, word2), result);
    return result;
}

From source file:edu.umass.cs.gigapaxos.PaxosPacketBatcher.java

protected static Map<String, Integer> getMaxLoggedDecisionMap(MessagingTask[] mtasks) {
    HashMap<String, Integer> maxLoggedDecisionMap = new HashMap<String, Integer>();
    for (MessagingTask mtask : mtasks) {
        PValuePacket loggedDecision = null;
        if (mtask.isEmptyMessaging() && mtask instanceof LogMessagingTask
                && (loggedDecision = (PValuePacket) ((LogMessagingTask) mtask).logMsg) != null
                && loggedDecision.getType().equals(PaxosPacketType.DECISION)) {
            int loggedDecisionSlot = loggedDecision.slot;
            String paxosID = loggedDecision.getPaxosID();
            if (!maxLoggedDecisionMap.containsKey(paxosID))
                maxLoggedDecisionMap.put(paxosID, loggedDecisionSlot);
            else if (maxLoggedDecisionMap.get(paxosID) - loggedDecisionSlot < 0)
                maxLoggedDecisionMap.put(paxosID, loggedDecisionSlot);
        }//from w  ww .  j av  a  2s  .c  om
    }
    return maxLoggedDecisionMap;
}

From source file:Main.java

public static final HashMap<String, String> getAllRawQueryParameters(Intent intent) {
    HashMap<String, String> queries = new HashMap<String, String>();
    if (intent != null) {
        Uri uri = intent.getData();/*from  w w w  .ja  va2s .  com*/
        if (null != uri) {
            final String query = uri.getEncodedQuery();
            if (query != null) {
                final int length = query.length();
                int start = 0;
                do {
                    int nextAmpersand = query.indexOf('&', start);
                    int end = nextAmpersand != -1 ? nextAmpersand : length;

                    int separator = query.indexOf('=', start);
                    if (separator > end || separator == -1) {
                        separator = end;
                    }

                    String encodedKey = query.substring(start, separator);
                    String encodedValue = query.substring(separator + 1, end);

                    String key = Uri.decode(encodedKey);
                    if (!queries.containsKey(key)) {
                        queries.put(key, encodedValue);
                    }

                    // Move start to end of name.
                    if (nextAmpersand != -1) {
                        start = nextAmpersand + 1;
                    } else {
                        break;
                    }
                } while (true);
            }
        }
    }
    return queries;
}

From source file:com.krawler.esp.servlets.FileImporterServlet.java

public static void mapImportedRes(String resmapval, HashMap mp) throws ServiceException {
    Connection conn = null;//  w w w  .ja  v a2 s. co m
    try {
        conn = DbPool.getConnection();
        com.krawler.utils.json.base.JSONArray jsonArray = new com.krawler.utils.json.base.JSONArray(resmapval);
        com.krawler.utils.json.base.JSONObject jobj = new com.krawler.utils.json.base.JSONObject();
        for (int k = 0; k < jsonArray.length(); k++) {
            jobj = jsonArray.getJSONObject(k);
            if (jobj.getString("resourceid").length() > 0 && mp.containsKey(jobj.getString("tempid"))) {
                ArrayList taskids = (ArrayList) mp.get(jobj.getString("tempid"));
                String tasks = taskids.toString();
                tasks = tasks.substring(1, tasks.lastIndexOf("]"));
                projdb.insertimportedtaskResources(conn, tasks, jobj.getString("resourceid"));
            }
        }
        conn.commit();
    } catch (JSONException ex) {
        DbPool.quietRollback(conn);
    } catch (ServiceException ex) {
        DbPool.quietRollback(conn);
    } catch (Exception ex) {
        DbPool.quietRollback(conn);
    } finally {
        DbPool.quietClose(conn);
    }
}

From source file:edu.ehu.galan.wiki2wordnet.wikipedia2wordnet.Mapper.java

/**
 * Maps LiteWi loaded topics (LionTopics) that have a Wikipedia Mapping to WordNet using
 * Babelnet and Fernando's work./*from   w w w. j  av a2s. c o  m*/
 *
 * @param pBabelnetMappings - Babelnet Mappings
 * @param pFernandoMappings - Samuel Fernando Mappings
 * @param pWikiTitles - The List of Wipedia articles that will be mapped to WordNet
 * @param pDesambiguationContext - The reference topics that will be used as context, MUST HAVE
 * an unique wordnet mapping (synset) in babelnet/fernando mappings
 * @param pFile - The file where the ubk will be processed in case its needed
 * @param pWordnet - A Wordnet dict using edu.mit.jwi library with WordNet 3.0
 * @param pUkbBinDir - The dir where the ukb binaries are
 * @return - a hashmap with the wikititles / synsets pairs
 */
public static HashMap<String, Integer> babelnetFernandoToWordnet(
        HashMap<String, List<Wiki2WordnetMapping>> pBabelnetMappings,
        HashMap<String, Wiki2WordnetMapping> pFernandoMappings, List<String> pWikiTitles, String pFile,
        IDictionary pWordnet, List<String> pDesambiguationContext, String pUkbBinDir) {
    HashMap<String, Integer> mappings = new HashMap<>(pWikiTitles.size());
    HashMap<String, List<Wiki2WordnetMapping>> ukbList = new HashMap<>();
    if (pBabelnetMappings != null && pFernandoMappings != null) {
        pWikiTitles.addAll(pDesambiguationContext);
        for (String title : pWikiTitles) {
            List<Wiki2WordnetMapping> babelMapping = null;
            Wiki2WordnetMapping fernandoMapping = null;
            if (pBabelnetMappings.containsKey(title)) {
                babelMapping = pBabelnetMappings.get(title);
            }
            if (pFernandoMappings.containsKey(title)) {
                fernandoMapping = pFernandoMappings.get(title);
            }
            if (babelMapping != null && fernandoMapping == null) {
                if (babelMapping.size() == 1) {
                    mappings.put(title, babelMapping.get(0).getWordNetSynset());
                } else if (babelMapping.size() > 1) {
                    ukbList.put(title, babelMapping);
                    int l = title.split("\\s").length;
                    for (Wiki2WordnetMapping babelMapping1 : babelMapping) {
                        int l1 = babelMapping1.getWordnetTitle().split("\\s+").length;
                        if (l == l1) {
                            mappings.put(title, babelMapping1.getWordNetSynset());
                            break;
                        }
                    }
                    if (!mappings.containsKey(title)) {
                        mappings.put(title, babelMapping.get(0).getWordNetSynset());
                    }
                }
            } else if (babelMapping == null && fernandoMapping != null) {
                mappings.put(title, fernandoMapping.getWordNetSynset());
            } else if (babelMapping != null && fernandoMapping != null) {
                if (babelMapping.size() == 1) {
                    if (babelMapping.get(0).getWordNetSynset() == fernandoMapping.getWordNetSynset()) {
                        mappings.put(title, +fernandoMapping.getWordNetSynset());
                    } else {
                        List<Wiki2WordnetMapping> maps = new ArrayList<>();
                        maps.add(fernandoMapping);
                        maps.add(babelMapping.get(0));
                        ukbList.put(title, maps);
                        mappings.put(title, fernandoMapping.getWordNetSynset());
                    }
                } else {
                    List<Wiki2WordnetMapping> maps = new ArrayList<>();
                    maps.add(fernandoMapping);
                    maps.addAll(babelMapping);
                    ukbList.put(title, maps);
                    int l = title.split("\\s+").length;
                    for (Wiki2WordnetMapping babelMapping1 : babelMapping) {
                        int l1 = babelMapping1.getWordnetTitle().split("\\s+").length;
                        if (l == l1) {
                            mappings.put(title, babelMapping1.getWordNetSynset());
                            break;
                        }
                    }
                    if (mappings.get(title) == -1) {
                        mappings.put(title, fernandoMapping.getWordNetSynset());
                    }
                }
            }
        }
    } else {
        logger.error("No mappings provided");
    }
    if (!ukbList.isEmpty()) {
        disambiguateUKB(ukbList, pDesambiguationContext, pFile, pWordnet, mappings, pUkbBinDir);
    }
    for (String context : pDesambiguationContext) {
        mappings.remove(context);
    }
    return mappings;
}

From source file:org.hfoss.posit.android.web.Communicator.java

/**
 * cleanup the item key,value pairs so that we can receive and save to the
 * internal database/*from  w  w w .  j  a v  a 2  s  . c  om*/
 * 
 * @param rMap
 */
public static void cleanupOnReceive(HashMap<String, Object> rMap) {
    rMap.put(PositDbHelper.FINDS_SYNCED, PositDbHelper.FIND_IS_SYNCED);
    rMap.put(PositDbHelper.FINDS_GUID, rMap.get("guid"));
    // rMap.put(PositDbHelper.FINDS_GUID, rMap.get("guid"));

    rMap.put(PositDbHelper.FINDS_PROJECT_ID, projectId);
    if (rMap.containsKey("add_time")) {
        rMap.put(PositDbHelper.FINDS_TIME, rMap.get("add_time"));
        rMap.remove("add_time");
    }
    if (rMap.containsKey("images")) {
        if (Utils.debug)
            Log.d(TAG, "contains image key");
        rMap.put(PositDbHelper.PHOTOS_IMAGE_URI, rMap.get("images"));
        rMap.remove("images");
    }
}

From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java

/**
 * This is the same as probs, only in a more convenient format. Does not include weights on productions.
 * @param probs production probabilities
 * @return hashmap mapping from Production[0] => Production[1]
 */// w w  w .j  a v a  2 s. c o m
public static HashMap<String, HashSet<String>> GetProbMap(HashMap<Production, Double> probs) {
    HashMap<String, HashSet<String>> result = new HashMap<>();
    for (Production pair : probs.keySet()) {
        if (!result.containsKey(pair.getFirst())) {
            result.put(pair.getFirst(), new HashSet<String>());
        }
        HashSet<String> set = result.get(pair.getFirst());
        set.add(pair.getSecond());

        result.put(pair.getFirst(), set);
    }

    return result;
}

From source file:com.thoughtworks.go.server.materials.postcommit.svn.SvnPostCommitHookImplementer.java

boolean isQualified(String incomingUUID, SvnMaterial material, HashMap urlToUUIDMap) {
    if (urlToUUIDMap.containsKey(material.urlForCommandLine())) {
        final String remoteUUID = (String) urlToUUIDMap.get(material.urlForCommandLine());
        return incomingUUID.equals(remoteUUID);
    }/*  w  ww  .  j a va  2  s  .c  o  m*/
    return false;
}

From source file:com.eucalyptus.webui.server.ConfigurationWebBackend.java

/**
 * @return the list of cluster configurations for UI display.
 *///from   w  w  w  . j ava2 s.  co m
public static List<SearchResultRow> getClusterConfigurations() {
    List<SearchResultRow> results = Lists.newArrayList();
    HashMap<String, List<String>> configProps = new HashMap<String, List<String>>();
    NavigableSet<ServiceConfiguration> configs = Components.lookup(ClusterController.class).services();
    for (ServiceConfiguration c : configs) {
        if (!configProps.containsKey(c.getPartition())) {
            //This is bad. We should never directly have to cast
            //This entire class should never reference backend props directly

            //Pick the first one. It shouldn't matter which one.
            ClusterConfiguration config = (ClusterConfiguration) c;
            List<String> props = new ArrayList<String>();
            props.add(config.getMinNetworkTag() == null ? "0" : config.getMinNetworkTag().toString());
            props.add(config.getMaxNetworkTag() == null ? "0" : config.getMaxNetworkTag().toString());
            configProps.put(c.getPartition(), props);
        }
    }
    for (ServiceConfiguration c : configs) {
        List<String> props = configProps.get(c.getPartition());
        if (props != null) {
            SearchResultRow row = new SearchResultRow();
            row.setExtraFieldDescs(CLUSTER_CONFIG_EXTRA_FIELD_DESCS);
            //ugly: this is temporary and needs to go away
            serializeClusterConfiguration(c, props.get(0), props.get(1), row);
            results.add(row);
        } else {
            LOG.debug("Got an error while trying to retrieving cluster configuration list");
        }
    }
    return results;
}