The Chinese Academy of Sciences participle tool Java configuration and the inside of the same explanation, the following is the code
PackageXieru;ImportHello. Hello.clibrary;ImportJava.io.BufferedReader;ImportJava.io.BufferedWriter;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileReader;ImportJava.io.FileWriter;Importjava.io.IOException;Importjava.io.UnsupportedEncodingException;ImportJava.nio.charset.Charset;ImportJava.util.regex.Pattern;ImportCom.csvreader.CsvReader;ImportCom.csvreader.CsvWriter;Importcom.sun.jna.Library;Importcom.sun.jna.Native; Public classWriteseparatewords { Public InterfaceClibraryextendsLibrary {//defining and initializing static variables for an interfaceClibrary Instance =(clibrary) native.loadlibrary ("E:\\workplace\\hello\\nlpir", clibrary.class); //printf Function Declaration Public BooleanNlpir_init (byte[] Sdatapath,intencoding,byte[] slicencecode); PublicString Nlpir_paragraphprocess (String sSrc,intbpostagged); PublicString Nlpir_getkeywords (String sline,intNmaxkeylimit,Booleanbweightout); Public voidNlpir_exit (); } Public Staticstring transstring (String aidstring, String ori_encoding, String new_encoding) {Try { return NewString (Aidstring.getbytes (ori_encoding), new_encoding); } Catch(unsupportedencodingexception e) {e.printstacktrace (); } return NULL; } Public Static voidIt (String infile,string outFile)throwsIOException {File file=NewFile (InFile); FileInputStream fi=Newfileinputstream (file); Csvreader CR=NewCsvreader (FI, ', ', Charset.forname ("GBK"))); Cr.readheaders (); String[] ReaderS; FileWriter WR=NewFileWriter (OutFile); BufferedWriter BW=NewBufferedWriter (WR); while(Cr.readrecord ()) {ReaderS=cr.getvalues (); if(Readers[10].equals ("Technology"))){ for(inti=0;i<readers.length-1;i++) Bw.write ("\" "+readers[i]+" \ "" + ","); Bw.write ("\" "+readers[readers.length-1]+" \ ""); Bw.newline (); }} bw.flush (); Bw.close (); } Public Static voidFenci (String infile,string outFile)throwsioexception{String Argu= ""; String System_charset= "UTF-8"; intCharset_type = 1; //int charset_type = 0; //Call printf Print information if(!CLibrary.Instance.NLPIR_Init (Argu.getbytes (System_charset), Charset_type,"0". GetBytes (System_charset))) {System.err.println ("Initialization failed!" "); } String FilePath=InFile; File File=NewFile (FilePath); FileInputStream fi=Newfileinputstream (file); Csvreader CR=NewCsvreader (FI, ', ', Charset.forname ("GBK"))); Cr.readheaders (); String[] ReaderS; FileWriter WR=NewFileWriter (OutFile); BufferedWriter BW=NewBufferedWriter (WR); while(Cr.readrecord ()) {ReaderS=cr.getvalues (); String nativebytes=NULL; Nativebytes= CLibrary.Instance.NLPIR_ParagraphProcess (Readers[1], 3); Bw.write (readers[0]+ "," + "\" "+nativebytes+" \ "+", "); System.out.println (The result of the word breaker is: "+nativebytes); String Nativebyte= CLibrary.Instance.NLPIR_GetKeyWords (readers[1],10,true); Bw.write (Nativebyte); System.out.println ("Keyword extraction result is:" +nativebyte); Bw.newline (); System.out.println ("-----------------------------------"); } bw.flush (); Bw.close (); CLibrary.Instance.NLPIR_Exit (); } Public Static voidMain (string[] args)throwsException {//Writeseparatewords.fenci ("F:/c/zhiweiyaoqiu.csv", "f:/c/fenci.csv");writeseparatewords.it ("F:/c/zhaopinxinxi.csv", "F:/c/it.csv"); }}
Chinese Academy of Sciences participle tool use