簡體   English   中英

Gremlin-如何計算具有特定屬性的頂點百分比

[英]Gremlin- How to compute percentage of vertices with a certain property

我試圖使用單個gremlin查詢來確定滿足某個謂詞的頂點的百分比,但是我在存儲和傳播計算值時遇到了麻煩。

假設我想計算具有標簽“A”的所有頂點的百分比,其具有帶有標簽“B”的傳出邊緣。 我可以打印出帶有標簽“A”的頂點數,以及在同一查詢中帶有標簽“B”的出口邊的頂點數:

g.V().limit(1).project("total","withEdgeB")
 .by(g.V().hasLabel("A").count())
 .by(g.V().hasLabel("A").match(__.as("a").outE("B").inV()).dedup().count())

這給了我兩個相關的值: totalwithEdgeB 如何使用這些值進行傳播和計算?

理想情況下,我想要這樣的東西:

g.V().limit(1).project("total","withEdgeB","percentage")
 .by(g.V().hasLabel("A").count().as("totalA"))
 .by(g.V().hasLabel("A").match(__.as("a").outE("B").inV()).dedup().count().as("totalWithEdgeB"))
 .by(totalWithEdgeB / totalA)

所以我的問題是,如何在第三個by()語句中訪問值totalAtotalWithEdgeB 或者我這樣做是錯的?

我會用一些簡單的計算。 使用現代圖形,找到具有傳出created邊緣的所有person頂點:

gremlin> g.V().hasLabel('person').
           choose(outE('created'),
                    constant(1),
                    constant(0)).fold().
           project('total','withCreated','percentage').
             by(count(local)).
             by(sum(local)).
             by(mean(local))
==>[total:4,withCreated:3,percentage:0.75]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM