public void HasLabelSoftwareAsNameAsLanguageAsCreatorsSelectNameLanguageCreatorsByNameByLangByInCreatedValuesNameFoldOrderLocal() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { command.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = command.g().V().HasLabel("software").As("name").As("language").As("creators").Select("name", "language", "creators").By("name").By("lang"). By(GraphTraversal2.__().In("created").Values("name").Fold().Order(GremlinKeyword.Scope.Local)); List <string> results = traversal.Next(); dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(results.FirstOrDefault()); Assert.AreEqual(2, dynamicResult.Count); foreach (dynamic result in dynamicResult) { if ((string)result["name"] == "lop") { Assert.AreEqual("java", (string)result["language"]); CheckOrderedResults(new [] { "josh", "marko", "peter" }, ConvertToList(result["creators"])); } else if ((string)result["name"] == "ripple") { Assert.AreEqual("java", (string)result["language"]); CheckOrderedResults(new[] { "josh" }, ConvertToList(result["creators"])); } else { Assert.Fail("Unknown result"); } } } }
public void VerticesHasAgeAsAOutInHasAgeAsBSelectABWhereAsAOutKnowsB() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = graphCommand.g().V().Has("age").As("a") .Out().In().Has("age").As("b") .Select("a", "b") .Where(GraphTraversal2.__().As("a").Out("knows").As("b")); List <string> result = traversal.Next(); dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault()); Assert.AreEqual(1, dynamicResult.Count); List <string> ans = new List <string>(); foreach (dynamic temp in dynamicResult) { ans.Add("a," + temp["a"]["id"].ToString() + ";b," + temp["b"]["id"].ToString()); } string markoId = this.ConvertToVertexId(graphCommand, "marko"); string joshId = this.ConvertToVertexId(graphCommand, "josh"); List <string> expected = new List <string> { "a," + markoId + ";b," + joshId, }; CheckUnOrderedResults(expected, ans); } }
private void AssertPath(GraphTraversal2 traversal) { dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next()[0]); int path1 = 0, path2 = 0, path3 = 0; foreach (dynamic path in results) { switch ((int)path["objects"].Count) { case 1: ++path1; break; case 2: ++path2; break; case 3: ++path3; break; default: Assert.Fail("Only path lengths of 1, 2, or 3 should be seen"); break; } } Assert.AreEqual(6, path1); Assert.AreEqual(6, path2); Assert.AreEqual(2, path3); }
public void HasVertexIdRepeatBothECreatedWhereWithoutEAggregateEOtherVEmitPath() { //==>[v[1], e[9][1 - created->3], v[3]] //==>[v[1], e[9][1 - created->3], v[3], e[11][4 - created->3], v[4]] //==>[v[1], e[9][1 - created->3], v[3], e[12][6 - created->3], v[6]] //==>[v[1], e[9][1 - created->3], v[3], e[11][4 - created->3], v[4], e[10][4 - created->5], v[5]] using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { string markoVertexId = this.ConvertToVertexId(graphCommand, "marko"); graphCommand.OutputFormat = OutputFormat.Regular; GraphTraversal2 traversal = graphCommand.g().V().HasId(markoVertexId) .Repeat(GraphTraversal2.__().BothE("created") .Where(Predicate.without("e")) .Aggregate("e") .OtherV()) .Emit().Path(); List <string> result = traversal.Next(); dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(traversal.FirstOrDefault()); //No idea how to evaluate the results. } }
public void VerticesAsAValuesNameOrderAsBSelectABByNameBy() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { command.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = command.g().V() .As("a") .Values("name") .Order().As("b"). Select("a", "b").By("name") .By(); List <string> result = traversal.Next(); dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault()); List <string> ans = new List <string>(); foreach (dynamic temp in dynamicResult) { ans.Add("a," + temp["a"].ToString() + ";b," + temp["b"].ToString()); } List <string> expected = new List <string> { "a,marko;b,marko", "a,vadas;b,vadas", "a,josh;b,josh", "a,ripple;b,ripple", "a,lop;b,lop", "a,peter;b,peter" }; CheckUnOrderedResults(expected, ans); } }
public void TwoDedups() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { command.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = command.g().V() .As("a") .Repeat(GraphTraversal2.__().Both()) .Times(3) .Emit() .Values("name") .As("b") .Group() .By(GraphTraversal2.__().Select("a")) .By(GraphTraversal2.__().Select("b") .Dedup() .Order() .Fold()) .Select(GremlinKeyword.Column.Values) .Unfold() .Dedup(); dynamic result = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); List <string> temp = ((JArray)result[0]).Select(j => j.ToString()).ToList(); CollectionAssert.AreEqual(new string[] { "josh", "lop", "marko", "peter", "ripple", "vadas" }, temp); } }
public void HasVertexIdAsAOutKnowsAsBSelectAB() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { string markoVertexId = this.ConvertToVertexId(command, "marko"); string vadasVertexId = this.ConvertToVertexId(command, "vadas"); string joshVertexId = this.ConvertToVertexId(command, "josh"); command.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = command.g().V() .HasId(markoVertexId).As("a") .Out("knows").As("b") .Select("a", "b"); List <string> result = traversal.Next(); dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault()); Assert.AreEqual(2, dynamicResult.Count); foreach (dynamic res in dynamicResult) { Assert.AreEqual(markoVertexId, res["a"]["id"].ToString()); Assert.IsTrue(vadasVertexId.Equals(res["b"]["id"].ToString()) || joshVertexId.Equals(res["b"]["id"].ToString())); } } }
public void AddMultipleEdges() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { command.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = command.g().V() .Aggregate("x") .As("a") .Select("x") .Unfold() .AddE("existsWith") .To("a") .Property("time", "now"); dynamic result = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); command.OutputFormat = OutputFormat.Regular; foreach (dynamic edge in result) { Assert.AreEqual("existsWith", (string)edge.label); Assert.AreEqual("now", (string)edge.properties.time); Assert.AreEqual(1, ((JObject)edge.properties).Count); } Assert.AreEqual(36, result.Count); Assert.AreEqual(42, command.g().E().Next().Count); foreach (string v in command.g().V().Id().Next()) { int outCount = command.g().V().HasId(v).OutE().HasLabel("existsWith").Next().Count; int inCount = command.g().V().HasId(v).InE().HasLabel("existsWith").Next().Count; Assert.AreEqual(6, outCount); Assert.AreEqual(6, inCount); } Assert.AreEqual(6, command.g().V().Next().Count); } }
public void DedupLocalMultipleLabels() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { command.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = command.g().V() .Out() .As("x") .In() .As("y") .Select("x", "y") .By("name") .Fold() .Dedup(GremlinKeyword.Scope.Local, "x", "y") .Unfold(); dynamic result = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); List <string> expected = new List <string> { "lop,marko", "lop,josh", "lop,peter", "vadas,marko", "josh,marko", "ripple,josh" }; AbstractGremlinTest.CheckUnOrderedResults(expected, ((JArray)result).Select(p => string.Format("{0},{1}", p["x"], p["y"])).ToList()); } }
public void get_g_V_out_out_path_byXnameX_byXageX() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = graphCommand.g().V().Out().Out().Path().By("name").By("age"); dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); Assert.AreEqual(2, results.Count); List <object> actualList = new List <object>(); actualList.Add((string)results[0][0]); actualList.Add((int)results[0][1]); actualList.Add((string)results[0][2]); CheckPathResults(new List <object> { "marko", 32, "ripple" }, actualList); actualList.Clear(); actualList.Add((string)results[1][0]); actualList.Add((int)results[1][1]); actualList.Add((string)results[1][2]); CheckPathResults(new List <object> { "marko", 32, "lop" }, actualList); } }
public void AddEdgeWithOneProperty() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { command.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = command.g().V() .Has("name", "marko") .As("a") .Out("created") .AddE("createdBy") .To("a") .Property("weight", 2.0d); dynamic result = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); command.OutputFormat = OutputFormat.Regular; foreach (dynamic edge in result) { Assert.AreEqual("createdBy", (string)edge.label); Assert.AreEqual(2.0d, (double)edge.properties.weight, delta: 0.00001d); Assert.AreEqual(1, ((JObject)edge.properties).Count); } Assert.AreEqual(1, result.Count); Assert.AreEqual(7, command.g().E().Next().Count); Assert.AreEqual(6, command.g().V().Next().Count); } }
public void get_g_V_repeatXoutX_timesX2X_path_by_byXnameX_byXlangX() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.GraphSON; string vertex = this.getVertexString(graphCommand, "marko"); GraphTraversal2 traversal = graphCommand.g().V().Repeat(GraphTraversal2.__().Out()).Times(2).Path().By().By("name").By("lang"); dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); Assert.AreEqual(2, results.Count); List <string> actualList = new List <string>(); foreach (dynamic result in results[0]["objects"]) { actualList.Add(result.ToString()); } CheckPathResults(new List <string> { vertex, "josh", "java" }, actualList); actualList.Clear(); foreach (dynamic result in results[1]["objects"]) { actualList.Add(result.ToString()); } CheckPathResults(new List <string> { vertex, "josh", "java" }, actualList); } }
public void VerticesAsAOutECreatedAsBInVAsCInCreatedAsDWhereALtBOrGtCAndNeqDByAgeByWeightByInCreatedValuesAgeMinSelectACDByName() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = graphCommand.g().V().As("a").OutE("created").As("b").InV().As("c").In("created").As("d").Where("a", Predicate.lt("b").Or(Predicate.gt("c")).And(Predicate.neq("d"))).By("age").By("weight").By(GraphTraversal2.__().In("created").Values("age").Min()).Select("a", "c", "d").By("name"); List <string> result = traversal.Next(); dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault()); Assert.AreEqual(4, dynamicResult.Count); List <string> ans = new List <string>(); foreach (dynamic temp in dynamicResult) { ans.Add("a," + temp["a"].ToString() + ";c," + temp["c"].ToString() + ";d," + temp["d"].ToString()); } List <string> expected = new List <string> { "a,josh;c,lop;d,marko", "a,josh;c,lop;d,peter", "a,peter;c,lop;d,marko", "a,peter;c,lop;d,josh", }; CheckUnOrderedResults(expected, ans); } }
public void VerticesAsAOutCreatedInCreatedAsBWhereAGtBByAgeSelectABByName() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.GraphSON; GraphTraversal2 traversal = graphCommand.g().V().As("a") .Out("created").In("created").As("b") .Where("a", Predicate.gt("b")) .By("age") .Select("a", "b").By("name"); List <string> result = traversal.Next(); dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault()); Assert.AreEqual(3, dynamicResult.Count); List <string> ans = new List <string>(); foreach (dynamic temp in dynamicResult) { ans.Add("a," + temp["a"].ToString() + ";b," + temp["b"].ToString()); } List <string> expected = new List <string> { "a,josh;b,marko", "a,peter;b,marko", "a,peter;b,josh", }; CheckUnOrderedResults(expected, ans); } }
public void AsAOutAsAOutASASelectAByUnfoldValuesNameFoldLimitRangeLocal_4_5() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = graphCommand.g().V().As("a").Out().As("a").Out().As("a").Select("a").By(GraphTraversal2.__().Unfold().Values("name").Fold()).Range(GremlinKeyword.Scope.Local, 4, 5); Assert.IsTrue(traversal.Next().Count == 0); } }
public void AsAOutAsAOutASASelectAByUnfoldValuesNameFoldLimitRangeLocal_1_2() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = graphCommand.g().V().As("a").Out().As("a").Out().As("a").Select("a").By(GraphTraversal2.__().Unfold().Values("name").Fold()).Range(GremlinKeyword.Scope.Local, 1, 2); CheckUnOrderedResults(new [] {"josh", "josh"}, traversal.Next()); } }
public void CoinWithProbabilityEq1() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Coin(1.0).Values("name"); List <string> result = traversal.Next(); CheckUnOrderedResults(new[] { "marko", "vadas", "lop", "josh", "ripple", "peter" }, result); } }
public void get_g_V_outE_order_byXweight_decrX_weight() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().OutE().Order().By("weight", GremlinKeyword.Order.Decr).Values("weight"); List <string> results = traversal.Next(); CheckOrderedResults(new[] { 1.0, 1.0, 0.5, 0.4, 0.4, 0.2 }, results.Select(double.Parse)); } }
public void get_g_V_hasLabelXsongX_order_byXperfomances_decrX_byXnameX_rangeX110_120X_name() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Both().HasLabel("song").Order().By("performances", GremlinKeyword.Order.Decr).By("name").Range(110, 120).Values("name"); List <string> results = traversal.Next(); Assert.AreEqual(0, results.Count); } }
public void get_g_V_age_max() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Values("age").Max(); List <string> result = traversal.Next(); Assert.AreEqual(35, int.Parse(result[0])); } }
public void get_g_V_repeatXbothX_timesX5X_age_max() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Repeat(GraphTraversal2.__().Both()).Times(5).Values("age").Max(); List <string> result = traversal.Next(); Assert.AreEqual(35, int.Parse(result[0])); } }
public void get_g_V_both_both_count() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Both().Both().Count(); List <string> result = traversal.Next(); Assert.AreEqual(30, int.Parse(result[0])); } }
public void get_g_V_repeatXoutX_timesX8X_count() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Repeat(GraphTraversal2.__().Out()).Times(8).Count(); List <string> result = traversal.Next(); Assert.AreEqual(0, int.Parse(result[0])); } }
public void g_E_sampleX2X_byXweightX() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = graphCommand.g().E().Sample(2).By("weight"); List <string> result = traversal.Next(); Assert.AreEqual(2, result.Count); } }
public void get_g_V_fold_countXlocalX() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Fold().Count(GremlinKeyword.Scope.Local); List <string> result = traversal.Next(); Assert.AreEqual(6, int.Parse(result[0])); } }
public void g_V_localXoutE_sampleX1X_byXweightXX() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = graphCommand.g().V().Local(GraphTraversal2.__().OutE().Sample(1).By("weight")); List <string> results = traversal.Next(); Assert.AreEqual(3, results.Count); } }
public void get_g_V_out_group_byXlabelX_selectXpersonX_unfold_outXcreatedX_name_limitX2X() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Out().Group().By("label").Select("person").Unfold().Out("created").Values("name").Limit(2); List <string> results = traversal.Next(); CheckUnOrderedResults(new [] { "ripple", "lop" }, results); } }
public void get_g_V_unionXoutXknowsX__outXcreatedX_inXcreatedXX_groupCount_selectXvaluesX_unfold_sum() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Union(GraphTraversal2.__().Out("knows"), GraphTraversal2.__().Out("created").In("created")).GroupCount().Select(GremlinKeyword.Column.Values).Unfold().Sum(); List <string> results = traversal.Next(); Assert.AreEqual(12, int.Parse(results[0])); } }
public void get_g_V_both_hasLabelXpersonX_order_byXage_decrX_name() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Both().HasLabel("person").Order().By("age", GremlinKeyword.Order.Decr).Values("name"); List <string> results = traversal.Next(); CheckOrderedResults(new[] { "peter", "josh", "josh", "josh", "marko", "marko", "marko", "vadas" }, results); } }
public void get_g_V_order_byXnameX_name() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal2 traversal = command.g().V().Order().By("name").Values("name"); List <string> results = traversal.Next(); CheckOrderedResults(new[] { "josh", "lop", "marko", "peter", "ripple", "vadas" }, results); } }