1

TitanGraphDB + Cassandraを使用しています。次のようにTitanを起動しています

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

上記の Titan + Cassandra との通信に使用できる Rexster シェルがあります。

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」を使用して vertex1 を取得し、キー「desc」を使用して vertex2 を取得したい

そして、取得した値を使用して、エッジを作成したいと思います。これを行うにはどうすればよいですか?

4

1 に答える 1

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)

注: エッジに「アウト」というラベルを付ける必要はありません (「アウト」は、頂点 1 から出て頂点 2 に向かうエッジの方向によって暗示されます)。よりわかりやすいラベルの使用を検討する必要があります。

見る...

レクスターインデックスのドキュメント:

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

于 2014-06-17T19:36:40.807 に答える