internal static void DebugInfo(PathSubstitution substitution)
        {
            var db = Configuration.Db;

            Console.WriteLine("Substitution trace: " + substitution.OriginalTrace.ToString());
            Console.WriteLine("Rank: " + substitution.Rank);
            Console.WriteLine("Substitution node: {0} ({1})", db.GetLabel(FreebaseDbProvider.GetMid(substitution.Substitution.Data)), substitution.Substitution);
            foreach (var node in substitution.OriginalTrace.CurrentNodes.Take(20))
            {
                Console.WriteLine("\t{0} ({1})", db.GetLabel(FreebaseDbProvider.GetMid(node.Data)), node);
            }
        }
        internal PatternSubstitutionMatch PatternMatchProbability(MultiTraceLog2 pattern, string questionSignature, IEnumerable <NodeReference> questionEnities, ComposedGraph graph)
        {
            var bestSubstitutions = new List <PathSubstitution>();

            foreach (var node in questionEnities)
            {
                var currentBestConfidence        = 0.0;
                PathSubstitution currentBestPath = null;
                foreach (var path in getSubstitutedPaths(pattern, node, graph))
                {
                    var currentPath   = path;
                    var originalNodes = currentPath.OriginalTrace.CurrentNodes;
                    var confidence    = currentPath.Rank / pattern.InitialNodes.Count();
                    //TODO consider context
                    confidence *= SubstitutionProbability(currentPath.Substitution, originalNodes);
                    currentPath = currentPath.Reranked(confidence);
                    if (currentBestConfidence < confidence)
                    {
                        currentBestPath       = currentPath;
                        currentBestConfidence = confidence;
                    }
                }

                if (currentBestPath == null)
                {
                    //substitution was not found
                    return(null);
                }

                bestSubstitutions.Add(currentBestPath);
            }


            //TODO we would like to have match information in the output
            return(new PatternSubstitutionMatch(bestSubstitutions));
        }