在 Neo4j 中表示(和递增)关系强度 [英] Representing (and incrementing) relationship strength in Neo4j

查看:17
本文介绍了在 Neo4j 中表示(和递增)关系强度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想表示 Neo4j 图中节点之间关系的变化强度.

I would like to represent the changing strength of relationships between nodes in a Neo4j graph.

对于静态图,这可以通过在关系上设置强度"属性来轻松完成:

For a static graph, this is easily done by setting a "strength" property on the relationship:

  A --knows--> B
       |
     strength
       |
       3

然而,对于需要随时间更新的图形,存在一个问题,因为递增属性的值不能以原子方式(通过 REST 接口)完成,因为自读之前- 写是必需的.如果为了响应传入的流数据而更新图形,则需要递增(而不仅仅是更新).

However, for a graph that needs updating over time, there is a problem, since incrementing the value of the property can't be done atomically (via the REST interface) since a read-before-write is required. Incrementing (rather than merely updating) is necessary if the graph is being updated in response to incoming streamed data.

我要么需要确保一次只有一个 REST 客户端读取和写入(外部同步),要么只使用嵌入式 API,以便我可以使用内置事务.这可能可行,但看起来很尴尬.

I would need to either ensure that only one REST client reads and writes at once (external synchronization), or stick to only the embedded API so I can use the built-in transactions. This may be workable but seems awkward.

另一种解决方案可能是记录多个关系,没有任何属性,因此强度"实际上是关系的计数,即

One other solution might be to record multiple relationships, without any properties, so that the "strength" is actually the count of relationships, i.e.

A knows B
A knows B
A knows B

表示强度为 3 的关系.

means a relationship of strength 3.

  • 缺点:只能记录整数强度
  • 优点:不需要先读后写
  • 缺点:(可能)需要更多存储空间
  • 缺点:(可能)提取值要慢得多,因为必须提取和计算多个关系

有没有人尝试过这种方法,它是否可能遇到性能问题,尤其是在阅读时?

Has anyone tried this approach, and is it likely to run into performance issues, particularly when reading?

有没有更好的方法来建模?

Is there a better way to model this?

推荐答案

好主意.为了减少存储和多次读取,可以将这些关系聚合为以事务方式运行的批处理作业中的一个.

Nice idea. To reduce storage and multi-reads those relationships could be aggregated to one in a batch job which runs transactionally.

每个 rel 还可以携带一个单独的权重值,其聚合值用作权重.它不必是基于整数的,也可以是负数来表示递减.

Each rel could also carry an individual weight value, whose aggregated value is used as weight. It doesn't have to be integer based and could also be negative to represent decrements.

您还可以编写一个小的服务器扩展,用于以事务方式更新单个关系的权重值.甚至可能对 REST API 有意义(因为除了设置单值"操作之外还有一个修改单值操作.

You could also write a small server-extension for updating a weight value on a single relationship transactionally. Would probably even make sense for the REST API (as addition to the "set single value" operation have a modify single value operation.

PUT http://localhost:7474/db/data/node/15/properties/mod/foo 

主体包含增量值 (1.5, -10).另一个想法是将 mode 关键字替换为实际操作.

The body contains the delta value (1.5, -10). Another idea would be to replace the mode keyword by the actual operation.

PUT http://localhost:7474/db/data/node/15/properties/add/foo 
PUT http://localhost:7474/db/data/node/15/properties/or/foo 
PUT http://localhost:7474/db/data/node/15/properties/concat/foo 

在非整数情况下,增量"是什么意思?

What would "increment" mean in a non integer case?

这篇关于在 Neo4j 中表示(和递增)关系强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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