Пример #1
0
        internal IEnumerable <PathFinder.Path> GetInternalPaths(Tree tree)
        {
            var finder = new PathFinder(tree, LengthLimit, WidthLimit);

            var allPairs = Utilities.ReservoirSample(Utilities.WeakConcat(Utilities.Choose2(variables),
                                                                          variables.Select((arg) => new Tuple <Variable, Variable>(arg, arg))), MaxContexts);

            //iterate over variable-variable pairs
            foreach (Tuple <Variable, Variable> varPair in allPairs)
            {
                bool pathToSelf = varPair.Item1 == varPair.Item2;

                foreach (var rhs in varPair.Item2.Leaves)
                {
                    foreach (var lhs in varPair.Item1.Leaves)
                    {
                        if (lhs == rhs)
                        {
                            continue;
                        }

                        PathFinder.Path path = finder.FindPath(lhs, rhs, limited: true);

                        if (path == null)
                        {
                            continue;
                        }

                        yield return(path);
                    }
                }
            }
        }
Пример #2
0
		internal IEnumerable<PathFinder.Path> GetInternalPaths(Tree tree)
		{
            var finder = new PathFinder(tree, LengthLimit, WidthLimit);
            foreach (Tuple<Variable, Variable> varPair in 
			         Utilities.WeakConcat(Utilities.Choose2(variables), 
			                              variables.Select((arg) => new Tuple<Variable,Variable>(arg,arg))))
			{
				bool pathToSelf = varPair.Item1 == varPair.Item2;

				foreach(var lhs in varPair.Item1.Leaves)
				foreach (var rhs in varPair.Item2.Leaves)
				{
					if (lhs == rhs)
							continue;
					
					PathFinder.Path path = finder.FindPath(lhs, rhs, limited: true);

					if (path == null)
						continue;
                    

					yield return path;
				}
			}
		}
Пример #3
0
        private string PathToString(PathFinder.Path path)
		{
			SyntaxNode ancesstor = path.Ancesstor;
			StringBuilder builder = new StringBuilder();
			builder.Append(path.Left.Text).Append(UpTreeChar);
			builder.Append(this.PathNodesToString(path));
			builder.Append(DownTreeChar).Append(path.Right.Text);
			return builder.ToString();
		}
Пример #4
0
        private string PathNodesToString(PathFinder.Path path)
        {
            builder.Clear();
            var nodeTypes = path.LeftSide;

            if (nodeTypes.Count() > 0)
            {
                builder.Append("(");
                builder.Append(nodeTypes.First().Kind());
                if (ParentTypeToAddChildId.Contains(nodeTypes.First().Parent.Kind()))
                {
                    builder.Append(GetTruncatedChildId(nodeTypes.First()));
                }
                builder.Append(")");
                foreach (var n in nodeTypes.Skip(1))
                {
                    builder.Append(UpTreeChar).Append("(").Append(n.Kind());
                    if (ParentTypeToAddChildId.Contains(n.Parent.Kind()))
                    {
                        builder.Append(GetTruncatedChildId(n));
                    }
                    builder.Append(")");
                }
                builder.Append(UpTreeChar);
            }
            builder.Append("(");
            builder.Append(path.Ancesstor.Kind());
            builder.Append(")");
            nodeTypes = path.RightSide;
            if (nodeTypes.Count() > 0)
            {
                builder.Append(DownTreeChar);
                builder.Append("(");
                builder.Append(nodeTypes.First().Kind());
                if (ParentTypeToAddChildId.Contains(nodeTypes.First().Parent.Kind()))
                {
                    builder.Append(GetTruncatedChildId(nodeTypes.First()));
                }
                builder.Append(")");
                foreach (var n in nodeTypes.Skip(1))
                {
                    builder.Append(DownTreeChar).Append("(").Append(n.Kind());
                    if (ParentTypeToAddChildId.Contains(n.Parent.Kind()))
                    {
                        builder.Append(GetTruncatedChildId(n));
                    }
                    builder.Append(")");
                }
            }
            return(builder.ToString());
        }