Skip to content

Gremlin Methods

okram edited this page Aug 28, 2011 · 41 revisions

IMPORTANT: The full Java API can be seamlessly accessed by Gremlin. Thus, both the Blueprints and Pipes APIs can be accessed from within Gremlin. For behaviors that are commonly used in Gremlin, Gremlin adds MetaClass methods/operators to make it easier and faster to work with the Blueprints and Pipes APIs. These MetaClass methods/operators are provided in the table below.

The Groovy API extends many of the Java API classes with methods that are useful for iteration. Its possible to use these methods with Gremlin as well. Two Groovy classes that are worth looking at are:

Developer Note: If you come up a with a generally useful method and would like to include it into the main Gremlin distribution, please make an issue or provide the appropriate pull request.

method/operator equivalence description
Graph.v(Object...) no simple representation get vertices by provided ids
Graph.e(Object...) no simple representation get edges by provided ids
Graph.idx(String) Graph.getIndex(String, Class) get an index by its name
Graph.addVertex() Graph.addVertex(null) add a vertex
Graph.addVertex(Object, Map) no simple representation add a vertex with property map
Graph.addVertex(Map) no simple representation add a vertex with property map
Graph.addEdge(Object, Vertex, Vertex, String, Map) no simple representation add an edge with property map
Graph.addEdge(Vertex, Vertex, String, Map) no simple representation add an edge with property map
Graph.loadGraphML(String or File) GraphMLReader.inputGraph(graph, new FileInputStream(file)) load GraphML file into graph
Graph.saveGraphML(String or File) GraphMLWriter.outputGraph(graph, new FileInputStream(file)) save graph to a GraphML file
Graph.loadGraphJSON(String or File) GraphJSONReader.inputGraph(graph, new FileInputStream(file)) load GraphJSON file into graph
Graph.saveGraphML(String or File, boolean?) GraphJSONWriter.outputGraph(graph, new FileInputStream(file), boolean) save graph to a GraphJSON file
Index[Map.Entry] Index.get(String, Object) get an element by its key/value
Element.key Element.getProperty(key) get the value of a property by key
Element.key = value Element.setProperty(key,value) set the value of a property
Element[key] Element.getProperty(key) get the value of a property by key
Element[key] = value Element.setProperty(key,value) set the value of a property
Element.keys() Element.getPropertyKeys() get the property keys of the element
Element.values() no simple representation get the property values of the element
Element.map() no simple representation get the property map of the element
Pipe>>1 Iterator.next() get the next object in the pipe
Pipe>>Integer no simple representation get the next n objects in pipe and return as a list
Pipe>>-1 PipeHelper.iterate(Pipe) next() all the objects out of the pipe
Pipe>>Collection PipeHelper.fillCollection(Pipe,Collection) add all the pipe objects to the collection
Pipe.next(int) no simple representation get the next int objects in the pipe as a list
Pipe.iterate() no simple representation next() all the objects out of the pipe
Pipe.toList() no simple representation return a list of all the objects in the pipe
Pipe.count() PipeHelper.counter(Pipe) count objects in the pipe
Pipe.mean() no simple representation the average of the objects in the pipe
Map[IntRange] no simple representation create a map of the entry range of the provided map

Note: All Pipe methods/operators also work for Iterator and Iterable.