Ejemplo n.º 1
0
        // Calc Stemming To List of Words
        private List <String> stemWord(List <string> index)
        {
            List <String> stemming = new List <String>();

            for (int i = 0; i < index.Count; i++)
            {
                char[]  w       = index.ElementAt(i).ToCharArray();
                int     wLength = index.ElementAt(i).Length;
                Stemmer s       = new Stemmer();
                s.add(w, wLength);
                s.stem();
                string stemmed = s.ToString();
                stemming.Add(stemmed);
            }
            return(stemming);
        }
Ejemplo n.º 2
0
        protected void SearchBtn_Click(object sender, EventArgs e)
        {
            Stemmer stemmer    = new Stemmer();
            ListBox DidUMean   = ((ListBox)form1.FindControl("DidUMeanLBID"));
            ListBox ResultsBox = ((ListBox)form1.FindControl("REsultsBoxID"));
            string  inputText  = ((TextBox)form1.FindControl("SearchTxt")).Text.ToLower();

            inputText = inputText.ToLower();
            string  DocID, frequency, Positions;
            Boolean exact_query = false;

            List <Term>       terms           = new List <Term>();
            List <singelTerm> SingleTermsList = new List <singelTerm>();
            Term          T;
            singelTerm    singleterm;
            Details       D;
            SqlConnection conn = new SqlConnection("Server = AYMAN-PC; Database = IRdb; Trusted_Connection = True; MultipleActiveResultSets = true");

            conn.Open();

            if (inputText[0] == '"')
            {
                inputText   = inputText.Replace(@"""", "");
                exact_query = true;
            }
            inputText = StopWords.RemoveStopwords(inputText);
            DidUMean.Items.Clear();
            ResultsBox.Items.Clear();
            string[] query = SplitWords(inputText);

            for (int i = 0; i < query.Count(); i++)
            {
                query[i] = stemmer.stem(query[i]);
                SqlCommand cmd = new SqlCommand("select [term],[doc_id],[frequency],[positions] from  [IRdb].[dbo].[Inverted_Index] where [term]= @term ", conn);
                cmd.Parameters.AddWithValue("@term", query[i]);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        singleterm      = new singelTerm();
                        singleterm.name = (reader["term"].ToString());//Term
                        frequency       = reader["frequency"].ToString();
                        DocID           = reader["doc_id"].ToString();
                        Positions       = reader["positions"].ToString();
                        string[]      Pos_terms     = Positions.Split('@');
                        string[]      freqs         = frequency.Split(',');
                        string[]      _DocIDs       = DocID.Split(',');
                        List <string> positionsList = new List <string>();
                        foreach (string p in Pos_terms)
                        {
                            positionsList = p.Split(',').ToList();
                        }

                        foreach (string doc_id in _DocIDs)
                        {
                            singleterm.doc_id.Add(int.Parse(doc_id));
                        }


                        //frequency
                        foreach (string f in freqs)
                        {
                            singleterm.frequency.Add(int.Parse(f));
                        }
                        //postions
                        foreach (string p in Pos_terms)
                        {
                            singleterm.position.Add(p);
                        }

                        SingleTermsList.Add(singleterm);
                    }
                }
            }
            ////////////////another Form ///////////
            for (int i = 0; i < SingleTermsList.Count(); i++)
            {
                T      = new Term();
                T.name = SingleTermsList[i].name;
                for (int j = 0; j < SingleTermsList[i].doc_id.Count(); j++)
                {
                    Details details = new Details();
                    details.doc_id    = SingleTermsList[i].doc_id[j];
                    details.frequency = SingleTermsList[i].frequency[j];
                    string [] positions = SingleTermsList[i].position[j].Split(',');
                    foreach (string pos in positions)
                    {
                        details.positions.Add(int.Parse(pos));
                    }
                    T.details.Add(details);
                }
                terms.Add(T);
            }
            /////////////////////////////////////////////////

            HtmlGenericControl div = ((HtmlGenericControl)form1.FindControl("SearchingResultsDiv"));//Div That Will Contain Links

            searchClass searchObj = new searchClass();

            if (terms.Count == 1)
            {
                searchObj.singleWordSearch(terms, query, ResultsBox, DidUMeanLabelID, div);
            }
            else
            {
                if (exact_query == false)
                {
                    //1.Multi Keyword Search

                    searchObj.MultiKeywordSearch(terms, query, ResultsBox, DidUMeanLabelID, div);
                }
                else
                {
                    searchObj.ExactSearch(terms, query, ResultsBox, DidUMeanLabelID, div);
                }
            }
        }