?? targettext.java~17~
字號:
/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import java.io.*;import java.util.*;public class TargetText { Dictionary newDict; float []NB=new float[3]; public TargetText() { } public void init(Dictionary dict){ newDict=dict; for(int i=0;i<3;i++){ NB[i]=1; } } public void categorize(Sample []v,int n,String filename){ for(int i=0;i<n;i++){ fileSegment(filename,v[i].wordTable,i); } System.out.println("NB[0]:"+NB[0]+" NB[1]:"+NB[1]+" NB[2]"+NB[2]); } public int wordSegment(String Sentence,HashMap hm,int n) { 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 (newDict.Find(word)) { if (j > i + 1) { if (hm.containsKey(word)) { System.out.println(((Float)hm.get(word)).floatValue()); NB[n]=NB[n]*((Float)hm.get(word)).floatValue(); } } bFind = true; i = j; break; } } if (bFind == false) { i = j + 1; } } return 1; } public void fileSegment(String fileName,HashMap hm,int n) { //按行讀入 try { BufferedReader in = new BufferedReader( new FileReader(fileName)); String s; while ((s = in.readLine()) != null) { wordSegment(s,hm,n); } } catch (IOException e) { System.out.println(e); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -