How does pacer handle traverse context?

12 views
Skip to first unread message

Pinyin

unread,
Mar 15, 2015, 5:31:57 AM3/15/15
to pacer...@googlegroups.com
Hi,

May I ask if it's possible to traverse a graph with context? 

I'm looking for a way to pass information to later steps during a traverse. Is there something like Neo4j's BranchState in Pacer?

Thanks for your help.

Darrick Wiebe

unread,
Mar 15, 2015, 12:22:39 PM3/15/15
to Pacer Group
Hi, there are multiple ways to provide forward context during a traversal. If you wish to filter on the current node or relationship that the traversal went through, you can use .as(:x) and later on use .is(:x) or .is_not(:x), which allows you to filter on the presence of a cycle in the graph. For other types of state, you can use a pair of blocks in the route. For instance, below we can select the first 10 attractions at each resort connected to vertex 1. 

count = 0
g.v(1).out(:resort).process { |v| count = 0 }.out(:attractions).filter { |v| count += 1; count < 10 }

Which is the same functionality as this:

g.v(1).out(:resort).as(:resort).out(:attractions).limit_section(10)

Hope that helps. If not then I might be able to be more helpful if you describe what you are trying to accomplish.

Enjoy!
Darrick


--
You received this message because you are subscribed to the Google Groups "pacer-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pacer-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

鲍博

unread,
Mar 15, 2015, 9:19:31 PM3/15/15
to pacer...@googlegroups.com
Hi,

I'm trying to store something similar to an abstract syntax tree and query against it to get simplest hints about where a symbol is defined.

For example, for the ruby codes 

class A
  def self.b

  end
end
A.b

I'm storing the follow graph:

(root)-[:defs]->('A')-[:defs]->('b')
    |
   +-->[:refs]->('A')-[:refs]->('b')

so when given the second ('b') vertex, my program should 

1 push ([:refs], ('b‘)) in an immutable stack S
2 push ([:refs], ('A')) into S
3 match S.top (which is ([:refs], ('A')) against ([:defs], ('A')). We found a pair of define/reference with the same identifier name so pop S and pass poped S to later step.
4 match S.top ([:refs], ('b')) against ([:defs], ('b')), pop S.  S is empty so we know A.b is defined in A.

Sorry for the long description. In short, I'm trying to traverse through a DAG while [1] keeping knowledge of previously visited vertices and edges in an immutable stack, [2]filter later steps according to this knowledge, and [3] occasionally pass a difference stack to deeper traversals.

I wasn't aware of the existene of the .process route operation before. It seems promising, can it be used to dynamically define sections? 

And, would I ask for some recommendations about my use case?

Thanks.



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

Darrick Wiebe

unread,
Mar 16, 2015, 12:54:20 AM3/16/15
to Pacer Group
Hi,

Because Pacer is built on stateless dataflow – rather than operating on a stack like in functional programming – I don't think it would be practical to do what you describe as a single traversal. It may be possible with mutable data structures, but I suspect it would become quite complex.

Darrick

鲍博

unread,
Mar 16, 2015, 3:25:05 AM3/16/15
to pacer...@googlegroups.com
Thanks, that's very clear.
Reply all
Reply to author
Forward
0 new messages