本文整理匯總了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));
}
}
}
}