本文整理汇总了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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
}
示例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));
}
}
}
}