📄 clustering.java
字号:
package src.paper;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
public class Clustering {
/*
* matricPath:聚类所需文件存放的位置
* query:查询词
* Ncluster:聚类数目
* 返回聚类结果的完整路径
*/
public static String cmdCluster(String matricPath,String query,String option,int Ncluster){
String clusterResultPath = matricPath;
Process segProcess = null;
String command = null;
BufferedReader br = null;
StringBuffer output = null;
String line = null;
//command = "cmd /c vcluster " + matricPath + query +".mat "+ Ncluster;
command = ".\\.\\bin\\cluto-2.1.1\\Win32\\vcluster.exe " + matricPath + query + "_" + option + ".mat "+ Ncluster;
System.out.println(command);
try {
segProcess = Runtime.getRuntime().exec(command);
br = new BufferedReader(new InputStreamReader(segProcess.getInputStream()));
output = new StringBuffer();
while ((line = br.readLine()) != null)
{
output.append(line);
output.append("\n");
}
System.out.println(output.toString());
} catch (IOException e) {
e.printStackTrace(System.err);
}
finally
{
try { br.close(); }
catch(Exception e){e.printStackTrace(System.err);};
}
return clusterResultPath;
}
//testmain
public static void main(String[] args) {
Store store = new Store("F:\\navy\\Project\\论文\\Paper.mdb");
//option:"doc" or "para" or "sent"
String option = "doc";
String query = "news";
//聚类个数-20,50,100
int Ncluster = 100;
String clusterResultPath = cmdCluster("F:\\navy\\Project\\论文\\",query,option,Ncluster);
store.create(query,option,Ncluster);
store.storeToDB(clusterResultPath + query + "_" + option + ".mat.rlabel",
clusterResultPath + query + "_" + option + ".mat.clustering." + Ncluster, query,option,Ncluster);
try {
store.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream("F:\\navy\\Project\\SumNation\\query.txt")));
query = br.readLine();
while(query != null){
System.out.println(query);
clusterResultPath = cmdCluster("F:\\navy\\Project\\SumNation\\",query,option,Ncluster);
store.create(query,option,Ncluster);
store.storeToDB(clusterResultPath + query + "_" + option + ".mat.rlabel",
clusterResultPath + query + "_" + option + ".mat.clustering." + Ncluster, query,option,Ncluster);
query = br.readLine();
}
store.con.close();
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -