【问题标题】:edges.create() function causes duplication if called multiple times如果多次调用edges.create() 函数会导致重复
【发布时间】:2014-07-06 00:30:20
【问题描述】:

我正在使用 TitanGraphDB + Cassandra。我正在按如下方式启动 Titan

cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties

我有一个 Rexster shell,可以用来与上面的 Titan+Cassandra 通信。

cd rexster-console-2.3.0
bin/rexster-console.sh

我正在尝试使用 Titan Graph DB 对网络拓扑进行建模。我想从我的 python 程序中对 Titan Graph DB 进行编程。我正在为此使用灯泡包。 我创建了三种类型的顶点 - 转变 - 港口 - 设备

如果不存在,我使用以下函数创建唯一顶点。

    self.g.vertices.index.get_unique( "dpid", dpid_str)

    self.g.vertices.index.get_unique( "port_id", port_id_str)

    self.g.vertices.index.get_unique( "dl_addr", dl_addr_str)

我在相关顶点之间创建边,如下所示。

    self.g.edges.create(switch_vertex,"out",port_vertex)

但是,如果这个函数被调用两次,它会创建一个已经存在的边缘的副本。是否有一个类似于 get_or_create() 的函数用于边缘,这样我就可以避免重复。?

【问题讨论】:

    标签: titan bulbs


    【解决方案1】:

    一般来说,图允许顶点之间存在重复边,因为重复边的定义是不明确的并且是特定于应用程序的。

    例如,根据标签、方向或某些属性组合,边是否重复?

    但是,Titan 0.5 引入了Multiplicity.SIMPLE 约束,使您能够定义一对顶点之间的唯一边

    参见Matthias 的 Titan 0.5 公告:

    此新功能尚未记录,但 Titan 团队正在更新 Titan 0.5 的文档,因此很快就会记录下来。

    观看类型定义概述页面了解更新:

    另请参阅基数约束部分:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 2021-06-23
      • 2013-05-05
      • 1970-01-01
      相关资源
      最近更新 更多