public void Match_does_not_include_live_only_filter_by_default()
        {
            var query = _cypherFluentQuery
                        .Match("(p:Pathway)")
                        .Query
                        .QueryText;

            Assert.AreEqual("MATCH (p:Pathway)", query);
        }
        public static ICypherFluentQuery Match(this ICypherFluentQuery query, bool onlyLive = false, params string[] matchText)
        {
            if (!onlyLive)
            {
                return(query.Match(matchText));
            }

            return(query
                   .Match(matchText)
                   .Where(string.Format("p.title in [{0}]", string.Join(", ", PathwaysConfigurationManager.GetLivePathwaysElements().Select(p => string.Format("'{0}'", p.Title))))));
        }
 public void Setup()
 {
     CypherQuery.Match("(n)")
     .OptionalMatch("(n)-[r]-()")
     .Delete("n, r")
     .ExecuteWithoutResults();
 }
        public static ICypherFluentQuery MatchQuerry(this ICypherFluentQuery cypher, string varialbeName, Commit node)
        {
            string matchClause = "(" + varialbeName + ":" + node.GetType().Name + ")";
            string whereClause = varialbeName + "." + nameof(node.Sha) + "=\"" + node.Sha + "\"";

            return(cypher.Match(matchClause).Where(whereClause));
        }
        public static ICypherFluentQuery MatchQuerry(this ICypherFluentQuery cypher, string varialbeName, BaseNode node)
        {
            if (node is Person)
            {
                return(cypher.MatchQuerry(varialbeName, (Person)node));
            }
            if (node is Commit)
            {
                return(cypher.MatchQuerry(varialbeName, (Commit)node));
            }
            if (node is File)
            {
                return(cypher.MatchQuerry(varialbeName, (File)node));
            }
            if (node is AstElement)
            {
                return(cypher.MatchQuerry(varialbeName, (AstElement)node));
            }

            if (node is AstElementDeleted)
            {
                return(cypher.MatchQuerry(varialbeName, (AstElementDeleted)node));
            }

            string matchClause = "(" + varialbeName + ":" + node.GetType().Name + ")";

            if (node.Id > 0)
            {
                return(cypher.Match(matchClause).Where(varialbeName + ".Id=" + node.Id));
            }

            throw new NotImplementedException("Needs a specialices MatchQuery for " + node.GetType().Name);
        }
Example #6
0
        /// <summary>
        /// Matches the source and target nodes of the <paramref name="TVector"/>.
        /// </summary>
        /// <typeparam name="TVector"></typeparam>
        /// <param name="query"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="sourceGuid"></param>
        /// <param name="targetGuid"></param>
        /// <returns></returns>
        public static ICypherFluentQuery Match <TVector>(this ICypherFluentQuery query, string from, string to, Guid sourceGuid, Guid targetGuid) where TVector : Vector
        {
            var vectorType = Common.Unpack <TVector>();

            query = query.Match(
                "(" + from + ":" + Common.NodeLabel(vectorType.Source) + " { Guid: {sourceGuid} })",
                "(" + to + ":" + Common.NodeLabel(vectorType.Target) + " { Guid: {targetGuid} })")
                    .WithParams(new { sourceGuid, targetGuid });
            return(query);
        }
Example #7
0
        /// <summary>
        /// Returns a vectorised MATCH statement for <typeparamref name="TVector"/>.
        /// </summary>
        /// <typeparam name="TVector"></typeparam>
        /// <param name="query"></param>
        /// <param name="from"></param>
        /// <param name="rel"></param>
        /// <param name="relPath"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static ICypherFluentQuery Match <TVector>(this ICypherFluentQuery query, string path = null, string from = null, string rel = null, string relPath = null, string to = null) where TVector : Vector
        {
            var vars = ProcessVars(path);

            if (vars.Successful())
            {
                var result = vars.Data;
                from    = result.From;
                rel     = result.Rel;
                relPath = result.RelPath;
                to      = result.To;
            }
            query = query.Match(Common.Vector <TVector>(rel, from, to, relPath));
            return(query);
        }
        public static ICypherFluentQuery MatchQuerry(this ICypherFluentQuery cypher, string varialbeName, AstElementDeleted node)
        {
            string matchClause = "(" + varialbeName + ":" + node.GetType().Name + ")";

            var wherClause = new List <String>();

            if (!String.IsNullOrWhiteSpace(node.FilePath))
            {
                wherClause.Add(varialbeName + "." + nameof(node.FilePath) + "=\"" + node.FilePath + "\"");
            }

            if (!String.IsNullOrWhiteSpace(node.CommitSha))
            {
                wherClause.Add(varialbeName + "." + nameof(node.CommitSha) + "=\"" + node.CommitSha + "\"");
            }
            return(cypher.Match(matchClause).Where(String.Join(" and ", wherClause)));
        }
Example #9
0
        /// <summary>
        /// Returns a vectorised PATH statement for <typeparamref name="TVector"/>. Default value of <paramref name="path"/> is 'p'.
        /// </summary>
        /// <typeparam name="TVector"></typeparam>
        /// <param name="query"></param>
        /// <param name="path"></param>
        /// <param name="rel"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="relPath"></param>
        /// <param name="fromLabel"></param>
        /// <returns></returns>
        public static ICypherFluentQuery Path <TVector>(this ICypherFluentQuery query, string path = null, string pathPattern = null, string rel = null, string from = null, string to = null, string relPath = null, bool fromLabel = true) where TVector : Vector
        {
            path = path ?? "p";
            var vars = ProcessVars(pathPattern);

            if (vars.Successful())
            {
                var result = vars.Data;
                from    = result.From;
                rel     = result.Rel;
                relPath = result.RelPath;
                to      = result.To;
            }
            var pattern = $"{path}=" + Common.Vector <TVector>(rel, from, to, relPath, fromLabel);

            query = query.Match(pattern);
            return(query);
        }
Example #10
0
        public static ICypherFluentQuery Match <TFirstVector, TSecondVector, TThirdVector>(this ICypherFluentQuery query, string path)
            where TFirstVector : Vector
            where TSecondVector : Vector
            where TThirdVector : Vector
        {
            var vars = ProcessVars(path);

            if (vars.Unsuccessful())
            {
                throw new InvalidOperationException();
                // return query;
            }
            var first  = Common.Vector <TFirstVector>(vars.Data.Rel, vars.Data.From, vars.Data.To, vars.Data.RelPath);
            var second = Common.JoinVector <TSecondVector>(vars.Data.Rel2, vars.Data.RelPath2, vars.Data.To2);
            var third  = Common.JoinVector <TThirdVector>(vars.Data.Rel3, vars.Data.RelPath3, vars.Data.To3);

            query = query.Match(first + second + third);
            return(query);
        }
Example #11
0
        /// <summary>
        /// Returns a MATCH statement for a hypernode starting with <typeparamref name="TFirstVector"/> and ending in <typeparamref name="TSecondVector"/>.
        /// </summary>
        /// <typeparam name="TFirstVector"></typeparam>
        /// <typeparam name="TSecondVector"></typeparam>
        /// <param name="query"></param>
        /// <param name="from"></param>
        /// <param name="rel"></param>
        /// <param name="relPath"></param>
        /// <param name="to"></param>
        /// <param name="rel2"></param>
        /// <param name="relPath2"></param>
        /// <param name="to2"></param>
        /// <returns></returns>
        public static ICypherFluentQuery Match <TFirstVector, TSecondVector>(this ICypherFluentQuery query, string path = null, string from = null, string rel = null, string relPath = null, string to = null, string rel2 = null, string relPath2 = null, string to2 = null) where TFirstVector : Vector where TSecondVector : Vector
        {
            var vars = ProcessVars(path);

            if (vars.Successful())
            {
                var result = vars.Data;
                from     = result.From;
                rel      = result.Rel;
                relPath  = result.RelPath;
                to       = result.To;
                rel2     = result.Rel2;
                relPath2 = result.RelPath2;
                to2      = result.To2;
            }
            var pattern = HyperNodeVector <TFirstVector, TSecondVector>(from, rel, relPath, to, rel2, relPath2, to2);

            query = query.Match(pattern);
            return(query);
        }
Example #12
0
        /// <summary>
        /// Returns a vectorised PATH statement for hypernode starting with <typeparamref name="TFirstVector"/> and ending in <typeparamref name="TSecondVector"/>. Default value of <paramref name="path"/> is 'p'.
        /// </summary>
        /// <typeparam name="TFirstVector"></typeparam>
        /// <typeparam name="TSecondVector"></typeparam>
        /// <param name="query"></param>
        /// <param name="path"></param>
        /// <param name="rel"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="relPath"></param>
        /// <param name="fromLabel"></param>
        /// <param name="to2"></param>
        /// <param name="rel2"></param>
        /// <param name="relPath2"></param>
        /// <returns></returns>
        public static ICypherFluentQuery Path <TFirstVector, TSecondVector>(this ICypherFluentQuery query,
                                                                            string path = null, string pathPattern = null, string rel = null, string from = null, string to = null, string relPath = null, bool fromLabel = true, string to2 = null, string rel2 = null, string relPath2 = null)
            where TFirstVector : Vector
            where TSecondVector : Vector
        {
            path = path ?? "p";
            var vars = ProcessVars(pathPattern);

            if (vars.Successful())
            {
                var result = vars.Data;
                from     = result.From;
                rel      = result.Rel;
                relPath  = result.RelPath;
                to       = result.To;
                rel2     = result.Rel2;
                relPath2 = result.RelPath2;
                to2      = result.To2;
            }
            var pattern = $"{path}=" + Common.Vector <TFirstVector>(rel, from, to, relPath, fromLabel).Join <TSecondVector>(rel: rel2, to: to2, relPath: relPath2);

            query = query.Match(pattern);
            return(query);
        }
Example #13
0
 public static ICypherFluentQuery From <TEntity>(this ICypherFluentQuery query, string nodeVar, Guid guid) where TEntity : Root
 {
     query = query.Match("(" + nodeVar + ":" + Common.NodeLabel <TEntity>() + " { Guid: {" + nodeVar + "Guid} })").WithParam(nodeVar + "Guid", guid);
     return(query);
 }
        public void Execute(ICypherFluentQuery cypher)
        {

            ProcessStacks();

            foreach (var query in _queryStack)
            {

                if (query.QueryType == QueryTypeEnum.Match)
                {
                    cypher = cypher.Match(query.QueryString);
                    continue;
                }
                if (query.QueryType == QueryTypeEnum.OptionalMatch)
                {
                    cypher = cypher.OptionalMatch(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Where)
                {
                    cypher = cypher.Where(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Create)
                {
                    cypher = cypher.Create(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Merge)
                {
                    cypher = cypher.Merge(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Delete)
                {
                    cypher = cypher.Delete(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.With)
                {
                    cypher = cypher.With(query.QueryString);
                    continue;
                }

            }

            cypher.ExecuteWithoutResults();
        }
Example #15
0
        private async Task <DialogTurnResult> SebuViewAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (workDetails.sebu.Count == 0)
            {
                var choice = (FoundChoice)stepContext.Result;
                workDetails.sebu.Add(choice.Value);
            }

            Ablt   selectAblt = workDetails.ablt[workDetails.selectAbltIndex];
            string msg        = $"{selectAblt.AbltCn}에 대해 선택하신 세부 내용은 다음과 같습니다.";

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(msg), cancellationToken);

            //MATCH쿼리 직무 능력 노드 찾아놓기
            ICypherFluentQuery query = client.Cypher.Match("(ablt:Ablt)").
                                       Where((Ablt ablt) => ablt.AbltCn == selectAblt.AbltCn);

            foreach (string sebuString in workDetails.sebu)
            {
                string sebuMsg = "";
                //원하는 세부 능력에 따른 쿼리 이어 붙인 후 결과값 도출
                switch (sebuString)
                {
                case "훈련":
                    var abltTrng = query.Match("(ablt)-[:TRNG]->(trng:AbltTrng)").
                                   Return(trng => trng.As <AbltTrng>()).Results;
                    sebuMsg += "----- 훈련 -----\n";
                    foreach (AbltTrng trng in abltTrng)
                    {
                        sebuMsg += (trng.Name + "\n");
                    }
                    break;

                case "전공":
                    var abltMajor = query.Match("(ablt)-[:MAJOR]->(major:AbltMajor)").
                                    Return(major => major.As <AbltMajor>()).Results;
                    sebuMsg += "----- 전공 -----\n";
                    foreach (AbltMajor major in abltMajor)
                    {
                        sebuMsg += (major.Name + "\n");
                    }
                    break;

                case "자격증":
                    var abltCrfItem = query.Match("(ablt)-[:CRFITEM]->(crfItem:AbltCrfItem)").
                                      Return(crfItem => crfItem.As <AbltCrfItem>()).Results;
                    sebuMsg += "----- 자격증 -----\n";
                    foreach (AbltCrfItem crfItem in abltCrfItem)
                    {
                        sebuMsg += (crfItem.Name + "\n");
                    }
                    break;

                case "수행태도":
                    var abltAtt = query.Match("(ablt)-[:ATT]->(att:AbltAtt)").
                                  Return(att => att.As <AbltAtt>()).Results;
                    sebuMsg += "----- 수행태도 -----\n";
                    foreach (AbltAtt att in abltAtt)
                    {
                        sebuMsg += (att.Name + "\n");
                    }
                    break;

                case "지식및기술":
                    var abltKnwSkl = query.Match("(ablt)-[:KNWSKL]->(knwSkl:AbltKnwSkl)").
                                     Return(knwSkl => knwSkl.As <AbltKnwSkl>()).Results;
                    sebuMsg += "-----지식 및 기술 -----\n";
                    foreach (AbltKnwSkl knwSkl in abltKnwSkl)
                    {
                        sebuMsg += (knwSkl.Name + "\n");
                    }
                    break;
                }
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(sebuMsg), cancellationToken);
            }
            return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
            {
                Prompt = MessageFactory.Text("더 필요하신 것 있으신가요?"),
                RetryPrompt = MessageFactory.Text("아래에서 골라주세요"),
                Choices = ChoiceFactory.ToChoices(EndList)
            }));
        }
Example #16
0
 public static ICypherFluentQuery From <TEntity>(this ICypherFluentQuery query, Guid guid) where TEntity : Root
 {
     query = query.Match($"({Common.GraphNodeKey<TEntity>()}:{Common.NodeLabel<TEntity>()} {{ Guid: {{guid}} }})").WithParams(new { guid });
     return(query);
 }
Example #17
0
        //public static ICypherFluentQuery CreateUnique<TRel, TSource, TTarget>(this ICypherFluentQuery query, Vector<TRel, TSource, TTarget> vector, string relKey = "relation", string sourceKey = "source", string targetKey = "target")
        //    where TRel : Relation, new()
        //    where TSource : Entity
        //    where TTarget : Entity
        //{
        //    query = query.CreateUnique(Common.Pattern(vector.GetType(), relKey, sourceKey, targetKey));
        //    return query;
        //}

        public static ICypherFluentQuery From <TEntity>(this ICypherFluentQuery query, string nodeVar = null) where TEntity : Root
        {
            nodeVar = nodeVar ?? Common.GraphNodeKey <TEntity>();
            query   = query.Match($"({nodeVar}:{Common.NodeLabel<TEntity>()})");
            return(query);
        }