|
|
|
@ -161,50 +161,60 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MyResultResponse analysis(String id,Boolean reAnalysis) {
|
|
|
|
|
if(StringUtils.isBlank(id)){
|
|
|
|
|
public MyResultResponse analysis(String id, Boolean reAnalysis) {
|
|
|
|
|
if (StringUtils.isBlank(id)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
MyResultResponse response = null;
|
|
|
|
|
DocInfo docInfo = this.selectDocInfoById(id);
|
|
|
|
|
String grapData = docInfo.getParserGraphData();
|
|
|
|
|
if(StringUtils.isNotBlank(grapData)&&!reAnalysis){
|
|
|
|
|
response = JSONObject.parseObject(grapData,MyResultResponse.class);
|
|
|
|
|
if(response!=null){
|
|
|
|
|
if (StringUtils.isNotBlank(grapData) && !reAnalysis) {
|
|
|
|
|
response = JSONObject.parseObject(grapData, MyResultResponse.class);
|
|
|
|
|
if (response != null) {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String content = docInfo.getContent();
|
|
|
|
|
String content = docInfo.getContent();
|
|
|
|
|
List<Node> nodes = new ArrayList<>();
|
|
|
|
|
List<Relationship> relationships = new ArrayList<>();
|
|
|
|
|
//拆句
|
|
|
|
|
if(StringUtils.isNotBlank(content)){
|
|
|
|
|
if (StringUtils.isNotBlank(content)) {
|
|
|
|
|
content = MyObjects.delHTMLTag(content);
|
|
|
|
|
content = MyObjects.delSpace(content);
|
|
|
|
|
String regx = "\n|!|\\.|\\。|\\;|\\;|\\!|\\,|\\,|\\、|\\@|\\#|\\$|\\¥|\\%|\\&|\\*|\\(|\\)|\\=|\\+|\\-|\\_|\\>|\\<|\\[|\\]|\\【|\\】|\\?|\\?|”|\\\"";
|
|
|
|
|
String [] strArr = content.split(regx);
|
|
|
|
|
String[] strArr = content.split(regx);
|
|
|
|
|
Set<String> allRelations = getAllRelations(strArr);
|
|
|
|
|
int i = 1;
|
|
|
|
|
//Map<String,String> nodesMap = getAllNodes(allRelations);
|
|
|
|
|
|
|
|
|
|
if(allRelations!=null&&allRelations.size()>0){
|
|
|
|
|
if (allRelations != null && allRelations.size() > 0) {
|
|
|
|
|
for (String relation : allRelations) {
|
|
|
|
|
String[] nrn = StringUtils.isNotBlank(relation)?relation.split(","):null;
|
|
|
|
|
if(nrn==null||nrn.length<3){
|
|
|
|
|
String[] nrn = StringUtils.isNotBlank(relation) ? relation.split(",") : null;
|
|
|
|
|
if (nrn == null || nrn.length < 3) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String nodeName1 = nrn[0];
|
|
|
|
|
String relationName = nrn[1];
|
|
|
|
|
String nodeName2 = nrn[2];
|
|
|
|
|
Node node1 = new Node();
|
|
|
|
|
Node node1 = new Node();
|
|
|
|
|
//node1.setId(nodesMap.get(nodeName1));
|
|
|
|
|
node1.setId(nodeName1);
|
|
|
|
|
node1.setLabels(new ArrayList<String>(){{add(nodeName1);}});
|
|
|
|
|
node1.setProperties(new HashMap<String,Object>(){{put("name",nodeName1);put("email","9094908@qq.com");}});
|
|
|
|
|
Node node2 = new Node();
|
|
|
|
|
node1.setLabels(new ArrayList<String>() {{
|
|
|
|
|
add(nodeName1);
|
|
|
|
|
}});
|
|
|
|
|
node1.setProperties(new HashMap<String, Object>() {{
|
|
|
|
|
put("name", nodeName1);
|
|
|
|
|
put("email", "9094908@qq.com");
|
|
|
|
|
}});
|
|
|
|
|
Node node2 = new Node();
|
|
|
|
|
node2.setId(nodeName2);
|
|
|
|
|
node2.setLabels(new ArrayList<String>(){{add(nodeName2);}});
|
|
|
|
|
node2.setProperties(new HashMap<String,Object>(){{put("name",nodeName2);put("email","9094908@qq.com");}});
|
|
|
|
|
node2.setLabels(new ArrayList<String>() {{
|
|
|
|
|
add(nodeName2);
|
|
|
|
|
}});
|
|
|
|
|
node2.setProperties(new HashMap<String, Object>() {{
|
|
|
|
|
put("name", nodeName2);
|
|
|
|
|
put("email", "9094908@qq.com");
|
|
|
|
|
}});
|
|
|
|
|
nodes.add(node1);
|
|
|
|
|
nodes.add(node2);
|
|
|
|
|
Relationship relationship = new Relationship();
|
|
|
|
@ -212,11 +222,15 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
|
relationship.setType(relationName);
|
|
|
|
|
relationship.setStartNode(nodeName1);
|
|
|
|
|
relationship.setEndNode(nodeName2);
|
|
|
|
|
relationship.setProperties(new HashMap<String,Object>(){{put("source",nodeName1);put("relation",relationName);put("target",nodeName2);}});
|
|
|
|
|
relationship.setProperties(new HashMap<String, Object>() {{
|
|
|
|
|
put("source", nodeName1);
|
|
|
|
|
put("relation", relationName);
|
|
|
|
|
put("target", nodeName2);
|
|
|
|
|
}});
|
|
|
|
|
relationships.add(relationship);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//获取命名实体
|
|
|
|
|
// 获取命名实体
|
|
|
|
|
try {
|
|
|
|
|
Map<String,Set<String>> nerTagSet = DependencyParserUtils.getMyNERTagSet(strArr);
|
|
|
|
|
docInfo.setParserNamedEntity(JSONObject.toJSONString(nerTagSet));
|
|
|
|
@ -225,7 +239,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
response = returnResponse(nodes,relationships);
|
|
|
|
|
response = returnResponse(nodes, relationships);
|
|
|
|
|
docInfo.setParserGraphData(JSONObject.toJSONString(response));
|
|
|
|
|
docInfo.setStatus(1);
|
|
|
|
|
insertOrUpdateDocInfo(docInfo);
|
|
|
|
@ -295,28 +309,55 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
|
return summary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 不用集合耗时:293270952500 不用集合耗时:245180467700
|
|
|
|
|
|
|
|
|
|
// //社会网络分析
|
|
|
|
|
// public List<MyResultResponse> socialNetworkAnalysis(String[] ids) {
|
|
|
|
|
// List<MyResultResponse> list = new ArrayList<>();
|
|
|
|
|
// long stratTime = System.nanoTime();
|
|
|
|
|
// if (ids != null && ids.length > 0) {
|
|
|
|
|
// for (int i = 0; i < ids.length; i++) {
|
|
|
|
|
//// list.add(analysis(ids[i], true));
|
|
|
|
|
// list.add(analysis(ids[i], false));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// long endTime = System.nanoTime();
|
|
|
|
|
// System.out.println("方法耗时:" + (endTime - stratTime));
|
|
|
|
|
// return list;
|
|
|
|
|
// }
|
|
|
|
|
//社会网络分析
|
|
|
|
|
public List<MyResultResponse> socialNetworkAnalysis(String[] ids) {
|
|
|
|
|
List<MyResultResponse> list = new ArrayList<>();
|
|
|
|
|
long stratTime = System.nanoTime();
|
|
|
|
|
public MyResultResponse socialNetworkAnalysis(String[] ids) {
|
|
|
|
|
MyResultResponse response2 = new MyResultResponse();
|
|
|
|
|
MyResultResponse response3 = new MyResultResponse();
|
|
|
|
|
if (ids != null && ids.length > 0) {
|
|
|
|
|
for (int i = 0; i < ids.length; i++) {
|
|
|
|
|
// list.add(analysis(ids[i], true));
|
|
|
|
|
list.add(analysis(ids[i], true));
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
response2 = analysis(ids[0], false);
|
|
|
|
|
} else {
|
|
|
|
|
response3 = analysis(ids[1], false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
long endTime = System.nanoTime();
|
|
|
|
|
System.out.println("不用集合耗时:" + (endTime - stratTime));
|
|
|
|
|
return list;
|
|
|
|
|
MyResultResponse myResultResponse = new MyResultResponse();
|
|
|
|
|
List<MyResultResponse.Datas> results = new ArrayList<>();
|
|
|
|
|
List<MyResultResponse.Datas> results2 = response2.getResults();
|
|
|
|
|
List<MyResultResponse.Datas> results3 = response3.getResults();
|
|
|
|
|
|
|
|
|
|
results.addAll(0,results3);
|
|
|
|
|
results.addAll(1,results2);
|
|
|
|
|
|
|
|
|
|
List<String> errors = myResultResponse.getErrors();
|
|
|
|
|
errors.addAll(response2.getErrors());
|
|
|
|
|
errors.addAll(response3.getErrors());
|
|
|
|
|
myResultResponse.setResults(results);
|
|
|
|
|
myResultResponse.setErrors(errors);
|
|
|
|
|
return myResultResponse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//文章管理--批量分析
|
|
|
|
|
public String batchAnalysis(String[] ids) {
|
|
|
|
|
if(ids!=null&&ids.length>0){
|
|
|
|
|
for(int i=0;i<ids.length;i++) {
|
|
|
|
|
analysis(ids[i],true);
|
|
|
|
|
if (ids != null && ids.length > 0) {
|
|
|
|
|
for (int i = 0; i < ids.length; i++) {
|
|
|
|
|
analysis(ids[i], true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "ok";
|
|
|
|
|