コード例 #1
0
        public string GetGroups(int seed, int iterations)
        {
            tfidf = new TFIDF(terms, documents);
            var similarityMatrix = tfidf.GetDocumentTerm();

            kMeans = new KMeans(similarityMatrix);
            var groups = kMeans.GetGroups(seed, iterations);
            var result = "";

            for (int i = 0; i < seed; i++)
            {
                result += "GROUP #" + (i + 1).ToString() + "\n";
                foreach (var document in groups[i])
                {
                    result += documents[document].Item1 + "\n";
                }
                result += "\n\n";
            }
            return(result);
        }
コード例 #2
0
        public string GetDocumentsSimilarity()
        {
            tfidf = new TFIDF(terms, documents, query);
            var similarity = tfidf.GetDocumentQuery();

            var rank = new List <Tuple <string, double> >();

            for (int i = 0; i < documents.Count; i++)
            {
                rank.Add(new Tuple <string, double>(documents[i].Item1, similarity[i]));
            }
            rank = rank.OrderByDescending(doc => doc.Item2).ToList();

            var result = "";

            foreach (var record in rank)
            {
                result += record.Item2 + "\n" + record.Item1 + "\n\n";
            }
            return(result);
        }