accessing subgraph vertices and edges

55 views
Skip to first unread message

Burak Arikan

unread,
Nov 23, 2012, 9:37:21 AM11/23/12
to pacer...@googlegroups.com
Hi Darrick, 

I am using pacer (1.1.1 java), pacer-neo4j (2.1.0 java) on jruby 1.7.0. 

In the past versions of Pacer there used to be vertices and edges method for subgraph, but now they seem to be gone... What are the new methods to access to vertices and edges in a generated subgraph? 

subgraph = friend.out_e('follows').in_v.out_e('follows').in_v.subgraph
=> #<PacerGraph tinkergraph[vertices:7 edges:8]
subgraph.vertices
NoMethodError: undefined method `vertices' for #<PacerGraph tinkergraph[vertices:7 edges:8]
from (irb):42:in `evaluate'
from org/jruby/RubyKernel.java:1065:in `eval'
from org/jruby/RubyKernel.java:1390:in `loop'
from org/jruby/RubyKernel.java:1173:in `catch'
from org/jruby/RubyKernel.java:1173:in `catch'
from /Users/arikan/.rvm/gems/jruby-1.7.0/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /Users/arikan/.rvm/gems/jruby-1.7.0/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /Users/arikan/.rvm/gems/jruby-1.7.0/gems/railties-3.2.8/lib/rails/commands.rb:41:in `(root)'
from org/jruby/RubyKernel.java:1019:in `require'
from script/rails:6:in `(root)'


Burak

Burak Arikan

unread,
Nov 23, 2012, 9:52:04 AM11/23/12
to pacer...@googlegroups.com
So I got it, subgraph.v and subgraph.e works to get the elements respectively. I guess longer methods removed for api consistency. 

Burak Arikan

unread,
Nov 23, 2012, 9:55:50 AM11/23/12
to pacer...@googlegroups.com
But inrelation to this question. The basic access to the id of the vertice is not the same as it used to be. 

subgraph.e[0].in_v.id
undefined method `id' for #<GraphE -> E-Range(0..0) -> inV>
from (irb):84:in `evaluate'
from org/jruby/RubyKernel.java:1065:in `eval'
from org/jruby/RubyKernel.java:1390:in `loop'
from org/jruby/RubyKernel.java:1173:in `catch'
from org/jruby/RubyKernel.java:1173:in `catch'
from /Users/arikan/.rvm/gems/jruby-1.7.0/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /Users/arikan/.rvm/gems/jruby-1.7.0/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /Users/arikan/.rvm/gems/jruby-1.7.0/gems/railties-3.2.8/lib/rails/commands.rb:41:in `(root)'
from org/jruby/RubyKernel.java:1019:in `require'
from script/rails:6:in `(root)'

subgraph.e[0].in_v[:id]
nil

Darrick Wiebe

unread,
Nov 23, 2012, 10:54:30 AM11/23/12
to Pacer Group
Hi Burak,

Try vertex.element_id or g.v.element_ids. It's the same for edges, too.

I changed it because the old one was causing me name conflicts.

Cheers,
Darrick

Burak Arikan

unread,
Nov 23, 2012, 11:54:00 AM11/23/12
to pacer...@googlegroups.com
hmm got it, so this works: 

subgraph.v.each {|n| puts n.element_id}

I think for API consistency this should work as well, it currently returns nil.

g.v.each {|n| puts n[:id]} 


Burak

Darrick Wiebe

unread,
Nov 23, 2012, 12:27:13 PM11/23/12
to Pacer Group
I'll give that some thought. It would be handy in some cases, but it's worth noting that in Neo4j and OrientDB, element IDs are implementation details that really shouldn't be messed with too much. For instance, in Neo4j, IDs are recycled if an element is deleted, while in Orient, ids are some sort of special object.

It actually bugs me a little bit that Blueprints reserves the id property from being used for modelling data and I'm actually tempted to work around that limitation in Pacer, rather than make id a special read-only property...

Darrick

Burak Arikan

unread,
Nov 23, 2012, 4:59:50 PM11/23/12
to pacer...@googlegroups.com
Now I got a different value type when using element_ids with an individual edge. Did not get the class value, how can we get the element id from it? Thanks.

>> subgraph.e[0].in_v.element_ids
"48"
Total: 1
=> #<GraphE -> E-Range(0..0) -> inV -> Obj(Java::ComTinkerpopGremlinPipesTransform::IdPipe)>

>> subgraph.e.to_a.each {|e| puts e.in_v.element_ids}
#<#<Class:0x4dbad3b1>:0x6bca69a5>
#<#<Class:0x4dbad3b1>:0x5e36ba3b>
#<#<Class:0x4dbad3b1>:0xc845640>
#<#<Class:0x4dbad3b1>:0x79b9048d>
#<#<Class:0x4dbad3b1>:0x55c8a526>
#<#<Class:0x4dbad3b1>:0xb2cfc7e>
#<#<Class:0x4dbad3b1>:0x3652ac26>
#<#<Class:0x4dbad3b1>:0x3636c89d>
=> [#<E[146]:57-follows-48>, #<E[147]:57-follows-55>, #<E[375]:96-follows-59>, #<E[148]:57-follows-53>, #<E[374]:96-follows-57>, #<E[376]:96-follows-55>, #<E[660]:142-follows-57>, #<E[661]:142-follows-96>]

Burak

Darrick Wiebe

unread,
Nov 23, 2012, 6:33:03 PM11/23/12
to Pacer Group
That's just because you're printing the routes rather than the values the routes would produce. The following should do the trick:

subgraph.e.to_a.each {|e| puts e.in_v.element_ids.to_a}

Cheers,
Darrick
Reply all
Reply to author
Forward
0 new messages