当前位置: 首页>>代码示例>>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;未经允许,请勿转载。