예제 #1
0
        public static void Main()
        {
            Parser           parser = new Parser(@"C:\Users\Hadar\Desktop\לימודים\סמסטר ז\אחזור\מנוע חלק ב\SearchEngine.v3.1\SearchEngine.v2.1\stop_words.txt", false);
            VariablesAjuster va     = new VariablesAjuster(@"C:\Users\Hadar\Desktop\לימודים\סמסטר ז\אחזור\מנוע חלק ב\SearchEngine.v3.1\SearchEngine.v2.1\qrels.txt");
            //QueryMutator qm = new QueryMutator(@"X:\Junk\glove.6B.100dc.vec", 1);
            Ranker ranker    = new Ranker(@"C:\a\results", false, @"C:\a\glove.6B.100dc.vec");
            double cosSimVal = 0.01;
            double bm25Val   = 0.01;
            double maxCosSim = 0;
            double maxBM25   = 0;
            int    max       = 0;
            String queries   = File.ReadAllText(@"C:\Users\Hadar\Desktop\לימודים\סמסטר ז\אחזור\מנוע חלק ב\SearchEngine.v3.1\SearchEngine.v2.1\queries.txt");

            String[]  q        = queries.Split(new string[] { "\r\n\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            Token[][] arr      = new Token[15][];
            Token[][] relevant = new Token[15][];
            //Token[][] irrelevant = new Token[15][];
            Query[] col = new Query[15];
            for (int i = 0; i < 15; i++)
            {
                col[i]      = new Query(q[i]);
                arr[i]      = parser.processDoc(new Document(null, null, null, null, col[i].getQuery(), null));
                relevant[i] = parser.processDoc(new Document(null, null, null, null, col[i].getRelevant(), null));
                //irrelevant[i] = parser.processDoc(new Document(null, null, null, null, col[i].getNonRelevant(), null));
            }

            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    //ranker.bm25Mult = bm25Val;
                    //ranker.cosSimMult = cosSimVal;
                    int score = 0;
                    //calculate query and compare
                    for (int k = 0; k < 15; k++)
                    {
                        //Token[][] mutated = qm.getPermutations(arr[k]);
                        //Dictionary<string,double> queryResult= ranker.processQuery(arr[k],relevant[k]);
                        Dictionary <string, double> queryResult = ranker.processQuerySemantically(arr[k], relevant[k]);

                        //Dictionary<string, double> irrelevantResults = ranker.processQuery(irrelevant[k]);
                        //queryResult = va.manipulateResults(queryResult, irrelevantResults, "substract");
                        score += va.compareResults(col[k], queryResult);
                    }
                    Console.WriteLine("BM=" + Math.Round(bm25Val, 2) + " CosSim=" + Math.Round(cosSimVal, 2) + " Score: " + score);
                    //compare with max if larger - update
                    if (score > max)
                    {
                        max       = score;
                        maxBM25   = bm25Val;
                        maxCosSim = cosSimVal;
                    }
                    bm25Val += 0.05;
                }
                cosSimVal += 0.05;
                bm25Val    = 0.01;
            }
            Console.WriteLine("MAX: BM=" + Math.Round(maxBM25, 2) + " CosSim=" + Math.Round(maxCosSim, 2) + " Score: " + max);
        }
예제 #2
0
        public static void Main()
        {
            Parser           parser = new Parser(@"stop_words.txt", false);
            VariablesAjuster va     = new VariablesAjuster(@"qrel.txt");
            //QueryMutator qm = new QueryMutator(@"X:\Junk\glove.6B.100dc.vec", 1);
            Ranker ranker  = new Ranker(@"D:\Posting", false, @"C:\a\glove.6B.100dc.vec");
            double b       = 0.00;
            double k       = 1.2;
            double maxB    = 0;
            double maxK    = 0;
            int    max     = 0;
            String queries = File.ReadAllText(@"queries.txt");

            String[]  q        = queries.Split(new string[] { "\r\n\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            Token[][] arr      = new Token[15][];
            Token[][] relevant = new Token[15][];
            //Token[][] irrelevant = new Token[15][];
            Query[] col = new Query[15];
            for (int i = 0; i < 15; i++)
            {
                col[i]      = new Query(q[i]);
                arr[i]      = parser.processDoc(new Document(null, null, null, null, col[i].getQuery(), null));
                relevant[i] = parser.processDoc(new Document(null, null, null, null, col[i].getRelevant(), null));
                //irrelevant[i] = parser.processDoc(new Document(null, null, null, null, col[i].getNonRelevant(), null));
            }

            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    ranker.b = b;
                    ranker.k = k;
                    int score = 0;
                    //calculate query and compare
                    for (int ki = 0; ki < 15; ki++)
                    {
                        //Token[][] mutated = qm.getPermutations(arr[k]);
                        Dictionary <string, double> queryResult = ranker.processQuery(arr[ki], relevant[ki]);
                        //Dictionary<string, double> queryResult = ranker.processQuerySemantically(arr[k], relevant[k]);

                        //Dictionary<string, double> irrelevantResults = ranker.processQuery(irrelevant[k]);
                        //queryResult = va.manipulateResults(queryResult, irrelevantResults, "substract");
                        score += va.compareResults(col[ki], queryResult);
                    }
                    Console.WriteLine("k=" + Math.Round(k, 2) + " b=" + Math.Round(b, 2) + " Score: " + score);
                    //compare with max if larger - update
                    if (score > max)
                    {
                        max  = score;
                        maxB = b;
                        maxK = k;
                    }
                    b += 0.05;
                }
                k += 0.05;
                b  = 0.00;
            }
            Console.WriteLine("MAX: B=" + Math.Round(maxB, 2) + " K=" + Math.Round(maxK, 2) + " Score: " + max);
        }