Gizmo API
The graph
object
graph
objectName: graph
, Alias: g
This is the only special object in the environment, generates the query objects. Under the hood, they're simple objects that get compiled to a Go iterator tree when executed.
graph.addDefaultNamespaces()
graph.addDefaultNamespaces()
AddDefaultNamespaces register all default namespaces for automatic IRI resolution.
graph.addNamespace(pref, ns)
graph.addNamespace(pref, ns)
AddNamespace associates prefix with a given IRI namespace.
graph.emit(*)
graph.emit(*)
Emit adds data programmatically to the JSON result list. Can be any JSON type.
graph.loadNamespaces()
graph.loadNamespaces()
LoadNamespaces loads all namespaces saved to graph.
graph.M()
graph.M()
M is a shorthand for Morphism.
graph.Morphism()
graph.Morphism()
Morphism creates a morphism path object. Unqueryable on it's own, defines one end of the path. Saving these to variables with
is the common use case. See also: path.follow(), path.followR().
graph.IRI(s)
graph.IRI(s)
Uri creates an IRI values from a given string.
graph.V(*)
graph.V(*)
V is a shorthand for Vertex.
graph.Vertex([nodeId],[nodeId]...)
graph.Vertex([nodeId],[nodeId]...)
Vertex starts a query path at the given vertex/vertices. No ids means "all vertices".
Arguments:
nodeId
(Optional): A string or list of strings representing the starting vertices.
Returns: Path object
Path object
Both .Morphism()
and .Vertex()
create path objects, which provide the following traversal methods. Note that .Vertex()
returns a query object, which is a subclass of path object.
For these examples, suppose we have the following graph:
Where every link is a <follows>
relationship, and the nodes with an extra #
in the name have an extra <status>
link. As in,
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:
path.all()
path.all()
All executes the query and adds the results, with all tags, as a string-to-string (tag to node) map in the output set, one for each path that a traversal could take.
path.and(path)
path.and(path)
And is an alias for Intersect.
path.as(tags)
path.as(tags)
As is an alias for Tag.
path.back([tag])
path.back([tag])
Back returns current path to a set of nodes on a given tag, preserving all constraints.
If still valid, a path will now consider their vertex to be the same one as the previously tagged one, with the added constraint that it was valid all the way here. Useful for traversing back in queries and taking another route for things that have matched so far.
Arguments:
tag
: A previous tag in the query to jump back to.
Example:
path.both([predicatePath], [tags])
path.both([predicatePath], [tags])
Both follow the predicate in either direction. Same as Out or In.
Example:
path.count()
path.count()
Count returns a number of results and returns it as a value.
Example:
path.difference(path)
path.difference(path)
Difference is an alias for Except.
path.except(path)
path.except(path)
Except removes all paths which match query from current path.
In a set-theoretic sense, this is (A - B). While g.V().except(path)
to achieve U - B = !B
is supported, it's often very slow. Example:
path.filter(args)
path.filter(args)
Filter applies constraints to a set of nodes. Can be used to filter values by range or match strings.
path.filter(regex(expression, includeIRIs))
path.filter(regex(expression, includeIRIs))
Filters by match a regular expression (syntax). By default works only on literals unless includeEntities is set to true
.
path.follow(path)
path.follow(path)
Follow is the way to use a path prepared with Morphism. Applies the path chain on the morphism object to the current path.
Starts as if at the g.M() and follows through the morphism path.
Example:
path.followR(path)
path.followR(path)
FollowR is the same as Follow but follows the chain in the reverse direction. Flips "In" and "Out" where appropriate, the net result being a virtual predicate followed in the reverse direction.
Starts at the end of the morphism and follows it backwards (with appropriate flipped directions) to the g.M() location.
Example:
path.followRecursive(*)
path.followRecursive(*)
FollowRecursive is the same as Follow but follows the chain recursively.
Starts as if at the g.M() and follows through the morphism path multiple times, returning all nodes encountered.
Example:
path.forEach(callback) or (limit, callback)
path.forEach(callback) or (limit, callback)
ForEach calls callback(data) for each result, where data is the tag-to-string map as in All case.
Arguments:
limit
(Optional): An integer value on the firstlimit
paths to process.callback
: A javascript function of the formfunction(data)
Example:
path.getLimit(limit)
path.getLimit(limit)
GetLimit is the same as All, but limited to the first N unique nodes at the end of the path, and each of their possible traversals.
path.has(predicate, object)
path.has(predicate, object)
Has filters all paths which are, at this point, on the subject for the given predicate and object, but do not follow the path, merely filter the possible paths.
Usually useful for starting with all nodes, or limiting to a subset depending on some predicate/value pair.
Arguments:
predicate
: A string for a predicate node.object
: A string for a object node or a set of filters to find it.
Example:
path.hasR(*)
path.hasR(*)
HasR is the same as Has, but sets constraint in reverse direction.
path.in([predicatePath], [tags])
path.in([predicatePath], [tags])
In is inverse of Out. Starting with the nodes in path
on the object, follow the quads with predicates defined by predicatePath
to their subjects.
Arguments:
predicatePath
(Optional): One of:null or undefined: All predicates pointing into this node
a string: The predicate name to follow into this node
a list of strings: The predicates to follow into this node
a query path object: The target of which is a set of predicates to follow.
tags
(Optional): One of:null or undefined: No tags
a string: A single tag to add the predicate used to the output set.
a list of strings: Multiple tags to use as keys to save the predicate used to the output set.
Example:
path.inPredicates()
path.inPredicates()
InPredicates gets the list of predicates that are pointing in to a node.
Example:
path.intersect(path)
path.intersect(path)
Intersect filters all paths by the result of another query path.
This is essentially a join where, at the stage of each path, a node is shared. Example:
path.is(node, [node..])
path.is(node, [node..])
Filter all paths to ones which, at this point, are on the given node.
Arguments:
node
: A string for a node. Can be repeated or a list of strings.
Example:
path.labelContext([labelPath], [tags])
path.labelContext([labelPath], [tags])
LabelContext 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).
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.
Example:
path.labels()
path.labels()
Labels gets the list of inbound and outbound quad labels
path.limit(limit)
path.limit(limit)
Limit limits a number of nodes for current path.
Arguments:
limit
: A number of nodes to limit results to.
Example:
path.map(*)
path.map(*)
Map is a alias for ForEach.
path.or(path)
path.or(path)
Or is an alias for Union.
path.out([predicatePath], [tags])
path.out([predicatePath], [tags])
Out is the work-a-day way to get between nodes, in the forward direction. Starting with the nodes in path
on the subject, follow the quads with predicates defined by predicatePath
to their objects.
Arguments:
predicatePath
(Optional): One of:null or undefined: All predicates pointing out from this node
a string: The predicate name to follow out from this node
a list of strings: The predicates to follow out from this node
a query path object: The target of which is a set of predicates to follow.
tags
(Optional): One of:null or undefined: No tags
a string: A single tag to add the predicate used to the output set.
a list of strings: Multiple tags to use as keys to save the predicate used to the output set.
Example:
path.outPredicates()
path.outPredicates()
OutPredicates gets the list of predicates that are pointing out from a node.
Example:
path.save(predicate, tag)
path.save(predicate, tag)
Save saves the object of all quads with predicate into tag, without traversal.
Arguments:
predicate
: A string for a predicate node.tag
: A string for a tag key to store the object node.
Example:
path.saveInPredicates(tag)
path.saveInPredicates(tag)
SaveInPredicates tags the list of predicates that are pointing in to a node.
Example:
path.saveOpt(*)
path.saveOpt(*)
SaveOpt is the same as Save, but returns empty tags if predicate does not exists.
path.saveOptR(*)
path.saveOptR(*)
SaveOptR is the same as SaveOpt, but tags values via reverse predicate.
path.saveOutPredicates(tag)
path.saveOutPredicates(tag)
SaveOutPredicates tags the list of predicates that are pointing out from a node.
Example:
path.saveR(*)
path.saveR(*)
SaveR is the same as Save, but tags values via reverse predicate.
path.skip(offset)
path.skip(offset)
Skip skips a number of nodes for current path.
Arguments:
offset
: A number of nodes to skip.
Example:
path.tag(tags)
path.tag(tags)
Tag saves a list of nodes to a given tag.
In order to save your work or learn more about how a path got to the end, we have tags. The simplest thing to do is to add a tag anywhere you'd like to put each node in the result set.
Arguments:
tag
: A string or list of strings to act as a result key. The value for tag was the vertex the path was on at the time it reached "Tag"Example:
path.tagArray(*)
path.tagArray(*)
TagArray is the same as ToArray, but instead of a list of top-level nodes, returns an Array of tag-to-string dictionaries, much as All would, except inside the JS environment.
Example:
path.tagValue()
path.tagValue()
TagValue is the same as TagArray, but limited to one result node. Returns a tag-to-string map.
path.toArray(*)
path.toArray(*)
ToArray executes a query and returns the results at the end of the query path as an JS array.
Example:
path.toValue()
path.toValue()
ToValue is the same as ToArray, but limited to one result node.
path.union(path)
path.union(path)
Union returns the combined paths of the two queries.
Notice that it's per-path, not per-node. Once again, if multiple paths reach the same destination, they might have had different ways of getting there (and different tags). See also: path.Tag()
Example:
path.unique()
path.unique()
Unique removes duplicate values from the path.
path.order()
path.order()
Order returns values from the path in ascending order.
Last updated