Skip to content

Instantly share code, notes, and snippets.

g = TinkerGraph.open().traversal()
g.addV().property('name','united states').as('united states').
addV().property('name', 'california').as('california').
addV().property('name', 'los angeles').as('los angeles').
addV().property('name', 'san francisco').property('marked', 'true').as('san francisco').
addE('contains').from('united states').to('california').
addE('contains').from('california').to('los angeles').
addE('contains').from('california').to('san francisco').
addV().property('name', 'texas').as('texas').
@dkuppitz
dkuppitz / gist:f76a7699ff78af20a0147b35a8c4041f
Created May 4, 2019 14:07
Don't implement path as a step
gremlin> g.V().repeat(out()).emit().path()
==>[v[1],v[3]]
==>[v[1],v[2]]
==>[v[1],v[4]]
==>[v[1],v[4],v[5]]
==>[v[1],v[4],v[3]]
==>[v[4],v[5]]
==>[v[4],v[3]]
==>[v[6],v[3]]
gremlin> g.withSack {[]} {it.clone()} V().sack(addAll).by(fold()).repeat(out().sack(addAll).by(fold())).emit().sack()
package test.tinkerpop.subgraph.pagerank;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
package com.stackoverflow;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import static org.apache.tinkerpop.gremlin.process.traversal.Operator.*;
import static org.apache.tinkerpop.gremlin.process.traversal.Order.*;
@dkuppitz
dkuppitz / input.asciidoc
Last active September 19, 2017 17:16
cat input.asciidoc | awk -f replace.awk > output.asciidoc

Header

Subheader

SubSubHeader

blabla

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.BinaryOperator;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.io.GraphWriter;
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
gremlin> g.V().order().by("name", {a, b -> println "$b compared to $a: ${b.compareToIgnoreCase(a)}"; b.compareToIgnoreCase(a)}).values("name")
marko compared to vadas: -9
vadas compared to lop: 10
marko compared to lop: 1
marko compared to josh: 3
lop compared to josh: 2
lop compared to ripple: -6
marko compared to ripple: -5
vadas compared to ripple: 4
marko compared to peter: -3
gremlin> createGraph = { numV, numE ->
......1> graph = TinkerGraph.open()
......2> rand = new Random()
......3> vertices = []
......4> (1..numV).each {vertices << graph.addVertex()}
......5> (1..numE).each {
......6> v1 = vertices[rand.nextInt() % numV]
......7> v2 = vertices[rand.nextInt() % numV]
......8> v1.addEdge("link", v2)
......9> }
// RULES:
//
// * only follow edges with the same speed values
// * if there are multiple edges to the same vertex, pick the one with the smallest difference between departure time (from outV) and arrival time (from inV)
// * ignore negative differences
//
graph = TinkerGraph.open()
v0 = graph.addVertex(id, 0, "code", "0")