Chain query

28 views
Skip to first unread message

Disruptive Solutions

unread,
Dec 3, 2016, 4:29:58 PM12/3/16
to Aurelius
Oke I have been filling TitanDB with nodes and edges. Now I want to find a related node or instance which is in distance 4+ from the primary node from which I am starting the search.

In SPARQL I just can use the + sign in the query to look beyond the 1st distance. How can I do this in Gremlin? I am using Java (API) to make Gremlin queries.

Thanks in advance.

Daniel Kuppitz

unread,
Dec 3, 2016, 9:03:20 PM12/3/16
to aureliu...@googlegroups.com
The following query will start at particular vertex, then traverse in both direction - preventing circular paths - and emit every vertex at depth 4+:

g.V(startNodeId).repeat(both().simplePath()).emit(loops().is(gte(4)))

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraphs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/d9d8e0ee-2dd9-4322-ae2f-7226cfa69850%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Disruptive Solutions

unread,
Dec 4, 2016, 6:33:41 AM12/4/16
to aureliu...@googlegroups.com
loops() is a own made method?

2016-12-04 3:03 GMT+01:00 Daniel Kuppitz <m...@gremlin.guru>:
The following query will start at particular vertex, then traverse in both direction - preventing circular paths - and emit every vertex at depth 4+:

g.V(startNodeId).repeat(both().simplePath()).emit(loops().is(gte(4)))

Cheers,
Daniel


On Sat, Dec 3, 2016 at 10:29 PM, Disruptive Solutions <disruptivesolutionsnl@gmail.com> wrote:
Oke I have been filling TitanDB with nodes and edges. Now I want to find a related node or instance which is in distance 4+ from the primary node from which I am starting the search.

In SPARQL I just can use the + sign in the query to look beyond the 1st distance. How can I do this in Gremlin? I am using Java (API) to make Gremlin queries.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraphs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/d9d8e0ee-2dd9-4322-ae2f-7226cfa69850%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Aurelius" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/aureliusgraphs/SkReOC3yV28/unsubscribe.
To unsubscribe from this group and all its topics, send an email to aureliusgraphs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/CA%2Bf9seXHcVVj-67kDKSYwfKx0O4%2BTvLkwYsesno6vMXyn-Q9_w%40mail.gmail.com.

Disruptive Solutions

unread,
Dec 4, 2016, 6:50:18 AM12/4/16
to Aurelius
<dependency>
                <groupId>org.apache.tinkerpop</groupId>
                <artifactId>gremlin-driver</artifactId>
                <version>3.0.2-incubating</version>
</dependency>

Does not have loops()

But when I use:
3.2.0-incubating loops() seems to be there but I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategy$VendorOptimizationStrategy
   
I use the "stable??"
<dependency>
            <groupId>com.thinkaurelius.titan</groupId>
            <artifactId>titan-cassandra</artifactId>
            <version>1.0.0</version>
         </dependency>
         <dependency>
            <groupId>com.thinkaurelius.titan</groupId>
            <artifactId>titan-es</artifactId>
            <version>1.0.0</version>
         </dependency>

Op zondag 4 december 2016 12:33:41 UTC+1 schreef Disruptive Solutions:

Daniel Kuppitz

unread,
Dec 4, 2016, 11:37:31 AM12/4/16
to aureliu...@googlegroups.com
You'll have to use a lambda in older version of TP:

g.V(startNodeId).repeat(both().simplePath()).emit {it.loops() >= 4}

Cheers,
Daniel


Disruptive Solutions

unread,
Dec 4, 2016, 2:35:31 PM12/4/16
to Aurelius
And it = iterator??

Op zondag 4 december 2016 17:37:31 UTC+1 schreef Daniel Kuppitz:
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Aurelius" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/aureliusgraphs/SkReOC3yV28/unsubscribe.
To unsubscribe from this group and all its topics, send an email to aureliusgraph...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.

Daniel Kuppitz

unread,
Dec 4, 2016, 3:35:10 PM12/4/16
to aureliu...@googlegroups.com
No, it = it. It's the current traverser. You can give "it" another name if you want:

g.V(startNodeId).repeat(both().simplePath()).emit {traverser -> traverser.loops() >= 4}

"it" is just the default name for single argument closures provided by Groovy.

Cheers,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraphs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/d094d8e1-d301-4458-abb0-8effe9f5c93c%40googlegroups.com.

Disruptive Solutions

unread,
Dec 4, 2016, 5:40:01 PM12/4/16
to Aurelius
Daniel... I am using Java to address the code below... so it wants to know the variable.

Op zondag 4 december 2016 21:35:10 UTC+1 schreef Daniel Kuppitz:

Daniel Kuppitz

unread,
Dec 4, 2016, 8:33:44 PM12/4/16
to aureliu...@googlegroups.com
So? Did that not work in 3.0.2?

g.V(startNodeId).repeat(both().simplePath()).emit(traverser -> traverser.loops() >= 4)

Cheers,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraphs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/88c59f88-6aae-410c-b2fb-9d88639ba547%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages