traning.java

来自「垃圾邮件过滤器Java源码 本软件基于朴素贝叶斯算法」· Java 代码 · 共 58 行

JAVA
58
字号
/*
 * Traning.java
 *
 * Created on 2008年12月2日, 下午12:07
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package newpackage;

import java.util.*;
/**
 *
 * @author Administrator
 */
public class Traning {
  FMMSegment vocabulary;
  Sample []v=new Sample[2];
  Dictionary dict;

  public Traning(Dictionary newDict) {
    vocabulary=new FMMSegment(newDict);
    dict=newDict;
  }



  public void train(){
    for(int i=0;i<2;i++){
      v[i]=new Sample();
      v[i].init(dict,vocabulary.vocabulary,vocabulary.NumOfVoc());
    }
    //扫描文本样例,计算P(wk|vj)
    v[0].countFreq("Sample/垃圾邮件");
    v[0].getP();
    v[1].countFreq("Sample/合法邮件");
    v[1].getP();
    //v[2].countFreq("sample/history.txt");
    //v[2].getP();

  }

  public void loadVocabulary(){
    vocabulary.fileSegment("Sample/垃圾邮件");
    vocabulary.fileSegment("Sample/合法邮件");
    //vocabulary.fileSegment("Sample/history.txt");
    
    train();
   // System.out.println("totle number of vocabulary is:"+vocabulary.NumOfVoc());
    //System.out.println(vocabulary.vocabulary.containsKey("颗粒"));

    
  }


}

⌨️ 快捷键说明

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