From 851d9c4b7fa385b1be480f2742f135f2237f0895 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Wed, 10 Dec 2014 14:05:53 +0100 Subject: [PATCH 01/15] add util classes, beginning of a Twitter graph --- .../bio4j/angulillos/test/TwitterGraph.java | 340 ++++++++++++++++++ 1 file changed, 340 insertions(+) create mode 100644 src/main/java/com/bio4j/angulillos/test/TwitterGraph.java diff --git a/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java b/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java new file mode 100644 index 0000000..0e08e8b --- /dev/null +++ b/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java @@ -0,0 +1,340 @@ +package com.bio4j.angulillos.test; + +import com.bio4j.angulillos.*; + +public abstract class TwitterGraph < + I extends UntypedGraph, + RV, RVT, + RE, RET +> +implements + TypedGraph< + TwitterGraph, + I, RV,RVT, RE,RET + > +{ + + protected I rawGraph = null; + public TwitterGraph(I graph) { rawGraph = graph; } + @Override public I raw() { return rawGraph; } + + // types + public abstract UserType User(); + + /* + ### Vertices and their types + */ + + /* + #### User + */ + public final class UserType + extends + VertexType< + TwitterGraph.User, + TwitterGraph.UserType + > + { + public UserType(RVT raw) { super(raw); } + @Override public final UserType value() { return graph().User(); } + @Override public final User from(RV vertex) { return new User(vertex, this); } + + /* ##### User properties */ + public final name name = new name(); + public final class name extends Property { + public name() { super(UserType.this); } + @Override public final Class valueClass() { return String.class; } + } + public final text text = new text(); + public final class text extends Property { + public text() { super(UserType.this); } + @Override public final Class valueClass() { return String.class; } + } + public final url url = new url(); + public final class url extends Property { + public url() { super(UserType.this); } + @Override public final Class valueClass() { return String.class; } + } + public final age age = new age(); + public final class age extends Property { + public age() { super(UserType.this); } + @Override public final Class valueClass() { return Integer.class; } + } + } + + public final class User + extends + Vertex< + TwitterGraph.User, + TwitterGraph.UserType + > + { + public User(RV vertex, UserType type) { super(vertex, type); } + @Override public final User self() { return this; } + } + + + + + + + + + + + + + + + + + + + /* + ### Abstract helper classes + + These classes bound the types to be from this graph + */ + + public abstract class ElementType< + E extends TwitterGraph.Element, + ET extends TwitterGraph.ElementType + > + implements + TypedElement.Type, I, RV, RVT, RE, RET> + { + @Override public final TwitterGraph graph() { return TwitterGraph.this; } + } + + public abstract class Element< + E extends TwitterGraph.Element, + ET extends TwitterGraph.ElementType + > + implements + TypedElement, I, RV, RVT, RE, RET> + { + @Override public final TwitterGraph graph() { return TwitterGraph.this; } + } + + public abstract class VertexType< + V extends TwitterGraph.Vertex, + VT extends TwitterGraph.VertexType + > + extends + ElementType + implements + com.bio4j.angulillos.TypedVertex.Type, I,RV,RVT,RE,RET> + { + private RVT raw; + protected VertexType(RVT type) { this.raw = type; } + @Override public final RVT raw() { return this.raw; } + } + + public abstract class Vertex< + V extends TwitterGraph.Vertex, + VT extends TwitterGraph.VertexType + > + extends + Element + implements + com.bio4j.angulillos.TypedVertex, I,RV,RVT,RE,RET> + { + private RV raw; + private VT type; + protected Vertex(RV vertex, VT type) { + this.raw = vertex; + this.type = type; + } + @Override public final RV raw() { return this.raw; } + @Override public final VT type() { return type; } + } + + public abstract class EdgeType< + S extends TwitterGraph.Vertex, + ST extends TwitterGraph.VertexType, + E extends TwitterGraph.Edge, + ET extends TwitterGraph.EdgeType, + T extends TwitterGraph.Vertex, + TT extends TwitterGraph.VertexType + > + extends + ElementType + implements + com.bio4j.angulillos.TypedEdge.Type< + S, ST, TwitterGraph, + E, ET, TwitterGraph, I, RV, RVT, RE, RET, + T, TT, TwitterGraph + > + { + private RET raw; + private ST srcT; + private TT tgtT; + protected EdgeType(ST srcT, RET raw, TT tgtT) { + this.raw = raw; + this.srcT = srcT; + this.tgtT = tgtT; + } + @Override public final ST sourceType() { return srcT; } + @Override public final TT targetType() { return tgtT; } + @Override public final RET raw() { return raw; } + } + + public abstract class Edge< + S extends TwitterGraph.Vertex, + ST extends TwitterGraph.VertexType, + E extends TwitterGraph.Edge, + ET extends TwitterGraph.EdgeType, + T extends TwitterGraph.Vertex, + TT extends TwitterGraph.VertexType + > + extends + Element + implements + com.bio4j.angulillos.TypedEdge< + S, ST, TwitterGraph, + E, ET, TwitterGraph, I, RV, RVT, RE, RET, + T, TT, TwitterGraph + > + { + private RE edge; + private ET type; + protected Edge(RE edge, ET type) { + this.edge = edge; + this.type = type; + } + @Override public final RE raw() { return this.edge; } + @Override public final ET type() { return type; } + } + + + + + public abstract class Property< + V extends TwitterGraph.Element, + VT extends TwitterGraph.ElementType, + P extends TwitterGraph.Property, + PV + > + implements + com.bio4j.angulillos.Property, I, RV, RVT, RE, RET> + { + private VT type; + protected Property(VT type) { this.type = type; } + @Override public final VT elementType() { return type; } + } + + + + // public abstract static class GoEdge< + // S extends TwitterVertex, + // ST extends TwitterGraph.TwitterVertexType, + // E extends GoEdge, + // ET extends TwitterGraph.GoEdgeType, + // T extends TwitterVertex, + // TT extends TwitterGraph.TwitterVertexType, + // I extends UntypedGraph, RV, RVT, RE, RET + // > + // implements + // TypedEdge< + // S, ST, TwitterGraph, + // E, ET, TwitterGraph, I, RV, RVT, RE, RET, + // T, TT, TwitterGraph + // > { + + // private RE edge; + // private ET type; + + // protected GoEdge(RE edge, ET type) { + + // this.edge = edge; + // this.type = type; + // } + + // @Override + // public TwitterGraph graph() { + // return type().graph(); + // } + + // @Override + // public RE raw() { + // return this.edge; + // } + + // @Override + // public ET type() { + // return type; + // } + // } + + // abstract class GoEdgeType< + // S extends TwitterVertex, + // ST extends TwitterGraph.TwitterVertexType, + // E extends GoEdge, + // ET extends TwitterGraph.GoEdgeType, + // T extends TwitterVertex, + // TT extends TwitterGraph.TwitterVertexType + // > + // implements + // TypedEdge.Type< + // S, ST, TwitterGraph, + // E, ET, TwitterGraph, I, RV, RVT, RE, RET, + // T, TT, TwitterGraph + // > { + + // private RET raw; + // private ST srcT; + // private TT tgtT; + + // protected GoEdgeType(ST srcT, RET raw, TT tgtT) { + + // this.raw = raw; + // this.srcT = srcT; + // this.tgtT = tgtT; + // } + + // @Override + // public final ST sourceType() { + // return srcT; + // } + + // @Override + // public final TT targetType() { + // return tgtT; + // } + + // @Override + // public final RET raw() { + // return raw; + // } + + // @Override + // public final TwitterGraph graph() { + // return TwitterGraph.this; + // } + // } + +} + + + + +// // case class Date(day: Integer, month: Integer, year: Integer) +// case object time extends Property[String] + +// case object User extends VertexType("user", name :~: age :~: ∅) +// case object Tweet extends VertexType("tweet", text :~: ∅) + +// case object Posted extends EdgeType(User, "posted", Tweet, time :~: url :~: ∅) with OneIn with ManyOut +// case object Follows extends EdgeType(User, "follows", User, ∅) with ManyIn with ManyOut + +// case object UserNameIx extends CompositeIndex(User, name) +// case object TweetTextIx extends CompositeIndex(Tweet, text) +// case object PostedTimeIx extends CompositeIndex(Posted, time) + +// val schema = GraphSchema("twitter", +// vertexTypes = U +// ser :~: Tweet :~: ∅, +// edgeTypes = Posted :~: Follows :~: ∅, +// indexes = UserNameIx :~: TweetTextIx :~: PostedTimeIx :~: ∅ +// ) + From f59916ba2ebca0e953ac3dbd715092b13f867d9c Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Wed, 10 Dec 2014 18:35:29 +0100 Subject: [PATCH 02/15] add edges stuff, fix properties for the Twitter graph --- .../bio4j/angulillos/test/TwitterGraph.java | 176 +++++++----------- 1 file changed, 71 insertions(+), 105 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java b/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java index 0e08e8b..07e6162 100644 --- a/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java +++ b/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java @@ -1,6 +1,7 @@ package com.bio4j.angulillos.test; import com.bio4j.angulillos.*; +import com.bio4j.angulillos.TypedEdge.Type.*; public abstract class TwitterGraph < I extends UntypedGraph, @@ -19,7 +20,9 @@ public abstract class TwitterGraph < @Override public I raw() { return rawGraph; } // types - public abstract UserType User(); + public abstract UserType User(); + public abstract TweetType Tweet(); + public abstract PostedType Posted(); /* ### Vertices and their types @@ -45,16 +48,6 @@ public final class name extends Property { public name() { super(UserType.this); } @Override public final Class valueClass() { return String.class; } } - public final text text = new text(); - public final class text extends Property { - public text() { super(UserType.this); } - @Override public final Class valueClass() { return String.class; } - } - public final url url = new url(); - public final class url extends Property { - public url() { super(UserType.this); } - @Override public final Class valueClass() { return String.class; } - } public final age age = new age(); public final class age extends Property { public age() { super(UserType.this); } @@ -73,9 +66,74 @@ public final class User @Override public final User self() { return this; } } + /* + #### Tweet + */ + public final class TweetType + extends + VertexType< + TwitterGraph.Tweet, + TwitterGraph.TweetType + > + { + public TweetType(RVT raw) { super(raw); } + @Override public final TweetType value() { return graph().Tweet(); } + @Override public final Tweet from(RV vertex) { return new Tweet(vertex, this); } + /* ##### Tweet properties */ + public final text text = new text(); + public final class text extends Property { + public text() { super(TweetType.this); } + @Override public final Class valueClass() { return String.class; } + } + public final url url = new url(); + public final class url extends Property { + public url() { super(TweetType.this); } + @Override public final Class valueClass() { return String.class; } + } + } + public final class Tweet + extends + Vertex< + TwitterGraph.Tweet, + TwitterGraph.TweetType + > + { + public Tweet(RV vertex, TweetType type) { super(vertex, type); } + @Override public final Tweet self() { return this; } + } + + + /* + ### Edges + */ + public final class PostedType + extends + EdgeType< + User,UserType, + Posted,PostedType, + Tweet,TweetType + > + implements + ManyOptionalToOne + { + public PostedType(RET edgeType) { super(TwitterGraph.this.User(), edgeType, TwitterGraph.this.Tweet()); } + @Override public final PostedType value() { return graph().Posted(); } + @Override public final Posted from(RE edge) { return new Posted(edge, this); } + } + public final class Posted + extends + Edge< + User,UserType, + Posted,PostedType, + Tweet,TweetType + > + { + public Posted(RE edge, PostedType type) { super(edge, type); } + @Override public final Posted self() { return this; } + } @@ -90,6 +148,8 @@ public final class User + + /////////////////////////////////////////////////////////////////////////////////////////////////// /* ### Abstract helper classes @@ -206,9 +266,6 @@ protected Edge(RE edge, ET type) { @Override public final ET type() { return type; } } - - - public abstract class Property< V extends TwitterGraph.Element, VT extends TwitterGraph.ElementType, @@ -222,97 +279,6 @@ public abstract class Property< protected Property(VT type) { this.type = type; } @Override public final VT elementType() { return type; } } - - - - // public abstract static class GoEdge< - // S extends TwitterVertex, - // ST extends TwitterGraph.TwitterVertexType, - // E extends GoEdge, - // ET extends TwitterGraph.GoEdgeType, - // T extends TwitterVertex, - // TT extends TwitterGraph.TwitterVertexType, - // I extends UntypedGraph, RV, RVT, RE, RET - // > - // implements - // TypedEdge< - // S, ST, TwitterGraph, - // E, ET, TwitterGraph, I, RV, RVT, RE, RET, - // T, TT, TwitterGraph - // > { - - // private RE edge; - // private ET type; - - // protected GoEdge(RE edge, ET type) { - - // this.edge = edge; - // this.type = type; - // } - - // @Override - // public TwitterGraph graph() { - // return type().graph(); - // } - - // @Override - // public RE raw() { - // return this.edge; - // } - - // @Override - // public ET type() { - // return type; - // } - // } - - // abstract class GoEdgeType< - // S extends TwitterVertex, - // ST extends TwitterGraph.TwitterVertexType, - // E extends GoEdge, - // ET extends TwitterGraph.GoEdgeType, - // T extends TwitterVertex, - // TT extends TwitterGraph.TwitterVertexType - // > - // implements - // TypedEdge.Type< - // S, ST, TwitterGraph, - // E, ET, TwitterGraph, I, RV, RVT, RE, RET, - // T, TT, TwitterGraph - // > { - - // private RET raw; - // private ST srcT; - // private TT tgtT; - - // protected GoEdgeType(ST srcT, RET raw, TT tgtT) { - - // this.raw = raw; - // this.srcT = srcT; - // this.tgtT = tgtT; - // } - - // @Override - // public final ST sourceType() { - // return srcT; - // } - - // @Override - // public final TT targetType() { - // return tgtT; - // } - - // @Override - // public final RET raw() { - // return raw; - // } - - // @Override - // public final TwitterGraph graph() { - // return TwitterGraph.this; - // } - // } - } From 8184cd33515560abaffaa23fb30211aefad7b063 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Wed, 10 Dec 2014 20:36:46 +0100 Subject: [PATCH 03/15] add stub for generic test --- .../bio4j/angulillos/test/TwitterGraph.java | 6 ++--- .../test/TwitterGraphTestSuite.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java diff --git a/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java b/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java index 07e6162..91d12cd 100644 --- a/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java +++ b/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java @@ -20,9 +20,9 @@ public abstract class TwitterGraph < @Override public I raw() { return rawGraph; } // types - public abstract UserType User(); - public abstract TweetType Tweet(); - public abstract PostedType Posted(); + public abstract TwitterGraph.UserType User(); + public abstract TwitterGraph.TweetType Tweet(); + public abstract TwitterGraph.PostedType Posted(); /* ### Vertices and their types diff --git a/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java b/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java new file mode 100644 index 0000000..0bcec04 --- /dev/null +++ b/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java @@ -0,0 +1,23 @@ +package com.bio4j.angulillos.test; + +import com.bio4j.angulillos.*; +// import com.bio4j.angulillos.test.TwitterGraph.*; + +import java.util.stream.Stream; +import java.util.Optional; + +public abstract class TwitterGraphTestSuite< + I extends UntypedGraph, + RV, RVT, + RE, RET +> +{ + + public abstract TwitterGraph g(); + + public void doSomething(TwitterGraph.User user) { + + Optional.Tweet>> tweets = user.outV(g().Posted()); + } + +} \ No newline at end of file From 83940ed05c84f865fbf5a9f5484953cac2b8f527 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Wed, 10 Dec 2014 20:40:05 +0100 Subject: [PATCH 04/15] make the graph ref a field --- .../java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java b/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java index 0bcec04..1ed671b 100644 --- a/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java +++ b/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java @@ -13,11 +13,11 @@ public abstract class TwitterGraphTestSuite< > { - public abstract TwitterGraph g(); + protected TwitterGraph g; public void doSomething(TwitterGraph.User user) { - Optional.Tweet>> tweets = user.outV(g().Posted()); + Optional.Tweet>> tweets = user.outV(g.Posted()); } } \ No newline at end of file From edcb4b6c4c24bffa25fcee5750eeaee1ec130fca Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 11 Dec 2014 01:06:07 +0100 Subject: [PATCH 05/15] Moved tests to the right place; added sample serialised twitter graph --- .../com/bio4j/angulillos}/TwitterGraph.java | 3 +- .../angulillos}/TwitterGraphTestSuite.java | 5 +- src/test/resources/twitter_graph.json | 292 ++++++++++++++++++ 3 files changed, 295 insertions(+), 5 deletions(-) rename src/{main/java/com/bio4j/angulillos/test => test/java/com/bio4j/angulillos}/TwitterGraph.java (99%) rename src/{main/java/com/bio4j/angulillos/test => test/java/com/bio4j/angulillos}/TwitterGraphTestSuite.java (86%) create mode 100644 src/test/resources/twitter_graph.json diff --git a/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java b/src/test/java/com/bio4j/angulillos/TwitterGraph.java similarity index 99% rename from src/main/java/com/bio4j/angulillos/test/TwitterGraph.java rename to src/test/java/com/bio4j/angulillos/TwitterGraph.java index 91d12cd..5f9ae8d 100644 --- a/src/main/java/com/bio4j/angulillos/test/TwitterGraph.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraph.java @@ -1,6 +1,5 @@ -package com.bio4j.angulillos.test; +package com.bio4j.angulillos; -import com.bio4j.angulillos.*; import com.bio4j.angulillos.TypedEdge.Type.*; public abstract class TwitterGraph < diff --git a/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java similarity index 86% rename from src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java rename to src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 1ed671b..715fb5d 100644 --- a/src/main/java/com/bio4j/angulillos/test/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -1,6 +1,5 @@ -package com.bio4j.angulillos.test; +package com.bio4j.angulillos; -import com.bio4j.angulillos.*; // import com.bio4j.angulillos.test.TwitterGraph.*; import java.util.stream.Stream; @@ -20,4 +19,4 @@ public void doSomething(TwitterGraph.User user) { Optional.Tweet>> tweets = user.outV(g.Posted()); } -} \ No newline at end of file +} diff --git a/src/test/resources/twitter_graph.json b/src/test/resources/twitter_graph.json new file mode 100644 index 0000000..c9372a5 --- /dev/null +++ b/src/test/resources/twitter_graph.json @@ -0,0 +1,292 @@ +{ + "mode": "EXTENDED", + "vertices": [ + { + "name": { + "type": "string", + "value": "@eparejatobes" + }, + "age": { + "type": "integer", + "value": 95 + }, + "_id": 256, + "_type": "vertex" + }, + { + "name": { + "type": "string", + "value": "@laughedelic" + }, + "age": { + "type": "integer", + "value": 5 + }, + "_id": 512, + "_type": "vertex" + }, + { + "name": { + "type": "string", + "value": "@evdokim" + }, + "age": { + "type": "integer", + "value": 22 + }, + "_id": 768, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "#programming languages should be explicit (= code) about what they are and their needs: syntax, underlying platform, semantics" + }, + "_id": 1024, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "type definitions in titan #graphdb https://github.com/thinkaurelius/titan/wiki/Type-Definition-Overview … killer feature! example of how type info can be used to get better performance" + }, + "_id": 1280, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "just read \"Categories for synchrony and asynchrony\" http://bit.ly/15sBf22 nice paper with conditions for completeness of Kleisli cats" + }, + "_id": 1536, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "back to twitter :)" + }, + "_id": 1792, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "Spend the whole night trying to build Idris from sources. I lost any hope. Cabal is hell \"(" + }, + "_id": 2048, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "What I don’t like about going to bed at 8am is that the next morning there are no interesting news/notifications anywhere \"/ boring morning" + }, + "_id": 2304, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "больше недели искал нормальную jQuery-библиотеку для галереи - в итоге написал свою" + }, + "_id": 2560, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "java.util.concurrent вообще круть!)))" + }, + "_id": 2816, + "_type": "vertex" + }, + { + "text": { + "type": "string", + "value": "в раю все ездят на фиксах и смотрят арт-хаус @ ЛХ" + }, + "_id": 3072, + "_type": "vertex" + } + ], + "edges": [ + { + "time": { + "type": "string", + "value": "27.10.2013" + }, + "url": { + "type": "string", + "value": "https://twitter.com/eparejatobes/status/394430900051927041" + }, + "_id": "3kw-74-9hx-sg", + "_type": "edge", + "_outV": 256, + "_inV": 1024, + "_label": "posted" + }, + { + "time": { + "type": "string", + "value": "20.3.2013" + }, + "url": { + "type": "string", + "value": "https://twitter.com/eparejatobes/status/314353912276738048" + }, + "_id": "3og-74-9hx-zk", + "_type": "edge", + "_outV": 256, + "_inV": 1280, + "_label": "posted" + }, + { + "time": { + "type": "string", + "value": "19.2.2013" + }, + "url": { + "type": "string", + "value": "https://twitter.com/eparejatobes/status/303939214423236608" + }, + "_id": "3s0-74-9hx-16o", + "_type": "edge", + "_outV": 256, + "_inV": 1536, + "_label": "posted" + }, + { + "time": { + "type": "string", + "value": "13.11.2012" + }, + "url": { + "type": "string", + "value": "https://twitter.com/eparejatobes/status/268324310614167552" + }, + "_id": "3vk-74-9hx-1ds", + "_type": "edge", + "_outV": 256, + "_inV": 1792, + "_label": "posted" + }, + { + "_id": "3cw-74-b2t-e8", + "_type": "edge", + "_outV": 256, + "_inV": 512, + "_label": "follows" + }, + { + "_id": "3ds-74-b2t-lc", + "_type": "edge", + "_outV": 256, + "_inV": 768, + "_label": "follows" + }, + { + "time": { + "type": "string", + "value": "15.2.2014" + }, + "url": { + "type": "string", + "value": "https://twitter.com/laughedelic/status/444717461150388224" + }, + "_id": "3z4-e8-9hx-1kw", + "_type": "edge", + "_outV": 512, + "_inV": 2048, + "_label": "posted" + }, + { + "time": { + "type": "string", + "value": "7.2.2014" + }, + "url": { + "type": "string", + "value": "https://twitter.com/laughedelic/status/441939905963622400" + }, + "_id": "42o-e8-9hx-1s0", + "_type": "edge", + "_outV": 512, + "_inV": 2304, + "_label": "posted" + }, + { + "_id": "3eo-e8-b2t-74", + "_type": "edge", + "_outV": 512, + "_inV": 256, + "_label": "follows" + }, + { + "_id": "3fk-e8-b2t-lc", + "_type": "edge", + "_outV": 512, + "_inV": 768, + "_label": "follows" + }, + { + "time": { + "type": "string", + "value": "23.2.2012" + }, + "url": { + "type": "string", + "value": "https://twitter.com/evdokim/status/172712624931348480" + }, + "_id": "468-lc-9hx-1z4", + "_type": "edge", + "_outV": 768, + "_inV": 2560, + "_label": "posted" + }, + { + "time": { + "type": "string", + "value": "7.7.2011" + }, + "url": { + "type": "string", + "value": "https://twitter.com/evdokim/status/88926033750929409" + }, + "_id": "49s-lc-9hx-268", + "_type": "edge", + "_outV": 768, + "_inV": 2816, + "_label": "posted" + }, + { + "time": { + "type": "string", + "value": "22.6.2011" + }, + "url": { + "type": "string", + "value": "https://twitter.com/evdokim/status/83373880454025216" + }, + "_id": "4dc-lc-9hx-2dc", + "_type": "edge", + "_outV": 768, + "_inV": 3072, + "_label": "posted" + }, + { + "_id": "3hc-lc-b2t-74", + "_type": "edge", + "_outV": 768, + "_inV": 256, + "_label": "follows" + }, + { + "_id": "3gg-lc-b2t-e8", + "_type": "edge", + "_outV": 768, + "_inV": 512, + "_label": "follows" + } + ] +} From fdd783ee75e1c5ea7bcdcfbde30513ec59ee51d4 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Thu, 11 Dec 2014 12:05:28 +0100 Subject: [PATCH 06/15] full type signatures --- .../com/bio4j/angulillos/TwitterGraph.java | 38 +++++++++---------- .../angulillos/TwitterGraphTestSuite.java | 23 ++++++----- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraph.java b/src/test/java/com/bio4j/angulillos/TwitterGraph.java index 5f9ae8d..5234a1a 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraph.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraph.java @@ -9,7 +9,7 @@ public abstract class TwitterGraph < > implements TypedGraph< - TwitterGraph, + TwitterGraph, I, RV,RVT, RE,RET > { @@ -33,8 +33,8 @@ public abstract class TwitterGraph < public final class UserType extends VertexType< - TwitterGraph.User, - TwitterGraph.UserType + TwitterGraph.User, + TwitterGraph.UserType > { public UserType(RVT raw) { super(raw); } @@ -57,8 +57,8 @@ public final class age extends Property { public final class User extends Vertex< - TwitterGraph.User, - TwitterGraph.UserType + TwitterGraph.User, + TwitterGraph.UserType > { public User(RV vertex, UserType type) { super(vertex, type); } @@ -72,8 +72,8 @@ public final class User public final class TweetType extends VertexType< - TwitterGraph.Tweet, - TwitterGraph.TweetType + TwitterGraph.Tweet, + TwitterGraph.TweetType > { public TweetType(RVT raw) { super(raw); } @@ -96,8 +96,8 @@ public final class url extends Property { public final class Tweet extends Vertex< - TwitterGraph.Tweet, - TwitterGraph.TweetType + TwitterGraph.Tweet, + TwitterGraph.TweetType > { public Tweet(RV vertex, TweetType type) { super(vertex, type); } @@ -111,9 +111,9 @@ public final class Tweet public final class PostedType extends EdgeType< - User,UserType, - Posted,PostedType, - Tweet,TweetType + TwitterGraph.User,TwitterGraph.UserType, + TwitterGraph.Posted,TwitterGraph.PostedType, + TwitterGraph.Tweet,TwitterGraph.TweetType > implements ManyOptionalToOne @@ -125,9 +125,9 @@ public final class PostedType public final class Posted extends Edge< - User,UserType, - Posted,PostedType, - Tweet,TweetType + TwitterGraph.User,TwitterGraph.UserType, + TwitterGraph.Posted,TwitterGraph.PostedType, + TwitterGraph.Tweet,TwitterGraph.TweetType > { public Posted(RE edge, PostedType type) { super(edge, type); } @@ -180,7 +180,7 @@ public abstract class VertexType< VT extends TwitterGraph.VertexType > extends - ElementType + TwitterGraph.ElementType implements com.bio4j.angulillos.TypedVertex.Type, I,RV,RVT,RE,RET> { @@ -194,7 +194,7 @@ public abstract class Vertex< VT extends TwitterGraph.VertexType > extends - Element + TwitterGraph.Element implements com.bio4j.angulillos.TypedVertex, I,RV,RVT,RE,RET> { @@ -217,7 +217,7 @@ public abstract class EdgeType< TT extends TwitterGraph.VertexType > extends - ElementType + TwitterGraph.ElementType implements com.bio4j.angulillos.TypedEdge.Type< S, ST, TwitterGraph, @@ -247,7 +247,7 @@ public abstract class Edge< TT extends TwitterGraph.VertexType > extends - Element + TwitterGraph.Element implements com.bio4j.angulillos.TypedEdge< S, ST, TwitterGraph, diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 715fb5d..7fd4db1 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -1,22 +1,25 @@ package com.bio4j.angulillos; -// import com.bio4j.angulillos.test.TwitterGraph.*; +import com.bio4j.angulillos.TwitterGraph.*; import java.util.stream.Stream; import java.util.Optional; -public abstract class TwitterGraphTestSuite< - I extends UntypedGraph, - RV, RVT, - RE, RET -> -{ +public abstract class TwitterGraphTestSuite,V,VT,E,ET> { - protected TwitterGraph g; + protected TwitterGraph o; - public void doSomething(TwitterGraph.User user) { + public class Do> { + + protected G g; + + public void doSomething(TwitterGraph.User user) { + + Optional.Tweet>> tweets = user.outV(g.Posted()); + } - Optional.Tweet>> tweets = user.outV(g.Posted()); } + + } From b3416ed837dfbc59aa8d6ddc2606cefd6477c44d Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Thu, 11 Dec 2014 12:11:58 +0100 Subject: [PATCH 07/15] left some weird stuff behind, fix it --- .../com/bio4j/angulillos/TwitterGraphTestSuite.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 7fd4db1..99393ab 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -7,19 +7,10 @@ public abstract class TwitterGraphTestSuite,V,VT,E,ET> { - protected TwitterGraph o; + protected TwitterGraph g; - public class Do> { - - protected G g; - - public void doSomething(TwitterGraph.User user) { + public void doSomething(TwitterGraph.User user) { Optional.Tweet>> tweets = user.outV(g.Posted()); } - - } - - - } From 5f64185e9edd25693a5d0e02a9ed4182b84c3aa6 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Mon, 16 Mar 2015 11:11:07 +0100 Subject: [PATCH 08/15] update readme and build def --- build.sbt | 14 ++++++-------- project/plugins.sbt | 2 +- readme.md | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/build.sbt b/build.sbt index 15c28b8..eac84bc 100644 --- a/build.sbt +++ b/build.sbt @@ -1,13 +1,11 @@ Nice.javaProject -name := "angulillos" +name := "angulillos" +organization := "bio4j" +description := "A Java API for typed property graphs with a lot of angulillos" +javaVersion := "1.8" -description := "A Java API for typed property graphs with a lot of angulillos" - -organization := "bio4j" - -javaVersion := "1.8" +libraryDependencies += "com.tinkerpop.blueprints" % "blueprints-core" % "2.5.0" -bucketSuffix := "era7.com" +bucketSuffix := "era7.com" -libraryDependencies += "com.tinkerpop.blueprints" % "blueprints-core" % "2.5.0" diff --git a/project/plugins.sbt b/project/plugins.sbt index b0b4564..ebc9a15 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ resolvers += "Era7 maven releases" at "http://releases.era7.com.s3.amazonaws.com" -addSbtPlugin("ohnosequences" % "nice-sbt-settings" % "0.5.0-RC1") +addSbtPlugin("ohnosequences" % "nice-sbt-settings" % "0.5.1") diff --git a/readme.md b/readme.md index 3bb7a18..157d462 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,3 @@ -### Angulillos +# Angulillos -This is a Java 8 library for working with strongly typed graph data in a generic way. \ No newline at end of file +Angulillos is a Java 8 library for working with strongly typed graph data in a generic way. You write graph schemas using the Java type system, with graph traversals being statically checked over graph schemas. The same schemas and traversals can then be used with any graph technology implementing the Angulillos API. \ No newline at end of file From 4b4ac97eef7422b3ab9a7242044dbf8e186b5e6a Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Mon, 16 Mar 2015 12:54:00 +0100 Subject: [PATCH 09/15] generate docs --- .../com/bio4j/angulillos/Property.java.md | 10 + .../com/bio4j/angulillos/TypedEdge.java.md | 10 + .../bio4j/angulillos/TypedEdgeIndex.java.md | 10 + .../com/bio4j/angulillos/TypedElement.java.md | 10 + .../angulillos/TypedElementIndex.java.md | 10 + .../com/bio4j/angulillos/TypedGraph.java.md | 10 + .../com/bio4j/angulillos/TypedVertex.java.md | 10 + .../bio4j/angulillos/TypedVertexIndex.java.md | 10 + .../bio4j/angulillos/TypedVertexQuery.java.md | 10 + .../com/bio4j/angulillos/UntypedGraph.java.md | 10 + .../com/bio4j/angulillos/conversions.java.md | 10 + .../com/bio4j/angulillos/TwitterGraph.java.md | 370 ++++++++++++++++++ .../angulillos/TwitterGraphTestSuite.java.md | 65 +++ 13 files changed, 545 insertions(+) create mode 100644 docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md create mode 100644 docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/Property.java.md b/docs/src/main/java/com/bio4j/angulillos/Property.java.md index 2160e55..9e84b3a 100644 --- a/docs/src/main/java/com/bio4j/angulillos/Property.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/Property.java.md @@ -55,6 +55,14 @@ public interface Property < ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -72,6 +80,8 @@ public interface Property < + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md index 5cfed7d..9dfd3e8 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md @@ -273,6 +273,14 @@ public interface TypedEdge < ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -290,6 +298,8 @@ public interface TypedEdge < + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java.md index e787a52..689e032 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java.md @@ -100,6 +100,14 @@ get a list of nodes by providing a value of the indexed property. ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -117,6 +125,8 @@ get a list of nodes by providing a value of the indexed property. + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedElement.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedElement.java.md index 96adac3..ab3aeba 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedElement.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedElement.java.md @@ -129,6 +129,14 @@ public interface TypedElement < ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -146,6 +154,8 @@ public interface TypedElement < + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedElementIndex.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedElementIndex.java.md index 445472b..6206447 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedElementIndex.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedElementIndex.java.md @@ -103,6 +103,14 @@ get a list of elements by providing a value of the property. The default ... ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -120,6 +128,8 @@ get a list of elements by providing a value of the property. The default ... + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedGraph.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedGraph.java.md index 2d5e860..0afe607 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedGraph.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedGraph.java.md @@ -739,6 +739,14 @@ gets the out edges of a vertex N of G. ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -756,6 +764,8 @@ gets the out edges of a vertex N of G. + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedVertex.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedVertex.java.md index a607891..074ea63 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedVertex.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedVertex.java.md @@ -460,6 +460,14 @@ public interface TypedVertex < ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -477,6 +485,8 @@ public interface TypedVertex < + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java.md index 94d935d..da638a2 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java.md @@ -92,6 +92,14 @@ This interface declares that this index is over a property that classifies lists ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -109,6 +117,8 @@ This interface declares that this index is over a property that classifies lists + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java.md index 051372a..6088802 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java.md @@ -150,6 +150,14 @@ interface VertexQueryIn < ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -167,6 +175,8 @@ interface VertexQueryIn < + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/UntypedGraph.java.md b/docs/src/main/java/com/bio4j/angulillos/UntypedGraph.java.md index 0d646f2..84e7dd7 100644 --- a/docs/src/main/java/com/bio4j/angulillos/UntypedGraph.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/UntypedGraph.java.md @@ -149,6 +149,14 @@ public interface UntypedGraph { ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -166,6 +174,8 @@ public interface UntypedGraph { + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/main/java/com/bio4j/angulillos/conversions.java.md b/docs/src/main/java/com/bio4j/angulillos/conversions.java.md index 6a1c3af..3b101d1 100644 --- a/docs/src/main/java/com/bio4j/angulillos/conversions.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/conversions.java.md @@ -80,6 +80,14 @@ public class conversions { ### Index + src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + main + java + com @@ -97,6 +105,8 @@ public class conversions { + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] +[test/java/com/bio4j/angulillos/TwitterGraph.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: ../../../../../test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md [main/java/com/bio4j/angulillos/TypedGraph.java]: TypedGraph.java.md [main/java/com/bio4j/angulillos/TypedVertexIndex.java]: TypedVertexIndex.java.md [main/java/com/bio4j/angulillos/UntypedGraph.java]: UntypedGraph.java.md diff --git a/docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md b/docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md new file mode 100644 index 0000000..e090134 --- /dev/null +++ b/docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md @@ -0,0 +1,370 @@ + +```java +package com.bio4j.angulillos; + +import com.bio4j.angulillos.TypedEdge.Type.*; + +public abstract class TwitterGraph < + I extends UntypedGraph, + RV, RVT, + RE, RET +> +implements + TypedGraph< + TwitterGraph, + I, RV,RVT, RE,RET + > +{ + + protected I rawGraph = null; + public TwitterGraph(I graph) { rawGraph = graph; } + @Override public I raw() { return rawGraph; } + + // types + public abstract TwitterGraph.UserType User(); + public abstract TwitterGraph.TweetType Tweet(); + public abstract TwitterGraph.PostedType Posted(); +``` + + + ### Vertices and their types + + + #### User + + +```java + public final class UserType + extends + VertexType< + TwitterGraph.User, + TwitterGraph.UserType + > + { + public UserType(RVT raw) { super(raw); } + @Override public final UserType value() { return graph().User(); } + @Override public final User from(RV vertex) { return new User(vertex, this); } +``` + +##### User properties + +```java + public final name name = new name(); + public final class name extends Property { + public name() { super(UserType.this); } + @Override public final Class valueClass() { return String.class; } + } + public final age age = new age(); + public final class age extends Property { + public age() { super(UserType.this); } + @Override public final Class valueClass() { return Integer.class; } + } + } + + public final class User + extends + Vertex< + TwitterGraph.User, + TwitterGraph.UserType + > + { + public User(RV vertex, UserType type) { super(vertex, type); } + @Override public final User self() { return this; } + } +``` + + + #### Tweet + + +```java + public final class TweetType + extends + VertexType< + TwitterGraph.Tweet, + TwitterGraph.TweetType + > + { + public TweetType(RVT raw) { super(raw); } + @Override public final TweetType value() { return graph().Tweet(); } + @Override public final Tweet from(RV vertex) { return new Tweet(vertex, this); } +``` + +##### Tweet properties + +```java + public final text text = new text(); + public final class text extends Property { + public text() { super(TweetType.this); } + @Override public final Class valueClass() { return String.class; } + } + public final url url = new url(); + public final class url extends Property { + public url() { super(TweetType.this); } + @Override public final Class valueClass() { return String.class; } + } + } + + public final class Tweet + extends + Vertex< + TwitterGraph.Tweet, + TwitterGraph.TweetType + > + { + public Tweet(RV vertex, TweetType type) { super(vertex, type); } + @Override public final Tweet self() { return this; } + } +``` + + + ### Edges + + +```java + public final class PostedType + extends + EdgeType< + TwitterGraph.User,TwitterGraph.UserType, + TwitterGraph.Posted,TwitterGraph.PostedType, + TwitterGraph.Tweet,TwitterGraph.TweetType + > + implements + ManyOptionalToOne + { + public PostedType(RET edgeType) { super(TwitterGraph.this.User(), edgeType, TwitterGraph.this.Tweet()); } + @Override public final PostedType value() { return graph().Posted(); } + @Override public final Posted from(RE edge) { return new Posted(edge, this); } + } + public final class Posted + extends + Edge< + TwitterGraph.User,TwitterGraph.UserType, + TwitterGraph.Posted,TwitterGraph.PostedType, + TwitterGraph.Tweet,TwitterGraph.TweetType + > + { + public Posted(RE edge, PostedType type) { super(edge, type); } + @Override public final Posted self() { return this; } + } + + + + + + + + + + + + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////// + +``` + + + ### Abstract helper classes + + These classes bound the types to be from this graph + + +```java + public abstract class ElementType< + E extends TwitterGraph.Element, + ET extends TwitterGraph.ElementType + > + implements + TypedElement.Type, I, RV, RVT, RE, RET> + { + @Override public final TwitterGraph graph() { return TwitterGraph.this; } + } + + public abstract class Element< + E extends TwitterGraph.Element, + ET extends TwitterGraph.ElementType + > + implements + TypedElement, I, RV, RVT, RE, RET> + { + @Override public final TwitterGraph graph() { return TwitterGraph.this; } + } + + public abstract class VertexType< + V extends TwitterGraph.Vertex, + VT extends TwitterGraph.VertexType + > + extends + TwitterGraph.ElementType + implements + com.bio4j.angulillos.TypedVertex.Type, I,RV,RVT,RE,RET> + { + private RVT raw; + protected VertexType(RVT type) { this.raw = type; } + @Override public final RVT raw() { return this.raw; } + } + + public abstract class Vertex< + V extends TwitterGraph.Vertex, + VT extends TwitterGraph.VertexType + > + extends + TwitterGraph.Element + implements + com.bio4j.angulillos.TypedVertex, I,RV,RVT,RE,RET> + { + private RV raw; + private VT type; + protected Vertex(RV vertex, VT type) { + this.raw = vertex; + this.type = type; + } + @Override public final RV raw() { return this.raw; } + @Override public final VT type() { return type; } + } + + public abstract class EdgeType< + S extends TwitterGraph.Vertex, + ST extends TwitterGraph.VertexType, + E extends TwitterGraph.Edge, + ET extends TwitterGraph.EdgeType, + T extends TwitterGraph.Vertex, + TT extends TwitterGraph.VertexType + > + extends + TwitterGraph.ElementType + implements + com.bio4j.angulillos.TypedEdge.Type< + S, ST, TwitterGraph, + E, ET, TwitterGraph, I, RV, RVT, RE, RET, + T, TT, TwitterGraph + > + { + private RET raw; + private ST srcT; + private TT tgtT; + protected EdgeType(ST srcT, RET raw, TT tgtT) { + this.raw = raw; + this.srcT = srcT; + this.tgtT = tgtT; + } + @Override public final ST sourceType() { return srcT; } + @Override public final TT targetType() { return tgtT; } + @Override public final RET raw() { return raw; } + } + + public abstract class Edge< + S extends TwitterGraph.Vertex, + ST extends TwitterGraph.VertexType, + E extends TwitterGraph.Edge, + ET extends TwitterGraph.EdgeType, + T extends TwitterGraph.Vertex, + TT extends TwitterGraph.VertexType + > + extends + TwitterGraph.Element + implements + com.bio4j.angulillos.TypedEdge< + S, ST, TwitterGraph, + E, ET, TwitterGraph, I, RV, RVT, RE, RET, + T, TT, TwitterGraph + > + { + private RE edge; + private ET type; + protected Edge(RE edge, ET type) { + this.edge = edge; + this.type = type; + } + @Override public final RE raw() { return this.edge; } + @Override public final ET type() { return type; } + } + + public abstract class Property< + V extends TwitterGraph.Element, + VT extends TwitterGraph.ElementType, + P extends TwitterGraph.Property, + PV + > + implements + com.bio4j.angulillos.Property, I, RV, RVT, RE, RET> + { + private VT type; + protected Property(VT type) { this.type = type; } + @Override public final VT elementType() { return type; } + } +} + + + + +// // case class Date(day: Integer, month: Integer, year: Integer) +// case object time extends Property[String] + +// case object User extends VertexType("user", name :~: age :~: ∅) +// case object Tweet extends VertexType("tweet", text :~: ∅) + +// case object Posted extends EdgeType(User, "posted", Tweet, time :~: url :~: ∅) with OneIn with ManyOut +// case object Follows extends EdgeType(User, "follows", User, ∅) with ManyIn with ManyOut + +// case object UserNameIx extends CompositeIndex(User, name) +// case object TweetTextIx extends CompositeIndex(Tweet, text) +// case object PostedTimeIx extends CompositeIndex(Posted, time) + +// val schema = GraphSchema("twitter", +// vertexTypes = U +// ser :~: Tweet :~: ∅, +// edgeTypes = Posted :~: Follows :~: ∅, +// indexes = UserNameIx :~: TweetTextIx :~: PostedTimeIx :~: ∅ +// ) + + +``` + + +------ + +### Index + ++ src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + + main + + java + + com + + bio4j + + angulillos + + [TypedGraph.java][main/java/com/bio4j/angulillos/TypedGraph.java] + + [TypedVertexIndex.java][main/java/com/bio4j/angulillos/TypedVertexIndex.java] + + [UntypedGraph.java][main/java/com/bio4j/angulillos/UntypedGraph.java] + + [TypedEdge.java][main/java/com/bio4j/angulillos/TypedEdge.java] + + [conversions.java][main/java/com/bio4j/angulillos/conversions.java] + + [TypedElementIndex.java][main/java/com/bio4j/angulillos/TypedElementIndex.java] + + [Property.java][main/java/com/bio4j/angulillos/Property.java] + + [TypedVertexQuery.java][main/java/com/bio4j/angulillos/TypedVertexQuery.java] + + [TypedElement.java][main/java/com/bio4j/angulillos/TypedElement.java] + + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] + +[test/java/com/bio4j/angulillos/TwitterGraph.java]: TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: TwitterGraphTestSuite.java.md +[main/java/com/bio4j/angulillos/TypedGraph.java]: ../../../../../main/java/com/bio4j/angulillos/TypedGraph.java.md +[main/java/com/bio4j/angulillos/TypedVertexIndex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedVertexIndex.java.md +[main/java/com/bio4j/angulillos/UntypedGraph.java]: ../../../../../main/java/com/bio4j/angulillos/UntypedGraph.java.md +[main/java/com/bio4j/angulillos/TypedEdge.java]: ../../../../../main/java/com/bio4j/angulillos/TypedEdge.java.md +[main/java/com/bio4j/angulillos/conversions.java]: ../../../../../main/java/com/bio4j/angulillos/conversions.java.md +[main/java/com/bio4j/angulillos/TypedElementIndex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedElementIndex.java.md +[main/java/com/bio4j/angulillos/Property.java]: ../../../../../main/java/com/bio4j/angulillos/Property.java.md +[main/java/com/bio4j/angulillos/TypedVertexQuery.java]: ../../../../../main/java/com/bio4j/angulillos/TypedVertexQuery.java.md +[main/java/com/bio4j/angulillos/TypedElement.java]: ../../../../../main/java/com/bio4j/angulillos/TypedElement.java.md +[main/java/com/bio4j/angulillos/TypedEdgeIndex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedEdgeIndex.java.md +[main/java/com/bio4j/angulillos/TypedVertex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedVertex.java.md \ No newline at end of file diff --git a/docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md b/docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md new file mode 100644 index 0000000..ebff144 --- /dev/null +++ b/docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md @@ -0,0 +1,65 @@ + +```java +package com.bio4j.angulillos; + +import com.bio4j.angulillos.TwitterGraph.*; + +import java.util.stream.Stream; +import java.util.Optional; + +public abstract class TwitterGraphTestSuite,V,VT,E,ET> { + + protected TwitterGraph g; + + public void doSomething(TwitterGraph.User user) { + + Optional.Tweet>> tweets = user.outV(g.Posted()); + } +} + +``` + + +------ + +### Index + ++ src + + test + + java + + com + + bio4j + + angulillos + + [TwitterGraph.java][test/java/com/bio4j/angulillos/TwitterGraph.java] + + [TwitterGraphTestSuite.java][test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java] + + resources + + main + + java + + com + + bio4j + + angulillos + + [TypedGraph.java][main/java/com/bio4j/angulillos/TypedGraph.java] + + [TypedVertexIndex.java][main/java/com/bio4j/angulillos/TypedVertexIndex.java] + + [UntypedGraph.java][main/java/com/bio4j/angulillos/UntypedGraph.java] + + [TypedEdge.java][main/java/com/bio4j/angulillos/TypedEdge.java] + + [conversions.java][main/java/com/bio4j/angulillos/conversions.java] + + [TypedElementIndex.java][main/java/com/bio4j/angulillos/TypedElementIndex.java] + + [Property.java][main/java/com/bio4j/angulillos/Property.java] + + [TypedVertexQuery.java][main/java/com/bio4j/angulillos/TypedVertexQuery.java] + + [TypedElement.java][main/java/com/bio4j/angulillos/TypedElement.java] + + [TypedEdgeIndex.java][main/java/com/bio4j/angulillos/TypedEdgeIndex.java] + + [TypedVertex.java][main/java/com/bio4j/angulillos/TypedVertex.java] + +[test/java/com/bio4j/angulillos/TwitterGraph.java]: TwitterGraph.java.md +[test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java]: TwitterGraphTestSuite.java.md +[main/java/com/bio4j/angulillos/TypedGraph.java]: ../../../../../main/java/com/bio4j/angulillos/TypedGraph.java.md +[main/java/com/bio4j/angulillos/TypedVertexIndex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedVertexIndex.java.md +[main/java/com/bio4j/angulillos/UntypedGraph.java]: ../../../../../main/java/com/bio4j/angulillos/UntypedGraph.java.md +[main/java/com/bio4j/angulillos/TypedEdge.java]: ../../../../../main/java/com/bio4j/angulillos/TypedEdge.java.md +[main/java/com/bio4j/angulillos/conversions.java]: ../../../../../main/java/com/bio4j/angulillos/conversions.java.md +[main/java/com/bio4j/angulillos/TypedElementIndex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedElementIndex.java.md +[main/java/com/bio4j/angulillos/Property.java]: ../../../../../main/java/com/bio4j/angulillos/Property.java.md +[main/java/com/bio4j/angulillos/TypedVertexQuery.java]: ../../../../../main/java/com/bio4j/angulillos/TypedVertexQuery.java.md +[main/java/com/bio4j/angulillos/TypedElement.java]: ../../../../../main/java/com/bio4j/angulillos/TypedElement.java.md +[main/java/com/bio4j/angulillos/TypedEdgeIndex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedEdgeIndex.java.md +[main/java/com/bio4j/angulillos/TypedVertex.java]: ../../../../../main/java/com/bio4j/angulillos/TypedVertex.java.md \ No newline at end of file From b41ff296b53602aa7fdb0154fe86159d69c80dc9 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Mon, 16 Mar 2015 17:16:28 +0100 Subject: [PATCH 10/15] add examples, fix bug in arities; needs to be backported to #40 --- .../java/com/bio4j/angulillos/TypedEdge.java | 22 +++++++++++++++++++ .../java/com/bio4j/angulillos/TypedGraph.java | 8 +++---- .../com/bio4j/angulillos/TypedVertex.java | 8 +++---- .../com/bio4j/angulillos/TwitterGraph.java | 1 + .../angulillos/TwitterGraphTestSuite.java | 17 +++++++++++++- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index 35068a4..d6b0ef5 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -154,13 +154,35 @@ public enum Arity { manyOptionalToManyOptional; } + /* + `AlwaysDefined` implies that `out` will always return something + */ public interface AlwaysDefined extends HasArity {} + /* + `Surjctive` implies that `in` will always return something + */ public interface Surjective extends HasArity {} + /* + `ToMany` means that `in` will in general return more than one + */ public interface ToMany extends HasArity {} + /* + `ToOne` means that `in` will at most return one + */ public interface ToOne extends HasArity {} + /* + `FromOne` means that `out` will at most return one + */ public interface FromOne extends HasArity {} + /* + `FromMany` means that `out` will in general return more than one + */ public interface FromMany extends HasArity {} + /* + Built-in combinations + */ + public interface OneToOne extends FromOne, AlwaysDefined, ToOne, Surjective { default Arity arity() { return Arity.oneToOne; } diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index cba7f15..44ccb9e 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -459,8 +459,8 @@ Stream inV(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne & + TypedEdge.Type.Surjective, RG extends TypedGraph, // tgt N extends TypedVertex, @@ -484,8 +484,8 @@ R inOneE(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne & + TypedEdge.Type.Surjective, RG extends TypedGraph, // tgt N extends TypedVertex, diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/TypedVertex.java index 02acc4c..dd7568b 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertex.java @@ -129,8 +129,8 @@ Stream inV(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne & + TypedEdge.Type.Surjective, RG extends TypedGraph > R inOneE(RT relType) { @@ -145,8 +145,8 @@ R inOneE(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne & + TypedEdge.Type.Surjective, RG extends TypedGraph > S inOneV(RT relType) { diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraph.java b/src/test/java/com/bio4j/angulillos/TwitterGraph.java index 5234a1a..be8c9b6 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraph.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraph.java @@ -116,6 +116,7 @@ public final class PostedType TwitterGraph.Tweet,TwitterGraph.TweetType > implements + // a user can have no tweets, but a tweet is always tweeted by some and exactly one user ManyOptionalToOne { public PostedType(RET edgeType) { super(TwitterGraph.this.User(), edgeType, TwitterGraph.this.Tweet()); } diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 99393ab..8a1c0c9 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -11,6 +11,21 @@ public abstract class TwitterGraphTestSuite,V, public void doSomething(TwitterGraph.User user) { - Optional.Tweet>> tweets = user.outV(g.Posted()); + Stream.Tweet> tweets = user.outV(g.Posted()); + } + + public Stream.User> tweetedTheTweetsThatTweeted(TwitterGraph.User user) { + + return user.outV(g.Posted()).flatMap( + tw -> tw.inV(g.Posted()) + ); + } + + /* + This uses arity-specific methods to return **the** user that tweeted a tweet. + */ + public TwitterGraph.User tweeted(TwitterGraph.Tweet tweet) { + + return tweet.inOneV(g.Posted()); } } From 9f06cfda2be8329569a3fde9fd862f765bcde003 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Mon, 16 Mar 2015 18:19:12 +0100 Subject: [PATCH 11/15] fix arity names again --- .../java/com/bio4j/angulillos/TypedEdge.java | 203 +++++++++++------- .../com/bio4j/angulillos/TwitterGraph.java | 6 +- 2 files changed, 133 insertions(+), 76 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index 913df94..8c71b81 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -133,25 +133,25 @@ public interface Type < */ public enum Arity { - oneToOne, - oneToOneOptional, - oneToMany, - oneToManyOptional, - - oneOptionalToOne, - oneOptionalToOneOptional, - oneOptionalToMany, - oneOptionalToManyOptional, + fromOneToOne, + fromOneToOptional, + fromOneToMany, + fromOneToManyOptional, + + fromOptionalToOne, + fromOptionalToOptional, + fromOptionalToMany, + fromOptionalToManyOptional, - manyToOne, - manyToOneOptional, - manyToMany, - manyToManyOptional, - - manyOptionalToOne, - manyOptionalToOneOptional, - manyOptionalToMany, - manyOptionalToManyOptional; + fromManyToOne, + fromManyToOptional, + fromManyToMany, + fromManyToManyOptional, + + fromManyOptionalToOne, + fromManyOptionalToOptional, + fromManyOptionalToMany, + fromManyOptionalToManyOptional; } /* @@ -159,106 +159,161 @@ public enum Arity { We have six basic arities: three for in, three for out. */ + + /* + #### in arities + */ + /* An edge type `e` being _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices */ + public interface Surjective extends HasArity {} + /* An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex */ + public interface FromMany extends HasArity {} + /* An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex */ + public interface FromOne extends HasArity {} - /* That an edge type `e` is _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices */ + /* + #### out arities + */ + /* That an edge type `e` being _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices */ public interface AlwaysDefined extends HasArity {} /* An edge type `e` being _to many_ implies that calling `outV(e)` will in general return more than one vertex */ public interface ToMany extends HasArity {} /* An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex */ public interface ToOne extends HasArity {} - /* An edge type `e` is _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices */ - public interface Surjective extends HasArity {} - /* An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex */ - public interface FromMany extends HasArity {} - /* An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex */ - public interface FromOne extends HasArity {} /* #### Arity combinations - These are all the possible combinations of the different arities. + These are all the possible combinations of the different arities. In the first line under `extends` you see those that correspond to `in`, and in the second one those that correspond to `out` */ - public interface OneToOne extends FromOne, AlwaysDefined, ToOne, Surjective { - - default Arity arity() { return Arity.oneToOne; } + public interface FromOneToOne + extends + FromOne, Surjective, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromOneToOne; } } - public interface OneToOneOptional extends FromOne, AlwaysDefined, ToOne { - - default Arity arity() { return Arity.oneToOneOptional; } + public interface FromOneToOptional + extends + FromOne, Surjective, + ToOne + { + default Arity arity() { return Arity.fromOneToOptional; } } - public interface OneToMany extends FromOne, AlwaysDefined, ToMany, Surjective { - - default Arity arity() { return Arity.oneToMany; } + public interface FromOneToMany + extends + FromOne, Surjective, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromOneToMany; } } - public interface OneToManyOptional extends FromOne, AlwaysDefined, ToMany { - - default Arity arity() { return Arity.oneToManyOptional; } + public interface FromOneToManyOptional + extends + FromOne, Surjective, + ToMany + { + default Arity arity() { return Arity.fromOneToManyOptional; } } - public interface OneOptionalToOne extends FromOne, ToOne, Surjective { - - default Arity arity() { return Arity.oneOptionalToOne; } + public interface FromOptionalToOne + extends + FromOne, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromOptionalToOne; } } - public interface OneOptionalToOneOptional extends FromOne, ToOne { - - default Arity arity() { return Arity.oneOptionalToOneOptional; } + public interface FromOptionalToOptional + extends + FromOne, + ToOne + { + default Arity arity() { return Arity.fromOptionalToOptional; } } - public interface OneOptionalToMany extends FromOne, ToMany, Surjective { - - default Arity arity() { return Arity.oneOptionalToMany; } + public interface FromOptionalToMany + extends + FromOne, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromOptionalToMany; } } - public interface OneOptionalToManyOptional extends FromOne, ToMany { - - default Arity arity() { return Arity.oneOptionalToManyOptional; } + public interface FromOptionalToManyOptional + extends + FromOne, + ToMany + { + default Arity arity() { return Arity.fromOptionalToManyOptional; } } - public interface ManyToOne extends FromMany, AlwaysDefined, ToOne, Surjective { - - default Arity arity() { return Arity.manyToOne; } + public interface FromManyToOne + extends + FromMany, Surjective, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromManyToOne; } } - public interface ManyToOneOptional extends FromMany, AlwaysDefined, ToOne { - - default Arity arity() { return Arity.manyToOneOptional; } + public interface FromManyToOptional + extends + FromMany, Surjective, + ToOne + { + default Arity arity() { return Arity.fromManyToOptional; } } - public interface ManyToMany extends FromMany, AlwaysDefined, ToMany, Surjective { - - default Arity arity() { return Arity.manyToMany; } + public interface FromManyToMany + extends + FromMany, Surjective, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromManyToMany; } } - public interface ManyToManyOptional extends FromMany, AlwaysDefined, ToMany { - - default Arity arity() { return Arity.manyToManyOptional; } + public interface FromManyToManyOptional + extends + FromMany, Surjective, + ToMany + { + default Arity arity() { return Arity.fromManyToManyOptional; } } - public interface ManyOptionalToOne extends FromMany, ToOne, Surjective { - - default Arity arity() { return Arity.manyOptionalToOne; } + public interface FromManyOptionalToOne + extends + FromMany, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromManyOptionalToOne; } } - public interface ManyOptionalToOneOptional extends FromMany, ToOne { - - default Arity arity() { return Arity.manyOptionalToOneOptional; } + public interface FromManyOptionalToOptional + extends + FromMany, + ToOne + { + default Arity arity() { return Arity.fromManyOptionalToOptional; } } - public interface ManyOptionalToMany extends FromMany, ToMany, Surjective { - - default Arity arity() { return Arity.manyOptionalToMany; } + public interface FromManyOptionalToMany + extends + FromMany, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromManyOptionalToMany; } } - public interface ManyOptionalToManyOptional extends FromMany, ToMany { - - default Arity arity() { return Arity.manyOptionalToManyOptional; } + public interface FromManyOptionalToManyOptional + extends + FromMany, + ToMany + { + default Arity arity() { return Arity.fromManyOptionalToManyOptional; } } } } diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraph.java b/src/test/java/com/bio4j/angulillos/TwitterGraph.java index be8c9b6..23d48c8 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraph.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraph.java @@ -116,8 +116,10 @@ public final class PostedType TwitterGraph.Tweet,TwitterGraph.TweetType > implements - // a user can have no tweets, but a tweet is always tweeted by some and exactly one user - ManyOptionalToOne + // u -[posted]-> t + // u.outV(posted) = many maybe none + // t.inV(posted) = one + FromOneToManyOptional { public PostedType(RET edgeType) { super(TwitterGraph.this.User(), edgeType, TwitterGraph.this.Tweet()); } @Override public final PostedType value() { return graph().Posted(); } From e8338ef2c8b04a94eef88c94ada89e27f040e1df Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Mon, 16 Mar 2015 18:23:24 +0100 Subject: [PATCH 12/15] merge generic testing with fix for arities --- .../com/bio4j/angulillos/TypedEdge.java.md | 212 +++++++++++------- .../com/bio4j/angulillos/TwitterGraph.java.md | 5 +- .../angulillos/TwitterGraphTestSuite.java.md | 20 +- 3 files changed, 156 insertions(+), 81 deletions(-) diff --git a/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md b/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md index 7c31611..65a78cd 100644 --- a/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md +++ b/docs/src/main/java/com/bio4j/angulillos/TypedEdge.java.md @@ -153,25 +153,25 @@ public interface TypedEdge < ```java public enum Arity { - oneToOne, - oneToOneOptional, - oneToMany, - oneToManyOptional, - - oneOptionalToOne, - oneOptionalToOneOptional, - oneOptionalToMany, - oneOptionalToManyOptional, + fromOneToOne, + fromOneToOptional, + fromOneToMany, + fromOneToManyOptional, + + fromOptionalToOne, + fromOptionalToOptional, + fromOptionalToMany, + fromOptionalToManyOptional, - manyToOne, - manyToOneOptional, - manyToMany, - manyToManyOptional, - - manyOptionalToOne, - manyOptionalToOneOptional, - manyOptionalToMany, - manyOptionalToManyOptional; + fromManyToOne, + fromManyToOptional, + fromManyToMany, + fromManyToManyOptional, + + fromManyOptionalToOne, + fromManyOptionalToOptional, + fromManyOptionalToMany, + fromManyOptionalToManyOptional; } ``` @@ -180,129 +180,183 @@ public interface TypedEdge < We have six basic arities: three for in, three for out. -That an edge type `e` is _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices + +#### in arities + +An edge type `e` being _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices ```java - public interface AlwaysDefined extends HasArity {} + public interface Surjective extends HasArity {} ``` -An edge type `e` being _to many_ implies that calling `outV(e)` will in general return more than one vertex +An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex ```java - public interface ToMany extends HasArity {} + public interface FromMany extends HasArity {} ``` -An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex +An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex ```java - public interface ToOne extends HasArity {} + public interface FromOne extends HasArity {} ``` -An edge type `e` is _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices + +#### out arities + +That an edge type `e` being _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices ```java - public interface Surjective extends HasArity {} + public interface AlwaysDefined extends HasArity {} ``` -An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex +An edge type `e` being _to many_ implies that calling `outV(e)` will in general return more than one vertex ```java - public interface FromMany extends HasArity {} + public interface ToMany extends HasArity {} ``` -An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex +An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex ```java - public interface FromOne extends HasArity {} + public interface ToOne extends HasArity {} ``` #### Arity combinations -These are all the possible combinations of the different arities. +These are all the possible combinations of the different arities. In the first line under `extends` you see those that correspond to `in`, and in the second one those that correspond to `out` ```java - public interface OneToOne extends FromOne, AlwaysDefined, ToOne, Surjective { - - default Arity arity() { return Arity.oneToOne; } + public interface FromOneToOne + extends + FromOne, Surjective, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromOneToOne; } } - public interface OneToOneOptional extends FromOne, AlwaysDefined, ToOne { - - default Arity arity() { return Arity.oneToOneOptional; } + public interface FromOneToOptional + extends + FromOne, Surjective, + ToOne + { + default Arity arity() { return Arity.fromOneToOptional; } } - public interface OneToMany extends FromOne, AlwaysDefined, ToMany, Surjective { - - default Arity arity() { return Arity.oneToMany; } + public interface FromOneToMany + extends + FromOne, Surjective, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromOneToMany; } } - public interface OneToManyOptional extends FromOne, AlwaysDefined, ToMany { - - default Arity arity() { return Arity.oneToManyOptional; } + public interface FromOneToManyOptional + extends + FromOne, Surjective, + ToMany + { + default Arity arity() { return Arity.fromOneToManyOptional; } } - public interface OneOptionalToOne extends FromOne, ToOne, Surjective { - - default Arity arity() { return Arity.oneOptionalToOne; } + public interface FromOptionalToOne + extends + FromOne, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromOptionalToOne; } } - public interface OneOptionalToOneOptional extends FromOne, ToOne { - - default Arity arity() { return Arity.oneOptionalToOneOptional; } + public interface FromOptionalToOptional + extends + FromOne, + ToOne + { + default Arity arity() { return Arity.fromOptionalToOptional; } } - public interface OneOptionalToMany extends FromOne, ToMany, Surjective { - - default Arity arity() { return Arity.oneOptionalToMany; } + public interface FromOptionalToMany + extends + FromOne, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromOptionalToMany; } } - public interface OneOptionalToManyOptional extends FromOne, ToMany { - - default Arity arity() { return Arity.oneOptionalToManyOptional; } + public interface FromOptionalToManyOptional + extends + FromOne, + ToMany + { + default Arity arity() { return Arity.fromOptionalToManyOptional; } } - public interface ManyToOne extends FromMany, AlwaysDefined, ToOne, Surjective { - - default Arity arity() { return Arity.manyToOne; } + public interface FromManyToOne + extends + FromMany, Surjective, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromManyToOne; } } - public interface ManyToOneOptional extends FromMany, AlwaysDefined, ToOne { - - default Arity arity() { return Arity.manyToOneOptional; } + public interface FromManyToOptional + extends + FromMany, Surjective, + ToOne + { + default Arity arity() { return Arity.fromManyToOptional; } } - public interface ManyToMany extends FromMany, AlwaysDefined, ToMany, Surjective { - - default Arity arity() { return Arity.manyToMany; } + public interface FromManyToMany + extends + FromMany, Surjective, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromManyToMany; } } - public interface ManyToManyOptional extends FromMany, AlwaysDefined, ToMany { - - default Arity arity() { return Arity.manyToManyOptional; } + public interface FromManyToManyOptional + extends + FromMany, Surjective, + ToMany + { + default Arity arity() { return Arity.fromManyToManyOptional; } } - public interface ManyOptionalToOne extends FromMany, ToOne, Surjective { - - default Arity arity() { return Arity.manyOptionalToOne; } + public interface FromManyOptionalToOne + extends + FromMany, + ToOne, AlwaysDefined + { + default Arity arity() { return Arity.fromManyOptionalToOne; } } - public interface ManyOptionalToOneOptional extends FromMany, ToOne { - - default Arity arity() { return Arity.manyOptionalToOneOptional; } + public interface FromManyOptionalToOptional + extends + FromMany, + ToOne + { + default Arity arity() { return Arity.fromManyOptionalToOptional; } } - public interface ManyOptionalToMany extends FromMany, ToMany, Surjective { - - default Arity arity() { return Arity.manyOptionalToMany; } + public interface FromManyOptionalToMany + extends + FromMany, + ToMany, AlwaysDefined + { + default Arity arity() { return Arity.fromManyOptionalToMany; } } - public interface ManyOptionalToManyOptional extends FromMany, ToMany { - - default Arity arity() { return Arity.manyOptionalToManyOptional; } + public interface FromManyOptionalToManyOptional + extends + FromMany, + ToMany + { + default Arity arity() { return Arity.fromManyOptionalToManyOptional; } } } } diff --git a/docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md b/docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md index e090134..5238cca 100644 --- a/docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md +++ b/docs/src/test/java/com/bio4j/angulillos/TwitterGraph.java.md @@ -130,7 +130,10 @@ implements TwitterGraph.Tweet,TwitterGraph.TweetType > implements - ManyOptionalToOne + // u -[posted]-> t + // u.outV(posted) = many maybe none + // t.inV(posted) = one + FromOneToManyOptional { public PostedType(RET edgeType) { super(TwitterGraph.this.User(), edgeType, TwitterGraph.this.Tweet()); } @Override public final PostedType value() { return graph().Posted(); } diff --git a/docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md b/docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md index ebff144..c4356a6 100644 --- a/docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md +++ b/docs/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java.md @@ -13,7 +13,25 @@ public abstract class TwitterGraphTestSuite,V, public void doSomething(TwitterGraph.User user) { - Optional.Tweet>> tweets = user.outV(g.Posted()); + Stream.Tweet> tweets = user.outV(g.Posted()); + } + + public Stream.User> tweetedTheTweetsThatTweeted(TwitterGraph.User user) { + + return user.outV(g.Posted()).flatMap( + tw -> tw.inV(g.Posted()) + ); + } +``` + + +This uses arity-specific methods to return **the** user that tweeted a tweet. + + +```java + public TwitterGraph.User tweeted(TwitterGraph.Tweet tweet) { + + return tweet.inOneV(g.Posted()); } } From 54732ead88a9e10ca3ed6032b1f8d78604a672a1 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Wed, 18 Mar 2015 16:08:41 +0100 Subject: [PATCH 13/15] Change the names of arities #40, add more edges to the twitter graph --- .../java/com/bio4j/angulillos/TypedEdge.java | 190 ++++++++---------- .../java/com/bio4j/angulillos/TypedGraph.java | 32 ++- .../com/bio4j/angulillos/TypedVertex.java | 32 ++- .../com/bio4j/angulillos/TwitterGraph.java | 66 +++++- 4 files changed, 174 insertions(+), 146 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index 8c71b81..9f73192 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -133,25 +133,26 @@ public interface Type < */ public enum Arity { - fromOneToOne, - fromOneToOptional, - fromOneToMany, - fromOneToManyOptional, - - fromOptionalToOne, - fromOptionalToOptional, - fromOptionalToMany, - fromOptionalToManyOptional, - - fromManyToOne, - fromManyToOptional, - fromManyToMany, - fromManyToManyOptional, - - fromManyOptionalToOne, - fromManyOptionalToOptional, - fromManyOptionalToMany, - fromManyOptionalToManyOptional; + oneToOne, + oneToAtMostOne, + oneToAtLeastOne, + oneToAny, + + atMostOneToOne, + atMostOneToAtMostOne, + atMostOneToAtLeastOne, + atMostOneToAny, + + atLeastOneToOne, + atLeastOneToAtMostOne, + atLeastOneToAtLeastOne, + atLeastOneToAny, + + anyToOne, + anyToAtMostOne, + anyToAtLeastOne, + // whatever + anyToAny; } /* @@ -164,21 +165,21 @@ public enum Arity { #### in arities */ /* An edge type `e` being _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices */ - public interface Surjective extends HasArity {} + public interface FromAtLeastOne extends HasArity {} /* An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex */ - public interface FromMany extends HasArity {} - /* An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex */ public interface FromOne extends HasArity {} + /* An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex */ + public interface FromAtMostOne extends HasArity {} /* #### out arities */ /* That an edge type `e` being _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices */ - public interface AlwaysDefined extends HasArity {} + public interface ToAtLeastOne extends HasArity {} /* An edge type `e` being _to many_ implies that calling `outV(e)` will in general return more than one vertex */ - public interface ToMany extends HasArity {} - /* An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex */ public interface ToOne extends HasArity {} + /* An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex */ + public interface ToAtMostOne extends HasArity {} /* @@ -186,134 +187,121 @@ public interface ToOne extends HasArity {} These are all the possible combinations of the different arities. In the first line under `extends` you see those that correspond to `in`, and in the second one those that correspond to `out` */ - public interface FromOneToOne + + // oneTo + public interface OneToOne extends - FromOne, Surjective, - ToOne, AlwaysDefined + FromOne, + ToOne { - default Arity arity() { return Arity.fromOneToOne; } + default Arity arity() { return Arity.oneToOne; } } - - public interface FromOneToOptional + public interface OneToAtMostOne extends - FromOne, Surjective, - ToOne + FromOne, + ToAtMostOne { - default Arity arity() { return Arity.fromOneToOptional; } + default Arity arity() { return Arity.oneToAtMostOne; } } - - public interface FromOneToMany + public interface OneToAtLeastOne extends - FromOne, Surjective, - ToMany, AlwaysDefined + FromOne, + ToAtLeastOne { - default Arity arity() { return Arity.fromOneToMany; } + default Arity arity() { return Arity.oneToAtLeastOne; } } - - public interface FromOneToManyOptional + public interface OneToAny extends - FromOne, Surjective, - ToMany + FromOne { - default Arity arity() { return Arity.fromOneToManyOptional; } + default Arity arity() { return Arity.oneToAny; } } - public interface FromOptionalToOne + + // atMostOneTo + public interface AtMostOneToOne extends - FromOne, - ToOne, AlwaysDefined + FromAtMostOne, + ToOne { - default Arity arity() { return Arity.fromOptionalToOne; } + default Arity arity() { return Arity.atMostOneToOne; } } - - public interface FromOptionalToOptional + public interface AtMostOneToAtMostOne extends - FromOne, - ToOne + FromAtMostOne, + ToAtMostOne { - default Arity arity() { return Arity.fromOptionalToOptional; } + default Arity arity() { return Arity.atMostOneToAtMostOne; } } - - public interface FromOptionalToMany + public interface AtMostOneToAtLeastOne extends - FromOne, - ToMany, AlwaysDefined + FromAtMostOne, + ToAtLeastOne { - default Arity arity() { return Arity.fromOptionalToMany; } + default Arity arity() { return Arity.atMostOneToAtLeastOne; } } - - public interface FromOptionalToManyOptional + public interface AtMostOneToAny extends - FromOne, - ToMany + FromAtMostOne { - default Arity arity() { return Arity.fromOptionalToManyOptional; } + default Arity arity() { return Arity.atMostOneToAny; } } - - public interface FromManyToOne + // fromAtLeastOne + public interface AtLeastOneToOne extends - FromMany, Surjective, - ToOne, AlwaysDefined + FromAtLeastOne, + ToOne { - default Arity arity() { return Arity.fromManyToOne; } + default Arity arity() { return Arity.atLeastOneToOne; } } - - public interface FromManyToOptional + public interface AtLeastOneToAtMostOne extends - FromMany, Surjective, - ToOne + FromAtLeastOne, + ToAtMostOne { - default Arity arity() { return Arity.fromManyToOptional; } + default Arity arity() { return Arity.atLeastOneToAtMostOne; } } - - public interface FromManyToMany + public interface AtLeastOneToAtLeastOne extends - FromMany, Surjective, - ToMany, AlwaysDefined + FromAtLeastOne, + ToAtLeastOne { - default Arity arity() { return Arity.fromManyToMany; } + default Arity arity() { return Arity.atLeastOneToAtLeastOne; } } - public interface FromManyToManyOptional + public interface AtLeastOneToAny extends - FromMany, Surjective, - ToMany + FromAtLeastOne { - default Arity arity() { return Arity.fromManyToManyOptional; } + default Arity arity() { return Arity.atLeastOneToAny; } } - public interface FromManyOptionalToOne + // from any + public interface AnyToOne extends - FromMany, - ToOne, AlwaysDefined + ToOne { - default Arity arity() { return Arity.fromManyOptionalToOne; } + default Arity arity() { return Arity.anyToOne; } } - - public interface FromManyOptionalToOptional + public interface AnyToAtMostOne extends - FromMany, - ToOne + ToAtMostOne { - default Arity arity() { return Arity.fromManyOptionalToOptional; } + default Arity arity() { return Arity.anyToAtMostOne; } } - - public interface FromManyOptionalToMany + public interface AnyToAtLeastOne extends - FromMany, - ToMany, AlwaysDefined + ToAtLeastOne { - default Arity arity() { return Arity.fromManyOptionalToMany; } + default Arity arity() { return Arity.anyToAtLeastOne; } } - - public interface FromManyOptionalToManyOptional + public interface AnyToAny extends - FromMany, - ToMany + HasArity { - default Arity arity() { return Arity.fromManyOptionalToManyOptional; } + default Arity arity() { return Arity.anyToAny; } } } } diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 627df18..20f89b3 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -250,8 +250,7 @@ Stream outV(N node, RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -276,8 +275,7 @@ R outOneE(N node, RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -303,7 +301,7 @@ T outOneV(N node, RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne, + TypedEdge.Type.ToAtMostOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -327,7 +325,7 @@ Optional outOptionalE(N node, RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne, + TypedEdge.Type.ToAtMostOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -353,8 +351,7 @@ Optional outOptionalV(N node, RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToMany & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToAtLeastOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -377,8 +374,7 @@ Stream outManyE(N node, RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToMany & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToAtLeastOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -459,8 +455,7 @@ Stream inV(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromOne, RG extends TypedGraph, // tgt N extends TypedVertex, @@ -484,8 +479,7 @@ R inOneE(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromOne, RG extends TypedGraph, // tgt N extends TypedVertex, @@ -511,7 +505,7 @@ S inOneV(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne, + TypedEdge.Type.FromAtMostOne, RG extends TypedGraph, // tgt N extends TypedVertex, @@ -536,7 +530,7 @@ Optional inOptionalE(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne, + TypedEdge.Type.FromAtMostOne, RG extends TypedGraph, // tgt N extends TypedVertex, @@ -563,8 +557,7 @@ Optional inOptionalV(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromMany & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromAtLeastOne, RG extends TypedGraph, // tgt N extends TypedVertex, @@ -588,8 +581,7 @@ Stream inManyE(RT relType, N node) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromMany & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromAtLeastOne, RG extends TypedGraph, // tgt N extends TypedVertex, diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/TypedVertex.java index 3213026..b5519fb 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertex.java @@ -129,8 +129,7 @@ Stream inV(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromOne, RG extends TypedGraph > R inOneE(RT relType) { @@ -145,8 +144,7 @@ R inOneE(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromOne, RG extends TypedGraph > S inOneV(RT relType) { @@ -162,7 +160,7 @@ S inOneV(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne, + TypedEdge.Type.FromAtMostOne, RG extends TypedGraph > Optional inOptionalE(RT relType) { @@ -177,7 +175,7 @@ Optional inOptionalE(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromOne, + TypedEdge.Type.FromAtMostOne, RG extends TypedGraph > Optional inOptionalV(RT relType) { @@ -193,8 +191,7 @@ Optional inOptionalV(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromMany & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromAtLeastOne, RG extends TypedGraph > Stream inManyE(RT relType) { @@ -209,8 +206,7 @@ Stream inManyE(RT relType) { // rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.FromMany & - TypedEdge.Type.Surjective, + TypedEdge.Type.FromAtLeastOne, RG extends TypedGraph > Stream inManyV(RT relType) { @@ -256,8 +252,7 @@ Stream outV(RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToMany & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToAtLeastOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -273,8 +268,7 @@ Stream outManyE(RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToMany & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToAtLeastOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -290,8 +284,7 @@ Stream outManyV(RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -307,8 +300,7 @@ T outOneV(RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne & - TypedEdge.Type.AlwaysDefined, + TypedEdge.Type.ToOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -324,7 +316,7 @@ R outOneE(RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne, + TypedEdge.Type.ToAtMostOne, RG extends TypedGraph, // target node T extends TypedVertex, @@ -341,7 +333,7 @@ Optional outOptionalE(RT relType) { //rel R extends TypedEdge, RT extends TypedEdge.Type & - TypedEdge.Type.ToOne, + TypedEdge.Type.ToAtMostOne, RG extends TypedGraph, // target node T extends TypedVertex, diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraph.java b/src/test/java/com/bio4j/angulillos/TwitterGraph.java index 23d48c8..da0a8b6 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraph.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraph.java @@ -18,10 +18,13 @@ public abstract class TwitterGraph < public TwitterGraph(I graph) { rawGraph = graph; } @Override public I raw() { return rawGraph; } - // types - public abstract TwitterGraph.UserType User(); - public abstract TwitterGraph.TweetType Tweet(); - public abstract TwitterGraph.PostedType Posted(); + // vertices + public abstract TwitterGraph.UserType User(); + public abstract TwitterGraph.TweetType Tweet(); + // edges + public abstract TwitterGraph.PostedType Posted(); + public abstract TwitterGraph.RepliesToType RepliesTo(); + public abstract TwitterGraph.FollowsType Follows(); /* ### Vertices and their types @@ -119,7 +122,7 @@ public final class PostedType // u -[posted]-> t // u.outV(posted) = many maybe none // t.inV(posted) = one - FromOneToManyOptional + OneToAny { public PostedType(RET edgeType) { super(TwitterGraph.this.User(), edgeType, TwitterGraph.this.Tweet()); } @Override public final PostedType value() { return graph().Posted(); } @@ -137,6 +140,59 @@ public final class Posted @Override public final Posted self() { return this; } } + public final class FollowsType + extends + EdgeType< + TwitterGraph.User,TwitterGraph.UserType, + TwitterGraph.Follows,TwitterGraph.FollowsType, + TwitterGraph.User,TwitterGraph.UserType + > + implements + AnyToAny + { + public FollowsType(RET edgeType) { super(TwitterGraph.this.User(), edgeType, TwitterGraph.this.User()); } + @Override public final FollowsType value() { return graph().Follows(); } + @Override public final Follows from(RE edge) { return new Follows(edge, this); } + } + public final class Follows + extends + Edge< + TwitterGraph.User,TwitterGraph.UserType, + TwitterGraph.Follows,TwitterGraph.FollowsType, + TwitterGraph.User,TwitterGraph.UserType + > + { + public Follows(RE edge, FollowsType type) { super(edge, type); } + @Override public final Follows self() { return this; } + } + + public final class RepliesToType + extends + EdgeType< + TwitterGraph.Tweet,TwitterGraph.TweetType, + TwitterGraph.RepliesTo,TwitterGraph.RepliesToType, + TwitterGraph.Tweet,TwitterGraph.TweetType + > + implements + // a tweet can be a reply to at most one tweet + AnyToAtMostOne + { + public RepliesToType(RET edgeType) { super(TwitterGraph.this.Tweet(), edgeType, TwitterGraph.this.Tweet()); } + @Override public final RepliesToType value() { return graph().RepliesTo(); } + @Override public final RepliesTo from(RE edge) { return new RepliesTo(edge, this); } + } + public final class RepliesTo + extends + Edge< + TwitterGraph.Tweet,TwitterGraph.TweetType, + TwitterGraph.RepliesTo,TwitterGraph.RepliesToType, + TwitterGraph.Tweet,TwitterGraph.TweetType + > + { + public RepliesTo(RE edge, RepliesToType type) { super(edge, type); } + @Override public final RepliesTo self() { return this; } + } + From 360f814a87a5792dfb0551d130861941e97bbd80 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Wed, 18 Mar 2015 16:23:40 +0100 Subject: [PATCH 14/15] add a sample method to the Twitter tests --- .../java/com/bio4j/angulillos/TwitterGraphTestSuite.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 8a1c0c9..c45404b 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -28,4 +28,13 @@ public TwitterGraph.User tweeted(TwitterGraph.Tweet tw return tweet.inOneV(g.Posted()); } + + public Stream.User> repliedToSomeTweetFrom(TwitterGraph.User user) { + + return user + .outV( g.Posted() ) + .flatMap( tw -> tw.inV( g.RepliesTo() ) ) + .map( tw -> tw.inOneV( g.Posted() ) ) + .distinct(); + } } From 2ff82ef029471ba78981fe85ef369f2782dba4d4 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Sat, 21 Mar 2015 20:34:03 +0100 Subject: [PATCH 15/15] remove old stale code from the Twitter graph schema --- .../com/bio4j/angulillos/TwitterGraph.java | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraph.java b/src/test/java/com/bio4j/angulillos/TwitterGraph.java index da0a8b6..2fd40dd 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraph.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraph.java @@ -337,28 +337,4 @@ public abstract class Property< protected Property(VT type) { this.type = type; } @Override public final VT elementType() { return type; } } -} - - - - -// // case class Date(day: Integer, month: Integer, year: Integer) -// case object time extends Property[String] - -// case object User extends VertexType("user", name :~: age :~: ∅) -// case object Tweet extends VertexType("tweet", text :~: ∅) - -// case object Posted extends EdgeType(User, "posted", Tweet, time :~: url :~: ∅) with OneIn with ManyOut -// case object Follows extends EdgeType(User, "follows", User, ∅) with ManyIn with ManyOut - -// case object UserNameIx extends CompositeIndex(User, name) -// case object TweetTextIx extends CompositeIndex(Tweet, text) -// case object PostedTimeIx extends CompositeIndex(Posted, time) - -// val schema = GraphSchema("twitter", -// vertexTypes = U -// ser :~: Tweet :~: ∅, -// edgeTypes = Posted :~: Follows :~: ∅, -// indexes = UserNameIx :~: TweetTextIx :~: PostedTimeIx :~: ∅ -// ) - +} \ No newline at end of file