Skip to content

Commit

Permalink
use ascii arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
mpollmeier committed Jan 26, 2018
1 parent 668fffa commit b7fad2f
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 66 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ val Distance = Key[Int]("distance")
val paris = graph + "Paris"

// create vertex with typed properties
val london = graph + ("London", Founded "43 AD")
val london = graph + ("London", Founded -> "43 AD")

// create labelled edges
paris --- "OneWayRoad" --> london
paris <-- "OtherWayAround" --- london
paris <-- "Eurostar" --> london

// create edge with typed properties
paris --- ("Eurostar", Distance 495) --> london
paris --- ("Eurostar", Distance -> 495) --> london

// type safe access to properties
paris.out("Eurostar").value(Founded).head //43 AD
Expand All @@ -100,8 +100,8 @@ val v1 = graph + ("person", Name -> "marko", Age -> 29) asScala

v1.keys // Set(Key("name"), Key("age"))
v1.property(Name) // "marko"
v1.valueMap // Map("name" "marko", "age" 29)
v1.valueMap("name", "age") // Map("name" "marko", "age" 29)
v1.valueMap // Map("name" -> "marko", "age" -> 29)
v1.valueMap("name", "age") // Map("name" -> "marko", "age" -> 29)
```

More working examples in [SchemaSpec](https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/test/scala/gremlin/scala/SchemaSpec.scala), [ArrowSyntaxSpec](https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/test/scala/gremlin/scala/ArrowSyntaxSpec.scala) and [ElementSpec](https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/test/scala/gremlin/scala/ElementSpec.scala).
Expand Down
6 changes: 3 additions & 3 deletions gremlin-scala/src/main/scala/gremlin/scala/ScalaVertex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ case class ScalaVertex(vertex: Vertex) extends ScalaElement[Vertex] {
se.from.asScala.addEdge(se.label, vertex, se.properties)

def <--(de: SemiDoubleEdge): (Edge, Edge) =
addEdge(de.label, de.right, de.properties) de.right.asScala
addEdge(de.label, de.right, de.properties) -> de.right.asScala
.addEdge(de.label, vertex, de.properties)

def ---(label: String): SemiEdge = SemiEdge(vertex, label)
Expand All @@ -87,13 +87,13 @@ case class ScalaVertex(vertex: Vertex) extends ScalaElement[Vertex] {

def ---(label: String, properties: Map[String, Any]): SemiEdge =
SemiEdge(vertex, label, properties.map {
case (key, value) => Key[Any](key) value
case (key, value) => Key[Any](key) -> value
}.toSeq)

def ---[CC <: Product: Marshallable](cc: CC): SemiEdge = {
val fromCC = implicitly[Marshallable[CC]].fromCC(cc)
SemiEdge(vertex, fromCC.label, fromCC.valueMap.map { r =>
Key[Any](r._1) r._2
Key[Any](r._1) -> r._2
}.toSeq)
}

Expand Down
2 changes: 0 additions & 2 deletions gremlin-scala/src/main/scala/gremlin/scala/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package gremlin.scala

// a type safe key for a property of vertices or edges
case class Key[A](name: String) {
def (value: A): KeyValue[A] = KeyValue(this, value)

def ->(value: A): KeyValue[A] = KeyValue(this, value)

def of(value: A): KeyValue[A] = KeyValue(this, value)
Expand Down
18 changes: 9 additions & 9 deletions gremlin-scala/src/test/scala/gremlin/scala/ArrowSyntaxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class ArrowSyntaxSpec extends WordSpec with Matchers {
}

"has a label and one property" in new Fixture {
paris --- (Eurostar, Name "alpha") --> london
paris --- (Eurostar, Name -> "alpha") --> london

paris.out(Eurostar).head shouldBe london
paris.outE(Eurostar).value(Name).head shouldBe "alpha"
}

"has a label and multiple properties" in new Fixture {
paris --- (Eurostar, Name "alpha", Length 100) --> london
paris --- (Eurostar, Name -> "alpha", Length -> 100) --> london

paris.out(Eurostar).head shouldBe london
paris.outE(Eurostar).value(Name).head shouldBe "alpha"
Expand All @@ -43,13 +43,13 @@ class ArrowSyntaxSpec extends WordSpec with Matchers {
}

"has a label and one property" in new Fixture {
paris <-- (Eurostar, Name "alpha") --- london
paris <-- (Eurostar, Name -> "alpha") --- london
paris.in(Eurostar).head shouldBe london
paris.inE(Eurostar).value(Name).head shouldBe "alpha"
}

"has a label and multiple properties" in new Fixture {
paris <-- (Eurostar, Name "alpha", Length -> 100) --- london
paris <-- (Eurostar, Name -> "alpha", Length -> 100) --- london

paris.in(Eurostar).head shouldBe london
paris.inE(Eurostar).value(Name).head shouldBe "alpha"
Expand All @@ -74,7 +74,7 @@ class ArrowSyntaxSpec extends WordSpec with Matchers {
}

"have labels and one property" in new Fixture {
paris <-- (Eurostar, Name "alpha") --> london
paris <-- (Eurostar, Name -> "alpha") --> london

paris.out(Eurostar).head shouldBe london
paris.outE(Eurostar).value(Name).head shouldBe "alpha"
Expand All @@ -83,7 +83,7 @@ class ArrowSyntaxSpec extends WordSpec with Matchers {
}

"have labels and multiple properties" in new Fixture {
paris <-- (Eurostar, Name "alpha", Length 100) --> london
paris <-- (Eurostar, Name -> "alpha", Length -> 100) --> london

paris.out(Eurostar).head shouldBe london
paris.outE(Eurostar).value(Name).head shouldBe "alpha"
Expand Down Expand Up @@ -118,7 +118,7 @@ class ArrowSyntaxSpec extends WordSpec with Matchers {
// Long.MaxValue,
// Some("option type"),
// Seq("test1", "test2"),
// Map("key1" "value1", "key2" "value2"),
// Map("key1" -> "value1", "key2" -> "value2"),
// NestedClass("nested")
// ) --> london

Expand All @@ -137,7 +137,7 @@ class ArrowSyntaxSpec extends WordSpec with Matchers {
// Long.MaxValue,
// Some("option type"),
// Seq("test1", "test2"),
// Map("key1" "value1", "key2" "value2"),
// Map("key1" -> "value1", "key2" -> "value2"),
// NestedClass("nested")
// ) --> london

Expand All @@ -160,7 +160,7 @@ class ArrowSyntaxSpec extends WordSpec with Matchers {
// Long.MaxValue,
// Some("option type"),
// Seq("test1", "test2"),
// Map("key1" "value1", "key2" "value2"),
// Map("key1" -> "value1", "key2" -> "value2"),
// NestedClass("nested")
// ) --- london

Expand Down
14 changes: 7 additions & 7 deletions gremlin-scala/src/test/scala/gremlin/scala/ElementSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class ElementSpec extends TestBase {
v1.keys shouldBe Set(Key("name"), Key("age"))
v1.property(Name).value shouldBe "marko"
v1.property(DoesNotExist).isPresent shouldBe false
v1.valueMap shouldBe Map("name" "marko", "age" 29)
v1.valueMap("name", "age") shouldBe Map("name" "marko", "age" 29)
v1.valueMap shouldBe Map("name" -> "marko", "age" -> 29)
v1.valueMap("name", "age") shouldBe Map("name" -> "marko", "age" -> 29)
v1.properties("name", "age").length shouldBe 2
v1.properties.length shouldBe 2

e7.keys shouldBe Set(Key("weight"))
e7.property(Weight).value shouldBe 0.5
e7.property(DoesNotExist).isPresent shouldBe false
e7.valueMap("weight") shouldBe Map("weight" 0.5)
e7.valueMap("weight") shouldBe Map("weight" -> 0.5)
}

it("maps properties to scala.Option") {
Expand Down Expand Up @@ -128,7 +128,7 @@ class ElementSpec extends TestBase {
val label1 = "label1"
val label2 = "label2"
val v1 = graph.addVertex(label1)
val v2 = graph.addVertex(label2, Map(TestProperty.name "testValue"))
val v2 = graph.addVertex(label2, Map(TestProperty.name -> "testValue"))

graph.V.has(T.label, label1).head shouldBe v1.vertex
graph.V.has(T.label, label2).head shouldBe v2.vertex
Expand All @@ -141,7 +141,7 @@ class ElementSpec extends TestBase {
val label2 = "label2"

val v1 = graph + label1
val v2 = graph + (label2, TestProperty "testValue")
val v2 = graph + (label2, TestProperty -> "testValue")

graph.V.hasLabel(label1).head shouldBe v1.vertex
graph.V.hasLabel(label2).head shouldBe v2.vertex
Expand All @@ -167,10 +167,10 @@ class ElementSpec extends TestBase {
val v2 = graph.addVertex()

val e =
v1.asScala.addEdge("testLabel", v2, Seq(TestProperty "testValue"))
v1.asScala.addEdge("testLabel", v2, Seq(TestProperty -> "testValue"))
e.label shouldBe "testLabel"
e.value2(TestProperty) shouldBe "testValue"
e.valueMap(TestProperty.name) shouldBe Map(TestProperty.name "testValue")
e.valueMap(TestProperty.name) shouldBe Map(TestProperty.name -> "testValue")
v1.outE().head shouldBe e.edge
v1.out("testLabel").head shouldBe v2.vertex
}
Expand Down
14 changes: 7 additions & 7 deletions gremlin-scala/src/test/scala/gremlin/scala/FilterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class FilterSpec extends WordSpec with Matchers {

"has - sugar" in new Fixture {
val g = TinkerGraph.open.asScala
g + ("software", Name "blueprints", Created 2010)
g + ("software", Name -> "blueprints", Created -> 2010)

g.V
.has(Name "blueprints")
.head <-- "dependsOn" --- (g + ("software", Name "gremlin", Created 2009))
.has(Name -> "blueprints")
.head <-- "dependsOn" --- (g + ("software", Name -> "gremlin", Created -> 2009))
g.V
.has(Name "gremlin")
.head <-- "dependsOn" --- (g + ("software", Name "gremlinScala"))
.has(Name -> "gremlin")
.head <-- "dependsOn" --- (g + ("software", Name -> "gremlinScala"))
g.V
.has(Name "gremlinScala")
.head <-- "createdBy" --- (g + ("person", Name "mpollmeier"))
.has(Name -> "gremlinScala")
.head <-- "createdBy" --- (g + ("person", Name -> "mpollmeier"))

g.V.toList().size shouldBe 4
g.V.hasLabel("software").toList().size shouldBe 3
Expand Down
32 changes: 16 additions & 16 deletions gremlin-scala/src/test/scala/gremlin/scala/MarshallableSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class MarshallableSpec extends WordSpec with Matchers {

val vl = graph.V(v.id).head
vl.label shouldBe cc.getClass.getSimpleName
vl.valueMap should contain("s" cc.s)
vl.valueMap should contain("i" cc.i)
vl.valueMap should contain("s" -> cc.s)
vl.valueMap should contain("i" -> cc.i)
}

"contain options" should {
Expand Down Expand Up @@ -80,8 +80,8 @@ class MarshallableSpec extends WordSpec with Matchers {

val vl = graph.V(v.id).head
vl.label shouldBe cc.getClass.getSimpleName
vl.valueMap should contain("s" cc.s)
vl.valueMap should contain("i" cc.i.value)
vl.valueMap should contain("s" -> cc.s)
vl.valueMap should contain("i" -> cc.i.value)
vl.toCC[CCWithValueClass] shouldBe cc
}

Expand All @@ -91,8 +91,8 @@ class MarshallableSpec extends WordSpec with Matchers {

val vl = graph.V(v.id).head
vl.label shouldBe cc.getClass.getSimpleName
vl.valueMap should contain("s" cc.s)
vl.valueMap should contain("i" cc.i.get.value)
vl.valueMap should contain("s" -> cc.s)
vl.valueMap should contain("i" -> cc.i.get.value)
vl.toCC[CCWithOptionValueClass] shouldBe cc
}

Expand All @@ -102,7 +102,7 @@ class MarshallableSpec extends WordSpec with Matchers {

val vl = graph.V(v.id).head
vl.label shouldBe cc.getClass.getSimpleName
vl.valueMap should contain("s" cc.s)
vl.valueMap should contain("s" -> cc.s)
vl.valueMap.keySet should not contain ("i")
vl.toCC[CCWithOptionValueClass] shouldBe cc
}
Expand All @@ -113,7 +113,7 @@ class MarshallableSpec extends WordSpec with Matchers {

val marshaller = new Marshallable[CCWithOption] {
def fromCC(cc: CCWithOption) =
FromCC(None, "CCWithOption", Map("i" -> cc.i, "s" cc.s.getOrElse("undefined")))
FromCC(None, "CCWithOption", Map("i" -> cc.i, "s" -> cc.s.getOrElse("undefined")))

def toCC(id: AnyRef, valueMap: Map[String, Any]): CCWithOption =
CCWithOption(i = valueMap("i").asInstanceOf[Int],
Expand All @@ -131,7 +131,7 @@ class MarshallableSpec extends WordSpec with Matchers {
Long.MaxValue,
Some("option type"),
Seq("test1", "test2"),
Map("key1" "value1", "key2" "value2"),
Map("key1" -> "value1", "key2" -> "value2"),
NestedClass("nested")
)

Expand All @@ -142,12 +142,12 @@ class MarshallableSpec extends WordSpec with Matchers {
val vl = graph.V(v.id).head()
vl.label shouldBe "the_label"
vl.id shouldBe ccWithLabelAndId.id
vl.valueMap should contain("s" ccWithLabelAndId.s)
vl.valueMap should contain("l" ccWithLabelAndId.l)
vl.valueMap should contain("o" ccWithLabelAndId.o.get)
vl.valueMap should contain("seq" ccWithLabelAndId.seq)
vl.valueMap should contain("map" ccWithLabelAndId.map)
vl.valueMap should contain("nested" ccWithLabelAndId.nested)
vl.valueMap should contain("s" -> ccWithLabelAndId.s)
vl.valueMap should contain("l" -> ccWithLabelAndId.l)
vl.valueMap should contain("o" -> ccWithLabelAndId.o.get)
vl.valueMap should contain("seq" -> ccWithLabelAndId.seq)
vl.valueMap should contain("map" -> ccWithLabelAndId.map)
vl.valueMap should contain("nested" -> ccWithLabelAndId.nested)
}

"have an Option @id annotation" in new Fixture {
Expand All @@ -159,7 +159,7 @@ class MarshallableSpec extends WordSpec with Matchers {
val vl = graph.V(v.id).head()
vl.label shouldBe cc.getClass.getSimpleName
vl.id shouldBe cc.id.get
vl.valueMap should contain("s" cc.s)
vl.valueMap should contain("s" -> cc.s)
}

}
Expand Down
14 changes: 7 additions & 7 deletions gremlin-scala/src/test/scala/gremlin/scala/SchemaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class SchemaSpec extends WordSpec with Matchers {
"create vertices" in {
val g = TinkerGraph.open.asScala

val v0 = g + (Software, Name "blueprints", Created 2010)
val v1 = g + (Software, Created 2009, Name "gremlin")
val v2 = g + (Software, Name "gremlinScala")
val v3 = g + (Person, Name "mpollmeier")
val v0 = g + (Software, Name -> "blueprints", Created -> 2010)
val v1 = g + (Software, Created -> 2009, Name -> "gremlin")
val v2 = g + (Software, Name -> "gremlinScala")
val v3 = g + (Person, Name -> "mpollmeier")

g.V.toList().size shouldBe 4
g.V.hasLabel(Software).toList().size shouldBe 3
Expand Down Expand Up @@ -95,9 +95,9 @@ class SchemaSpec extends WordSpec with Matchers {
object Distance extends Key[Int]("distance")

val g = TinkerGraph.open.asScala
val paris = g + (City, Name "paris")
val london = g + (City, Name "london")
val rail = paris --- (EuroStar, Distance 495) --> london
val paris = g + (City, Name -> "paris")
val london = g + (City, Name -> "london")
val rail = paris --- (EuroStar, Distance -> 495) --> london
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions gremlin-scala/src/test/scala/gremlin/scala/TraversalSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ class TraversalSpec extends WordSpec with Matchers {
} yield (software.value2(Name), meanAge)

softwareAndDevAges.toSet shouldBe Set(
"lop" 32d,
"ripple" 32d
"lop" -> 32d,
"ripple" -> 32d
)
}
}
Expand Down Expand Up @@ -264,22 +264,22 @@ class TraversalSpec extends WordSpec with Matchers {

val scala = graph + "scala"
val groovy = graph + "groovy"
val michael = graph + (Person, Name "michael")
val marko = graph + (Person, Name "marko")
val michael = graph + (Person, Name -> "michael")
val marko = graph + (Person, Name -> "marko")

michael --- (Likes, Weight 3) --> groovy
michael --- (Likes, Weight 5) --> scala
marko --- (Likes, Weight 4) --> groovy
marko --- (Likes, Weight 3) --> scala
michael --- (Likes, Weight -> 3) --> groovy
michael --- (Likes, Weight -> 5) --> scala
marko --- (Likes, Weight -> 4) --> groovy
marko --- (Likes, Weight -> 3) --> scala

val traversal = for {
person <- graph.V.hasLabel(Person)
favorite <- person.outE(Likes).order(by(Weight, Order.decr)).limit(1).inV
} yield (person.value2(Name), favorite.label)

traversal.toMap shouldBe Map(
"michael" "scala",
"marko" "groovy"
"michael" -> "scala",
"marko" -> "groovy"
)
}

Expand Down Expand Up @@ -713,7 +713,7 @@ class TraversalSpec extends WordSpec with Matchers {
.property(NewProperty, "someValue")
.iterate()
graph.V.hasLabel("newLabel").count.head shouldBe 2
graph.V.has(NewProperty "someValue").count.head shouldBe 2
graph.V.has(NewProperty -> "someValue").count.head shouldBe 2
}
}

Expand Down

0 comments on commit b7fad2f

Please sign in to comment.