发信人: huanghwh(五云人)
整理人: zhcharles(2002-01-30 15:41:34), 站内信件
|
Chinput2基本上没有词组库, 但支持词组输入。 首先用windows的通用输入法编辑器
逆转换windows\system(32)\winpy.mb 文件, 删除[Text]以上的内容, 用以下小程序
可增加词组库(需要/usr/ports/databases/mysql-jdbc-mm):
import java.sql.*;
import java.io.*;
public class TestPy {
public TestPy() {
}
private int getPyIdx(String HzPy) {
for( int i=0;i<HzPy.length(); i++) {
int c = HzPy.charAt(i);
if( c>='a' && c <= 'z' )
return i;
}
return -1;
}
public void file2Mysql(String pyFile) throws Exception{
String jdbcDriver= "org.gjt.mm.mysql.Driver";
String dbURL = "jdbc:mysql://localhost/pydb?user=hwh&password=dummy";
Connection conn = null;
PreparedStatement stmt = null;//
BufferedReader br = null;
try {
br = new BufferedReader( new FileReader(pyFile));
Class.forName(jdbcDriver).newInstance();
conn = DriverManager.getConnection(dbURL);
conn.setAutoCommit(true);
stmt = conn.prepareStatement("INSERT INTO pydb (pinyin, hanzi, freq, last_used) VALUES (?,?,?,?)");
String line = null;
while( (line=br.readLine()) != null) {
int len = getPyIdx(line);
if(len==1)
continue;
String py = line.substring(len);
String hz = new String( line.substring(0,len).getBytes("gb2312"),"ISO-8859-1");
stmt.setString(1, py);
stmt.setString(2, hz);
stmt.setFloat(3, 1.0f);
stmt.setTimestamp(4, new Timestamp(new java.util.Date().getTime()));
try {
stmt.executeUpdate();
}
catch(java.sql.SQLException sqlEx) {
System.err.println("py=:"+py +" / hz=:"+line.substring(0,len));
System.err.println(sqlEx);
}
// stmt.addBatch();
}
// stmt.executeBatch();
}
catch(java.sql.SQLException sqlEx) {
sqlEx.printStackTrace();
}
catch(IOException ioEx) {
ioEx.printStackTrace();
}
finally {
if(stmt != null) {
try {
stmt.close();
}
catch(SQLException sEx){}
}
if(conn !=null) {
try {
conn.close();
}
catch(SQLException sEx){}
}
}
}
public static void main(String[] args) throws Exception{
TestPy testPy1 = new TestPy();
testPy1.file2Mysql("/home/hwh/winpy.txt");
}
} |
|