Exemplo n.º 1
0
        public static void mainProgram(string pathDocs, string pathQueries, string pathRel, string pathStopWord)
        {
            // read file
            string text = System.IO.File.ReadAllText(@pathDocs);

            // read queries
            qs = new Queries(@pathQueries);
            //qs.print();

            // read stopwords
            StopwordTool.AddDictionaryFromText(@pathStopWord);

            createInvertedFile(text); //uncomment
        }
Exemplo n.º 2
0
        public static void findResultQueries(Queries queries, int k)
        {
            // list of hasil tiap query (list of list of result)
            allResults = new List<List<Docvalue>>();

            // list of list query old and new
            lQueryWeightOld = new List<List<WeightedTermQuery>>();
            lQueryWeightOld.Clear();
            lQueryWeightNew = new List<List<WeightedTermQuery>>();
            lDQueryWeightNew = new List<Dictionary<string, double>>();

            //for each query
            for (int i = 0; i < queries.nQuery(); i++)
            {
                List<Docvalue> result = new List<Docvalue>();
                List<WeightedTermQuery> queryWithWeight = new List<WeightedTermQuery>();
                queryWithWeight = weightingQuery(queries.getQuery(i), ListDocuments);

                lQueryWeightOld.Add(queryWithWeight);   // add list of query

                // initialize list new query, same as list old query
                List<WeightedTermQuery> lQueryWeight = new List<WeightedTermQuery>();
                foreach (var item in queryWithWeight)
                {
                    WeightedTermQuery queryWeight = new WeightedTermQuery(item.term, item.weight);
                    lQueryWeight.Add(queryWeight);
                }
                lQueryWeightNew.Add(lQueryWeight);

                // initialize dictionary new query
                Dictionary<string, double> dQueryWeight = new Dictionary<string, double>();
                foreach(var item in queryWithWeight)
                {
                    if(!dQueryWeight.ContainsKey(item.term))
                    {
                        dQueryWeight.Add(item.term, item.weight);
                    }
                }
                lDQueryWeightNew.Add(dQueryWeight);
                //Console.WriteLine("query ke : " + i);
                Similarity sim = new Similarity(queryWithWeight);
                result = sim.calculateDocumentsValue();
                result = result.OrderByDescending(o => o.val).ToList();
                if (k != -1) //-1 kalau hasil diretrieve semua
                {
                    result = result.Take(k).ToList();
                }
                allResults.Add(result);
            }

            //print hasil pencarian to console
            /*
            Console.WriteLine("RESULT : ");
            for (int i = 0; i < allResults.Count(); i++)
            {
                Console.WriteLine("result for query" + i);
                for (int j = 0; j < allResults.ElementAt(i).Count(); j++)
                {
                    Console.Write(allResults[i][j].docNum);
                    Console.Write("-");
                    Console.Write(allResults[i][j].val);
                    Console.Write("\n");
                }
            }*/

            //print hasil ke file

            /*
            string outputResult = "D:/SearchResult.txt";
            string line;
            using (StreamWriter writer = new StreamWriter(outputResult))
            {
                //Console.WriteLine("jumlah allresult count " + allResults.Count());
                for (int i = 0; i < allResults.Count(); i++)
                {
                    //Console.WriteLine("jumlah result count " + i + (" : ") + allResults.ElementAt(i).Count());
                    for (int j = 0; j < allResults.ElementAt(i).Count(); j++)
                    {
                        line = i + 1 + " ";
                        line = line + allResults[i][j].docNum;
                        writer.WriteLine(line);
                    }
                }
            }*/
            Console.WriteLine("Selesai!!");
            Console.ReadLine();
        }
Exemplo n.º 3
0
 public static void findResultQueriesTopK(Queries queries, int k)
 {
 }
        private void buttonInteractiveSearch_Click(object sender, EventArgs e)
        {
            //here
            Queries interactiveQuery = new Queries();
            interactiveQuery.query[0] = textBoxInteractiveQuery.Text;
            //Program.qs.query = textBoxInteractiveQuery.Text.Split(' ');
            Program.findResultQueries(interactiveQuery, Program.nRetrieve1);

            if (Program.relevanceFeedbackMethod.Equals("pseudo"))
            {
                RelevanceFeedback.assignRelFeedback(); //kalo pseudo yang top N dianggap relevan
                Program.createInvertedFileFromListDocuments();

                if (Program.useQueryExpansion == 1)
                {
                    QueryExpansion.doQueryExpansion();
                }
                RelevanceFeedback.reWeightingQuery();
                RelevanceFeedback.reCalculateSimilarity(-1);
            }

            //reset listdocuments
            Program.ListDocuments.Clear();
            Program.ListDocuments = new List<Document>(Program.ListDocumentsFixed);

            //// test relevance
            //RelevanceFeedback.assignRelFeedback();
            //QueryExpansion.doQueryExpansion();
            //RelevanceFeedback.reWeightingQuery();

            listBoxResultInteractive.Items.Clear();
            string line;
            int nd;

            for (int i = 0; i < Program.allResults.Count(); i++)
            {
                for (int j = 0; j < Program.allResults.ElementAt(i).Count(); j++)
                {
                    line = j + 1 + ". ";
                    line = line + ("similarity = ") + Program.allResults[i][j].val + ("-- ");
                    nd = Int32.Parse(Program.allResults[i][j].docNum)-1;
                    line = line + ("((") + Program.ListDocuments[nd].No + ("))");
                    line = line + (" ---- ");
                    line = line + Program.ListDocuments[nd].Title;
                    listBoxResultInteractive.Items.Add(line);
                }
            }
        }