|
|
@ -14,6 +14,7 @@ import com.ruoyi.biemo.mongodb.utils.MongoHelper;
|
|
|
|
import com.ruoyi.biemo.nlp.DependencyParserUtils;
|
|
|
|
import com.ruoyi.biemo.nlp.DependencyParserUtils;
|
|
|
|
import com.ruoyi.biemo.nlp.SummaryUtils;
|
|
|
|
import com.ruoyi.biemo.nlp.SummaryUtils;
|
|
|
|
import com.ruoyi.biemo.utils.MyObjects;
|
|
|
|
import com.ruoyi.biemo.utils.MyObjects;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
@ -49,6 +50,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
if (Objects.isNull(id) || StringUtil.isEmpty(id)) return null;
|
|
|
|
if (Objects.isNull(id) || StringUtil.isEmpty(id)) return null;
|
|
|
|
return mongoHelper.findById(id, DocInfo.class);
|
|
|
|
return mongoHelper.findById(id, DocInfo.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DocInfo> batchLoadData(SearchSourceBuilder context, SearchHit[] hitArr) {
|
|
|
|
public List<DocInfo> batchLoadData(SearchSourceBuilder context, SearchHit[] hitArr) {
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
@ -59,14 +61,14 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mongoHelper.findListByIds(ids, DocInfo.class);
|
|
|
|
return mongoHelper.findListByIds(ids, DocInfo.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询文章管理
|
|
|
|
* 查询文章管理
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param id 文章管理主键
|
|
|
|
* @param id 文章管理主键
|
|
|
|
* @return 文章管理
|
|
|
|
* @return 文章管理
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public DocInfo selectDocInfoById(String id)
|
|
|
|
public DocInfo selectDocInfoById(String id) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (id == null || id.trim().length() == 0) {
|
|
|
|
if (id == null || id.trim().length() == 0) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,8 +84,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
* @param docInfo 文章管理
|
|
|
|
* @param docInfo 文章管理
|
|
|
|
* @return 文章管理
|
|
|
|
* @return 文章管理
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public List<DocInfo> selectDocInfoList(DocInfo docInfo)
|
|
|
|
public List<DocInfo> selectDocInfoList(DocInfo docInfo) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return esLambdaQuery().eqAll(docInfo).query();
|
|
|
|
return esLambdaQuery().eqAll(docInfo).query();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -103,8 +104,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
* @param docInfo 文章管理
|
|
|
|
* @param docInfo 文章管理
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public String insertOrUpdateDocInfo(DocInfo docInfo)
|
|
|
|
public String insertOrUpdateDocInfo(DocInfo docInfo) {
|
|
|
|
{
|
|
|
|
|
|
|
|
String id = mongoHelper.insert(docInfo);
|
|
|
|
String id = mongoHelper.insert(docInfo);
|
|
|
|
docInfo.setId(id);
|
|
|
|
docInfo.setId(id);
|
|
|
|
applicationContext.publishEvent(new DocInfoSaveEvent(this, docInfo));
|
|
|
|
applicationContext.publishEvent(new DocInfoSaveEvent(this, docInfo));
|
|
|
@ -114,6 +114,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
public void insertBatchEs(List<DocInfo> docInfos) {
|
|
|
|
public void insertBatchEs(List<DocInfo> docInfos) {
|
|
|
|
insertBatch(docInfos);
|
|
|
|
insertBatch(docInfos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void insertEs(DocInfo docInfo) {
|
|
|
|
public void insertEs(DocInfo docInfo) {
|
|
|
|
List<DocInfo> docInfos = new ArrayList<>();
|
|
|
|
List<DocInfo> docInfos = new ArrayList<>();
|
|
|
|
docInfos.add(docInfo);
|
|
|
|
docInfos.add(docInfo);
|
|
|
@ -127,8 +128,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
* @param ids 需要删除的文章管理主键
|
|
|
|
* @param ids 需要删除的文章管理主键
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void deleteDocInfoByIds(String[] ids)
|
|
|
|
public void deleteDocInfoByIds(String[] ids) {
|
|
|
|
{
|
|
|
|
|
|
|
|
List<String> list = Arrays.stream(ids).collect(Collectors.toList());
|
|
|
|
List<String> list = Arrays.stream(ids).collect(Collectors.toList());
|
|
|
|
mongoHelper.deleteByIds(list, DocInfo.class);
|
|
|
|
mongoHelper.deleteByIds(list, DocInfo.class);
|
|
|
|
applicationContext.publishEvent(new DocInfoDeleteEvent(this, list));
|
|
|
|
applicationContext.publishEvent(new DocInfoDeleteEvent(this, list));
|
|
|
@ -141,8 +141,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
* @param id 文章管理主键
|
|
|
|
* @param id 文章管理主键
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void deleteDocInfoById(String id)
|
|
|
|
public void deleteDocInfoById(String id) {
|
|
|
|
{
|
|
|
|
|
|
|
|
mongoHelper.deleteById(id, DocInfo.class);
|
|
|
|
mongoHelper.deleteById(id, DocInfo.class);
|
|
|
|
applicationContext.publishEvent(new DocInfoDeleteEvent(this, id));
|
|
|
|
applicationContext.publishEvent(new DocInfoDeleteEvent(this, id));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -232,6 +231,7 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
insertOrUpdateDocInfo(docInfo);
|
|
|
|
insertOrUpdateDocInfo(docInfo);
|
|
|
|
return response;
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> getAllNodes(Set<String> allRelations) {
|
|
|
|
private Map<String, String> getAllNodes(Set<String> allRelations) {
|
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
|
Set<String> nodeSets = new HashSet<>();
|
|
|
|
Set<String> nodeSets = new HashSet<>();
|
|
|
@ -276,7 +276,10 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
graph.setRelationships(relationships);
|
|
|
|
graph.setRelationships(relationships);
|
|
|
|
data.setGraph(graph);
|
|
|
|
data.setGraph(graph);
|
|
|
|
dataList.add(data);
|
|
|
|
dataList.add(data);
|
|
|
|
datas.setColumns(new ArrayList<String>(){{add("user");add("entity");}});
|
|
|
|
datas.setColumns(new ArrayList<String>() {{
|
|
|
|
|
|
|
|
add("user");
|
|
|
|
|
|
|
|
add("entity");
|
|
|
|
|
|
|
|
}});
|
|
|
|
datas.setData(dataList);
|
|
|
|
datas.setData(dataList);
|
|
|
|
datass.add(datas);
|
|
|
|
datass.add(datas);
|
|
|
|
response.setResults(datass);
|
|
|
|
response.setResults(datass);
|
|
|
@ -292,6 +295,24 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
return summary;
|
|
|
|
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], true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
long endTime = System.nanoTime();
|
|
|
|
|
|
|
|
System.out.println("不用集合耗时:" + (endTime - stratTime));
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//文章管理--批量分析
|
|
|
|
public String batchAnalysis(String[] ids) {
|
|
|
|
public String batchAnalysis(String[] ids) {
|
|
|
|
if(ids!=null&&ids.length>0){
|
|
|
|
if(ids!=null&&ids.length>0){
|
|
|
|
for(int i=0;i<ids.length;i++) {
|
|
|
|
for(int i=0;i<ids.length;i++) {
|
|
|
@ -300,4 +321,86 @@ public class DocInfoService extends EsService<DocInfo> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "ok";
|
|
|
|
return "ok";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MyResultResponse socialAnalysis(String content) {
|
|
|
|
|
|
|
|
// String grapData = docInfo.getParserGraphData();
|
|
|
|
|
|
|
|
MyResultResponse response = null;
|
|
|
|
|
|
|
|
// if(StringUtils.isNotBlank(grapData)&&reAnalysis){
|
|
|
|
|
|
|
|
// response = JSONObject.parseObject(grapData,MyResultResponse.class);
|
|
|
|
|
|
|
|
// if(response!=null){
|
|
|
|
|
|
|
|
// return response;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
List<Node> nodes = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Relationship> relationships = new ArrayList<>();
|
|
|
|
|
|
|
|
//拆句
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(content)) {
|
|
|
|
|
|
|
|
content = MyObjects.delHTMLTag(content);
|
|
|
|
|
|
|
|
content = MyObjects.delSpace(content);
|
|
|
|
|
|
|
|
String regx = "\n|!|\\.|\\。|\\;|\\;|\\!|\\,|\\,|\\、|\\@|\\#|\\$|\\¥|\\%|\\&|\\*|\\(|\\)|\\=|\\+|\\-|\\_|\\>|\\<|\\[|\\]|\\【|\\】|\\?|\\?|”|\\\"";
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
for (String relation : allRelations) {
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
|
|
|
node2.setId(nodeName2);
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
relationship.setId(String.valueOf(i++));
|
|
|
|
|
|
|
|
relationship.setType(relationName);
|
|
|
|
|
|
|
|
relationship.setStartNode(nodeName1);
|
|
|
|
|
|
|
|
relationship.setEndNode(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));
|
|
|
|
|
|
|
|
// docInfo.setSummary(SummaryUtils.autoSummary(content));
|
|
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
response = returnResponse(nodes, relationships);
|
|
|
|
|
|
|
|
// docInfo.setParserGraphData(JSONObject.toJSONString(response));
|
|
|
|
|
|
|
|
// docInfo.setStatus(1);
|
|
|
|
|
|
|
|
// insertOrUpdateDocInfo(docInfo);
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|