示例#1
0
 public static void sortAndPrintMap(Map<String, Double> map) throws FileNotFoundException {
   // pr = new PrintStream(new FileOutputStream("/semplest/lluis/keywordExp/wordmap.txt"));
   pr = System.out;
   ValueComparator bvc = new ValueComparator(map);
   TreeMap<String, Double> sorted = new TreeMap<String, Double>(bvc);
   sorted.putAll(map);
   for (String key : sorted.keySet()) {
     pr.println(key + " : " + map.get(key));
   }
   System.out.println("Number of words : " + map.size());
 }
示例#2
0
  public static Map<String, Double> getWordCount(Map<String, List<String>> data) {
    Map<String, Double> wordMap = new HashMap<String, Double>();
    for (String url : data.keySet()) {
      for (String line : data.get(url)) {
        line = line.toLowerCase();
        line = line.replaceAll("\\p{Punct}", " ");
        line = line.replaceAll("[0-9]+", "");
        String[] words = line.split("\\s+");
        for (String word : words) {
          if (wordMap.containsKey(word)) {
            wordMap.put(word, wordMap.get(word) + 1);
          } else {
            wordMap.put(word, new Double(0.0));
          }
        }
      }
    }

    return wordMap;
  }