Skip to content

Commit

Permalink
Replace all valueMaps with values
Browse files Browse the repository at this point in the history
  • Loading branch information
ryn5 committed Oct 2, 2023
1 parent 97a8f60 commit 3daa0e1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 75 deletions.
60 changes: 25 additions & 35 deletions gremlin-dotnet/example/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Gremlin.Net.Driver;
using Gremlin.Net.Driver.Remote;
using Gremlin.Net.Structure.IO.GraphSON;
using Gremlin.Net.Process.Traversal;
using Gremlin.Net.Process.Traversal;

// Common imports
using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;
Expand All @@ -17,11 +17,11 @@
using static Gremlin.Net.Process.Traversal.Direction;
using static Gremlin.Net.Process.Traversal.Cardinality;
using static Gremlin.Net.Process.Traversal.CardinalityValue;
using static Gremlin.Net.Process.Traversal.T;


ConnectionExample();
BasicGremlinExample();
using static Gremlin.Net.Process.Traversal.T;


ConnectionExample();
BasicGremlinExample();
ModernTraversalExample();

static void ConnectionExample()
Expand Down Expand Up @@ -59,35 +59,25 @@ static void BasicGremlinExample()
g.V(v1).AddE("knows").To(v3).Property("weight", 0.75).Iterate();

// Retrieve the data from the "marko" vertex
var marko = g.V().Has("person","name","marko").ValueMap<object,object>().Next();
foreach (var kvp in marko)
{
if (kvp.Value is IEnumerable<object> enumerable)
{
Console.WriteLine($"{kvp.Key}: {enumerable.First()}");
}
}

var marko = g.V().Has("person","name","marko").Values<string>("name").Next();
Console.WriteLine("name: " + marko);
// Find the "marko" vertex and then traverse to the people he "knows" and return their data
var peopleMarkoKnows = g.V().Has("person","name","marko").Out("knows").ValueMap<object,object>().ToList();
var peopleMarkoKnows = g.V().Has("person","name","marko").Out("knows").Values<string>("name").ToList();
foreach (var person in peopleMarkoKnows)
{
if (person["name"] is IEnumerable<object> enumerable)
{
Console.WriteLine($"marko knows {enumerable.First()}");
}
Console.WriteLine("marko knows " + person);
}
}

static void ModernTraversalExample()
static void ModernTraversalExample()
{
var server = new GremlinServer("localhost", 8182);
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
var g = Traversal().WithRemote(remoteConnection);

/*
This example requires the Modern toy graph to be preloaded upon launching the Gremlin server.
For details, see https://tinkerpop.apache.org/docs/current/reference/#gremlin-server-docker-image and use
var g = Traversal().WithRemote(remoteConnection);

/*
This example requires the Modern toy graph to be preloaded upon launching the Gremlin server.
For details, see https://tinkerpop.apache.org/docs/current/reference/#gremlin-server-docker-image and use
conf/gremlin-server-modern.yaml.
*/
var e1 = g.V(1).BothE().ToList(); // (1)
Expand All @@ -98,14 +88,14 @@ This example requires the Modern toy graph to be preloaded upon launching the Gr
var e4 = g.V(v1).OutE().Where(InV().Is(v2)).ToList(); // (4)
var e5 = g.V(1).OutE().Where(InV().Has(T.Id, Within(2, 3))).ToList(); // (5)
var e6 = g.V(1).Out().Where(__.In().HasId(6)).ToList(); // (6)

Console.WriteLine(string.Join(", ", e1));
Console.WriteLine(string.Join(", ", e2));
Console.WriteLine(string.Join(", ", e3));
Console.WriteLine(string.Join(", ", e4));
Console.WriteLine(string.Join(", ", e5));
Console.WriteLine(string.Join(", ", e6));


Console.WriteLine(string.Join(", ", e1));
Console.WriteLine(string.Join(", ", e2));
Console.WriteLine(string.Join(", ", e3));
Console.WriteLine(string.Join(", ", e4));
Console.WriteLine(string.Join(", ", e5));
Console.WriteLine(string.Join(", ", e6));

/*
1. There are three edges from the vertex with the identifier of "1".
2. Filter those three edges using the where()-step using the identifier of the vertex returned by otherV() to
Expand All @@ -118,5 +108,5 @@ steps of outE() and inV() since the schema allows it.
case, vertices with identifiers "2" and "3".
6. There’s no reason why the same pattern of exclusion used for edges with where() can’t work for a vertex
between two vertices.
*/
*/
}
10 changes: 5 additions & 5 deletions gremlin-driver/src/main/java/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ private static void basicGremlinExample() {
g.V(v1).addE("knows").to(v3).property("weight",0.75).iterate();

// Retrieve the data from the "marko" vertex
Map<Object,Object> marko = g.V().has("person","name","marko").values("name").next();
System.out.println("name: " + ((ArrayList) marko.get("name")).get(0));
Object marko = g.V().has("person","name","marko").values("name").next();
System.out.println("name: " + marko);

// Find the "marko" vertex and then traverse to the people he "knows" and return their data
List<Map<Object,Object>> peopleMarkoKnows = g.V().has("person","name","marko").out("knows").valueMap().toList();
for (Map<Object, Object> map : peopleMarkoKnows) {
System.out.println("marko knows " + ((ArrayList) map.get("name")).get(0));
List<Object> peopleMarkoKnows = g.V().has("person","name","marko").out("knows").values("name").toList();
for (Object person : peopleMarkoKnows) {
System.out.println("marko knows " + person);
}
}

Expand Down
46 changes: 21 additions & 25 deletions gremlin-go/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package main
import (
"fmt"
gremlingo "github.com/apache/tinkerpop/gremlin-go/driver"
"strconv"
)

// syntactic sugar
Expand All @@ -33,9 +32,9 @@ var T = gremlingo.T
var P = gremlingo.P

func main() {
//connectionExample()
connectionExample()
basicGremlinExample()
//modernTraversalExample()
modernTraversalExample()
}

func connectionExample() {
Expand Down Expand Up @@ -74,10 +73,13 @@ func basicGremlinExample() {
defer driverRemoteConnection.Close()
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

prom := g.V().Drop().Iterate()
<-prom

// Basic Gremlin: adding and retrieving data
v1, err := g.AddV("person").Property("name", "marko").Next()
v2, err := g.AddV("person").Property("name", "go1").Next()
v3, err := g.AddV("person").Property("name", "go2").Next()
v2, err := g.AddV("person").Property("name", "stephen").Next()
v3, err := g.AddV("person").Property("name", "vadas").Next()

// Be sure to use a terminating step like next() or iterate() so that the traversal "executes"
// Iterate() does not return any data and is used to just generate side-effects (i.e. write data to the database)
Expand All @@ -86,20 +88,14 @@ func basicGremlinExample() {

// Retrieve the data from the "marko" vertex
marko, err := g.V().Has("person", "name", "marko").Values("name").Next()
//marko, err := g.V().HasLabel("person").Has("name", "marko").Values("name").Next()
//fmt.Println("test")
fmt.Sprintln(marko)
vert, err := g.V().Count().ToList()
fmt.Println(vert)
//// Find the "marko" vertex and then traverse to the people he "knows" and return their data
//peopleMarkoKnows, err := g.V().HasLabel("person").Has("name", __.Is("marko")).Out("knows").ToList()
//if err != nil {
// fmt.Println(err)
// return
//}
//for _, person := range peopleMarkoKnows {
// fmt.Println("marko knows ", person.GetString())
//}
fmt.Println("name:", marko.GetString())

// Find the "marko" vertex and then traverse to the people he "knows" and return their data
peopleMarkoKnows, err := g.V().HasLabel("person").Out("knows").ToList()
//peopleMarkoKnows, err := g.V().Has("person", "name", "marko").Out("knows").Values("name").ToList()
for _, person := range peopleMarkoKnows {
fmt.Println("marko knows", person.GetString())
}

}

Expand All @@ -126,12 +122,12 @@ func modernTraversalExample() {
e5, err := g.V(1).OutE().Where(__.InV().Has(T.Id, P.Within(2, 3))).ToList() // (5)
e6, err := g.V(1).Out().Where(__.In().HasId(6)).ToList() // (6)

fmt.Sprintf(strconv.Itoa(len(e1)))
fmt.Sprintf(strconv.Itoa(len(e2)))
fmt.Sprintf(strconv.Itoa(len(e3)))
fmt.Sprintf(strconv.Itoa(len(e4)))
fmt.Sprintf(strconv.Itoa(len(e5)))
fmt.Sprintf(strconv.Itoa(len(e6)))
fmt.Println(e1)
fmt.Println(e2)
fmt.Println(e3)
fmt.Println(e4)
fmt.Println(e5)
fmt.Println(e6)

/*
1. There are three edges from the vertex with the identifier of "1".
Expand Down
10 changes: 5 additions & 5 deletions gremlin-javascript/example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ async function basicGremlinExample() {
await g.V(v1.value).addE('knows').to(v3.value).property('weight',0.75).iterate();

// Retrieve the data from the "marko" vertex
const marko = await g.V().has('person','name','marko').valueMap().next();
console.log(marko.value.get('name')[0]);
const marko = await g.V().has('person','name','marko').values('name').toList();
console.log("name: " + marko[0]);

// Find the "marko" vertex and then traverse to the people he "knows" and return their data
const peopleMarkoKnows = await g.V().has('person','name','marko').out('knows').valueMap().toList();
peopleMarkoKnows.forEach((kvp) => {
console.log("marko knows " + kvp.get('name'));
const peopleMarkoKnows = await g.V().has('person','name','marko').out('knows').values('name').toList();
peopleMarkoKnows.forEach((person) => {
console.log("marko knows " + person);
});

await dc.close();
Expand Down
10 changes: 5 additions & 5 deletions gremlin-python/src/main/python/example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def basic_gremlin_example():
g.V(v1).addE('knows').to(v3).property('weight', 0.75).iterate()

# retrieve the data from the "marko" vertex
marko = g.V().has('person', 'name', 'marko').value_map().next()
print("name: " + marko.get('name')[0])
marko = g.V().has('person', 'name', 'marko').values('name').next()
print("name: " + marko)

# find the "marko" vertex and then traverse to the people he "knows" and return their data
people_marko_knows = g.V().has('person', 'name', 'marko').out('knows').value_map().toList()
people_marko_knows = g.V().has('person', 'name', 'marko').out('knows').values('name').toList()
for person in people_marko_knows:
print("marko knows " + person.get('name')[0])
# DriverRemoteConnection('ws://localhost:8182/gremlin', 'g').close()
print("marko knows " + person)


def modern_traversal_example():
# This example requires the Modern toy graph to be preloaded upon launching the Gremlin server.
Expand Down

0 comments on commit 3daa0e1

Please sign in to comment.