diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/response/MyResultResponse.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/response/MyResultResponse.java index de3c9d5..4d39ba1 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/response/MyResultResponse.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/response/MyResultResponse.java @@ -3,6 +3,7 @@ package com.ruoyi.biemo.business.response; import com.ruoyi.biemo.business.domain.Node; import com.ruoyi.biemo.business.domain.Relationship; +import java.util.ArrayList; import java.util.List; public class MyResultResponse { @@ -10,7 +11,13 @@ public class MyResultResponse { private List results; private List errors; + public MyResultResponse() { + } + public List getErrors() { + if (errors == null) { + errors = new ArrayList<>(); + } return errors; } @@ -19,6 +26,9 @@ public class MyResultResponse { } public List getResults() { + if (results == null) { + results = new ArrayList<>(); + } return results; } diff --git a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java index 2e0b2fd..0486130 100644 --- a/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java +++ b/ruoyi-biemo/src/main/java/com/ruoyi/biemo/business/service/DocInfoService.java @@ -161,50 +161,60 @@ public class DocInfoService extends EsService { } - 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 nodes = new ArrayList<>(); List 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 allRelations = getAllRelations(strArr); int i = 1; //Map 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(){{add(nodeName1);}}); - node1.setProperties(new HashMap(){{put("name",nodeName1);put("email","9094908@qq.com");}}); - Node node2 = new Node(); + node1.setLabels(new ArrayList() {{ + add(nodeName1); + }}); + node1.setProperties(new HashMap() {{ + put("name", nodeName1); + put("email", "9094908@qq.com"); + }}); + Node node2 = new Node(); node2.setId(nodeName2); - node2.setLabels(new ArrayList(){{add(nodeName2);}}); - node2.setProperties(new HashMap(){{put("name",nodeName2);put("email","9094908@qq.com");}}); + node2.setLabels(new ArrayList() {{ + add(nodeName2); + }}); + node2.setProperties(new HashMap() {{ + 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 { relationship.setType(relationName); relationship.setStartNode(nodeName1); relationship.setEndNode(nodeName2); - relationship.setProperties(new HashMap(){{put("source",nodeName1);put("relation",relationName);put("target",nodeName2);}}); + relationship.setProperties(new HashMap() {{ + put("source", nodeName1); + put("relation", relationName); + put("target", nodeName2); + }}); relationships.add(relationship); } } - //获取命名实体 +// 获取命名实体 try { Map> nerTagSet = DependencyParserUtils.getMyNERTagSet(strArr); docInfo.setParserNamedEntity(JSONObject.toJSONString(nerTagSet)); @@ -225,7 +239,7 @@ public class DocInfoService extends EsService { 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 { return summary; } -// 不用集合耗时:293270952500 不用集合耗时:245180467700 + + // //社会网络分析 +// public List socialNetworkAnalysis(String[] ids) { +// List 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 socialNetworkAnalysis(String[] ids) { - List 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 results = new ArrayList<>(); + List results2 = response2.getResults(); + List results3 = response3.getResults(); + + results.addAll(0,results3); + results.addAll(1,results2); + + List 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 0) { + for (int i = 0; i < ids.length; i++) { + analysis(ids[i], true); } } return "ok";