【问题标题】:Can't make the pattern matching with a single gremlin statement无法使模式与单个 gremlin 语句匹配
【发布时间】:2013-03-26 19:55:30
【问题描述】:

我有一个依赖关系图:

dep1 -> dep2 -> ... -> dep3 -> ...
    |                   ^
    +-> dep4            |
    |                   |
    +-------------------+

我正在寻找不必要的依赖关系,这些依赖关系存在直接链接,但也存在通过子依赖关系的链接。在上面的例子中,链接“dep1 -> dep3”是不必要的。

找到这些的密码语句是:

start n = node(*)
match n -[:dependency]-> n2,
      n -[:dependency*2..]-> n2
 with n, n2
return distinct id(n), n.name, id(n2), n2.name

我试图用一个 gremlin 语句(使用“table”-step)来解决这个问题,但我就是无法让它工作。这甚至可能吗,还是我必须用多个语句来解决这个问题?

任何提示、提示、想法将不胜感激。

提前致谢

【问题讨论】:

    标签: neo4j cypher gremlin tinkerpop


    【解决方案1】:

    对于它的价值,这个问题在 gremlin-users 组中得到了讨论/回答:

    https://groups.google.com/forum/?fromgroups=&hl=en#!topic/gremlin-users/N9NYG-aBrvw

    【讨论】:

      【解决方案2】:

      感谢 Marko 和 Stephen,我们提出了这个解决方案:

      g.V.transform{
          s-> singleStep = [];
              s.as('origin')
                  .out('dependency').aggregate(singleStep)
                  .out('dependency')
                      .loop(1){ true }{ true }
                  .retain(singleStep).as('redundant')
                  .dedup()
                  .table(new Table(), ['origin', 'redundant']){ it.name + '(' + it.id + ')' }
                  .cap().next()
      }.filter{ it.size() > 0 }
      

      【讨论】:

        猜你喜欢
        • 2021-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-18
        • 1970-01-01
        • 2020-04-19
        • 2011-07-05
        相关资源
        最近更新 更多