Gremlin/Janusgraph 中的多个顶点标签是否可能,或者是否有更好的替代解决方案?

Are multiple vertex labels in Gremlin/Janusgraph possible, or is an alternative solution better?

我正在为一个新的图形数据库导入 运行ner。

需要配合:

所以我正在创建实体 (Nodes/Verticies) 具有多种类型(标签)的图形,其中一些类型彼此正交,并且是多维的。

例如,表示在线订单的实体将被标记为 OrderOnlineSpendTransaction

             | Spend       Chargeback
----------------------------------------
 Transaction | Purchase    Refund
 Line        | Sale        Return

正在放大 Spend 列。

          | Online      Instore
----------------------------------------
 Purchase | Order       InstorePurchase
 Sale     | OnlineSale  InstoreSale 

在 Neo4j 及其 Cypher 查询语言中,这被证明对于跨多种类型创建 Relationships/Edges 非常强大,而无需明确知道图中的 transaction_id 值是什么:

MATCH (a:Transaction), (b:Line)
WHERE a.transaction_id = b.transaction_id
MERGE (a)<-[edge:TRANSACTED_IN]-(b)
RETURN count(edge);

问题是,Gremlin/Tinkerpop 本身不支持其 Verticies 的多个标签。

AWS Neptune will support this using a delimiter eg. Order::Online::Spend::Transaction and the Gremlin client does support it for a Neo4j server 这样的服务器实现,但我没能找到适用于 JanusGraph 的示例。

最终,我需要能够 运行 与上面的 Cypher 等效的 Gremlin 查询:

g
  .V().hasLabel("Line").as("b")
  .V().hasLabel("Transaction").as("a")
  .where("b", eq("a")).by("transaction_id")
  .addE("TRANSACTED_IN").from("b").to("a")';

所以这里有多个问题:

  1. 有没有办法让 JanusGraph 接受多个顶点标签?
  2. 如果不可能,或者这不是最好的方法,是否应该有一个包含标签列表的附加顶点属性?
  3. 对于选项2,标签名称应该是高级标签(Transaction)还是低级标签(Order)?

Is there a way to make JanusGraph accept multiple vertex labels?

不,JanusGraph 中没有办法拥有多个顶点标签。

If not possible, or this is not the best approach, should there be an additional vertex property containing a list of labels?

In the case of option 2, should the label name be the high-level label (Transaction) or the low-level label (Order)?

这两个我一起回答。根据您上面描述的内容,我将创建一个标签,可能名为 Transaction,并具有与之关联的不同属性,例如位置(在线或店内)和类型(购买、退款、Return、退款等。 ).看看你如何描述上面的问题,你实际上只在谈论一个单一的实体,一个交易,其中你用作标签的所有其他项目(Online/InStore,Spend/Refund)实际上只是关于如何的额外元数据该交易发生。因此,上述方法将允许对这些属性中的一个或多个进行简单过滤,以实现您在 Neo4j 中使用的多个标签可以完成的任何事情。