コード例 #1
0
        public void TestAddAndDropEdges_Small()
        {
            const int           EDGE_COUNT = 10;
            GraphViewConnection connection = CreateConnection($"E={EDGE_COUNT}");
            GraphViewCommand    graph      = new GraphViewCommand(connection);

            graph.g().AddV("SourceV").Next();
            graph.g().AddV("SinkV").Next();
            for (int i = 0; i < EDGE_COUNT; i++)
            {
                graph.g().V().HasLabel("SourceV").AddE(edgeLabel: "Dummy").To(graph.g().V().HasLabel("SinkV")).Next();
            }
            graph.g().E().HasLabel("Dummy").Drop().Next();
        }
コード例 #2
0
        public void TestAddAndDropEdges_DropSome_Small()
        {
            const int           EDGE_COUNT = 20;
            GraphViewConnection connection = CreateConnection($"AddAndDropEdges_DropSome_Small E={EDGE_COUNT}");
            GraphViewCommand    graph      = new GraphViewCommand(connection);

            graph.g().AddV("SourceV").Next();
            graph.g().AddV("SinkV").Next();
            for (int i = 0; i < EDGE_COUNT; i++)
            {
                graph.g().V().HasLabel("SourceV").AddE(edgeLabel: $"MOD_{i % 4}").To(graph.g().V().HasLabel("SinkV")).Next();
            }
            graph.g().V().OutE().HasLabel("MOD_0", "MOD_2").Drop().Next();
        }
コード例 #3
0
        public void Test_Inject_Sample_Local()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                var traversal = command.g().Inject(1).Sample(GremlinKeyword.Scope.Local, 1);
                var result    = traversal.Next();
                Assert.IsTrue(result.Count == 1);

                foreach (var r in result)
                {
                    Console.WriteLine(r);
                }
            }
        }
コード例 #4
0
        public async Task AddVertexTest()
        {
            GraphViewCommand cmd = new GraphViewCommand(graphConnection);

            cmd.OutputFormat = OutputFormat.GraphSON;
            cmd.CommandText  = "g.AddV('character').Property('name', 'VENUS II').Property('weapon', 'shield')";
            cmd.OutputFormat = OutputFormat.GraphSON;
            var results = cmd.Execute();

            foreach (var result in results)
            {
                Console.WriteLine(result);
            }
        }
コード例 #5
0
        public void VerticesAndEdgesDrop()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = graphCommand.g().V().Drop();
                List <string>   result    = traversal.Next();

                GraphTraversal2 vertexTraversalAfterDrop = graphCommand.g().V();
                Assert.AreEqual(0, vertexTraversalAfterDrop.Next().Count);

                GraphTraversal2 edgeTraversalAfterDrop = graphCommand.g().E();
                Assert.AreEqual(0, edgeTraversalAfterDrop.Next().Count);
            }
        }
コード例 #6
0
ファイル: DropTest.cs プロジェクト: seanliu96/GraphView
        public void OutEdgesDrop()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g().V().OutE().Drop();
                var result    = traversal.Next();

                var vertexTraversalAfterDrop = graphCommand.g().V();
                Assert.AreEqual(6, vertexTraversalAfterDrop.Next().Count);

                var edgeTraversalAfterDrop = graphCommand.g().E();
                Assert.AreEqual(0, edgeTraversalAfterDrop.Next().Count);
            }
        }
コード例 #7
0
        public void VerticesUntilOutOutRepeatInAsASelectAByTailLocalName()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g().V().Until(GraphTraversal2.__().Out().Out()).Repeat(GraphTraversal2.__().In().As("a")).Select("a").By(GraphTraversal2.__().Tail(GremlinKeyword.Scope.Local).Values("name"));

                List <string> results = traversal.Next();
                Assert.AreEqual(5, results.Count);
                foreach (string result in results)
                {
                    Assert.AreEqual("marko", result);
                }
            }
        }
コード例 #8
0
        public void TestAddHeavyEdges_MidiumQuantity()
        {
            const int           EDGE_COUNT = 10;
            GraphViewConnection connection = CreateConnection($"E={EDGE_COUNT}");
            GraphViewCommand    graph      = new GraphViewCommand(connection);

            graph.g().AddV("SourceV").Next();
            graph.g().AddV("SinkV").Next();
            for (int i = 0; i < EDGE_COUNT; i++)
            {
                string longLabel = new string((char)('0' + i), 1024 * 900);  // Size = 900KB
                graph.g().V().HasLabel("SourceV").AddE(edgeLabel: longLabel).To(graph.g().V().HasLabel("SinkV")).Next();
            }
        }
コード例 #9
0
        public void InsertMarvelData()
        {
            GraphViewConnection connection = new GraphViewConnection("https://graphview.documents.azure.com:443/",
                                                                     "MqQnw4xFu7zEiPSD+4lLKRBQEaQHZcKsjlHxXn2b96pE/XlJ8oePGhjnOofj1eLpUdsfYgEhzhejk2rjH/+EKA==",
                                                                     "GroupMatch", "MarvelUniverse", GraphType.GraphAPIOnly, AbstractGremlinTest.TEST_USE_REVERSE_EDGE, 1, AbstractGremlinTest.TEST_PARTITION_BY_KEY);

            GraphViewCommand graph = new GraphViewCommand(connection);

            var results = graph.g().V();

            foreach (var result in results)
            {
                Console.WriteLine(result);
            }

            //var results = graph.g().V().Has("type", "University").Union(GraphTraversal.__().Properties("label", "type"), GraphTraversal.__().OutE().Properties("label")).next();

            //Insert character
            //string[] characterLines = File.ReadAllLines(@"C:\Users\v-jinjl\Desktop\GraphView-Development\GraphView\data\character.txt");
            //foreach (string line in characterLines)
            //{
            //    var arr = line.Split('\"');
            //    var id = arr[0].Substring(0, arr[0].Length - 1);
            //    var name = arr[1];
            //    graph.g().AddV("character").Property("id", id).Property("name", name).next();
            //}

            //Insert comicbook
            //string[] comicbookLines = File.ReadAllLines(@"C:\Users\v-jinjl\Desktop\GraphView-Development\GraphView\data\comicbook.txt");
            //foreach (string line in comicbookLines)
            //{
            //    var arr = line.Split('\"');
            //    var id = arr[0].Substring(0, arr[0].Length - 1);
            //    var name = arr[1];
            //    graph.g().AddV("comicbook").Property("id", id).Property("name", name).next();
            //}

            //Insert Edge
            //string[] edgeLines = File.ReadAllLines(@"C:\Users\v-jinjl\Desktop\GraphView-Development\GraphView\data\edge.txt");
            //foreach (string line in edgeLines)
            //{
            //    var arr = line.Split(' ');
            //    var sourceId = arr[0];
            //    for (var i = 1; i < arr.Length; i++)
            //    {
            //        var sinkId = arr[i];
            //        graph.g().V().Has("id", sourceId).AddE("appeared").To(graph.g().V().Has("id", sinkId)).next();
            //    }
            //}
        }
コード例 #10
0
        public void HasVertexIdOutEKnowsAsHereHasWeight1AsFakeInVHasNameJoshSelectHere()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                string vertexId1 = this.ConvertToVertexId(command, "marko");

                command.OutputFormat = OutputFormat.GraphSON;
                GraphTraversal2 traversal = command.g().V().HasId(vertexId1).OutE("knows").As("here").Has("weight", 1.0d).As("fake").InV().Has("name", "josh").Select("here");

                List <string> result        = traversal.Next();
                dynamic       dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault());
                AssertCommonB(dynamicResult);
            }
        }
コード例 #11
0
        public void GetEdgeById()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                // E(Id), E().HasId() and E().Id() does not work

                var expectedEdgeId = this.ConvertToEdgeId(graphCommand, "josh", "created", "lop");
                var traversal      = graphCommand.g().E(expectedEdgeId).Id();
                var result         = traversal.Next();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(expectedEdgeId, result.First());
            }
        }
コード例 #12
0
        public void EdgesHasEIdHasLabelKnows()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                string edgeId = this.ConvertToEdgeId(GraphViewCommand, "marko", "knows", "vadas");

                var traversal = GraphViewCommand.g().E().HasId(edgeId).HasLabel("knows");
                //var traversal = GraphViewCommand.g().E().Has("_edgeId", edgeId).HasLabel("knows");

                var result = traversal.Label().Next();
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("knows", result.FirstOrDefault());
            }
        }
コード例 #13
0
        public void EdgesHasLabelKnows()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().E().HasLabel("knows");

                var result = traversal.Label().Next();
                Assert.AreEqual(2, result.Count);
                foreach (var res in result)
                {
                    Assert.AreEqual("knows", res);
                }
            }
        }
コード例 #14
0
        public void AndWithSelect()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g().V()
                                            .As("a")
                                            .And(
                    GraphTraversal2.__().Select("a"),
                    GraphTraversal2.__().Select("a"));
                List <string> result = traversal.Next();

                Assert.AreEqual(6, result.Count());
            }
        }
コード例 #15
0
        public void HasAgeIsGT30()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V().Has("age", GraphTraversal.__().Is(Predicate.gt(30)));

                var result = traversal.Values("age").Next();
                Assert.AreEqual(2, result.Count);
                foreach (var age in result)
                {
                    Assert.IsTrue(int.Parse(age) > 30);
                }
            }
        }
コード例 #16
0
        public void AndWithParameters()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g().V()
                                            .And(
                    GraphTraversal2.__().Has("age", Predicate.gt(27)),
                    GraphTraversal2.__().OutE().Count().Is(Predicate.gte(2)))
                                            .Values("name");
                List <string> result = traversal.Next();

                AbstractGremlinTest.CheckUnOrderedResults(new string[] { "marko", "josh" }, result);
            }
        }
コード例 #17
0
ファイル: PropertiesTest.cs プロジェクト: seanliu96/GraphView
        public void VerticesHasAgePropertiesHasIdNameIdValue()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                string markoNameVertexPropertyId = this.ConvertToPropertyId(graphCommand, "marko", "name", "marko");

                var traversal = graphCommand.g().V().Has("age").Properties().Has("id", markoNameVertexPropertyId).Value();

                var result = traversal.Next();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("marko", result.First());
            }
        }
コード例 #18
0
ファイル: WhereTest.cs プロジェクト: seanliu96/GraphView
        public void VerticesAsAOutABWhereAndAsAOutKnowsAsBOrAsBOutCreatedHasNameRippleAsBInKnowsCountIsNotEq0SelectAB()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;

                var traversal = graphCommand.g().V()
                                .As("a")
                                .Out()
                                .As("b")
                                .Where(
                    GraphTraversal.__()
                    .And(
                        GraphTraversal.__()
                        .As("a")
                        .Out("knows")
                        .As("b"),
                        GraphTraversal.__()
                        .Or(
                            GraphTraversal.__()
                            .As("b")
                            .Out("created")
                            .Has("name", "ripple"),
                            GraphTraversal.__().As("b")
                            .In("knows")
                            .Count()
                            .Is(Predicate.not(Predicate.eq(0))))))
                                .Select("a", "b");

                var     result        = traversal.Next();
                dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault());

                Assert.AreEqual(2, dynamicResult.Count);
                List <string> ans = new List <string>();
                foreach (var temp in dynamicResult)
                {
                    ans.Add("a," + temp["a"]["id"].ToString() + ";b," + temp["b"]["id"].ToString());
                }
                var markoId = ConvertToVertexId(graphCommand, "marko");
                var joshId  = ConvertToVertexId(graphCommand, "josh");
                var vadasId = ConvertToVertexId(graphCommand, "vadas");

                List <string> expected = new List <string>
                {
                    "a," + markoId + ";b," + joshId,
                    "a," + markoId + ";b," + vadasId,
                };
                CheckUnOrderedResults(expected, ans);
            }
        }
コード例 #19
0
        public void DedupLargeAmountStrings()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V()
                                .Both()
                                .Both()
                                .Values("name")
                                .Dedup();
                var result = traversal.Next();

                AbstractGremlinTest.CheckUnOrderedResults(new string[] { "vadas", "josh", "lop", "marko", "peter", "ripple" }, result);
            }
        }
コード例 #20
0
        public void VerticesAsHereOutValuesNameSelectHere()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g().V().As("here").Out().Values("name").Select("here");

                // NOTE: actual tests for complete vertice, but here we just validate that the names are correct. We can do so since the names are unique.
                List <string> result         = traversal.Values("name").Next();
                List <string> expectedResult = new List <string> {
                    "marko", "marko", "marko", "josh", "josh", "peter"
                };
                CheckUnOrderedResults(expectedResult, result);
            }
        }
コード例 #21
0
        public void VerticesRepeatOutTimes2()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g().V().Repeat(GraphTraversal2.__().Out()).Times(2);

                var results = traversal.Values("name").Next();
                foreach (string name in results)
                {
                    Assert.IsTrue(string.Equals(name, "lop") || string.Equals(name, "ripple"));
                }
                Assert.AreEqual(2, results.Count);
            }
        }
コード例 #22
0
ファイル: AndTest.cs プロジェクト: seanliu96/GraphView
        public void AndWithSelect()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V()
                                .As("a")
                                .And(
                    GraphTraversal.__().Select("a"),
                    GraphTraversal.__().Select("a"));
                var result = traversal.Next();

                Assert.AreEqual(6, result.Count());
            }
        }
コード例 #23
0
        public void g_V_Group()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                GraphViewCommand.OutputFormat = OutputFormat.Regular;
                var traversal = GraphViewCommand.g().V().Group();
                var results   = traversal.Next();

                foreach (var result in results)
                {
                    Console.WriteLine(result);
                }
            }
        }
コード例 #24
0
ファイル: StoreTest.cs プロジェクト: georgeycliu/k-core
        public void VertexWithIdStoreAByNameOutStoreAByNameValuesNameCapA()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                string          markoVertexId = this.ConvertToVertexId(command, "marko");
                GraphTraversal2 traversal     = command.g().V(markoVertexId).Store("a").By("name").Out().Store("a").By("name").Values("name").Cap("a");

                IEnumerable <string> result         = traversal.Next().First().Trim('[', ']').Split(',').Select(r => r.Trim(' '));
                List <string>        expectedResult = new List <string> {
                    "marko", "josh", "vadas", "lop"
                };
                CheckUnOrderedResults(expectedResult, result);
            }
        }
コード例 #25
0
        public void GetOutEdges()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g()
                                .V(this.ConvertToVertexId(graphCommand, "marko"))
                                .OutE()
                                .Label();
                var result = traversal.Next();

                Assert.AreEqual(3, result.Count);
                CheckUnOrderedResults(new[] { "knows", "knows", "created" }, result);
            }
        }
コード例 #26
0
        public void AndAsInfixNotation()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g().V()
                                            .And(
                    GraphTraversal2.__().OutE(),
                    GraphTraversal2.__().HasLabel("person").And().Has("age", Predicate.gte(32)))
                                            .Values("name");
                List <string> result = traversal.Next();

                AbstractGremlinTest.CheckUnOrderedResults(new string[] { "josh", "peter" }, result);
            }
        }
コード例 #27
0
        static void test()
        {
            GraphViewConnection connection =
                new GraphViewConnection(DOCDB_URL, DOCDB_AUTHKEY, DOCDB_DATABASE, DOCDB_COLLECTION);
            //connection.ResetCollection();
            GraphViewCommand graph = new GraphViewCommand(connection);

            try
            {
                /*graph.g().AddV(NODE_LABEL).Property(NODE_PROPERTY, "1").Next();
                 * graph.g().AddV(NODE_LABEL).Property(NODE_PROPERTY, "3").Next();
                 * graph.g().AddV(NODE_LABEL).Property(NODE_PROPERTY, "2").Next();
                 *
                 * graph.g().V().Has(NODE_PROPERTY, "1").
                 *             AddE(EDGE_LABEL).Property(EDGE_PROPERTY, 1).
                 *             To(graph.g().V().Has(NODE_PROPERTY, "2")).Next();
                 * graph.g().V().Has(NODE_PROPERTY, "1").
                 *            AddE(EDGE_LABEL).Property(EDGE_PROPERTY, -2).
                 *            To(graph.g().V().Has(NODE_PROPERTY, "3")).Next();
                 */              /*  graph.g().V().Has(NODE_PROPERTY, "6242519").
                 *            AddE(EDGE_LABEL).Property(EDGE_PROPERTY, 1.35183386).
                 *            To(graph.g().V().Has(NODE_PROPERTY, "343")).Next();
                 */
                //graph.CommandText = "g.E().Order().By("+EDGE_PROPERTY+", incr)";
                //var res= graph.Execute();

                //var res = graph.g().V().Has(NODE_PROPERTY, "12").BothV().Has(NODE_PROPERTY, "2").Values(NODE_PROPERTY).Next();

                //graph.g().V().Has(NODE_PROPERTY, "1").OutE(EDGE_LABEL).As("e").InV().Has(NODE_PROPERTY, "2").Select("e").Drop().Next();

                /*graph.g().V().Has(NODE_PROPERTY, "198036").OutE(EDGE_LABEL).As("e").
                 *          InV().Has(NODE_PROPERTY, "3888").Select("e").Drop().Next();
                 */
                var res = graph.g().V().Has(NODE_PROPERTY, "198036").OutE(EDGE_LABEL).As("e").
                          InV().Has(NODE_PROPERTY, "3888").Select("e").Next();



                foreach (var x in res)
                {
                    System.Console.WriteLine(x);
                }
                System.Console.WriteLine("");
            }
            finally
            {
                //connection.ResetCollection();
            }
        }
コード例 #28
0
        public void VerticesAsAWhereOutKnowsSelectA()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;
                var traversal = graphCommand.g().V().As("a").Where(GraphTraversal.__().Out("knows")).Select("a");

                var     result        = traversal.Next();
                dynamic dynamicResult = JsonConvert.DeserializeObject <dynamic>(result.FirstOrDefault());

                Assert.AreEqual(1, dynamicResult.Count);
                var vertex = dynamicResult[0];
                Assert.AreEqual("marko", vertex["properties"]["name"][0]["value"].ToString());
            }
        }
コード例 #29
0
 static public void LoadClassicGraphData(GraphViewCommand graphCommand)
 {
     graphCommand.g().AddV("person").Property("name", "marko").Property("age", 29).Next();
     graphCommand.g().AddV("person").Property("name", "vadas").Property("age", 27).Next();
     graphCommand.g().AddV("software").Property("name", "lop").Property("lang", "java").Next();
     graphCommand.g().AddV("person").Property("name", "josh").Property("age", 32).Next();
     graphCommand.g().AddV("software").Property("name", "ripple").Property("lang", "java").Next();
     graphCommand.g().AddV("person").Property("name", "peter").Property("age", 35).Next();
     graphCommand.g().V().Has("name", "marko").AddE("knows").Property("weight", 0.5d).To(graphCommand.g().V().Has("name", "vadas")).Next();
     graphCommand.g().V().Has("name", "marko").AddE("knows").Property("weight", 1.0d).To(graphCommand.g().V().Has("name", "josh")).Next();
     graphCommand.g().V().Has("name", "marko").AddE("created").Property("weight", 0.4d).To(graphCommand.g().V().Has("name", "lop")).Next();
     graphCommand.g().V().Has("name", "josh").AddE("created").Property("weight", 1.0d).To(graphCommand.g().V().Has("name", "ripple")).Next();
     graphCommand.g().V().Has("name", "josh").AddE("created").Property("weight", 0.4d).To(graphCommand.g().V().Has("name", "lop")).Next();
     graphCommand.g().V().Has("name", "peter").AddE("created").Property("weight", 0.2d).To(graphCommand.g().V().Has("name", "lop")).Next();
 }
コード例 #30
0
        public void VerticesSelectA()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                GremlinKeyword.Pop?[] pops = { null, GremlinKeyword.Pop.All, GremlinKeyword.Pop.First, GremlinKeyword.Pop.Last };
                foreach (var pop in pops)
                {
                    var root      = graphCommand.g().V();
                    var traversal = (!pop.HasValue) ? root.Select("a") : root.Select(pop.Value, "a");

                    var result = traversal.Next();
                    Assert.AreEqual(0, result.Count);
                }
            }
        }