Beispiel #1
0
        internal void ConfigureStartAndEndSteps(GraphTraversal whereTraversal)
        {
            if (whereTraversal.GremlinTranslationOpList.Count >= 2)
            {
                //__.as()
                GremlinAsOp asOp = whereTraversal.GremlinTranslationOpList[1] as GremlinAsOp;
                if (asOp != null)
                {
                    whereTraversal.GremlinTranslationOpList.RemoveAt(1); //remove as-step
                    whereTraversal.InsertGremlinOperator(1, new GremlinSelectOp(GremlinKeyword.Pop.Last, asOp.Labels.First()));
                }

                //__.Or()
                GremlinOrOp orOp = whereTraversal.GremlinTranslationOpList[1] as GremlinOrOp;
                if (orOp != null)
                {
                    if (orOp.IsInfix)
                    {
                        ConfigureStartAndEndSteps(orOp.FirstTraversal);
                        ConfigureStartAndEndSteps(orOp.SecondTraversal);
                    }
                    else
                    {
                        foreach (var traversal in orOp.OrTraversals)
                        {
                            ConfigureStartAndEndSteps(traversal);
                        }
                    }
                }

                //__.And()
                GremlinAndOp andOp = whereTraversal.GremlinTranslationOpList[1] as GremlinAndOp;
                if (andOp != null)
                {
                    if (andOp.IsInfix)
                    {
                        ConfigureStartAndEndSteps(andOp.FirstTraversal);
                        ConfigureStartAndEndSteps(andOp.SecondTraversal);
                    }
                    else
                    {
                        foreach (var traversal in andOp.AndTraversals)
                        {
                            ConfigureStartAndEndSteps(traversal);
                        }
                    }
                }

                //__.Not()
                GremlinNotOp notOp = whereTraversal.GremlinTranslationOpList[1] as GremlinNotOp;
                if (notOp != null)
                {
                    ConfigureStartAndEndSteps(notOp.NotTraversal);
                }
            }

            var lastOp = WhereTraversal.GetEndOp() as GremlinAsOp;

            if (lastOp != null)
            {
                string label = lastOp.Labels.First();

                whereTraversal.GremlinTranslationOpList.RemoveAt(whereTraversal.GremlinTranslationOpList.Count - 1); //remove the last as-step
                whereTraversal.AddGremlinOperator(new GremlinWherePredicateOp(Predicate.eq(label)));
            }
        }