如何根据关系的类型将路径分为子路径?

时间:2019-04-29 13:46:35

标签: neo4j cypher

我有以下图形:

(:Stop)<-[:IS_LOCATED_AT]-(:Stoptime)-[:IS_PART_OF]->(:Trip),
(:Stop)<-[:IS_LOCATED_AT]-(:Stoptime)-[:IS_PART_OF]->(:Trip)
(:Stop)-[:TRANSFER]->(:Stop)
(st1:Stoptime)-[:CONNECTION]->(st2:Stoptime)

:Stop具有属性stop_id

:Trip具有属性startValidDateendValidDatetripExceptions。此行程仅在某些工作日有效。这些天被表示为属性,例如:monday: true, sunday: false。每次旅行都有两个停止时间(出发和到达)。

:Stoptime可以具有以下属性: 如果停止时间是出发事件(例如st1),则:Stoptime具有属性depatureTine,在其他情况下,st :Stoptime optime具有属性arrivalTime

每个:Stoptime都有st_id

[:CONNECTION][:TRANSFER]具有属性duration

在以下查询中,我尝试找到两个:Stop之间的路径:

MATCH (o:Stop)<-[:IS_LOCATED_AT]-(sto:Stoptime)-[:IS_PART_OF]->(tro:Trip)
WHERE o.stop_id=1000001
AND tro.startValidDate<"2019-04-25"
AND tro.endValidDate>"2019-04-25"
AND NOT "2019-04-25" IN tro.tripExceptions
AND tro.thursday=true
WITH sto, o
MATCH (d:Stop)<-[:IS_LOCATED_AT]-(std:Stoptime)-[:IS_PART_OF]->(trd:Trip)
WHERE d.stop_id=1000004
AND trd.startValidDate<"2019-04-25"
AND trd.endValidDate>"2019-04-25"
WITH sto, std, o
MATCH p=((sto)-[*]-(std))
WHERE NOT o IN nodes(p)
AND NONE (y in relationships(p) WHERE type(y)="IS_PART_OF")
RETURN p

此查询效果很好。但是我必须检查路径中是否包含关系[:TRANSFER]的情况,下一次旅行对于到达日是否有效。

例如,查询后有路径:

path=((sta1:Stoptime)-[c:CONNECTION]->(sta2:Stoptime)-[:IS_LOCATED_AT]->(s1:Stop)-[t:TRANSFER]->(s2:Stop)<-[:IS_LOCATED_AT]-(std3:Stoptime)-[:CONNECTION]->(sta2:Stoptime))

具有:

(sta1:Stoptime)-[:IS_PART_OF]->(a:Trip)
(sta2:Stoptime)-[:IS_PART_OF]->(a:Trip)
(stb1:Stoptime)-[:IS_PART_OF]->(b:Trip)
(stb2:Stoptime)-[:IS_PART_OF]->(b:Trip)

路线从星期四开始。我必须检查:

if (x in relationships(path) WHERE type(z)="TRANSFER"):
    if (the sum of duration of all connections between previous stoptimes + duration of transfer > 24) AND (b.friday=true): return path
    else if (b.thursday=true): return path
else return null

我不知道该如何用Cypher编写代码。还是最好扔掉业务层中的所有路径并检查这种情况? 我认为,也许最好在传输之间将路径分为子路径?

0 个答案:

没有答案