diff --git a/docs/GremlinAPI.md b/docs/GremlinAPI.md index f02d221..fcbf02d 100644 --- a/docs/GremlinAPI.md +++ b/docs/GremlinAPI.md @@ -52,11 +52,11 @@ For these examples, suppose we have the following graph: +-------+ +------+ | alice |----- ->| fred |<-- +-------+ \---->+-------+-/ +------+ \-+-------+ - ----->| #bob# | | | emily | + ----->| #bob# | | |*emily*| +---------+--/ --->+-------+ | +-------+ | charlie | / v +---------+ / +--------+ - \--- +--------+ | #greg# | + \--- +--------+ |*#greg#*| \-->| #dani# |------------>+--------+ +--------+ ``` @@ -66,7 +66,11 @@ Where every link is a "follows" relationship, and the nodes with an extra `#` in ``` dani -- status --> cool_person ``` -Perhaps these are the influencers in our community. +Perhaps these are the influencers in our community. So too are extra `*`s in the name -- these are our smart people, according to the `smart_graph` label, eg, the quad: +``` +greg status smart_person smart_graph . +``` + To load above graph into cayley and reproduce the following examples: @@ -193,6 +197,31 @@ g.V().Has("follows", "bob") g.V("charlie").Out("follows").Has("follows", "fred") ``` +####**`path.LabelContext([labelPath], [tags])`** + +Arguments: + + * `predicatePath` (Optional): One of: + * null or undefined: In future traversals, consider all edges, regardless of subgraph. + * a string: The name of the subgraph to restrict traversals to. + * a list of strings: A set of subgraphs to restrict traversals to. + * a query path object: The target of which is a set of subgraphs. + * `tags` (Optional): One of: + * null or undefined: No tags + * a string: A single tag to add the last traversed label to the output set. + * a list of strings: Multiple tags to use as keys to save the label used to the output set. + +Sets (or removes) the subgraph context to consider in the following traversals. Affects all In(), Out(), and Both() calls that follow it. The default LabelContext is null (all subgraphs) +Example: +```javascript +// Find the status of people Dani follows +g.V("dani").Out("follows").Out("status") +// Find only the statuses provided by the smart_graph +g.V("dani").Out("follows").LabelContext("smart_graph").Out("status") +// Find all people followed by people with statuses in the smart_graph. +g.V().LabelContext("smart_graph").In("status").LabelContext(null).In("follows") +``` + ### Tagging ####**`path.Tag(tag)`** diff --git a/query/gremlin/gremlin_test.go b/query/gremlin/gremlin_test.go index 1a1d1b8..44a548b 100644 --- a/query/gremlin/gremlin_test.go +++ b/query/gremlin/gremlin_test.go @@ -285,6 +285,13 @@ var testQueries = []struct { `, expect: []string{"smart_person"}, }, + { + message: "open and close a LabelContext", + query: ` + g.V().LabelContext("smart_graph").In("status").LabelContext(null).In("follows").All() + `, + expect: []string{"dani", "fred"}, + }, } func runQueryGetTag(g []quad.Quad, query string, tag string) []string {