グラフと探索に関するプロパティの検出

グラフおよび探索についての単純な情報を検出します。

スキーマとデータをグラフに挿入したら、情報が正しいことを確認することが重要です。挿入したデータに関する単純な情報の確認は、探索を開始するのに良い方法です。graph.schema()呼び出しは、グラフでのデータの保存方法の確認に使用できます。

手順

  • グラフ探索インスタンスgを使用して頂点の数を確認することにより、データが読み込まれたかどうかを確認します。このコマンドは、以下に示したすべての探索コマンドと同様に、Gremlin Serverに対するリモートのコマンドであることに注意してください。
    g.V().count()
    ==>56
  • 読み込んだ頂点のプロパティを確認します。nameの値がJulia Childである頂点のすべての情報を見つけます。
    g.V().has('name','Julia Child').valueMap()
    ==>{gender=[F], name=[Julia Child]}

  • 読み込んだ辺のプロパティを確認します。ratedというラベルが付いた辺のすべての情報を見つけます。
    g.E().hasLabel('rated').values()
    ==>5
    ==>Pretty tasty!
    ==>2014-01-01T00:00:00Z
  • 頂点のID情報を見つけます。
    g.V().hasLabel('FridgeSensor').id()
    ==>{~label=FridgeSensor, sensor_id=93c4ec9b-68ff-455e-8668-1056ebc3689f, city_id=santaCruz}
    ==>{~label=FridgeSensor, sensor_id=9c23b683-1de2-4c97-a26a-277b3733732a, city_id=sacramento}
    ==>{~label=FridgeSensor, sensor_id=eff4a8af-2b0d-4ba9-a063-c170130e2d84, city_id=sacramento}
  • describe()ステップを使用してスキーマ情報を見つけます。この探索ステップにより、後述の代替方法と同じ情報をソートしたリストが提供されます。
    schema.describe()
    ==>schema.propertyKey("member_id").Smallint().single().create()
    schema.propertyKey("instructions").Text().single().create()
    schema.propertyKey("amount").Text().single().create()
    schema.propertyKey("gender").Text().single().create()
    schema.propertyKey("year").Int().single().create()
    schema.propertyKey("calories").Int().single().create()
    schema.propertyKey("stars").Int().single().create()
    schema.propertyKey("community_id").Int().single().create()
    schema.propertyKey("ISBN").Text().single().create()
    schema.propertyKey("name").Text().single().create()
    schema.propertyKey("comment").Text().single().create()
    schema.propertyKey("timestamp").Timestamp().single().create()
    schema.edgeLabel("authored").multiple().create()
    schema.edgeLabel("rated").multiple().properties("timestamp", "stars", "comment").create()
    schema.edgeLabel("includedIn").multiple().create()
    schema.edgeLabel("created").multiple().properties("year").create()
    schema.edgeLabel("includes").multiple().properties("amount").create()
    schema.vertexLabel("meal").properties("name", "timestamp", "calories").create()
    schema.vertexLabel("ingredient").properties("name").create()
    schema.vertexLabel("author").properties("name", "gender").create()
     schema.vertexLabel("book").properties("name", "year", "ISBN").create()
     schema.vertexLabel("recipe").properties("name", "instructions").create()
    schema.vertexLabel("reviewer").properties("name").create()
    schema.edgeLabel("authored").connection("author", "book").connection("book", "author").add()
    schema.edgeLabel("rated").connection("recipe", "reviewer").connection("reviewer", "recipe").add()
    schema.edgeLabel("includedIn").connection("meal", "recipe").connection("meal", "book").connection("book", "recipe").connection("book", "meal").connection("recipe", "book").connection("recipe", "meal").add()
    schema.edgeLabel("created").connection("author", "recipe").connection("recipe", "author").add()
    schema.edgeLabel("includes").connection("ingredient", "recipe").connection("recipe", "ingredient").add()
    gremlin> schema.edgeLabel('includes').describe()
    ==>schema.edgeLabel("includes").multiple().properties("amount").create()
    schema.edgeLabel("includes").connection("ingredient", "recipe").connection("recipe", "ingredient").add()
    gremlin> schema.vertexLabel('author').describe()
    ==>schema.vertexLabel("author").properties("name", "gender").create()
  • このスキーマ情報の検出方法の代わりに、探索時にvalueMap()ステップを使用する方法があります。
    schema.traversal().V().valueMap()
    ==>{mode=[Development]}
    ==>{name=[author]}
    ==>{name=[recipe]}
    ==>{name=[ingredient]}
    ==>{name=[book]}
    ==>{name=[meal]}
    ==>{name=[reviewer]}
    ==>{name=[byName], type=[Secondary]}
    ==>{name=[includedIn], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{name=[fridgeItem_single]}
    ==>{name=[rated], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{name=[fridgeItem_multiple]}
    ==>{dataType=[Timestamp], name=[timestamp], cardinality=[Single]}
    ==>{dataType=[Text], name=[ISBN], cardinality=[Single]}
    ==>{dataType=[Text], name=[category], cardinality=[Single]}
    ==>{name=[byLocation]}
    ==>{dataType=[Int], name=[year], cardinality=[Single]}
    ==>{name=[ratedByStars], directionality=[OUT]}
    ==>{dataType=[Text], name=[gender], cardinality=[Single]}
    ==>{unique=[false], name=[byIngredient], type=[Materialized]}
    ==>{dataType=[Text], name=[instructions], cardinality=[Single]}
    ==>{unique=[false], name=[byReviewer], type=[Materialized]}
    ==>{unique=[false], name=[byRecipe], type=[Materialized]}
    ==>{unique=[false], name=[byMeal], type=[Materialized]}
    ==>{dataType=[Int], name=[stars], cardinality=[Single]}
    ==>{dataType=[Text], name=[comment], cardinality=[Single]}
    ==>{dataType=[Int], name=[calories], cardinality=[Single]}
    ==>{dataType=[Text], name=[blah], cardinality=[Single]}
    ==>{dataType=[Text], name=[amount], cardinality=[Single]}
    ==>{name=[created], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{name=[includes], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{dataType=[Bigint], name=[member_id], cardinality=[Single]}
    ==>{name=[authored], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{dataType=[Text], name=[country], cardinality=[Multiple]}
    ==>{dataType=[Text], name=[item_mult], cardinality=[Multiple]}
    ==>{dataType=[Int], name=[community_id], cardinality=[Single]}
    ==>{dataType=[Text], name=[livedIn], cardinality=[Single]}
    ==>{dataType=[Text], name=[item_single], cardinality=[Single]}
    ==>{dataType=[Text], name=[name], cardinality=[Single]}
  • valueMap()valueMap(true)に変えると、各フィールドのIDが追加されます。
    graph.schema().traversal().V().valueMap(true)
    ==>{mode=[Development], id=0, label=schema}
    ==>{id=129, label=incident}
    ==>{id=133, label=incident}
    ==>{id=73, label=incident}
    ==>{id=137, label=incident}
    ==>{id=77, label=incident}
    ==>{id=141, label=incident}
    ==>{id=32784, dataType=[Text], name=[comment], label=propertyKey, cardinality=[Single]}
    ==>{id=32782, name=[rated], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=32783, dataType=[Int], name=[stars], label=propertyKey, cardinality=[Single]}
    ==>{id=85, label=incident}
    ==>{id=149, label=incident}
    ==>{id=32780, dataType=[Timestamp], name=[timestamp], label=propertyKey, cardinality=[Single]}
    ==>{id=32781, dataType=[Int], name=[calories], label=propertyKey, cardinality=[Single]}
    ==>{id=32769, dataType=[Smallint], name=[member_id], label=propertyKey, cardinality=[Single]}
    ==>{id=94, label=incident}
    ==>{id=32767, dataType=[Int], name=[community_id], label=propertyKey, cardinality=[Single]}
    ==>{id=98, label=incident}
    ==>{id=108, label=incident}
    ==>{id=32775, name=[authored], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=112, label=incident}
    ==>{id=32776, name=[created], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=1, name=[author], label=vertexLabel}
    ==>{id=32773, dataType=[Text], name=[ISBN], label=propertyKey, cardinality=[Single]}
    ==>{id=2, name=[book], label=vertexLabel}
    ==>{id=32774, dataType=[Text], name=[instructions], label=propertyKey, cardinality=[Single]}
    ==>{id=3, name=[recipe], label=vertexLabel}
    ==>{id=32771, dataType=[Text], name=[gender], label=propertyKey, cardinality=[Single]}
    ==>{id=4, name=[ingredient], label=vertexLabel}
    ==>{id=116, label=incident}
    ==>{id=32772, dataType=[Int], name=[year], label=propertyKey, cardinality=[Single]}
    ==>{id=5, name=[meal], label=vertexLabel}
    ==>{id=6, name=[reviewer], label=vertexLabel}
    ==>{id=32770, dataType=[Text], name=[name], label=propertyKey, cardinality=[Single]}
    ==>{id=32779, name=[includedIn], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=125, label=incident}
    ==>{id=32777, name=[includes], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=32778, dataType=[Text], name=[amount], label=propertyKey, cardinality=[Single]}
  • traversal()を実行すると、頂点および辺に存在するスキーマ要素の数、およびTraversalSourceタイプに関する情報が提供されます。
    schema.traversal()
    ==>graphtraversalsource[tinkergraph[vertices:58 edges:106], standard]
  • ユーティリティsplit()およびgrep()を使用したすべての頂点ラベルのリスト。
    schema.describe().split('\n').grep(~/.*vertexLabel.*/)
    gremlin> schema.describe().split('\n').grep(~/.*vertexLabel.*/)
    ==>schema.vertexLabel("meal").properties("name", "timestamp", "calories").create()
    ==>schema.vertexLabel("ingredient").properties("name").create()
    ==>schema.vertexLabel("ingredient").index("byIngredient").materialized().by("name").add()
    ==>schema.vertexLabel("test").partitionKey("tester").clusteringKey("foor").create()
    ==>schema.vertexLabel("FridgeSensor").create()
    ==>schema.vertexLabel("author").properties("name", "gender", "nationality").create()
    ==>schema.vertexLabel("author").index("byName").secondary().by("name").add()
    ==>schema.vertexLabel("author").index("byAuthor").materialized().by("name").add()
    ==>schema.vertexLabel("FridgeItem").properties("name", "expiration_date", "amount").create()
    ==>schema.vertexLabel("book").properties("name", "year", "ISBN").create()
    ==>schema.vertexLabel("recipe").properties("name", "instructions").create()
    ==>schema.vertexLabel("recipe").index("byRecipe").materialized().by("name").add()
    ==>schema.vertexLabel("reviewer").properties("name").create()
    ==>schema.vertexLabel("reviewer").index("byReviewer").materialized().by("name").add()
    ==>schema.vertexLabel("reviewer").index("ratedByStars").outE("rated").by("stars").add()
  • 現在のグラフ名を取得します。
    graph.name()
    ==>quickstart