Skip to content
Permalink
ac4b295237
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
58 lines (47 sloc) 2.17 KB
package kb.howtokb.clustering;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.List;
import kb.howtokb.clustering.HeuristicBottomupClustering.ActivitySuperCluster;
import kb.howtokb.clustering.sim.Coefficient;
import kb.howtokb.taskframe.WikiHowTaskFrame;
import kb.howtokb.tools.InformationExtraction;
public class HeuristicBottomUpClusteringTest {
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
String activityTb = "all-words-category.txt";
HeuristicBottomupClustering cluster = new HeuristicBottomupClustering(activityTb);
double threshold = Coefficient.VVNN_TRHES;
String model = "articles-word2vec-word-pos.model.txt";
String allAct = "resources/all-strong-activities.txt";
SimplePruningSimilarity simFunc = new SimplePruningSimilarity(threshold, model, allAct);
List<ActivitySuperCluster> results = cluster.cluster(simFunc, Coefficient.VVNN_TRHES);
System.out.println("Number of clusters: " + results.size());
String output = "/var/tmp/cxchu/clustering-result-wikihow-task/bottom-up-cluster-";
String input = "/var/tmp/cxchu/data-server/For-Database/act-frame-wikihow-task.json"; //original data point file
List<WikiHowTaskFrame> allframe = InformationExtraction.getAllFrame(input);
int total = 0;
for (int i = 0; i < results.size(); i++) {
System.out.println("Cluster " + i + ": " + results.get(i).getSuperClusterMembers().size());
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(output+i+".json"), "utf-8"));
List<Integer> actitiviesID =
results.get(i).getSuperClusterMembers();
for (int j=0; j<allframe.size(); j++){
if (actitiviesID.contains(allframe.get(j).getID())){
out.write(allframe.get(j).toJsonObject().toJSONString() + "\n");
allframe.remove(j);
j--;
total++;
}
}
out.close();
}
long endTime = System.currentTimeMillis();
long totalTime = (endTime - startTime)/60000;
System.out.println("Number of activity frames: " + total);
System.out.println("Running Time: " + totalTime + " minute(s)");
}
}