Ejemplo n.º 1
0
        public static Dictionary<int, double> retrive(Query query)
        {
            searchSetTableAdapters.Document_TermTableAdapter documentTermTableAdapter = new searchSetTableAdapters.Document_TermTableAdapter();
            searchSet.Document_TermDataTable documentTermDataTable = new searchSet.Document_TermDataTable();

            Dictionary<int, double> list_document = new Dictionary<int, double>();

            foreach (KeyValuePair<string, double> entry in query.terms)
            {

                documentTermDataTable = documentTermTableAdapter.GetDataByTerm(entry.Key);

                foreach (searchSet.Document_TermRow row in documentTermDataTable)
                {
                    double SC = entry.Value * row.Weight;

                    if (list_document.ContainsKey(row.Document_ID))
                    {
                        list_document[row.Document_ID] += SC;
                    }
                    else
                    {
                        list_document.Add(row.Document_ID, SC);
                    }
                }
            }
            return list_document;
        }
Ejemplo n.º 2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            txtAnalysis.AppendText("Searching for query: ");
            txtAnalysis.AppendText(txtQuery.Text);
            txtAnalysis.AppendText("\r\n\r\nResult:\r\n");

            current_query = new Query(999, txtQuery.Text);

            current_query.preprocessQuery();
            current_query.calculateTerms();

            txtAnalysis.AppendText(" -- OLD WEIGHT --\r\n");
            foreach (KeyValuePair<string, double> entry in current_query.terms)
            {
                txtAnalysis.AppendText(entry.Key + " --> " + entry.Value + "\r\n");
            }
            txtAnalysis.AppendText("     --------\r\n\r\n Retrive results:\r\n");

            retrive_current_query(false);
        }
Ejemplo n.º 3
0
        private void cmbQuery_SelectedIndexChanged(object sender, EventArgs e)
        {
            //MessageBox.Show(queries[cmbQuery.SelectedIndex].content);
            txtAnalysis.AppendText("Searching for query: ");
            txtAnalysis.AppendText(queries[cmbQuery.SelectedIndex].content);

            current_query = queries[cmbQuery.SelectedIndex];

            current_query.preprocessQuery();
            current_query.calculateTerms();
            int _query = cmbQuery.SelectedIndex + 1;

            txtAnalysis.AppendText("  Relevant Docs: \r\n");
            foreach (RelevantJudgement rel in relevant_judgement)
            {
                if (rel.queryNumber == _query)
                    txtAnalysis.AppendText("   - D" + rel.documentNumber + "\r\n");
            }

            txtAnalysis.AppendText("\r\n\r\nResult:\r\n");
            retrive_current_query(false);

            txtAnalysis.AppendText("---------------------------\r\n");
            txtAnalysis.AppendText("Recall = " + Retrival.calculateRecall(relevant_judgement, result, cmbQuery.SelectedIndex) + "\r\n");
            txtAnalysis.AppendText("Precision = " + Retrival.calculatePrecision(relevant_judgement, result, cmbQuery.SelectedIndex) + "\r\n");
            txtAnalysis.AppendText("NIAP = " + Retrival.calculateNIAP(relevant_judgement, this.result, cmbQuery.SelectedIndex) + "\r\n");
            txtAnalysis.AppendText("---------------------------\r\n");
        }
Ejemplo n.º 4
0
        public static List<Query> openQueryFile(string pathName)
        {
            List<Query> queries = new List<Query>();
            System.IO.StreamReader file = new System.IO.StreamReader(pathName);

            string line;

            int number = 0;
            StringBuilder contentBuilder = new StringBuilder();
            string content = "";
            char nowState = ' ';

            while ((line = file.ReadLine()) != null)
            {
                if (line.Length > 1)
                {
                    if (line[0] == '.')
                    {
                        if (line[1] == 'I')
                        {
                            if (nowState == 'W')
                            {
                                content = contentBuilder.ToString().Trim();

                                List<String> splittedTerms = new List<String>();
                                splittedTerms = Utility.separateData(content.ToLower());
                                splittedTerms = splittedTerms.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();

                                Query query = new Query(number, content);
                                queries.Add(query);
                            }

                            nowState = 'I';
                            number = Int32.Parse(line.Split(' ')[1]);
                        }
                        else if (line[1] == 'W')
                        {
                            nowState = 'W';
                            contentBuilder = new StringBuilder("");
                        }
                    }
                    else
                    {
                        if (nowState == 'W')
                        {
                            contentBuilder.Append(line);
                            contentBuilder.Append(" ");
                        }
                    }
                }
            }
            file.Close();

            // last query
            content = contentBuilder.ToString().Trim();

            List<String> splitTerm = new List<String>();
            splitTerm = Utility.separateData(content.ToLower());
            splitTerm = splitTerm.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();

            Query query_ = new Query(number, content);
            queries.Add(query_);

            return queries;
        }
Ejemplo n.º 5
0
        public void applyAlgorithm(Query query)
        {
            double pembagi_relevan, pembagi_irelevan;

            if (MainForm.feedback_config.algorithm == 0)
            {
                pembagi_irelevan = irelevant_doc.Count;
                pembagi_relevan = relevant_doc.Count;
            }
            else
            {
                pembagi_irelevan = 1;
                pembagi_relevan = 1;
            }

            foreach (int rel in relevant_doc)
            {
                searchSetTableAdapters.Document_TermTableAdapter documentTermTableAdapter = new searchSetTableAdapters.Document_TermTableAdapter();
                searchSet.Document_TermDataTable documentTermDataTable = new searchSet.Document_TermDataTable();

                documentTermDataTable = documentTermTableAdapter.GetDataByDocID(rel);
                foreach (searchSet.Document_TermRow row in documentTermDataTable)
                {
                    if (MainForm.feedback_config.useexpand == 0)
                    {
                        if (query.terms.ContainsKey(row.Term))
                            query.terms[row.Term] += row.Weight / pembagi_relevan;
                    }
                    else
                    {
                        if (query.terms.ContainsKey(row.Term))
                            query.terms[row.Term] += row.Weight / pembagi_relevan;
                        else
                            query.terms.Add(row.Term, row.Weight / pembagi_relevan);
                    }
                }
            }

            foreach (int rel in irelevant_doc)
            {
                searchSetTableAdapters.Document_TermTableAdapter documentTermTableAdapter = new searchSetTableAdapters.Document_TermTableAdapter();
                searchSet.Document_TermDataTable documentTermDataTable = new searchSet.Document_TermDataTable();

                documentTermDataTable = documentTermTableAdapter.GetDataByDocID(rel);
                foreach (searchSet.Document_TermRow row in documentTermDataTable)
                {
                    if (query.terms.ContainsKey(row.Term))
                    {
                        query.terms[row.Term] -= row.Weight / pembagi_irelevan;

                        if (query.terms[row.Term] <= 0)
                            query.terms.Remove(row.Term);
                    }

                }

                if (MainForm.feedback_config.algorithm == 2) break;
            }

            foreach (KeyValuePair<string, double> entry in query.terms)
            {
                Console.WriteLine(entry.Key + " --> " + entry.Value);
            }
        }