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

查看:67
本文介绍了表示(和递增)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接口),因为先读后读-write是必需的.如果要根据传入的流数据更新图,则增加(而不是仅仅更新)是必要的.

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的关系.

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

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

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天全站免登陆