gremlin - 基于边排除顶点
问题描述
我有一个传统的社交媒体图表,其中用户发帖,其他用户评论该帖子,用户可以阻止其他用户。我正在尝试创建一个排除评论的遍历,其中评论用户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
)
)
这不起作用,但这是一般的想法。排除帖子所有者阻止评论者的评论。我怎样才能构造这个遍历?
解决方案
我修改了你的数据集,在帖子上有 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()
(它给出了用户对帖子的所有评论,来自未被阻止用户的评论者。)
推荐阅读
- oracle - 从规模很大(400 GB)的生产数据库创建测试数据库(包含所有数据)的最快方法是什么?
- graphql - GraphQL.NET 错误消息没有意义
- groovy - 如何在 groovy 脚本中格式化日期
- python - Python For循环卡住并且没有迭代
- angular - 升级到 Angular 8 后出现 Jasmine 错误
- javascript - 如何验证复选框是否被选中?
- javascript - 如何从选择列表中获取选定的值变量并将其分配为全局变量
- python - 如何指定输入类型函数
- google-cloud-firestore - Firestore 子集合 '!=' 查询
- public-key-encryption - 使用仅用于非商业用途的公钥加密数据是否违法?