Skip to content

Commit

Permalink
代码整理
Browse files Browse the repository at this point in the history
  • Loading branch information
Sry-maker committed Jun 11, 2022
1 parent 2a41574 commit 8817d84
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 103 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ public ResponseEntity<Object> getallpaper(@Param("index") String index) {
}


@Operation(summary = "查询author与author之间的5跳及以内关系")
@Operation(summary = "查询author与author之间的4跳及以内关系")
@GetMapping("auandau")
public ResponseEntity<Object> 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<Object> 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<Object> getallpaandpafour(@Param("index1") String index1, @Param("index2") String index2) {
return new ResponseEntity<>(basicFunctionService.getallpaandpafour(index1, index2), HttpStatus.OK);
Expand Down
10 changes: 4 additions & 6 deletions backend/src/main/java/com/bibackend/dao/AUTHORRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public interface AUTHORRepository extends Neo4jRepository<AUTHOR,Long> {

// 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 " +
Expand All @@ -25,16 +25,14 @@ public interface AUTHORRepository extends Neo4jRepository<AUTHOR,Long> {
List<Map<String,Object>> 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<Map<String,Object>> 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<Map<String,Object>> 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 " +
Expand Down
13 changes: 0 additions & 13 deletions backend/src/main/java/com/bibackend/dao/INTERESTRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,5 @@
import java.util.Map;

public interface INTERESTRepository extends Neo4jRepository<INTEREST,Long> {
// 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<Map<String,Object>> 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<Map<String,Object>> findauthorinterestRelation(@Param("index1") String index1,@Param("index2") String index2);


//

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface PAPERRepository extends Neo4jRepository<PAPER,Long> {
@Query("match p=(paper:PAPER)-[]-() where paper.index=$index return p")
List<Map<String,Object>> 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<Map<String,Object>> findpandpnode(@Param("index1") String index1,@Param("index2") String index2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ public class BasicFunctionService {

@Cacheable(key = "'author-relation-index-' + #p0")
public Map<String, Object> getallauthor(String index) {
List<Map<String, String>> data = new ArrayList<>();
List<Map<String, String>> links = new ArrayList<>();
List<Map<String, Object>> allttestnode = authorRepository.findAllonetonode(index);
for (Map<String, Object> temp : allttestnode) {
List<Map<String, String>> data = new ArrayList<>(); // 最后的节点的list
List<Map<String, String>> links = new ArrayList<>(); // 最后的关系的list
List<Map<String, Object>> allttestnode = authorRepository.findAllonetonode(index); //查询语句
for (Map<String, Object> temp : allttestnode) { //处理所有返回的p(关系及节点)
InternalPath.SelfContainedSegment[] ps = (InternalPath.SelfContainedSegment[]) temp.get("p");
for (InternalPath.SelfContainedSegment p : ps) {
InternalNode st = (InternalNode) p.start();
Map<String, Object> sttest = st.asMap();
Map<String, String> stret = new HashMap<>();
InternalNode st = (InternalNode) p.start(); //取开始节点
Map<String, Object> sttest = st.asMap(); //开始节点的数据
Map<String, String> stret = new HashMap<>(); //储存一下
for (Map.Entry<String, Object> entry : sttest.entrySet()) {
stret.put(entry.getKey(), (String) entry.getValue());
}
List<String> labels = (List<String>) 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")) {
Expand All @@ -50,6 +50,7 @@ public Map<String, Object> 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");
Expand All @@ -68,7 +69,7 @@ public Map<String, Object> getallauthor(String index) {
data.add(stret);
}


// 结束节点,同开始节点
InternalNode end = (InternalNode) p.end();
Map<String, Object> endtest = end.asMap();
Map<String, String> endret = new HashMap<>();
Expand Down Expand Up @@ -96,6 +97,7 @@ public Map<String, Object> getallauthor(String index) {
long endtempid = end.id();
String endid = String.valueOf(endtempid);
endret.put("name", endid);
// 节点去重
boolean endexist = false;
for (Map<String, String> newMap : data) {
if (newMap.get("name").equals(endret.get("name"))) {
Expand All @@ -106,7 +108,7 @@ public Map<String, Object> getallauthor(String index) {
data.add(endret);
}


// 关系储存
InternalRelationship relationship = (InternalRelationship) p.relationship();
Map<String, String> link = new HashMap<>();
long startNodeId = relationship.startNodeId();
Expand All @@ -124,7 +126,7 @@ public Map<String, Object> getallauthor(String index) {
result.put("links", links);
return result;
}

// 同上
@Cacheable(key = "'paper-relation-index-' + #p0")
public Map<String, Object> getallpaper(String index) {
List<Map<String, String>> data = new ArrayList<>();
Expand Down Expand Up @@ -227,7 +229,7 @@ public Map<String, Object> getallpaper(String index) {
return result;

}

// 同上
@Cacheable(key = "'a-a-relation-index1-' + #p0 + '-index2-' + #p1")
public Map<String, Object> getallauandau(String index1, String index2) {
List<Map<String, String>> data = new ArrayList<>();
Expand Down Expand Up @@ -329,7 +331,7 @@ public Map<String, Object> getallauandau(String index1, String index2) {
result.put("links", links);
return result;
}

// 同上
@Cacheable(key = "'p-p-relation-index1-' + #p0 + '-index2-' + #p1")
public Map<String, Object> getallpaandpa(String index1, String index2) {
List<Map<String, String>> data = new ArrayList<>();
Expand Down Expand Up @@ -431,7 +433,7 @@ public Map<String, Object> getallpaandpa(String index1, String index2) {
result.put("links", links);
return result;
}

// 同上
@Cacheable(key = "'p-a-relation-index1-' + #p0 + '-index2-' + #p1")
public Map<String, Object> getallpaandpafour(String index1, String index2) {
List<Map<String, String>> data = new ArrayList<>();
Expand Down Expand Up @@ -533,7 +535,7 @@ public Map<String, Object> getallpaandpafour(String index1, String index2) {
result.put("links", links);
return result;
}

// 同上
@Cacheable(key = "'id-relation-index-' + #p0")
public Map<String, Object> getallid(Long index) {
List<Map<String, String>> data = new ArrayList<>();
Expand Down

0 comments on commit 8817d84

Please sign in to comment.