List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
/** * Helper function.// w w w .j a v a 2 s .c o m * @param word1 * @param maxSubstringLength * @param probMap * @param probs * @param memoizationTable * @param pruneToSize * @return */ public static HashMap<String, Double> Predict2(String word1, int maxSubstringLength, Map<String, HashSet<String>> probMap, HashMap<Production, Double> probs, HashMap<String, HashMap<String, Double>> memoizationTable, int pruneToSize) { HashMap<String, Double> result; if (word1.length() == 0) { result = new HashMap<>(1); result.put("", 1.0); return result; } if (memoizationTable.containsKey(word1)) { return memoizationTable.get(word1); } result = new HashMap<>(); int maxSubstringLength1 = Math.min(word1.length(), maxSubstringLength); for (int i = 1; i <= maxSubstringLength1; i++) { String substring1 = word1.substring(0, i); if (probMap.containsKey(substring1)) { // recursion right here. HashMap<String, Double> appends = Predict2(word1.substring(i), maxSubstringLength, probMap, probs, memoizationTable, pruneToSize); //int segmentations = Segmentations( word1.Length - i ); for (String tgt : probMap.get(substring1)) { Production alignment = new Production(substring1, tgt); double alignmentProb = probs.get(alignment); for (String key : appends.keySet()) { Double value = appends.get(key); String word = alignment.getSecond() + key; //double combinedProb = (pair.Value/segmentations) * alignmentProb; double combinedProb = (value) * alignmentProb; // I hope this is an accurate translation... Dictionaries.IncrementOrSet(result, word, combinedProb, combinedProb); } } } } if (result.size() > pruneToSize) { Double[] valuesArray = result.values().toArray(new Double[result.values().size()]); String[] data = result.keySet().toArray(new String[result.size()]); //Array.Sort<Double, String> (valuesArray, data); TreeMap<Double, String> sorted = new TreeMap<>(); for (int i = 0; i < valuesArray.length; i++) { sorted.put(valuesArray[i], data[i]); } // FIXME: is this sorted in the correct order??? //double sum = 0; //for (int i = data.Length - pruneToSize; i < data.Length; i++) // sum += valuesArray[i]; result = new HashMap<>(pruneToSize); // for (int i = data.length - pruneToSize; i < data.length; i++) // result.put(data[i], valuesArray[i]); int i = 0; for (Double d : sorted.descendingKeySet()) { result.put(sorted.get(d), d); if (i++ > pruneToSize) { break; } } } memoizationTable.put(word1, result); return result; }
From source file:edu.usf.cutr.fdot7.io.IndividualCsvEntityReader.java
/** * Map data in the order of FDOT schema as described in the data-sources.xml *///from ww w . j a va2 s . co m private void mapGtfsToFdotSchema() { mapping = new HashMap<String, Integer>(); List<String> fdotFields = fdSchema.getFields(); if (_entity.contains("stops")) { fdotFields.remove("stop_pos"); fdotFields.add("stop_pos"); } ArrayList<String> gtfsFieldsUnmapped = new ArrayList<String>(); HashMap<String, String> specialMapping = getSpecialMapping(); for (int i = 0; i < _fields.size(); i++) { String gtfsField = _fields.get(i); boolean isMapped = false; if (specialMapping.keySet().contains(gtfsField)) gtfsField = specialMapping.get(gtfsField); for (int j = 0; j < fdotFields.size(); j++) { if (gtfsField.equals(fdotFields.get(j))) { mapping.put(_fields.get(i), j); isMapped = true; break; } } if (!isMapped) gtfsFieldsUnmapped.add(gtfsField); } }
From source file:com.test.mytest.network.request.VolleyRequest.java
/** * Passing some request headers/*from w ww . j a v a 2 s. c o m*/ * */ @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> headers = new HashMap<String, String>(); //headers.put("Content-Type", "application/json"); //headers.put("apiKey", "xxxxxxxxxxxxxxx"); // headers.put("Accept", "application/json"); if (entry != null && entry.etag != null) headers.put("If-None-Match", entry.etag); Log.v("222", "----send head----- "); for (String key : headers.keySet()) { Log.v("222", "key: " + key + " , " + headers.get(key)); } Log.v("222", "----------------- "); return headers; }
From source file:org.easyrec.controller.StatisticsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { if (Security.isSignedIn(request)) { int tenant; int month; int year; boolean flot; String actionType = request.getParameter("actionType"); try {//from www . jav a2 s . c om tenant = Integer.parseInt(request.getParameter("tenant")); month = Integer.parseInt(request.getParameter("month")); year = Integer.parseInt(request.getParameter("year")); flot = Integer.parseInt(request.getParameter("flot")) != 0; } catch (Exception e) { logger.warn(e); return null; } ModelAndView mav = new ModelAndView(); XYSeriesCollection dataset = new XYSeriesCollection(); FlotDataSet flotDataSet = new FlotDataSet(); Calendar from = Calendar.getInstance(); Calendar to = Calendar.getInstance(); from.set(year, month, Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH), 0, 0, 0); to.set(year, month, from.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); Integer actionTypeId = null; Integer assocTypeId = null; if (!Strings.isNullOrEmpty(actionType)) { if ("CLICKS_ON_RECS".equals(actionType)) assocTypeId = 1001; else if ("CLICKS_ON_CHARTS".equals(actionType)) assocTypeId = 998; else actionTypeId = typeMappingService.getIdOfActionType(tenant, actionType); } HashMap<Integer, HashMap<Integer, Integer>> actionBundleMap = statisticsDAO.getActionBundleMap(tenant, from.getTimeInMillis(), to.getTimeInMillis(), actionTypeId, assocTypeId); Iterator<Integer> iterator = actionBundleMap.keySet().iterator(); while (iterator.hasNext()) { actionTypeId = iterator.next(); if (actionTypeId == 1001) actionType = "clicks on recommendations"; else if (actionTypeId == 998) actionType = "clicks on rankings"; else actionType = typeMappingService.getActionTypeById(tenant, actionTypeId).toLowerCase() + " actions"; XYSeries xySeries = new XYSeries(actionType); FlotSeries flotSeries = new FlotSeries(); flotSeries.setTitle(actionType); for (int i = 1; i <= 31; i++) { Integer y = actionBundleMap.get(actionTypeId).get(i); xySeries.add(i, y != null ? y : 0); flotSeries.add(i, y != null ? y : 0); } //mav.addObject("data",flotDataSet.toString()); dataset.addSeries(xySeries); flotDataSet.add(flotSeries); } // create datapoints that are rendered in the clients browser // return array or html side that renders array if (flot) { boolean onlyData = (ServletUtils.getSafeParameter(request, "onlyData", 0) != 0); if (onlyData) { mav.setViewName("flot/dataOutput"); } else { mav.setViewName("flot/flotPlot"); } mav.addObject("data", flotDataSet.toString()); mav.addObject("flotDataSet", flotDataSet.getData()); mav.addObject("noActions", flotDataSet.getData().isEmpty()); return mav; // create a png } else { JFreeChart action_chart = ChartFactory.createXYLineChart("", "actions", "days", dataset, PlotOrientation.VERTICAL, true, // show legend true, // show tooltips false); // show urls XYPlot plot = action_chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setRange(1, 31); plot.setDomainAxis(axis); BufferedImage bi = action_chart.createBufferedImage(300, 200); byte[] bytes = ChartUtilities.encodeAsPNG(bi); if (bytes != null & !flot) { OutputStream os = response.getOutputStream(); response.setContentType("image/png"); response.setContentLength(bytes.length); os.write(bytes); os.close(); } } return null; } else { return Security.redirectHome(request, response); } }
From source file:hu.ppke.itk.nlpg.purepos.decoder.BeamedViterbi.java
private HashMap<NGram<Integer>, Node> prune(final HashMap<NGram<Integer>, Node> beam) { HashMap<NGram<Integer>, Node> ret = new HashMap<NGram<Integer>, Node>(); // System.err.println(beam); // try {// ww w . ja v a2s .c o m Node maxNode = Collections.max(beam.values()); Double max = maxNode.getWeight(); for (NGram<Integer> key : beam.keySet()) { Node actNode = beam.get(key); Double actVal = actNode.getWeight(); if (!(actVal < max - logTheta)) { ret.put(key, actNode); } } // } catch (Exception e) { // e.printStackTrace(); // System.err.println(beam); // } return ret; }
From source file:de.tudarmstadt.ukp.dkpro.tc.crfsuite.CRFSuiteOutcomeIDReport.java
@Override public void execute() throws Exception { List<String> labelGoldVsActual = getGoldAndPredictions(); HashMap<String, Integer> mapping = createMappingLabel2Number(labelGoldVsActual); List<String> testData = getTestData(); Properties props = generateProperties(mapping, labelGoldVsActual, testData); // add "#labels' line with all labels StringBuilder sb = new StringBuilder(); sb.append("labels"); for (String label : mapping.keySet()) { sb.append(" " + mapping.get(label) + "=" + label); }//from ww w .ja v a 2s . co m getContext().storeBinary(ID_OUTCOME_KEY, new PropertiesAdapter(props, "ID=PREDICTION" + SEPARATOR_CHAR + "GOLDSTANDARD" + "\n" + sb.toString())); }
From source file:ffx.potential.parameters.AngleType.java
/** * Remap new atom classes to known internal ones. * * @param typeMap a lookup between new atom types and known atom types. * @return/*from w ww . j a v a 2 s .com*/ */ public AngleType patchClasses(HashMap<AtomType, AtomType> typeMap) { int count = 0; int len = atomClasses.length; /** * Look for new AngleTypes that contain 1 or 2 mapped atom classes. */ for (AtomType newType : typeMap.keySet()) { for (int i = 0; i < len; i++) { if (atomClasses[i] == newType.atomClass) { count++; } } } /** * If found, create a new AngleType that bridges to known classes. */ if (count == 1 || count == 2) { int newClasses[] = Arrays.copyOf(atomClasses, len); for (AtomType newType : typeMap.keySet()) { for (int i = 0; i < len; i++) { if (atomClasses[i] == newType.atomClass) { AtomType knownType = typeMap.get(newType); newClasses[i] = knownType.atomClass; } } } return new AngleType(newClasses, forceConstant, angle, angleFunction); } return null; }
From source file:com.facebook.tsdb.tsdash.server.model.Metric.java
@SuppressWarnings("unchecked") private JSONObject encodeTagsSet(HashMap<String, HashSet<String>> tagsSet) { JSONObject tagsSetObj = new JSONObject(); for (String tag : tagsSet.keySet()) { JSONArray tagValuesArray = new JSONArray(); if (tagsSet.get(tag) != null) { for (String value : tagsSet.get(tag)) { tagValuesArray.add(value); }/*from w w w. j a v a 2s . c o m*/ } tagsSetObj.put(tag, tagValuesArray); } return tagsSetObj; }
From source file:net.triptech.metahive.model.KeyValue.java
/** * Find the related key values based on the supplied key value. * * @param def the definition//from w ww. j a v a 2s.c o m * @param primaryId the primary record id * @param secondaryId the secondary record id * @param tertiaryId the tertiary record id * @return the key value */ public static List<KeyValue> findRelatedKeyValues(final KeyValue keyValue) { List<KeyValue> relatedKeyValues = new ArrayList<KeyValue>(); if (keyValue == null) { throw new IllegalArgumentException("A valid key value is required"); } StringBuilder sql = new StringBuilder(); HashMap<String, Object> variables = new HashMap<String, Object>(); sql.append("SELECT k FROM KeyValue AS k LEFT JOIN k.definition d"); sql.append(" WHERE d.id = :definition AND k.primaryRecordId = :primary"); variables.put("definition", keyValue.getDefinition().getId()); variables.put("primary", keyValue.getPrimaryRecordId()); Applicability applicability = keyValue.getDefinition().getApplicability(); if (applicability == Applicability.RECORD_SECONDARY) { sql.append(" AND k.secondaryRecordId = :secondary"); variables.put("secondary", keyValue.getSecondaryRecordId()); } if (applicability == Applicability.RECORD_TERTIARY) { sql.append(" AND k.tertiaryRecordId = :tertiary"); variables.put("tertiary", keyValue.getTertiaryRecordId()); } TypedQuery<KeyValue> q = entityManager().createQuery(sql.toString(), KeyValue.class); for (String key : variables.keySet()) { q.setParameter(key, variables.get(key)); } if (q.getResultList() != null) { for (KeyValue kv : q.getResultList()) { relatedKeyValues.add(kv); } } System.out.println("Values: " + relatedKeyValues.size()); return relatedKeyValues; }
From source file:eu.riscoss.rdc.RDCFossology.java
private String getLicenseTypeForLicense(HashMap<String, Collection<String>> licensesMap, String license) { for (String l : licensesMap.keySet()) { //if (license.toLowerCase().contains(l.toLowerCase())) { //attention: order matters in the file! (e.g. to parse GPL/LGPL correctly) if (matchesOneOf(licensesMap.get(l), license)) return l; }//from w w w .j a va 2s .c om return "_unknown_"; }