This file contains hidden or 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
| 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'). |
This file contains hidden or 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
| 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() |
This file contains hidden or 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
| 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; |
This file contains hidden or 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
| 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.*; |
This file contains hidden or 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 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; |
This file contains hidden or 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 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; |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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> } |
This file contains hidden or 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
| // 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") |
NewerOlder