首页 文章

Tinkerpop框架:根据接口类型查询顶点

提问于
浏览
1

我正在使用 Tinkerpop Frames 来创建一组顶点和边 . 添加新顶点很简单,但基于类型的后退顶点似乎有点困难 .

假设我有一个类 AB ,我想添加一个新的:

framedGraph.addVertex(null, A.class);
framedGraph.addVertex(null, B.class);

那是直截了当的 . 但是如果我想要检索类型为 A 的所有顶点呢?

这样做失败了,因为它返回了所有顶点( AB ) .

framedGraph.query().vertices(A.class);

有没有办法做到这一点 . 我试图检查文件和测试用例没有运气 . 如何仅检索 A 类型的顶点列表

1 回答

  • 0

    这个问题看起来像是重复的 - How to Find Vertices of Specific class with Tinkerpop Frames(今天也问过) .

    据我所知,Tinkerpop Frame框架充当顶点周围的包装类 . 顶点实际上并不存储为接口类 . 因此,我们需要一种方法来将顶点识别为特定的 type .

    我的解决方案,我在框架类中添加了 @TypeField@TypeValue 注释 . 然后我使用这些值来查询我的 FramedGraph .

    这些注释的文档可以在这里找到:https://github.com/tinkerpop/frames/wiki/Typed-Graph

    示例代码

    @TypeField("type")
    @TypeValue("person")
    interface Person extends VertexFrame { /* ... */ }
    

    然后通过添加 TypedGraphModuleBuilder 来定义 FramedGraphFactory .

    static final FramedGraphFactory FACTORY = new FramedGraphFactory(
        new TypedGraphModuleBuilder()
            .withClass(Person.class)
            //add any more classes that use the above annotations. 
            .build()
    );
    

    然后检索 Person 类型的顶点

    Iterable<Person> people = framedGraph.getVertices('type', 'person', Person.class);
    

    我不确定这是最有效/简洁的解决方案(我想看看@stephen mallette的建议) . 目前还没有,但能够做到这样的事情是合乎逻辑的:

    // framedGraph.getVertices(Person.class)
    

相关问题