创业网站搭建设计方案创可贴在线设计平台
创业网站搭建设计方案,创可贴在线设计平台,新手建设什么网站好,搜索推广网站哪家做的最好我一直在研究一个包含英国国家铁路时刻表的数据集#xff0c;它们以文本格式为您提供每列火车的出发和到达时间。 例如#xff0c;可以这样创建代表停止的节点#xff1a; CREATE (stop:Stop {arrival: 0802, departure: 0803H})该时间格式不是特… 我一直在研究一个包含英国国家铁路时刻表的数据集它们以文本格式为您提供每列火车的出发和到达时间。 例如可以这样创建代表停止的节点 CREATE (stop:Stop {arrival: 0802, departure: 0803H}) 该时间格式不是特别适合查询因此我想添加另一个属性该属性指示自一天开始以来的秒数。 因此我们想向节点添加“ arrivalSecondsSinceStartOfDay”和“ departureSecondsSinceStartOfDay”属性。 我编写了以下查询来计算这些属性的值。 MATCH (stop:Stop)
UNWIND [arrival, departure] AS keyWITH key,toInteger(substring(stop[key], 0, 2)) AS hours, toInteger(substring(stop[key], 2, 2)) AS minutes,CASE WHEN substring(stop[key], 4,1) H THEN 30 ELSE 0 END AS secondsWITH key, (hours * 60 * 60) (minutes * 60) seconds AS secondsSinceStartOfDayRETURN key SecondsSinceStartOfDay AS newKey, secondsSinceStartOfDay╒═══════════════════════════════╤══════════════════════╕
│newKey │secondsSinceStartOfDay│
╞═══════════════════════════════╪══════════════════════╡
│arrivalSecondsSinceStartOfDay │28920 │
├───────────────────────────────┼──────────────────────┤
│departureSecondsSinceStartOfDay│29010 │
└───────────────────────────────┴──────────────────────┘ 现在我们准备在“停止”节点上设置这些属性。 MATCH (stop:Stop2)
UNWIND [arrival, departure] AS keyWITH stop,key,toInteger(substring(stop[key], 0, 2)) AS hours, toInteger(substring(stop[key], 2, 2)) AS minutes,CASE WHEN substring(stop[key], 4,1) H THEN 30 ELSE 0 END AS secondsWITH stop, key, (hours * 60 * 60) (minutes * 60) seconds AS secondsSinceStartOfDay
WITH stop, key SecondsSinceStartOfDay AS newKey, secondsSinceStartOfDay
SET stop[newKey] secondsSinceStartOfDayInvalid input [: expected an identifier character, whitespace, {, node labels, a property map, a relationship pattern, ., (, or (line 12, column 9 (offset: 447))
SET stop[newKey] secondsSinceStartOfDay^ 嗯没有按预期工作 看起来我们还不能使用Cypher设置动态属性。 幸运的是我的同事Michael Hunger和Neo4j社区一直在管理APOC程序库并且该程序正是可以帮助我们的程序。 您需要下载适用于您的Neo4j版本的jar 然后将其放在plugins目录中。 我正在使用Neo4j 3.1 Beta1因此对我来说是这样的 $ tree neo4j-enterprise-3.1.0-BETA1/plugins/neo4j-enterprise-3.1.0-BETA1/plugins/
└── apoc-3.1.0.1-all.jar0 directories, 1 file 完成之后您将需要重新启动Neo4j以便它可以采用我们添加的新过程。 完成后执行以下查询以检查它们是否正确安装 call dbms.procedures()
YIELD name
WITH name
WHERE name STARTS WITH apoc
RETURN COUNT(*)╒════════╕
│COUNT(*)│
╞════════╡
│183 │
└────────┘ 现在我们准备在图中动态设置属性。 我们将使用的过程是apoc.create.setProperty 很容易更新查询以使用它 MATCH (stop:Stop)
UNWIND [arrival, departure] AS keyWITH stop,key,toInteger(substring(stop[key], 0, 2)) AS hours, toInteger(substring(stop[key], 2, 2)) AS minutes,CASE WHEN substring(stop[key], 4,1) H THEN 30 ELSE 0 END AS secondsWITH stop, key, (hours * 60 * 60) (minutes * 60) seconds AS secondsSinceStartOfDay
WITH stop, key SecondsSinceStartOfDay AS newKey, secondsSinceStartOfDay
CALL apoc.create.setProperty(stop, newKey, secondsSinceStartOfDay)Query cannot conclude with CALL (must be RETURN or an update clause) (line 12, column 1 (offset: 439))
CALL apoc.create.setProperty(stop, newKey, secondsSinceStartOfDay)^ 糟糕我讲得太早了 我们需要产生过程的return列并返回它或者只是返回一个计数来解决此问题 MATCH (stop:Stop)
UNWIND [arrival, departure] AS keyWITH stop,key,toInteger(substring(stop[key], 0, 2)) AS hours, toInteger(substring(stop[key], 2, 2)) AS minutes,CASE WHEN substring(stop[key], 4,1) H THEN 30 ELSE 0 END AS secondsWITH stop, key, (hours * 60 * 60) (minutes * 60) seconds AS secondsSinceStartOfDay
WITH stop, key SecondsSinceStartOfDay AS newKey, secondsSinceStartOfDay
CALL apoc.create.setProperty(stop, newKey, secondsSinceStartOfDay)
YIELD node
RETURN COUNT(*)╒════════╕
│COUNT(*)│
╞════════╡
│2 │
└────────┘ 就是这样我们现在可以在查询中动态设置属性。 翻译自: https://www.javacodegeeks.com/2016/10/neo4j-dynamically-add-propertyset-dynamic-property.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/87979.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!