【问题标题】:Bulbs : Creating "in" and "out" edges between two vertices in TitanDB灯泡:在 TitanDB 中的两个顶点之间创建“入”和“出”边
【发布时间】:2014-06-16 01:42:38
【问题描述】:

我正在使用 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

我想从我的 python 程序中对 Titan Graph DB 进行编程。我为此使用了灯泡包。

 from bulbs.titan import Graph
   g = Graph()


   vertex1  = g.vertices.get_or_create('dpid',dpid_str,{'state':'active','dpid':dpid_str,'type':'switch'}))
   vertex2  = g.vertices.get_or_create('desc',desc,{'desc':desc,'port_id':port_id,'state':state,'port_state':port_state,'number':number,'type':'port'}))

从示例中我了解如何在以下顶点之间创建边

 g.edges.create(vertex1,"out",vertex2)

但假设我的程序中没有对顶点的引用。

我想使用它的键“dpid”检索顶点 1 并且 我想使用它的键“desc”检索vertex2

然后使用检索到的值创建边缘。我该怎么做?

【问题讨论】:

标签: cassandra titan bulbs


【解决方案1】:

要通过索引属性(而不是其数据库 ID)检索顶点,您可以使用 Bulbs 内置索引方法之一:

>>> # returns an iterator (can return more than 1)
>>> vertices = g.vertices.index.lookup("dpid", dpid_str)   
>>> vertex1 = vertices.next()

>>> # returns 1 vertex or None (errors if more than 1)
>>> vertex2 = g.vertices.index.get_unique( "dpid", dpid_str)  

要创建边缘,只需执行...

>>> g.edges.create(vertex1, "out", vertex2)

注意:您不需要将边标记为“out”(“out”是指边的方向从顶点 1 出来并进入顶点 2)。您应该考虑使用更具描述性的标签。

看...

Rexter 索引文档:

index.lookup() https://github.com/espeed/bulbs/blob/afa28ccbacd2fb92e0039800090b8aa8bf2c6813/bulbs/titan/index.py#L251

index.get_unique() https://github.com/espeed/bulbs/blob/afa28ccbacd2fb92e0039800090b8aa8bf2c6813/bulbs/titan/index.py#L274

【讨论】:

    猜你喜欢
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 2017-04-03
    • 2014-08-28
    • 2019-07-27
    • 1970-01-01
    • 2016-04-07
    相关资源
    最近更新 更多