Knowledge.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.seeckg.knowledgegraph_backend.pojo;
  2. import org.springframework.data.neo4j.core.schema.GeneratedValue;
  3. import org.springframework.data.neo4j.core.schema.Id;
  4. import org.springframework.data.neo4j.core.schema.Node;
  5. import lombok.Builder;
  6. import lombok.Data;
  7. import org.springframework.data.neo4j.core.schema.Relationship;
  8. import java.util.HashSet;
  9. import java.util.Set;
  10. @Node
  11. @Builder
  12. @Data
  13. public class Knowledge {
  14. @Id
  15. @GeneratedValue
  16. private Long id;
  17. /**
  18. * 绑定的课程id,0代表全局知识点
  19. */
  20. private long bindClassId;
  21. /**
  22. * 创建人id
  23. */
  24. private long creatorId;
  25. /**
  26. * 知识点名称
  27. */
  28. private String name;
  29. /**
  30. * 知识点内容
  31. */
  32. private String context;
  33. /**
  34. * Neo4j doesn't REALLY have bi-directional relationships. It just means when querying
  35. * to ignore the direction of the relationship.
  36. * https://dzone.com/articles/modelling-data-neo4j
  37. */
  38. //定义关系
  39. @Relationship(type = "DEFINE")
  40. public Set<Knowledge> define;
  41. public void defineRelationship(Knowledge knowledge) {
  42. if (define == null) {
  43. define = new HashSet<>();
  44. }
  45. define.add(knowledge);
  46. }
  47. //相似关系
  48. @Relationship(type = "SIMILAR")
  49. public Set<Knowledge> similar;
  50. public void similarRelationship(Knowledge knowledge) {
  51. if (similar == null) {
  52. similar = new HashSet<>();
  53. }
  54. similar.add(knowledge);
  55. }
  56. //子知识点关系
  57. @Relationship(type = "SUB")
  58. public Set<Knowledge> sub;
  59. public void subRelationship(Knowledge knowledge) {
  60. if (sub == null) {
  61. sub = new HashSet<>();
  62. }
  63. sub.add(knowledge);
  64. }
  65. }