Exemplo n.º 1
0
        //public Dictionary<HtmlNode, DocumentCluster> GetClusterByDocumentDictionary()
        //{
        //    Dictionary<HtmlNode, DocumentCluster> output = new Dictionary<HtmlNode, DocumentCluster>();

        //    foreach (DocumentCluster cluster in this.)
        //    {
        //        var nodes = cluster.items.Select(x => x);

        //        foreach (HtmlNode node in nodes)
        //        {
        //            context.DeclarationConstruction_ClusterAnalysisContext.ClusterByDocuments.Add(node, cluster);
        //        }

        //        if (cluster.ClusterSeed != null)
        //        {
        //            context.DeclarationConstruction_ClusterAnalysisContext.ClusterByDocuments.Add(cluster.ClusterSeed, cluster);
        //        }
        //    }
        //}

        public void Publish(Dictionary <HtmlNode, HtmlSourceAndUrl> documentNodeDictionary, folderNode folderWithResults, DocumentSimilarityResult result)
        {
            folderWithResults.generateReadmeFiles(null);
            var items = GetClusters <DocumentCluster>(true);

            Dictionary <HtmlNode, string> labelsByDocument = result.GetLabelsByDocument();

            if (!name.isNullOrEmpty())
            {
                folderWithResults = folderWithResults.Add(name, name, "Reports for cluster collection " + name);
            }

            builderForText reporter = new builderForText();

            foreach (DocumentCluster cluster in items)
            {
                cluster.Publish(labelsByDocument, documentNodeDictionary, folderWithResults, result);

                reporter.AppendPair(cluster.name, cluster.items.Count);
                reporter.AppendPair("- range", cluster.range.Range);
            }


            String reportPath    = folderWithResults.pathFor("report.txt", imbSCI.Data.enums.getWritableFileMode.overwrite);
            String reportContent = reporter.GetContent();


            File.WriteAllText(reportPath, reportContent);
        }
        public void Publish(Dictionary <HtmlNode, String> labelsByDocument, Dictionary <HtmlNode, HtmlSourceAndUrl> documentNodeDictionary, folderNode folderWithResults, DocumentSimilarityResult result)
        {
            var        cluster = this;
            folderNode cFolder = folderWithResults.Add(cluster.name, cluster.name, "Directory for cluster " + cluster.name);

            result.Publish(documentNodeDictionary, cFolder, cluster.items);

            builderForText reporter = new builderForText();

            reporter.AppendHeading("Name: " + cluster.name);
            reporter.AppendPair("Items", cluster.items.Count);

            if (cluster.ClusterSeed != null)
            {
                reporter.AppendPair("Seed", labelsByDocument[cluster.ClusterSeed]);
            }
            foreach (var pair in cluster.range.GetDictionary())
            {
                reporter.AppendPair(pair.Key, pair.Value.ToString("F3"));
            }

            foreach (var item in cluster.items)
            {
                if (item != cluster.ClusterSeed)
                {
                    if (cluster.scoreDictionary.ContainsKey(item))
                    {
                        String           label  = labelsByDocument[item];
                        Double           score  = cluster.scoreDictionary[item];
                        HtmlSourceAndUrl source = documentNodeDictionary[item];
                        reporter.AppendLine("-----------------------------------");
                        reporter.AppendLine(label + " => " + score.ToString("F3"));
                        reporter.AppendLine("Filepath: " + source.filepath);
                        reporter.AppendLine("Url: " + source.url);
                    }
                }
            }

            String reportPath    = cFolder.pathFor("report.txt", imbSCI.Data.enums.getWritableFileMode.overwrite);
            String reportContent = reporter.GetContent();

            File.WriteAllText(reportPath, reportContent);
        }