package com.seeckg.knowledgegraph_backend.pojo; import org.springframework.data.neo4j.core.schema.GeneratedValue; import org.springframework.data.neo4j.core.schema.Id; import org.springframework.data.neo4j.core.schema.Node; import lombok.Builder; import lombok.Data; import org.springframework.data.neo4j.core.schema.Relationship; import java.util.HashSet; import java.util.Set; @Node @Builder @Data public class Knowledge { @Id @GeneratedValue private Long id; /** * 绑定的课程id,0代表全局知识点 */ private long bindClassId; /** * 创建人id */ private long creatorId; /** * 知识点名称 */ private String name; /** * 知识点内容 */ private String context; /** * Neo4j doesn't REALLY have bi-directional relationships. It just means when querying * to ignore the direction of the relationship. * https://dzone.com/articles/modelling-data-neo4j */ //定义关系 @Relationship(type = "DEFINE") public Set define; public void defineRelationship(Knowledge knowledge) { if (define == null) { define = new HashSet<>(); } define.add(knowledge); } //相似关系 @Relationship(type = "SIMILAR") public Set similar; public void similarRelationship(Knowledge knowledge) { if (similar == null) { similar = new HashSet<>(); } similar.add(knowledge); } //子知识点关系 @Relationship(type = "SUB") public Set sub; public void subRelationship(Knowledge knowledge) { if (sub == null) { sub = new HashSet<>(); } sub.add(knowledge); } }