當前位置: 首頁>>代碼示例>>Java>>正文


Java MapCount類代碼示例

本文整理匯總了Java中com.ansj.vec.util.MapCount的典型用法代碼示例。如果您正苦於以下問題:Java MapCount類的具體用法?Java MapCount怎麽用?Java MapCount使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MapCount類屬於com.ansj.vec.util包,在下文中一共展示了MapCount類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readVocab

import com.ansj.vec.util.MapCount; //導入依賴的package包/類
/**
 * 統計詞頻
 * @param file
 * @throws java.io.IOException
 */
private void readVocab(File file) throws IOException {
    MapCount<String> mc = new MapCount<String>();
    BufferedReader br = new BufferedReader(
            new InputStreamReader(new FileInputStream(file)));
    try {
        String temp = null;
        while ((temp = br.readLine()) != null) {
            String[] split = temp.split(" ");
            trainWordsCount += split.length;
            for (String string : split) {
                mc.add(string);
            }
        }
    }catch (Exception e) {
        e.printStackTrace();
    }
    for (Entry<String, Integer> element : mc.get().entrySet()) {
        wordMap.put(element.getKey(), new WordNeuron(element.getKey(), element.getValue(),
            layerSize));
    }
}
 
開發者ID:DMinerJackie,項目名稱:JewelCrawler,代碼行數:27,代碼來源:Learn.java

示例2: readVocab

import com.ansj.vec.util.MapCount; //導入依賴的package包/類
/**
 * Count frequency
 * @param file
 * @throws java.io.IOException
 */
private void readVocab(File file) throws IOException {
    MapCount<String> mc = new MapCount<>();
    try (BufferedReader br = new BufferedReader(
        new InputStreamReader(new FileInputStream(file)))) {
        String temp = null;
        while ((temp = br.readLine()) != null) {
            String[] split = temp.split(" ");
            trainWordsCount += split.length;
            for (String string : split) {
                mc.add(string);
            }
        }
    }
    for (Entry<String, Integer> element : mc.get().entrySet()) {
        wordMap.put(element.getKey(), new WordNeuron(element.getKey(), element.getValue(),
            layerSize));
    }
}
 
開發者ID:RingBDStack,項目名稱:incremental-word2vec,代碼行數:24,代碼來源:Learn.java

示例3: readVocab

import com.ansj.vec.util.MapCount; //導入依賴的package包/類
/**
 * 統計詞頻
 * 
 * @param file
 * @throws IOException
 */
private void readVocab(File file) throws IOException {
  MapCount<String> mc = new MapCount<>();
  try (BufferedReader br = new BufferedReader(new InputStreamReader(
      new FileInputStream(file)))) {
    String temp = null;
    while ((temp = br.readLine()) != null) {
      String[] split = temp.split(" ");
      trainWordsCount += split.length;
      for (String string : split) {
        mc.add(string);
      }
    }
  }
  for (Entry<String, Integer> element : mc.get().entrySet()) {
    wordMap.put(element.getKey(), new WordNeuron(element.getKey(),
        (double) element.getValue() / mc.size(), layerSize));
  }
}
 
開發者ID:jsksxs360,項目名稱:Word2Vec,代碼行數:25,代碼來源:Learn.java

示例4: addVocab

import com.ansj.vec.util.MapCount; //導入依賴的package包/類
/**
     * Adjust word frequency
     * @param file
     * @throws java.io.IOException
     */
    private void addVocab(File file) throws IOException {
        MapCount<String> mc = new MapCount<>();int xx = 0;int cntBytes = 0;
        try (BufferedReader br = new BufferedReader(
                new InputStreamReader(new FileInputStream(file)))) {
            String temp = null;
            while ((temp = br.readLine()) != null) {
                    cntBytes += temp.getBytes().length;

                    String[] split = temp.split(" ");
                    trainWordsCount += split.length;
                    for (String string : split) {
                        mc.add(string);
                    }
                xx++;
            }
        }
        for (Entry<String, Integer> element : mc.get().entrySet()) {
            if(wordMap.containsKey(element.getKey())){
//                System.out.print(element.getKey() + ":" + wordMap.get(element.getKey()).freq + "+" + element.getValue());
                wordMap.get(element.getKey()).freq += element.getValue();
//                System.out.println("="+wordMap.get(element.getKey()).freq);
            }
            else {
//                System.out.println(element.getKey()+":"+element.getValue()+"(new word)");
                wordMap.put(element.getKey(), new WordNeuron(element.getKey(), element.getValue(),
                        layerSize));
            }
        }
    }
 
開發者ID:RingBDStack,項目名稱:incremental-word2vec,代碼行數:35,代碼來源:Learn.java

示例5: readVocabWithSupervised

import com.ansj.vec.util.MapCount; //導入依賴的package包/類
/**
 * 對文本進行預分類
 * 
 * @param files
 * @throws IOException
 * @throws FileNotFoundException
 */
private void readVocabWithSupervised(File[] files) throws IOException {
  for (int category = 0; category < files.length; category++) {
    // 對多個文件學習
    MapCount<String> mc = new MapCount<>();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(
        new FileInputStream(files[category])))) {
      String temp = null;
      while ((temp = br.readLine()) != null) {
        String[] split = temp.split(" ");
        trainWordsCount += split.length;
        for (String string : split) {
          mc.add(string);
        }
      }
    }
    for (Entry<String, Integer> element : mc.get().entrySet()) {
      double tarFreq = (double) element.getValue() / mc.size();
      if (wordMap.get(element.getKey()) != null) {
        double srcFreq = wordMap.get(element.getKey()).freq;
        if (srcFreq >= tarFreq) {
          continue;
        } else {
          Neuron wordNeuron = wordMap.get(element.getKey());
          wordNeuron.category = category;
          wordNeuron.freq = tarFreq;
        }
      } else {
        wordMap.put(element.getKey(), new WordNeuron(element.getKey(),
            tarFreq, category, layerSize));
      }
    }
  }
}
 
開發者ID:jsksxs360,項目名稱:Word2Vec,代碼行數:41,代碼來源:Learn.java


注:本文中的com.ansj.vec.util.MapCount類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。