Permalink
Cannot retrieve contributors at this time
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?
HowToKB/src/test/kb/howtokb/clustering/HeuristicBottomUpClusteringTest.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (49 sloc)
2.25 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.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; | |
import kb.howtokb.clustering.HeuristicBottomupClustering.ActivitySuperCluster; | |
import kb.howtokb.clustering.SimplePruningSimilarity; | |
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 = "howtokb-data/cluster-results/bottom-up-cluster-"; | |
String input = "howtokb-data/task-frame-before-clustering.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)"); | |
} | |
} |