首页 > 解决方案 > 基于边排除顶点

问题描述

我有一个传统的社交媒体图表,其中用户发帖,其他用户评论该帖子,用户可以阻止其他用户。我正在尝试创建一个排除评论的遍历,其中评论用户block与发布用户相比具有优势(发布用户已阻止评论用户,排除他们的评论)。

g.addV("user").as("poster")
.addV("post")
.addV("user").as("commenter")
.addV("comment")
.addE("post").from("poster").to("post")
.addE("comment").from("commenter").to("comment")
.addE("comment").from("comment").to("post")
.addE("block").from("poster").to("commenter")

这是据我所知,但没有编译:

g.V()
.hasLabel("comment")
.as("comment")
.not(
  __.in_("comment")
  .as("commenter")
  .select("comment")
  .where(
    __.out("comment")
    .in_("post")
    .out("block")
    .hasId(__.select("commentOwner").id()) // the poster is blocking the commenter
  )
)

这不起作用,但这是一般的想法。排除帖子所有者阻止评论者的评论。我怎样才能构造这个遍历?

标签: gremlinamazon-neptune

解决方案


我修改了你的数据集,在帖子上有 2 条评论。1 个来自被阻止的用户,1 个来自允许的用户。

(还更改了标签以更清楚地表示边缘标签中的动作)

g.addV("user").as("poster")
 .addV("post").as("post")
 .addV("user").as("commenter")
 .addV("user").property("name","user1").as("commenter1") # USERS

 .addV("comment").property("value", "commented by first user").as("comment")
 .addV("comment").property("value", "commented by second user").as("comment1") # COMMENTS

 .addE("posted").from("poster").to("post") 

 .addE("commentedBy").from("commenter").to("comment") 
 .addE("commentedBy").from("commenter1").to("comment1") 

 .addE("commentedOn").from("comment").to("post")
 .addE("commentedOn").from("comment1").to("post")

 .addE("block").from("poster").to("commenter")

那么下面的查询应该可以解决问题:

g.V().
 hasLabel("user").as("poster").
 out("posted").
 in("commentedOn").as("comments").
 not(in("commentedBy").in("block").where(eq("poster"))).
 valueMap()

(它给出了用户对帖子的所有评论,来自未被阻止用户的评论者。)


推荐阅读