Turn a pair of edges into one edge?

45 views
Skip to first unread message

Adolfo Onasontisi

unread,
Jun 6, 2016, 11:56:46 PM6/6/16
to gremli...@googlegroups.com
In gremlin, how do I express this? I want to take the first case and turn it into the second:

A <-- friend -- B -- friend --> C

A <-- FOAF --> C

Thanks,
Adolfo

Daniel Kuppitz

unread,
Jun 7, 2016, 4:55:40 AM6/7/16
to gremli...@googlegroups.com
g.V().as("a").in("friend").out("friend").where(neq("a")).
  addE("DOAF").from("a"). // from A to C
  addE("FOAF").to("a")    // from C to A

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/CACRvbzNh6_LFdd9H8GnS5%2BS3Je98XUGV%2B5Qx_oxgOBZsgi59jA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Adolfo Onasontisi

unread,
Jun 8, 2016, 2:11:13 AM6/8/16
to gremli...@googlegroups.com
Thank you, but when I run this I get an error. I am using tinkerpop 3.0.1:

gremlin> g.V().as("a").in("friend").out("friend").where(neq("a")).addE("DOAF").from("a").addE("FOAF").to("a")

No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.addE() is applicable for argument types: (java.lang.String) values: [DOAF]

Possible solutions: any(), size(), any(groovy.lang.Closure), any(groovy.lang.Closure), join(java.lang.String), wait()

Display stack trace? [yN] y

groovy.lang.MissingMethodException: No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.addE() is applicable for argument types: (java.lang.String) values: [DOAF]

Possible solutions: any(), size(), any(groovy.lang.Closure), any(groovy.lang.Closure), join(java.lang.String), wait()

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:56)

at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)

at groovysh_evaluate.run(groovysh_evaluate:3)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at org.codehaus.groovy.tools.shell.Interpreter.evaluate(Interpreter.groovy:69)

at org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:185)

at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:119)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)

at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:130)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:150)

at org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:58)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:130)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:150)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:82)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at org.apache.tinkerpop.gremlin.console.Console.<init>(Console.groovy:144)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at org.apache.tinkerpop.gremlin.console.Console.main(Console.groovy:303)


Daniel Kuppitz

unread,
Jun 8, 2016, 6:00:20 AM6/8/16
to gremli...@googlegroups.com
Here are the 3.0.1 docs for the AddEdge step: http://tinkerpop.apache.org/docs/3.0.1-incubating/#addedge-step

g.V().as("a").in("friend").out("friend").where(neq("a")).addOutE("FOAF","a").addInE("FOAF","a")

Cheers,
Daniel



Adolfo Onasontisi

unread,
Jun 8, 2016, 2:01:23 PM6/8/16
to gremli...@googlegroups.com
Thanks, when I use that syntax, I get this error:

gremlin> g.V().as("a").in("friend").out("friend").where(neq("a")).addOutE("co_friend","a").addInE("co_friend","a")

10:59:54 WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [()]. For better performance, use indexes

com.thinkaurelius.titan.graphdb.relations.StandardEdge cannot be cast to org.apache.tinkerpop.gremlin.structure.Vertex

Display stack trace? [yN] y

java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.relations.StandardEdge cannot be cast to org.apache.tinkerpop.gremlin.structure.Vertex

at org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeStep.flatMap(AddEdgeStep.java:86)

at org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep.processNextStart(FlatMapStep.java:47)

at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:140)

at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:117)

at org.apache.tinkerpop.gremlin.console.Console$_closure3.doCall(Console.groovy:205)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:292)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)

at org.codehaus.groovy.tools.shell.Groovysh.setLastResult(Groovysh.groovy:441)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

Adolfo Onasontisi

unread,
Jun 8, 2016, 2:19:21 PM6/8/16
to gremli...@googlegroups.com
Ah, but I can do this:

g.V().as("a").in("friend").out("friend").where(neq("a")).addOutE("co_friend","a")
g.V().as("a").in("friend").out("friend").where(neq("a")).addInE("co_friend","a")
This is equivalent?

Adolfo Onasontisi

unread,
Jun 8, 2016, 4:12:46 PM6/8/16
to gremli...@googlegroups.com
Oh, and how do I commit these new edges so that they persist between gremlin sessions?

Daniel Kuppitz

unread,
Jun 8, 2016, 5:36:13 PM6/8/16
to gremli...@googlegroups.com
Ah, then it should be:

g.V().as("a").in("friend").out("friend").where(neq("a")).
  sideEffect(addOutE("co_friend","a")).
  sideEffect(addInE("co_friend","a"))

Cheers,
Daniel


Marko Rodriguez

unread,
Jun 8, 2016, 5:41:05 PM6/8/16
to gremli...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages