1

I'm using Tinkerpop Frames to create a set of vertices and edges. Adding a new vertex is simple but retreiving vertices based on type seems a bit difficult.

Assume I have a class A and B and I want to add a new one so:

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

That's straight forward. But what if I want to retrieve all vertices with type A?

Doing this failed, because it returned all vertices (both A and B).

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

Is there any possible way to do this. I tried to check documentations and test cases with no luck. How can I retreive list of Vertices of type A only

Mohamed Taher Alrefaie
  • 15,698
  • 9
  • 48
  • 66
  • possible duplicate of [How to Find Vertices of Specific class with Tinkerpop Frames](http://stackoverflow.com/questions/29626160/how-to-find-vertices-of-specific-class-with-tinkerpop-frames) – Nick Grealy Apr 16 '15 at 23:08

1 Answers1

0

This question looks like it's a duplicate of - How to Find Vertices of Specific class with Tinkerpop Frames (also asked today).

As far as I understand, the Tinkerpop Frame framework acts as a wrapper class around a vertex. The vertex isn't actually stored as the interface class. As such, we need a way to identify the vertex as being of a particular type.

My solution, I added @TypeField and @TypeValue annotations to my Frame classes. Then I use these values to query my FramedGraph.

The documentation for these annotations can be found here: https://github.com/tinkerpop/frames/wiki/Typed-Graph

Example Code

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

Then define the FramedGraphFactory by adding TypedGraphModuleBuilder like this.

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

Then to retrieve vertices of type Person

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

I'm not sure this is the most efficient/succinct solution (I'd like to see what @stephen mallette suggests). It's not currently available, but it'd be logical to be able to do something like:

// framedGraph.getVertices(Person.class)
Community
  • 1
  • 1
Nick Grealy
  • 24,216
  • 9
  • 104
  • 119
  • Nick, I think you meant it's a duplicate of mine: http://stackoverflow.com/questions/29626160/how-to-find-vertices-of-specific-class-with-tinkerpop-frames/29639727#29639727 – Brian Dolan Apr 15 '15 at 19:34