From 8817d8435d16a610e8d5c612262e8af4dc02d555 Mon Sep 17 00:00:00 2001 From: Sry-maker <1961384758@qq.com> Date: Sat, 11 Jun 2022 13:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AUTHORController.java | 65 ------------------- .../controller/BasicServiceController.java | 6 +- .../com/bibackend/dao/AUTHORRepository.java | 10 ++- .../com/bibackend/dao/INTERESTRepository.java | 13 ---- .../com/bibackend/dao/PAPERRepository.java | 2 +- .../service/BasicFunctionService.java | 32 ++++----- 6 files changed, 25 insertions(+), 103 deletions(-) delete mode 100644 backend/src/main/java/com/bibackend/controller/AUTHORController.java diff --git a/backend/src/main/java/com/bibackend/controller/AUTHORController.java b/backend/src/main/java/com/bibackend/controller/AUTHORController.java deleted file mode 100644 index 339343b..0000000 --- a/backend/src/main/java/com/bibackend/controller/AUTHORController.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.bibackend.controller; - - -import com.bibackend.dao.*; -import io.swagger.annotations.Api; -import javax.annotation.Resource; - -import io.swagger.v3.oas.annotations.Operation; -import org.springframework.data.repository.query.Param; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -@RestController -@RequestMapping("api/author") -@Api(tags = "author") -public class AUTHORController { - @Resource - PAPERRepository paperRepository; - @Resource - AFFILIATIONRepository affiliationRepository; - - @Resource - AUTHORRepository authorRepository; - - @Resource - BELONG_TORepository belong_toRepository; - - @Resource - HAS_INTERESTRepository has_interestRepository; - - @Resource - CO_AUTHORRepository co_authorRepository; - @Resource - INTERESTRepository interestRepository; - @Resource - PUBLISHRepository publishRepository; - - @Resource - REFERRepository referRepository; - - @Resource - VENUERepository venueRepository; - @Resource - WRITERepository writeRepository; - - @Operation(summary = "AUTHOR其关联的所有关系和关联实体") - @GetMapping("authorlink") - public ResponseEntity getauthorlink(@Param("author") String author) { - - List> result = new ArrayList>(); - return new ResponseEntity<>(result, HttpStatus.OK); - } - - - - - -} diff --git a/backend/src/main/java/com/bibackend/controller/BasicServiceController.java b/backend/src/main/java/com/bibackend/controller/BasicServiceController.java index 01a3c91..1158540 100644 --- a/backend/src/main/java/com/bibackend/controller/BasicServiceController.java +++ b/backend/src/main/java/com/bibackend/controller/BasicServiceController.java @@ -68,21 +68,21 @@ public ResponseEntity getallpaper(@Param("index") String index) { } - @Operation(summary = "查询author与author之间的5跳及以内关系") + @Operation(summary = "查询author与author之间的4跳及以内关系") @GetMapping("auandau") public ResponseEntity getallauandau(@Param("index1") String index1, @Param("index2") String index2) { return new ResponseEntity<>(basicFunctionService.getallauandau(index1, index2), HttpStatus.OK); } - @Operation(summary = "查询paper与paper之间的5跳之内关系") + @Operation(summary = "查询paper与paper之间的4跳之内关系") @GetMapping("paandpa") public ResponseEntity getallpaandpa(@Param("index1") String index1, @Param("index2") String index2) { return new ResponseEntity<>(basicFunctionService.getallpaandpa(index1, index2), HttpStatus.OK); } - @Operation(summary = "查询author与paper之间的5跳之内关系") + @Operation(summary = "查询author与paper之间的4跳之内关系") @GetMapping("paandau") public ResponseEntity getallpaandpafour(@Param("index1") String index1, @Param("index2") String index2) { return new ResponseEntity<>(basicFunctionService.getallpaandpafour(index1, index2), HttpStatus.OK); diff --git a/backend/src/main/java/com/bibackend/dao/AUTHORRepository.java b/backend/src/main/java/com/bibackend/dao/AUTHORRepository.java index 22dc66a..a4f1236 100644 --- a/backend/src/main/java/com/bibackend/dao/AUTHORRepository.java +++ b/backend/src/main/java/com/bibackend/dao/AUTHORRepository.java @@ -11,7 +11,7 @@ public interface AUTHORRepository extends Neo4jRepository { -// match(n:AUTHOR)-[r]->(nn) WHERE n.name = 'Chun-Yen Chang' RETURN n,r,nn + // 查询某个领域的作者 @Query("match (interest:INTEREST{name:$interestName})<-[r:has_interest]-(author:AUTHOR)" + "return author " + @@ -25,16 +25,14 @@ public interface AUTHORRepository extends Neo4jRepository { List> findAllonetonode(@Param("index") String index); - + // 查询author和author之间有着4跳及以内的关系 @Query("MATCH p=(author1:AUTHOR)-[*..4]-(author2:AUTHOR) WHERE author1.index=$index1 AND author2.index=$index2 RETURN p limit 10") List> findAllaandanode(@Param("index1") String index1,@Param("index2") String index2); - + // 查询author和paper之间有着4跳及以内的关系 @Query("MATCH p=(author:AUTHOR)-[*..4]-(paper:PAPER) WHERE author.index=$index1 AND paper.index=$index2 RETURN p limit 10") List> findAllaandpnode(@Param("index1") String index1,@Param("index2") String index2); - -//根据id,返回所有一跳关系 -// MATCH p=(n)-[]-() where id(n)=4118488 RETURN p + //根据id,返回所有一跳关系 @Query("MATCH (n)-[]-() " + "where id(n)=$id " + "with count(*) as cnt " + diff --git a/backend/src/main/java/com/bibackend/dao/INTERESTRepository.java b/backend/src/main/java/com/bibackend/dao/INTERESTRepository.java index f1ec60b..4dae20b 100644 --- a/backend/src/main/java/com/bibackend/dao/INTERESTRepository.java +++ b/backend/src/main/java/com/bibackend/dao/INTERESTRepository.java @@ -9,18 +9,5 @@ import java.util.Map; public interface INTERESTRepository extends Neo4jRepository { -// MATCH p=(n:AUTHOR)-[:has_interest]-(i:INTEREST)-[:has_interest]-(m:AUTHOR) where n.index="1243827" and m.index="1340571" RETURN n.name,m.name,i.name limit 25 - - // 查询有共同interest的作者 - @Query("MATCH (author1:AUTHOR)-[:has_interest]-(interest:INTEREST)-[:has_interest]-(author2:AUTHOR) WHERE author1.index=$index1 AND author2.index=$index2 RETURN author1.name,author2.name,interest.name limit 25") - List> findInterestRelation(@Param("index1") String index1,@Param("index2") String index2); - - - // 查询有共同interest的作者写的文章,共4跳 - @Query("MATCH (paper1:PAPER)-[:write]-(author1:AUTHOR)-[:has_interest]-(interest:INTEREST)-[:has_interest]-(author2:AUTHOR)-[:write]-(paper2:PAPER) WHERE paper1.index=$index1 AND paper2.index=$index2 RETURN 'paper1-write-author1-has_interest-INTEREST-has_interest-author2-write-paper2',paper1.title,paper2.title,author1.name,author2.name,interest.name limit 25") - List> findauthorinterestRelation(@Param("index1") String index1,@Param("index2") String index2); - - - // } diff --git a/backend/src/main/java/com/bibackend/dao/PAPERRepository.java b/backend/src/main/java/com/bibackend/dao/PAPERRepository.java index 3c8d088..d5772d6 100644 --- a/backend/src/main/java/com/bibackend/dao/PAPERRepository.java +++ b/backend/src/main/java/com/bibackend/dao/PAPERRepository.java @@ -15,7 +15,7 @@ public interface PAPERRepository extends Neo4jRepository { @Query("match p=(paper:PAPER)-[]-() where paper.index=$index return p") List> findAllonenode(@Param("index") String index); - + // 查询paper和paper之间有着4跳及以内的关系 @Query("MATCH p=(paper1:PAPER)-[*..4]-(paper2:PAPER) WHERE paper1.index=$index1 AND paper2.index=$index2 RETURN p limit 10") List> findpandpnode(@Param("index1") String index1,@Param("index2") String index2); } diff --git a/backend/src/main/java/com/bibackend/service/BasicFunctionService.java b/backend/src/main/java/com/bibackend/service/BasicFunctionService.java index fdc96ec..b1103d9 100644 --- a/backend/src/main/java/com/bibackend/service/BasicFunctionService.java +++ b/backend/src/main/java/com/bibackend/service/BasicFunctionService.java @@ -25,20 +25,20 @@ public class BasicFunctionService { @Cacheable(key = "'author-relation-index-' + #p0") public Map getallauthor(String index) { - List> data = new ArrayList<>(); - List> links = new ArrayList<>(); - List> allttestnode = authorRepository.findAllonetonode(index); - for (Map temp : allttestnode) { + List> data = new ArrayList<>(); // 最后的节点的list + List> links = new ArrayList<>(); // 最后的关系的list + List> allttestnode = authorRepository.findAllonetonode(index); //查询语句 + for (Map temp : allttestnode) { //处理所有返回的p(关系及节点) InternalPath.SelfContainedSegment[] ps = (InternalPath.SelfContainedSegment[]) temp.get("p"); for (InternalPath.SelfContainedSegment p : ps) { - InternalNode st = (InternalNode) p.start(); - Map sttest = st.asMap(); - Map stret = new HashMap<>(); + InternalNode st = (InternalNode) p.start(); //取开始节点 + Map sttest = st.asMap(); //开始节点的数据 + Map stret = new HashMap<>(); //储存一下 for (Map.Entry entry : sttest.entrySet()) { stret.put(entry.getKey(), (String) entry.getValue()); } List labels = (List) st.labels(); - String q = labels.get(0); + String q = labels.get(0); //判断节点类型,储存类型 if (labels.get(0).equals("PAPER")) { stret.put("category", "0"); } else if (labels.get(0).equals("AUTHOR")) { @@ -50,6 +50,7 @@ public Map getallauthor(String index) { } else if (labels.get(0).equals("VENUE")) { stret.put("category", "4"); } + //将原来节点内的name转换为truename,将id储存为name boolean isEmpty = stret.containsKey("name"); if (isEmpty == true) { String truename = stret.get("name"); @@ -68,7 +69,7 @@ public Map getallauthor(String index) { data.add(stret); } - + // 结束节点,同开始节点 InternalNode end = (InternalNode) p.end(); Map endtest = end.asMap(); Map endret = new HashMap<>(); @@ -96,6 +97,7 @@ public Map getallauthor(String index) { long endtempid = end.id(); String endid = String.valueOf(endtempid); endret.put("name", endid); + // 节点去重 boolean endexist = false; for (Map newMap : data) { if (newMap.get("name").equals(endret.get("name"))) { @@ -106,7 +108,7 @@ public Map getallauthor(String index) { data.add(endret); } - + // 关系储存 InternalRelationship relationship = (InternalRelationship) p.relationship(); Map link = new HashMap<>(); long startNodeId = relationship.startNodeId(); @@ -124,7 +126,7 @@ public Map getallauthor(String index) { result.put("links", links); return result; } - + // 同上 @Cacheable(key = "'paper-relation-index-' + #p0") public Map getallpaper(String index) { List> data = new ArrayList<>(); @@ -227,7 +229,7 @@ public Map getallpaper(String index) { return result; } - + // 同上 @Cacheable(key = "'a-a-relation-index1-' + #p0 + '-index2-' + #p1") public Map getallauandau(String index1, String index2) { List> data = new ArrayList<>(); @@ -329,7 +331,7 @@ public Map getallauandau(String index1, String index2) { result.put("links", links); return result; } - + // 同上 @Cacheable(key = "'p-p-relation-index1-' + #p0 + '-index2-' + #p1") public Map getallpaandpa(String index1, String index2) { List> data = new ArrayList<>(); @@ -431,7 +433,7 @@ public Map getallpaandpa(String index1, String index2) { result.put("links", links); return result; } - + // 同上 @Cacheable(key = "'p-a-relation-index1-' + #p0 + '-index2-' + #p1") public Map getallpaandpafour(String index1, String index2) { List> data = new ArrayList<>(); @@ -533,7 +535,7 @@ public Map getallpaandpafour(String index1, String index2) { result.put("links", links); return result; } - + // 同上 @Cacheable(key = "'id-relation-index-' + #p0") public Map getallid(Long index) { List> data = new ArrayList<>();