How to get only incoming edges using Gremiln-Java

761 views
Skip to first unread message

Raja sankar

unread,
Jan 10, 2015, 1:01:20 PM1/10/15
to gremli...@googlegroups.com
Hi,

I want to get only incoming edges using Gremiln-Java. 

My Sample code is

OrientGraph graph = new OrientGraph("local:/data/test/");
GremlinPipeline<Iterable<Vertex>, Vertex> pipe = new GremlinPipeline<>();
pipe.start(graph.getVertices()).in("a");


In this how do I add a filter for only incoming edges?

Thanks
Rajasankar

Daniel Kuppitz

unread,
Jan 11, 2015, 12:26:48 PM1/11/15
to gremli...@googlegroups.com
Hi Raja,

not sure if this is what you're asking for, but if you just want the edges instead of the adjacent vertices, simply do this:

pipe.start(graph.getVertices()).inE("a");

Cheers,
Daniel

Raja sankar

unread,
Jan 11, 2015, 1:21:47 PM1/11/15
to gremli...@googlegroups.com
Hi Daniel, 

Thanks for the tip. I think, I havent explained my usecase completely. Sorry for that. 

I have the relationships like the below,

1->a->2
3->a->2
4->a->5
7->a->4

Here, 1, 3, 7,5 are unidirectional where as 2,4 are bidirectional. I need only 1,3,7,5. 1,3,7 has outgoing edges where as 5 has incoming edge. 

Is this possible? 

I am newbie to graphdb so sorry the wrong explanation before. 

Thanks for your help. 

Rajasankar


Daniel Kuppitz

unread,
Jan 11, 2015, 1:44:52 PM1/11/15
to gremli...@googlegroups.com
Sorry, but I still don't get it. Why is 2 bidirectional? Because it has 2 incoming edges? Maybe I should just show you a few examples and you pick the one you need.

Init sample graph:

gremlin> g = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]
gremlin> v1 = g.addVertex(1)
==>v[1]
gremlin> v2 = g.addVertex(2)
==>v[2]
gremlin> v3 = g.addVertex(3)
==>v[3]
gremlin> v4 = g.addVertex(4)
==>v[4]
gremlin> v5 = g.addVertex(5)
==>v[5]
gremlin> v7 = g.addVertex(7)
==>v[7]
gremlin> v1.addEdge("a", v2)
==>e[0][1-a->2]
gremlin> v3.addEdge("a", v2)
==>e[1][3-a->2]
gremlin> v4.addEdge("a", v5)
==>e[2][4-a->5]
gremlin> v7.addEdge("a", v4)
==>e[3][7-a->4]

Find vertices with only incoming edges:

gremlin> g.V().filter { !it.outE().hasNext() }
==>v[2]
==>v[5]

Find vertices with only outgoing edges:

gremlin> g.V().filter { !it.inE().hasNext() }
==>v[1]
==>v[3]
==>v[7]

Find vertices with at most 1 edge on any side:

gremlin> g.V().filter { it.bothE().count() == 1 }
==>v[1]
==>v[3]
==>v[5]
==>v[7]

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/b7c5965b-675b-4d7a-902b-3c9223d01f73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raja sankar

unread,
Jan 12, 2015, 2:03:49 PM1/12/15
to gremli...@googlegroups.com
Hi Daniel, 

This is exactly I need. Thanks for the gremlin query. However, I am stuck in converting that Java. 

I have looked at the examples these links but couldn't find any 

http://www.programcreek.com/java-api-examples/index.php?api=com.tinkerpop.gremlin.java.GremlinPipeline

http://stackoverflow.com/questions/9068657/two-questions-on-pipefunctions-using-gremlin-java-api

I think the Java API changed too. 

pipe.start(graph.getVetices())
.filter(new PipeFunction<Iterable<Vertex>,Boolean>(){
     public Boolean compute(Iterable<Vertex> i){
       ???
}
});

How do I put the condition !it.outE().hasNext() inside the function? 

Thanks again for your help. 

Daniel Kuppitz

unread,
Jan 12, 2015, 4:37:33 PM1/12/15
to gremli...@googlegroups.com
You can find the aforementioned samples converted to Java here: https://gist.github.com/dkuppitz/d2e3f30a9c3cd0efde60

Cheers,
Daniel

kurtuluş yılmaz

unread,
Feb 23, 2015, 8:20:39 AM2/23/15
to gremli...@googlegroups.com
Hi all;
I am new to Gremlin and Titan;
I searched at internet for one concrete example java startup project with titan and Gremlin but I did not succeed. 
Can you share me one example Java project.
Best Regards.


10 Ocak 2015 Cumartesi 20:01:20 UTC+2 tarihinde Raja sankar yazdı:

Bob B

unread,
Feb 23, 2015, 10:34:07 AM2/23/15
to gremlin-users
https://github.com/thinkaurelius/titan-web-example

This is a web-app so it might be more than you need but it still has the stuff to get you started. 

Bob

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

Jian Fang

unread,
Jun 4, 2015, 6:45:06 AM6/4/15
to gremli...@googlegroups.com

Hi Daniel,

I ran your sample code in Gremlin . I had two problems when running this code.
1) g.addVertex(1) didn't work. Reports indicated that I should provide Key/value. So I changed it to g.addVertex(id,1), and it works.
2) g.V().filter { !it.outE().hasNext() } didn't work either. It gave an error as follow.

gremlin> g = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]

gremlin
> v1 = g.addVertex(id,1)
==>v[1]
gremlin
> v2 = g.addVertex(id,2)
==>v[2]
gremlin
> v3 = g.addVertex(id,3)
==>v[3]
gremlin
> v4 = g.addVertex(id,4)
==>v[4]
gremlin
> v5 = g.addVertex(id,5)
==>v[5]
gremlin
> v7 = g.addVertex(id,7)

==>v[7]
gremlin
> v1.addEdge("a", v2)
==>e[0][1-a->2]
gremlin
> v3.addEdge("a", v2)
==>e[1][3-a->2]
gremlin
> v4.addEdge("a", v5)
==>e[2][4-a->5]
gremlin
> v7.addEdge("a", v4)
==>e[3][7-a->4]

gremlin
> g.V().filter { !it.outE().hasNext() }
No signature of method: com.tinkerpop.gremlin.process.traversers.SimpleTraverser.outE() is applicable for argument types: () values: []
Possible solutions: use([Ljava.lang.Object;), use(java.util.List, groovy.lang.Closure), use(java.lang.Class, groovy.lang.Closure), bulk(), get(), path()


Is it caused by the update of the gremlin? I can't find a right document of 3.0.0.M6. Could you please help to solve this? Thanks.

Regard,
Jian

在 2015年1月11日星期日 UTC+1下午7:44:52,Daniel Kuppitz写道:

Daniel Kuppitz

unread,
Jun 4, 2015, 7:02:56 AM6/4/15
to gremli...@googlegroups.com
This was a TP2 question initially. We shouldn't mix up TP2 and TP3 in one question, it's confusing enoughto deal with both versions on the same list.

Anyway, what you're looking for is this:

g.V().has(outE().count().is(0L)) // in M6
g.V().where(not(outE()))         // in the current snapshot

Please start a new thread if you have more TP3 related questions.

Cheers,
Daniel


green

unread,
Nov 25, 2016, 1:25:16 PM11/25/16
to Gremlin-users
g.V().where(not(outE())) is not working for me. any help is much appreciated

gremlin> Gremlin.version()
==>3.0.2-incubating

gremlin> g.V().where(not(outE()))
No signature of method: static org.apache.tinkerpop.gremlin.process.traversal.P.not() is applicable for argument types: (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) values: [[VertexStep(OUT,edge)]]
Possible solutions: not(org.apache.tinkerpop.gremlin.process.traversal.P), gt(java.lang.Object), lt(java.lang.Object), neq(java.lang.Object), or(java.util.function.Predicate), notify()
Display stack trace? [yN]
Reply all
Reply to author
Forward
0 new messages