Commit 0d7a1a14 by 侯昆

图谱信息

1 parent 5d4f5306
...@@ -211,9 +211,10 @@ public final class AipUtilBean { ...@@ -211,9 +211,10 @@ public final class AipUtilBean {
double score = doSimnet(word1, word); double score = doSimnet(word1, word);
if (score > RELATE_CRITICAL_VALUE) { if (score > RELATE_CRITICAL_VALUE) {
WordRelation relation = new WordRelation(); WordRelation relation = new WordRelation();
relation.setWord1(word1); int from = words.indexOf(word1);
relation.setWord2(word); int to = words.indexOf(word);
relation.setScore(score); relation.setFrom(from);
relation.setTo(to);
wordRelations.add(relation); wordRelations.add(relation);
} }
} }
......
...@@ -24,7 +24,6 @@ import lombok.Data; ...@@ -24,7 +24,6 @@ import lombok.Data;
*/ */
@Data @Data
public class WordRelation { public class WordRelation {
private String word1; private int from;
private String word2; private int to;
private double score;
} }
package com.dookay.cihai.core.aip;
/*****************************************
* *
* @dookay.com Internet make it happen *
* ----------- ----------------------- *
* dddd ddddd Internet make it happen *
* o o o Internet make it happen *
* k k k Internet make it happen *
* a a a Internet make it happen *
* yyyy yyyyy Internet make it happen *
* ----------- ----------------------- *
* @dookay.com Internet make it happen *
* *
****************************************/
import lombok.Data;
/**
* @author houkun
* @date 2017/12/7
*/
@Data
public class WordSequence {
private int id;
private String label;
public WordSequence(int id, String label) {
this.id = id;
this.label = label;
}
}
...@@ -17,6 +17,9 @@ package com.dookay.cihai.core; ...@@ -17,6 +17,9 @@ package com.dookay.cihai.core;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.dookay.cihai.core.aip.AipUtilBean; import com.dookay.cihai.core.aip.AipUtilBean;
import com.dookay.cihai.core.aip.WordRelation; import com.dookay.cihai.core.aip.WordRelation;
import com.dookay.cihai.core.aip.WordSequence;
import jdk.nashorn.internal.ir.annotations.Immutable;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
...@@ -29,6 +32,7 @@ import java.io.File; ...@@ -29,6 +32,7 @@ import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author houkun * @author houkun
...@@ -73,18 +77,11 @@ public class BaiduTest extends CihaiCoreApplicationTests { ...@@ -73,18 +77,11 @@ public class BaiduTest extends CihaiCoreApplicationTests {
FileReader reader = new FileReader(file); FileReader reader = new FileReader(file);
String text = FileCopyUtils.copyToString(reader); String text = FileCopyUtils.copyToString(reader);
List<String> list = aipUtilBean.extractKeyWords("中国共产党第十九次全国代表大会", text, 15); List<String> list = aipUtilBean.extractKeyWords("中国共产党第十九次全国代表大会", text, 15);
System.out.println(JSON.toJSONString(list)); List<WordSequence> wordSequences = list.stream().map(l -> new WordSequence(list.indexOf(l), l)).collect(Collectors.toList());
// Map<Pair<String, String>, Double> map = aipUtilBean.calcKeywordsRelated("中国共产党第十九次全国代表大会", list);
// System.out.println(map);
// for (String s : list) {
// Map<Pair<String, String>, Double> map1 = aipUtilBean.calcKeywordsRelated(s, list);
// System.out.println(map1);
// }
List<WordRelation> wordRelations = aipUtilBean.generateWordsMap(list); List<WordRelation> wordRelations = aipUtilBean.generateWordsMap(list);
System.out.println(wordSequences);
System.out.println(wordRelations); System.out.println(wordRelations);
System.out.println(wordRelations.size()); System.out.println(wordRelations.size());
// Map<String, Long> map = aipUtilBean.extractNounWordsWithCount(text);
// System.out.print(map.toString());
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!