- https://jamesthornton.com#EXIWlRrkjKE
- https://twitter.com/Rangers/status/1641554510605611011
- https://twitter.com/astros/status/1641996751618940936
- https://www.youtube.com/watch?v=S7c3lzpDkvQ#7SlILk2WMTI
- https://gist.github.com/espeed/dd3026536ec3d38afea1072941670f52#3ch6eXkQWU8-C5TDc46E1G4-trIjpVH8h88-UcW056B9jeQ-LvG_M_fAkXU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright 2011 James Thornton (http://jamesthornton.com) | |
# BSD License (see LICENSE for details) | |
# | |
# Gremlin scripts in Gremlin-Groovy v1.3 | |
# | |
# Each script is a string literal of a Python string template. | |
# | |
# See the Gremlin and Blueprints docs for the full Gremlin/Blueprints API. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright 2011 James Thornton (http://jamesthornton.com) | |
# BSD License (see LICENSE for details) | |
# | |
""" | |
An interface for executing Gremlin scripts on the resource. | |
""" | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map.Entry; | |
import groovy.json.JsonSlurper; | |
com.tinkerpop.blueprints.pgm.impls.tg.TinkerIndex.metaClass.put = { | |
final Map<String, Object> properties, final Element element -> | |
for (final Entry<String, Object> entry: properties.entrySet()) { | |
put(entry.getKey(), entry.getValue(), element); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_automatic_index: | | |
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
keys = $keys | |
if (keys != null) | |
keys = slurper.parseText(keys) | |
public abstract class $domain_class implements Vertex {} | |
index = g.createAutomaticIndex('ideas',Idea.class,keys) | |
create_indexed_vertex: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
data = slurper.parseText('{"age":34,"name":"James"}') | |
elementIndex = g.idx('people') | |
verticesIndex = g.idx('vertices') | |
g.setMaxBufferSize(0) | |
g.startTransaction() | |
vertex = g.addVertex(data) | |
AutomaticIndexHelper.addElement(elementIndex,vertex) | |
AutomaticIndexHelper.addElement(verticesIndex,vertex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
keys = null | |
if (keys != null) | |
keys = slurper.parseText(keys) | |
public abstract class People implements Vertex {} | |
index = g.createAutomaticIndex('people',People.class,keys) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outE: | | |
g.v($_id).outE($label) | |
inE: | | |
g.v($_id).inE($label) | |
bothE: | | |
g.v($_id).bothE($label) | |
outV: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vertex(Element): | |
"""A container for Vertex elements returned by the resource.""" | |
def outE(self,label=None): | |
"""Return the outgoing edges of the vertex.""" | |
params = dict(_id=self._id,label=label) | |
script = self._resource.scripts.get('outE',params) | |
return self.gremlin(script) | |
def inE(self,label=None): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
keys = data = null | |
if ('null' != 'null') | |
keys = slurper.parseText('null') | |
if ('{"age":35,"name":"James Thornton"}' != 'null') | |
data = slurper.parseText('{"age":35,"name":"James Thornton"}') | |
vertex = g.getRawGraph().getNodeById(9) | |
manager = g.getRawGraph().index() | |
index = manager.forNodes('test_idxV') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST url: http://localhost:7474/db/data/ext/GremlinPlugin/graphdb/execute_script | |
POST body: {"params":{"keys":["name"],"index_name":"test_idxV","data":{"age":34,"name":"James Thornton"}},"script":"manager = g.getRawGraph().index()\nindex = manager.forNodes(index_name)\ng.setMaxBufferSize(0)\ng.startTransaction()\nvertex = g.getRawGraph().createNode()\nfor (entry in data.entrySet()) {\n if (entry.value == null) continue;\n vertex.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n index.add(vertex,entry.key,entry.value)\n}\ng.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\nreturn vertex\n"} |