使用Neo4j进行联系人跟踪-未识别某些人 [英] Contact Tracing Using Neo4j - Some people are not identified

查看:60
本文介绍了使用Neo4j进行联系人跟踪-未识别某些人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Neo4j开发联系人跟踪框架.有两种类型的节点,即 Person (人)和 Location (位置).人与位置之间存在已访问关系,该关系具有属性 startTS endTS .示例:

I am developing a contact tracing framework using Neo4j. There are 2 types of nodes, namely Person and Location. There exists a relationship VISITED between a Person and a Location, which has properties startTS and endTS. Example:

如果人员1 被感染,我需要使用图形数据库检索与他直接或间接联系的所有其他人员节点.我遍历所有通向人员节点的关系,并应用公式确定 当前人员 (人员2)是否同时存在于特定位置 以前的人 (人1).对识别出的所有人员节点重复此过程.在上图中,人员2根据其startTS和endTS与人员1进行了联系.这是我的代码:

If Person 1 is infected, I need to retrieve all other Person Nodes who have been in direct or indirect contact with him using the graph database. I loop through all the relationships leading to a person node and apply a formula to determine if the current person (Person 2) was present at a particular location at the same time as the previous person (Person 1). This process is repeated for all person nodes identified. In the above picture, person 2 was in contact with person 1 based on their startTS and endTS. Here is my code:

MATCH path =(infected:Person {id:'1'})-[*]-(otherPerson:Person)
WITH RELATIONSHIPS(path) as rels,otherPerson
WHERE all(i in range(1,size(rels)-1)  WHERE (rels[i].endTS >= rels[i-1].startTS AND rels[i].startTS<= rels[i-1].endTS))
RETURN otherPerson

在以下情况下,第1个人感染了第2个人,第2个人感染了第3个人.但是,即使第3个人明显与第2个人联系,该代码也没有将第3个人识别为受感染.赞赏.谢谢.

In the scenario below, person 1 infected person 2, and person 2 infected person 3. However, the code does not identify person 3 as infected, even though person 3 was clearly in contact with person 2. Any help will be greatly appreciated. Thanks.

推荐答案

您遍历关系并将每个关系的时间戳与其前身进行比较.但是,您只想比较两个人(人)-[:VISITED]-(位置)-[:VISITED]-(人)之间的 VISITED 关系.但是在您的方法中,您还要比较两个位置(Location)-[:VISITED]-(Person)-[:VISITED]-(Location)之间的关系.一个人不可能同时在两个地方.

You iterate over the relationships and compare the timestamps of each relationship with its predecessor. However, you only want to compare the VISITED relationships between two persons (Person)-[:VISITED]-(Location)-[:VISITED]-(Person). But in your approach, you are also comparing the relationships between two locations (Location)-[:VISITED]-(Person)-[:VISITED]-(Location). A person could not have been at two locations at the same time.

因此,您只想比较每两对关系.由于您使用的是索引,因此可以轻松使用模运算符,这样两个位置(或一个人)之间的关系对始终为真:

So, you want to compare only every second pair of relationships. Since your are using an index, you can easily use the modulo operator, such that a relationship pair between two locations (or with one person) is always true:

MATCH path = (infected:Person {id:'1'})-[*]-(otherPerson:Person)
WITH relationships(path) as rels, otherPerson
WHERE all(i in range(1, size(rels)-1)
  WHERE i % 2 = 0
  OR (rels[i].endTS >= rels[i-1].startTS AND rels[i].startTS <= rels[i-1].endTS)
)
RETURN otherPerson

这篇关于使用Neo4j进行联系人跟踪-未识别某些人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆