Set keySet=myStorage.getStorage().keySet();
Iterator it=keySet.iterator();
String classpath=null; if(starinPath==null){ classpath=MODELPATH; }else{ classpath =starinPath;
}
File file_txt=new File(classpath+\ FileWriter fw=null;
try { fw=new FileWriter(file_txt); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } while(it.hasNext()){
String modelclass=(String) it.next(); File file=new File(classpath); if(!file.isDirectory()){ System.out.println(file.mkdirs()); }
if(!file_txt.isFile()){ try {
if(file_txt.createNewFile()){ BufferedWriter wb=new BufferedWriter(fw); wb.newLine();
wb.write(modelclass+\ wb.close();
}
} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
}
}
else{
18
// try { fw = new FileWriter(file_txt);
BufferedWriter wb=new BufferedWriter(fw);
wb.append(modelclass+\ector(modelclass).toString()); wb.newLine(); wb.flush();
} catch (IOException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
}
} }
public TermVectorStorage getModel(String modelpath){ TermVector tv=null;
if(modelpath==null){ modelpath=MODELPATH+\
}
File file=new File(modelpath);
FileReader fread; try { fread = new FileReader(file); BufferedReader br=new BufferedReader(fread,512); String line=null; String keyword=null; String value=null; do{ line=br.readLine(); if(line==null)
break;
int start=line.indexOf(\// System.out.println(\ if(start>0) {
keyword=line.substring(0,start);
19
line=line.substring(start+1);
// }
List
line=line.substring(line.indexOf(\ String value1=line.substring(0,line.indexOf(\ value1=value1.trim();
Integer value_int=new Integer(value1); list_String.add(key);
list_Integer.add(value_int);
}
String[] array_str=new String[list_String.size()]; for(int i=0;i } int[] array_int=new int[list_Integer.size()]; for(int i=0;i array_int[i]=list_Integer.get(i); } tv=new TermVector((String[]) array_str,array_int); storage.addTermVector(keyword, tv); } }while(line!=null); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(storage.getTermVector(\电气机械及器材制造业\ return storage; 20 public TermVectorStorage getModel(){ return getModel(null); } // private void writeFile(String path,String modelname,String key,Map StoreMap){ // // File file=new File(path); // if(!file.isFile()){ // System.out.println(file.mkdirs()); // } // File file_txt=new File(path+\// if(!file_txt.isFile()){ // try { // // if(file_txt.createNewFile()){ // FileWriter fw=new FileWriter(file_txt); // BufferedWriter wb=new BufferedWriter(fw); // // // } // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // } // } /** * @see net.sf.classifier4J.ICategorisedClassifier#isMatch(java.lang.String, java.lang.String) */ public boolean isMatch(String category, String input) throws ClassifierException { return (getMatchCutoff() < classify(category, input)); } /** * @see net.sf.classifier4J.ITrainable#teachMatch(java.lang.String, java.lang.String) */ public void teachMatch(String category, String input) throws ClassifierException { // Create a map of the word frequency from the input Map wordFrequencies = Utilities.getWordFrequency(input, false, tokenizer, stopWordsProvider); // get the numTermsInVector most used words in the input Set mostFrequentWords = Utilities.getMostFrequentWords(numTermsInVector, wordFrequencies); 21
相关推荐: