Example #1
0
        private void run(d.Clustering clustering, int toClusterCount, int topDocs)
        {
            d.VSSearcher vs = new d.VSSearcher(index, 0.6f);

            while (true)
            {
                Console.WriteLine("Query: ");
                string query = Console.ReadLine();
                Console.WriteLine(query);
                if (query == "")
                {
                    break;
                }
                d.ResultDocument[] searchResults = vs.Search(query);
                if (searchResults != null && searchResults.Length > 0)
                {
                    int     docs      = Math.Min(searchResults.Length, toClusterCount);
                    short[] toCluster = new short[docs];
                    for (int i = 0; i < docs; i++)
                    {
                        toCluster[i] = searchResults[i].DocId;
                    }

                    displayResults(clustering.GetClusters(toCluster, 10), topDocs, toCluster);
                }
                else
                {
                    Console.WriteLine("Your search returned 0 results -> there's nothing to cluster");
                }
            }
        }
Example #2
0
        private void execSearch()
        {
            float w = Convert.ToSingle(tbxPagerank.Text);

            d.Index            index    = new d.Index(getIndexDir());
            d.VSSearcher       searcher = new d.VSSearcher(index, w);
            d.ResultDocument[] results  = searcher.Search(tbxQuery.Text.Trim());
            if (results != null && results.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("<p style='border-bottom:solid 1px #999999;'>Your search returned <b>{0}</b> results. Displaying the top {1}:</p>", results.Length, tbxDisplay.Text);
                sb.Append("<table style='font-family:Verdana;font-size:10pt;' cellpadding='3' cellspacing='2' width='100%'>");
                sb.Append("<tr bgcolor='#f1f1f1'><td>#</td><td>similarity</td><td>pagerank</td><td>document</td></tr>");
                int max = Math.Min(results.Length, Convert.ToInt32(tbxDisplay.Text));
                for (int i = 0; i < max; i++)
                {
                    int    docId = results[i].DocId;
                    string url   = "http://" + index.GetURL(docId).Replace("%%", "/");
                    sb.AppendFormat("<tr><td>{4}</td><td>{0}</td><td>{1}</td><td><p style='margin-bottom:-10px;'><a style='font-size:11pt;' href='{2}'>{3}</a>",
                                    results[i].Similarity, results[i].PageRank, url, index.GetTitle(docId), i + 1);
                    sb.AppendFormat("<p><a style='color:green;font-size:9pt' href='{0}'>{0}</a></td></tr>", url);
                }
                sb.Append("</table>");
                ltrResults.Text = sb.ToString();
            }
            else
            {
                ltrResults.Text = "There were no results";
            }
        }
Example #3
0
        public void run()
        {
            d.VSSearcher vs = new d.VSSearcher(index, 0.6f);

            while (true)
            {
                Console.WriteLine("Query: ");
                string query = Console.ReadLine();
                if (query == "")
                {
                    break;
                }
                d.ResultDocument[] searchResults = vs.Search(query);
                if (searchResults != null && searchResults.Length > 0)
                {
                    Console.WriteLine(searchResults.Length + " results:");
                    int max = Math.Min(10, searchResults.Length);
                    for (int i = 0; i < max; i++)
                    {
                        Console.WriteLine("\t" + searchResults[i].DocId + " " + searchResults[i].Similarity + " " +
                                          index.GetURL(searchResults[i].DocId));
                    }
                }
                else
                {
                    Console.WriteLine("Your search returned 0 results");
                }
            }
        }
Example #4
0
        private void execAuthorities()
        {
            float w = Convert.ToSingle(tbxPagerank.Text);

            d.Index            index    = new d.Index(getIndexDir());
            d.VSSearcher       searcher = new d.VSSearcher(index, w);
            d.ResultDocument[] results  = searcher.Search(tbxQuery.Text.Trim());
            if (results != null && results.Length > 0)
            {
                StringBuilder sb = new StringBuilder();

                int            rootSize    = Convert.ToInt32(tbxRoot.Text);
                int            maxParents  = Convert.ToInt32(tbxParents.Text);
                int            maxChildren = Convert.ToInt32(tbxChildren.Text);
                d.AHPageLoader ahl         = new d.AHPageLoader(index, results, rootSize, maxParents, maxChildren);
                d.AHDocument[] authorities = ahl.Authorities;

                int max = Math.Min(authorities.Length, Convert.ToInt32(tbxDisplay.Text));

                sb.AppendFormat("<p style='border-bottom:solid 1px #999999;'>Your search returned <b>{0}</b> results. " +
                                "Displaying the top {1} authorities:</p>", results.Length, max);
                sb.Append("<table style='font-family:Verdana;font-size:10pt;' cellpadding='3' cellspacing='2' width='100%'>");
                sb.Append("<tr bgcolor='#f1f1f1'><td>authority score</td><td>hub score</td><td>document</td></tr>");

                for (int i = 0; i < max; i++)
                {
                    int    docId = authorities[i].DocId;
                    string url   = "http://" + index.GetURL(docId).Replace("%%", "/");
                    sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td><p style='margin-bottom:-10px;'><a style='font-size:11pt;' href='{2}'>{3}</a>",
                                    authorities[i].AuthorityScore, authorities[i].HubScore, url, index.GetTitle(docId));
                    sb.AppendFormat("<p><a style='color:green;font-size:9pt' href='{0}'>{0}</a></td></tr>", url);
                }
                sb.Append("</table>");
                ltrResults.Text = sb.ToString();
            }
            else
            {
                ltrResults.Text = "There were no results";
            }
        }
Example #5
0
        public void run()
        {
            d.VSSearcher vs = new d.VSSearcher(index, 0.6f);

            while (true)
            {
                Console.WriteLine("Query: ");
                string query = Console.ReadLine();
                if (query == "")
                {
                    break;
                }
                d.ResultDocument[] searchResults = vs.Search(query);

                if (searchResults != null && searchResults.Length > 0)
                {
                    d.AHPageLoader ahl         = new d.AHPageLoader(index, searchResults, 50, 20, 20); //if root>100, then bad results
                    d.AHDocument[] authorities = ahl.Authorities;
                    for (int i = 0; i < 20; i++)
                    {
                        Console.WriteLine(" a=" + authorities[i].AuthorityScore + " h=" + authorities[i].HubScore + " " + index.GetURL(authorities[i].DocId));
                    }

                    Console.WriteLine();

                    d.AHDocument[] hubs = ahl.Hubs;
                    for (int i = 0; i < 20; i++)
                    {
                        Console.WriteLine(" a=" + hubs[i].AuthorityScore + " h=" + hubs[i].HubScore + " " + index.GetURL(hubs[i].DocId));
                    }
                }
                else
                {
                    Console.WriteLine("Your search returned 0 results");
                }
            }
        }
Example #6
0
        private void execCluster()
        {
            float w = Convert.ToSingle(tbxPagerank.Text);

            d.Index            index    = new d.Index(getIndexDir());
            d.VSSearcher       searcher = new d.VSSearcher(index, w);
            d.ResultDocument[] results  = searcher.Search(tbxQuery.Text.Trim());
            if (results != null && results.Length > 0)
            {
                int toCluster = Convert.ToInt32(tbxDocs.Text);
                toCluster = Math.Min(toCluster, results.Length);
                short[] docIds = new short[toCluster];
                for (int i = 0; i < toCluster; i++)
                {
                    docIds[i] = results[i].DocId;
                }

                int k = Convert.ToInt32(tbxKmeans.Text);

                d.Cluster[] clusters;
                if (radKmeans.Checked)
                {
                    clusters = new d.KMeansClustering(index, k, true).GetClusters(docIds, 10);
                }
                else if (radBuckshot.Checked)
                {
                    clusters = new d.BisectingClustering(index, k).GetClusters(docIds, 10);
                }
                else
                {
                    clusters = new d.BisectingClustering(index, k).GetClusters(docIds, 10);
                }


                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("<p style='border-bottom:solid 1px #999999;'>Your search returned <b>{0}</b> results. " +
                                " Displaying the top {1} documents clustered into at most {2} clusters:</p>", results.Length, toCluster, k);

                for (int i = 0; i < clusters.Length; i++)
                {
                    sb.AppendFormat("<p style='margin-bottom:-10px;font-weight:bold;font-size:11pt;'>Cluster {0}", i + 1);
                    sb.Append("<p>Common terms: ");
                    IDictionaryEnumerator en = clusters[i].CommonTermIds.GetEnumerator();
                    while (en.MoveNext())
                    {
                        sb.AppendFormat("{0} ", index.GetTerm(Convert.ToInt32(en.Key)));
                    }

                    sb.Append("<p>");

                    en = clusters[i].DocIds.GetEnumerator();
                    int count   = 0;
                    int topDocs = 3;
                    while (count < topDocs && en.MoveNext())
                    {
                        short  docId = Convert.ToInt16(en.Key);
                        string url   = "http://" + index.GetURL(docId).Replace("%%", "/");
                        sb.AppendFormat("<p style='margin-bottom:-10px;'><a style='font-size:11pt;' href='{0}'>{1}</a>", url, index.GetTitle(docId));
                        sb.AppendFormat("<p><a style='color:green;font-size:9pt' href='{0}'>{0}</a>", url);
                        count++;
                    }
                    sb.Append("<p style='border-bottom: solid 1px #999999;'>");
                }
                ltrResults.Text = sb.ToString();
            }
            else
            {
                ltrResults.Text = "There were no results";
            }
        }
Example #7
0
 public void SetUp()
 {
     vs = new d.VSSearcher(new d.Index(EnvironmentBuilder.INDEX_DIRECTORY), 0.6f);
 }