简体   繁体   English

Neo4j中涉及3个NODES和1个RELATIONSHIP的域设计

[英]Domain design involving 3 NODES and 1 RELATIONSHIP in Neo4j

I need to design domain in neo4j for following use case 我需要在neo4j中为以下用例设计域

A PERSON can have many SKILLS . 一个人可以有很多技能。 PERSON can work in different Organizations . PERSON可以在不同的组织工作。 Each Organization can rank a Person on each SKILL they poses. 每个组织都可以在他们构成的每个技能上对一个人进行排名。 Now PersonA have SKILLS SkillA and SkillB . 现在PersonA具有技能SkillA和SkillB。 He work on TaskA which require SkillA in OrganizationA and TasKB which requires SkillA in OrganizationB . 他负责在OrganizationA中需要SkillA的TaskA和在OrganizationB中需要SkillA的TasKB。

How could I design above case in neo4j. 我如何在neo4j中设计以上案例。

What about this? 那这个呢?

(:Person), (:Organization), (:Skill), (:Ranking), (:Task)

(:Person)-[:works_at]->(:Organization)
(:Organization)-[:gives_ranking]->(:Ranking)
(:Ranking)-[:ranks_person {rank: value}]->(:Person)
(:Ranking)-[:for_skill]->(:Skill)
(:Person)-[:works_on]->(:Task)
(:Task)-[:requires_skill]->(:Skill)

In general, it depend on your queries. 通常,它取决于您的查询。 As I can imagine usage of your dataset structure, then I maybe choice something like that: 正如我可以想象的那样,您可以使用您的数据集结构,然后我可能会选择类似的内容:

(p:Person), (o:Organization), (s:Skill), (t:Task)
(p)-[:WORK_AT]->(o)
(p)-[:WORK_ON]->(t)
(p)-[:HAVE]->(s)
(t)-[:REQUIRE]->(s)
(t)-[:BELONGS_TO]->(o)

This totally depends on your use cases and what questions you're looking to answer from the graph. 这完全取决于您的用例以及您要从图中回答的问题。

As an example, take a look at the Recruitment GraphGist http://gist.neo4j.org/?0278fc6cbba43c4bf964 which models a subset of your data but from the perspective of recruitment. 例如,看看招聘GraphGist http://gist.neo4j.org/?0278fc6cbba43c4bf964 ,它从招聘的角度对数据的一部分进行了建模。

In order to properly answer this question, you really need to provide the types of queries that you want to make. 为了正确回答此问题,您确实需要提供要进行的查询的类型。 Many models are possible, but only some of them may be suitable for making your queries in a performant and/or elegant way. 可能有许多模型,但其中只有一些模型可能适合以高性能和/或优雅的方式进行查询。

Here is a sample model that may or may not suit your needs. 这是一个示例模型,可能会或可能不会满足您的需求。 It adds (to your stated requirements) a node for storing a person's own "claimed skill level" for each skill he says he has. 它(根据您所陈述的要求)添加了一个节点,用于存储一个人说自己拥有的每个技能的“要求的技能等级”。 This node allows multiple people to share a single :Skill node for each type of skill, while also providing a node per person/skill for the Organization's ratings ( :RATES ) relationships to point to. 该节点允许多个人为每种:Skill共享一个:Skill节点,同时还为要指向的组织的等级( :RATES )关系提供每人/每技能一个节点。

(:Person)-[:CLAIMS]->(:ClaimedSkillLevel {level:95})-[:FOR]->(:Skill {name: "Java"})<-[:REQURES]-(:Task)<-[:HAS_TASK]-(:Organization)
(:ClaimedSkillLevel)<-[:RATES {rating:75}]-(:Organization)
(:Person)-[:WORKED_ON]->(:Task)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM