|
@@ -3,7 +3,9 @@ package com.mooctest.cluster;
|
|
|
import com.hankcs.hanlp.mining.word2vec.DocVectorModel;
|
|
|
import com.hankcs.hanlp.mining.word2vec.WordVectorModel;
|
|
|
import com.mooctest.data.BugDTO;
|
|
|
+import lombok.Data;
|
|
|
import lombok.Getter;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import smile.clustering.GMeans;
|
|
|
import smile.clustering.HierarchicalClustering;
|
|
|
import smile.clustering.MEC;
|
|
@@ -16,10 +18,14 @@ import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Getter
|
|
|
+@Data
|
|
|
public class ClusterAnalyzer<K> {
|
|
|
|
|
|
protected Map<K, Doc<K>> documents;
|
|
|
protected List<K> idList;
|
|
|
+
|
|
|
+ @Value("${path.word}")
|
|
|
+ private String wordPath;
|
|
|
|
|
|
public ClusterAnalyzer() {
|
|
|
documents = new HashMap<>();
|
|
@@ -33,7 +39,7 @@ public class ClusterAnalyzer<K> {
|
|
|
}
|
|
|
|
|
|
public List<Set<K>> gmeans(List<BugDTO> bugs) throws IOException {
|
|
|
- DocVectorModel docVectorModel2 = new DocVectorModel(new WordVectorModel("/project/sgns.wiki.word"));
|
|
|
+ DocVectorModel docVectorModel2 = new DocVectorModel(new WordVectorModel(wordPath));
|
|
|
double[][] data = new double[bugs.size()][];
|
|
|
for (int i = 0; i < bugs.size(); i++) {
|
|
|
float[] vec = docVectorModel2.query(bugs.get(i).getDescription()).getElementArray();
|
|
@@ -46,7 +52,7 @@ public class ClusterAnalyzer<K> {
|
|
|
}
|
|
|
|
|
|
public List<Set<K>> sib(List<BugDTO> bugs) throws IOException {
|
|
|
- DocVectorModel docVectorModel2 = new DocVectorModel(new WordVectorModel("/project/sgns.wiki.word"));
|
|
|
+ DocVectorModel docVectorModel2 = new DocVectorModel(new WordVectorModel(wordPath));
|
|
|
double[][] data = new double[bugs.size()][];
|
|
|
for (int i = 0; i < bugs.size(); i++) {
|
|
|
float[] vec = docVectorModel2.query(bugs.get(i).getDescription()).getElementArray();
|
|
@@ -59,7 +65,7 @@ public class ClusterAnalyzer<K> {
|
|
|
}
|
|
|
|
|
|
public List<Set<K>> mec(List<BugDTO> bugs) throws IOException {
|
|
|
- DocVectorModel docVectorModel2 = new DocVectorModel(new WordVectorModel("/project/sgns.wiki.word"));
|
|
|
+ DocVectorModel docVectorModel2 = new DocVectorModel(new WordVectorModel(wordPath));
|
|
|
double[][] data = new double[bugs.size()][];
|
|
|
for (int i = 0; i < bugs.size(); i++) {
|
|
|
float[] vec = docVectorModel2.query(bugs.get(i).getDescription()).getElementArray();
|