⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample.java~5~

📁 基于朴素贝叶斯算法实现的中文文本分类程序。可以对中文文本进行分类识别
💻 JAVA~5~
字号:
/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import java.util.*;import java.io.*;public class Sample {  Dictionary dic;  HashMap wordTable= new HashMap();  int totleWord;  public Sample() {  }  public void init(Dictionary newDic,HashMap hm) {    dic = newDic;    totleWord=0;    wordTable.putAll(hm);  }  public int wordSegment(String Sentence) { //中文分词    int senLen = Sentence.length();    int i = 0, j = 0;    int M = 12;    String word;    boolean bFind = false;      while (i < senLen) {        int N = i + M < senLen ? i + M : senLen + 1;        bFind = false;        for (j = N - 1; j > i; j--) {          word = Sentence.substring(i, j);          if (dic.Find(word)) {            if (j > i + 1) {              totleWord++;  //统计总词汇数              if (wordTable.containsKey(word)) {                float c=((Float)wordTable.get(word)).floatValue()+1;                wordTable.put(word,new Float(c));               //统计每个在单词在文本中出现的次数              }            }            bFind = true;            i = j;            break;          }        }        if (bFind == false) {          i = j + 1;        }      }    return 1;  }  public void countFreq(String fileName) { //按行读入    try {      BufferedReader in = new BufferedReader(          new FileReader(fileName));      String s;      while ( (s = in.readLine()) != null) {        wordSegment(s);      }    }    catch (IOException e) {      System.out.println(e);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -