예제 #1
0
        public void IgnoreAllWord()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is a tst of a tst errr";

            _SpellChecker.SpellCheck();
            Assert.True(3 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("tst" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.IgnoreAllWord();

            _SpellChecker.SpellCheck();
            Assert.True(7 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("errr" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
        }
예제 #2
0
        public void IgnoreAllWord()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is a tst of a tst errr";

            _SpellChecker.SpellCheck();
            Assertion.AssertEquals("Incorrect WordOffset", 3, _SpellChecker.WordIndex);
            Assertion.AssertEquals("Incorrect CurrentWord", "tst", _SpellChecker.CurrentWord);
            _SpellChecker.IgnoreAllWord();

            _SpellChecker.SpellCheck();
            Assertion.AssertEquals("Incorrect WordOffset", 7, _SpellChecker.WordIndex);
            Assertion.AssertEquals("Incorrect CurrentWord", "errr", _SpellChecker.CurrentWord);
        }
예제 #3
0
        public void DeleteWord()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is is a tst.";
            _SpellChecker.SpellCheck();
            Assert.True(2 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("is" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            // basic delete test
            _SpellChecker.DeleteWord();
            Assert.True("this is a tst." == _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.True(3 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("tst" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            // before punctuation delete test
            _SpellChecker.DeleteWord();
            Assert.True("this is a." == _SpellChecker.Text, "Incorrect Text");


            _SpellChecker.Text = "Becuase people are realy bad spelers";
            _SpellChecker.SpellCheck();

            Assert.True(0 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("Becuase" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            //delete first word test
            _SpellChecker.DeleteWord();
            Assert.True("people are realy bad spelers" == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(2 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("realy" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            ////delete first word test
            //_SpellChecker.DeleteWord();
            //Assert.True("people are bad spelers" == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(3 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("spelers" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            ////delete last word test
            //_SpellChecker.DeleteWord();
            //Assert.True("people are bad" == _SpellChecker.Text, "Incorrect Text");
        }
예제 #4
0
        public void DeleteWord()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is is a tst.";
            _SpellChecker.SpellCheck();
            Assert.AreEqual(2, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("is", _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            // basic delete test
            _SpellChecker.DeleteWord();
            Assert.AreEqual("this is a tst.", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(3, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("tst", _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            // before punctuation delete test
            _SpellChecker.DeleteWord();
            Assert.AreEqual("this is a.", _SpellChecker.Text, "Incorrect Text");


            _SpellChecker.Text = "Becuase people are realy bad spelers";
            _SpellChecker.SpellCheck();

            Assert.AreEqual(0, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("Becuase", _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            //delete first word test
            _SpellChecker.DeleteWord();
            Assert.AreEqual("people are realy bad spelers", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(2, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("realy", _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            //delete first word test
            _SpellChecker.DeleteWord();
            Assert.AreEqual("people are bad spelers", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(3, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("spelers", _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            //delete last word test
            _SpellChecker.DeleteWord();
            Assert.AreEqual("people are bad", _SpellChecker.Text, "Incorrect Text");
        }
예제 #5
0
        public void CheckSpelling()
        {
            _customUnderlines.IllFormedLines.Clear();
            _customUnderlines.Lines.Clear();

            //Do not check spelling of watermark text
            if (!IsWatermarkShowing)
            {
                try
                {
                    if (_spelling != null && TextBox.Text.Length < 5000)
                    {
                        _spelling.Text       = TextBox.Text;
                        _spelling.ShowDialog = false;

                        if (File.Exists(_spelling.Dictionary.DictionaryFile))
                        {
                            _spelling.SpellCheck();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
                MarkLines();
            }

            TextBox.Refresh();
        }
예제 #6
0
        public void NoText()
        {
            Spelling _SpellChecker = NewSpellChecker();

            Assert.AreEqual(string.Empty, _SpellChecker.CurrentWord, "Incorrect Current Word");

            _SpellChecker.WordIndex = 1;
            Assert.AreEqual(0, _SpellChecker.WordIndex, "Incorrect Word Index");

            Assert.AreEqual(0, _SpellChecker.WordCount, "Incorrect Word Count");

            Assert.AreEqual(0, _SpellChecker.TextIndex, "Incorrect Text Index");

            _SpellChecker.DeleteWord();
            Assert.AreEqual(string.Empty, _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.IgnoreWord();
            Assert.AreEqual(string.Empty, _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.ReplaceWord("Test");
            Assert.AreEqual(string.Empty, _SpellChecker.Text, "Incorrect Text");

            Assert.IsFalse(_SpellChecker.SpellCheck(), "Spell Check not false");

            _SpellChecker.Suggest();
            Assert.AreEqual(0, _SpellChecker.Suggestions.Count, "Generated Suggestions with no text");
        }
예제 #7
0
        public void SpellCheck()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is an errr tst";

            _SpellChecker.SpellCheck();
            Assert.True(3 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("errr" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
        }
예제 #8
0
        public void SpellCheck()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is an errr tst";

            _SpellChecker.SpellCheck();
            Assertion.AssertEquals("Incorrect WordOffset", 3, _SpellChecker.WordIndex);
            Assertion.AssertEquals("Incorrect CurrentWord", "errr", _SpellChecker.CurrentWord);
        }
예제 #9
0
        public void HtmlSpellCheck()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.IgnoreHtml = true;
            _SpellChecker.Text       = "<a href=\"#\">this <span id=\"txt\">is</span> an errr tst</a>";

            _SpellChecker.SpellCheck();
            Assertion.AssertEquals("Incorrect WordOffset", 9, _SpellChecker.WordIndex);
            Assertion.AssertEquals("Incorrect CurrentWord", "errr", _SpellChecker.CurrentWord);
        }
예제 #10
0
        public void HtmlSpellCheck()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.IgnoreHtml = true;
            _SpellChecker.Text       = "<a href=\"#\">this <span id=\"txt\">is</span> an errr tst</a>";

            _SpellChecker.SpellCheck();
            Assert.True(9 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("errr" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
        }
예제 #11
0
        public void Suggest()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is tst";
            _SpellChecker.SpellCheck();
            Assert.True(2 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("tst" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");

            _SpellChecker.Suggest();
            Assert.True(25 == _SpellChecker.Suggestions.Count, "Incorrect Suggestion Count");
            Assert.True(true == _SpellChecker.Suggestions.Contains("test"), "Could not find 'test' in suggestions");
        }
예제 #12
0
        public void Suggest()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "this is tst";
            _SpellChecker.SpellCheck();
            Assertion.AssertEquals("Incorrect WordOffset", 2, _SpellChecker.WordIndex);
            Assertion.AssertEquals("Incorrect CurrentWord", "tst", _SpellChecker.CurrentWord);

            _SpellChecker.Suggest();
            Assertion.AssertEquals("Incorrect Suggestion Count", 25, _SpellChecker.Suggestions.Count);
            Assertion.AssertEquals("Could not find 'test' in suggestions", true, _SpellChecker.Suggestions.Contains("test"));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        wordCounterString = GetString("SpellCheck.wordCounterString");

        ScriptHelper.RegisterWOpenerScript(Page);
        ScriptHelper.RegisterScriptFile(Page, "Controls/MessagesPlaceHolder.js");
        ScriptHelper.RegisterSpellChecker(Page);

        // Control initialization
        IgnoreButton.Text     = GetString("SpellCheck.IgnoreButton");
        IgnoreAllButton.Text  = GetString("SpellCheck.IgnoreAllButton");
        ReplaceButton.Text    = GetString("SpellCheck.ReplaceButton");
        ReplaceAllButton.Text = GetString("SpellCheck.ReplaceAllButton");
        StatusText.Text       = GetString("SpellCheck.StatusText");
        RemoveButton.Text     = GetString("general.remove");

        headTitle.ResourceString = "SpellCheck.lblNotInDictionary";
        lblChangeTo.Text         = GetString("SpellCheck.lblChangeTo");
        lblSuggestions.Text      = GetString("SpellCheck.lblSuggestions");

        if (mDictExists)
        {
            // Add client side events
            Suggestions.Attributes.Add("onChange", "javascript: changeWord(this);");

            // Load spell checker settings
            LoadValues();
            switch (SpellMode.Value)
            {
            case "start":
                EnableButtons();
                SpellChecker.SpellCheck();
                break;

            case "suggest":
                EnableButtons();
                break;

            default:
                DisableButtons();
                break;
            }
        }
    }
예제 #14
0
        public void CheckSpelling()
        {
            _customUnderlines.IllFormedLines.Clear();
            _customUnderlines.Lines.Clear();
            try
            {
                if (_spelling != null)
                {
                    _spelling.Text       = TextBox.Text;
                    _spelling.ShowDialog = false;

                    if (File.Exists(_spelling.Dictionary.DictionaryFile))
                    {
                        _spelling.SpellCheck();
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
            MarkLines();
            TextBox.Refresh();
        }
예제 #15
0
        static void Main(string[] args)
        {
            // start connection with database
            SqlConnection sqlConnection = new SqlConnection("Data Source=AHMEDFATHY-PC;Initial Catalog=newDB;Integrated Security=True; MultipleActiveResultSets=true");

            sqlConnection.Open();
            // select statment to retrieve everything from database
            string     queryString = "SELECT * FROM crawler_Table";
            SqlCommand cmd         = new SqlCommand(queryString, sqlConnection);
            // declare variable from reader to read from database (all the content from  database)
            SqlDataReader rdr = cmd.ExecuteReader();

            int counterofopages = 0;   // counter for number of pages that i read it from database (at least 1500)

            // datastructure to save term and doc_id and frequency and list of positions for this term
            List <KeyValuePair <string, KeyValuePair <int[], List <int> > > > indexmap = new List <KeyValuePair <string, KeyValuePair <int[], List <int> > > >();

            // while loop to read row by row from the reader
            while (rdr.Read())
            {
                // this condition to break from loop when take at least 1500 page
                if (counterofopages == 1600)
                {
                    break;
                }
                // try and catch to throw any exceptions out if it retreive null from innertext or something else

                int boolll = 0; // boolean to check if the inner text has exception change boolean = 1 and skip tha link
                try
                {
                    //===================================================//
                    // retreive from each row docid , url (link) , content of the page (html page)
                    int    doc_id  = (int)rdr["doc_id"];
                    string url     = (string)rdr["URL"];
                    string content = (string)rdr["Page_Content"];
                    //===================================================//

                    // pasre html page from database and get the inner text  (step 1)
                    IHTMLDocument2 myDoc = new HTMLDocumentClass();
                    myDoc.write(content);
                    string elements = myDoc.body.innerText;
                    //===================================================//
                    //(it will be)
                    /// split in (step 2) (to take tokens and save it in array of strings named (tokens)
                    string[] tokens = elements.Split(',', ' ', '.', ':', '\t', '\n', '\r');

                    int i = 0; // counter to calculate the position for every term

                    // check if any string it will be null or empty
                    tokens = tokens.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                    //===================================================//

                    /// saves every term and its list (positions) (s in dictionary named (termsandpos) before removing stop words
                    Dictionary <string, List <int> > termsandpos = new Dictionary <string, List <int> >();
                    foreach (var words in tokens)
                    {
                        List <int> listofpos = new List <int>();
                        i++;
                        // using regex to remove punctuation characters from every word   (step 3) -> req 1
                        string word = Regex.Replace(words, @"[^\w\d\s]", "");
                        word = Regex.Replace(word, @"\d", "");
                        // if the word is empty after removing punctuation characters continues and don't save it
                        if (word == "")
                        {
                            continue;
                        }
                        // using spelling class from netspell reference and create object from it and using it to check if this word is real word in english or not.
                        Spelling ss = new Spelling();
                        // when the object from spelling class is used , the dialog window will opened and has many feature and i will closed by using next line to continue my run it's not used for my code.
                        ss.ShowDialog = false;
                        // check if this word is not found in dictionary in the spell library , continue ( go to the next word).
                        // esle continue the rest of the code (that is mean the word is found in the dictionary).
                        if (ss.SpellCheck(word))
                        {
                            continue;
                        }

                        word = word.ToLower(); //case folding in  (step 3) -> req 2

                        //If the word  is already existed ,add the new position in the list of this word
                        if (termsandpos.ContainsKey(word))
                        {
                            listofpos = termsandpos[word];
                            listofpos.Add(i);
                            termsandpos[word] = listofpos;
                        }
                        // else, add the word and the first position
                        else
                        {
                            listofpos.Add(i);
                            termsandpos.Add(word, listofpos);
                        }
                    }
                    //===================================================//

                    /////  stop words removing in (step 3) -> req 3
                    /// list of stop words
                    /// create anthor dictinary to copy all terms without stop words
                    Dictionary <string, List <int> > temp = new Dictionary <string, List <int> >();
                    List <string> stopwords = new List <string>()
                    {
                        "a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also", "although", "always", "am", "among", "amongst", "amoungst", "amount", "an", "and", "another", "any", "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around", "as", "at", "back", "be", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven", "else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own", "part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thick", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the"
                    };
                    for (int f = 0; f < termsandpos.Count; f++)
                    {
                        // if the term is already existed in the stopwords list or the term is a single character like ii or i , continue (and go to the next term).
                        if (stopwords.Contains(termsandpos.Keys.ElementAt(f)) || termsandpos.Keys.ElementAt(f).Length <= 2)
                        {
                            continue;
                        }
                        // else ,that's mean the term is not a stop word then add it and its positions in the temp dictionary.
                        else
                        {
                            List <int> copyofpositions = new List <int>();
                            copyofpositions = termsandpos[termsandpos.Keys.ElementAt(f)];
                            temp.Add(termsandpos.Keys.ElementAt(f), copyofpositions);
                        }
                    }
                    //===================================================//

                    ////  al stemming algorithm            (step 3) --> req 4
                    var stemmer = new PorterStemmer();    // declare object from claas of porterstemmer algorithm
                    Dictionary <string, List <int> > finalterm = new Dictionary <string, List <int> >();
                    foreach (KeyValuePair <string, List <int> > iter1 in temp)
                    {
                        //===================================================//

                        // add every term and its docid in table called (TermsBStemming_Table) in db before stemming (the note in step 3 -->req 4)
                        string       insertString3 = "INSERT INTO TermsBStemming_Table (termBstemming,docID) VALUES (@termBstemming,@docID)";
                        SqlCommand   cmd3          = new SqlCommand(insertString3, sqlConnection);
                        SqlParameter par1          = new SqlParameter("@termBstemming", iter1.Key);
                        SqlParameter par2          = new SqlParameter("@docID", doc_id);
                        cmd3.Parameters.Add(par1);
                        cmd3.Parameters.Add(par2);
                        cmd3.ExecuteNonQuery();
                        //===================================================//

                        List <int> listofpositions = new List <int>();
                        // called function (StemWord) and send the term and return term after stemming
                        string stem = stemmer.StemWord(iter1.Key);
                        // check if this stem is already existed in finalterm dictionary (the new datastructure to save the term and its list after stemmnig)
                        if (finalterm.ContainsKey(stem))
                        {
                            List <int> tempforsimlir = new List <int>();
                            tempforsimlir   = finalterm[stem]; // take the list of positions for this term (old positions added before for this term)
                            listofpositions = temp[iter1.Key]; // take the list of new positions for this term
                            /// added the new positions and old position in one list
                            for (int j = 0; j < listofpositions.Count; j++)
                            {
                                tempforsimlir.Add(listofpositions[j]);
                            }
                            // and save it again for the term
                            finalterm[stem] = tempforsimlir;
                        }
                        // addd the term ans its list to finalterm dictionary
                        else
                        {
                            listofpositions = temp[iter1.Key];
                            finalterm.Add(stem, listofpositions);
                        }
                    }

                    //===================================================//

                    ////  inverted index (step 4)

                    foreach (KeyValuePair <string, List <int> > iter in finalterm)
                    {
                        int   freq = iter.Value.Count; // calculate freq through count number of positions
                        int[] arr  = new int[2];       // save in this array doc id and the frequency
                        arr[0] = doc_id;
                        arr[1] = freq;
                        // convert list of the positions for every term to string
                        var resultofpositions = string.Join(", ", iter.Value);
                        //===================================================//

                        // save term and docid ans=d frequency and (list of positions as string ) in table called Inverted_Index in db.
                        string       insertString2 = "INSERT INTO Inverted_Index (Term,DocID,Frequency,position) VALUES (@Term,@DocID,@Frequency,@position)";
                        SqlCommand   cmd2          = new SqlCommand(insertString2, sqlConnection);
                        SqlParameter paramter1     = new SqlParameter("@Term", iter.Key);
                        SqlParameter paramter2     = new SqlParameter("@DocID", doc_id);
                        SqlParameter paramter3     = new SqlParameter("@Frequency", freq);
                        SqlParameter paramter4     = new SqlParameter("@position", resultofpositions);
                        cmd2.Parameters.Add(paramter1);
                        cmd2.Parameters.Add(paramter2);
                        cmd2.Parameters.Add(paramter3);
                        cmd2.Parameters.Add(paramter4);
                        cmd2.ExecuteNonQuery();
                        //===================================================//
                        /// store in index list term and arrof ints (arr[0]=docid,arr[1] = freqs of every term) and list of all positions of this term (if i needed in ranks or something else).
                        indexmap.Add(new KeyValuePair <string, KeyValuePair <int[], List <int> > >(iter.Key, new KeyValuePair <int[], List <int> >(arr, iter.Value)));
                    }

                    //===================================================//
                }
                //===================================================//
                //catch any type of exception and change the boolean that i decalred equal zero
                catch (NullReferenceException ex)
                {
                    boolll = 1;
                    Console.WriteLine(ex.Message);
                }
                catch (ArgumentOutOfRangeException exx)
                {
                    boolll = 1;
                    Console.WriteLine(exx.Message);
                }
                // if the boolean became equal 1 , then leave this link and go to anthor link
                if (boolll == 1)
                {
                    continue;
                }

                //===================================================//
                /// to count number of pages (at least 1500 page)
                counterofopages++;
                //===================================================//
            }
            //===================================================//
            // close the reader from database
            rdr.Close();
            /// close the connection
            sqlConnection.Close();
            //===================================================//
        }
예제 #16
0
        public void TestEvents()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "ths is is a tst.";

            ResetEvents();
            _SpellChecker.SpellCheck();
            //spelling check
            Assert.AreEqual(0, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("ths", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            // event check
            Assert.AreEqual(EventNames.MisspelledWord, _lastEvent, "Incorrect Event");
            Assert.IsNotNull(_lastSpellingEvent, "Event not fired");
            Assert.AreEqual(0, _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.AreEqual(0, _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.AreEqual("ths", _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.ReplaceWord("this");
            //spelling check
            Assert.AreEqual("this is is a tst.", _SpellChecker.Text, "Incorrect Text");
            // event check
            Assert.AreEqual(EventNames.ReplacedWord, _lastEvent, "Incorrect Event");
            Assert.IsNotNull(_lastReplaceEvent, "Null Event object fired");
            Assert.AreEqual(0, _lastReplaceEvent.WordIndex, "Incorrect Event Word Index");
            Assert.AreEqual(0, _lastReplaceEvent.TextIndex, "Incorrect Event Text Index");
            Assert.AreEqual("ths", _lastReplaceEvent.Word, "Incorrect Event Word");
            Assert.AreEqual("this", _lastReplaceEvent.ReplacementWord, "Incorrect Event Replacement Word");

            ResetEvents();
            _SpellChecker.SpellCheck();
            //spelling check
            Assert.AreEqual(2, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("is", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            // event check
            Assert.AreEqual(EventNames.DoubledWord, _lastEvent, "Incorrect Event");
            Assert.IsNotNull(_lastSpellingEvent, "Null Event object fired");
            Assert.AreEqual(2, _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.AreEqual(8, _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.AreEqual("is", _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.DeleteWord();
            //spelling check
            Assert.AreEqual("this is a tst.", _SpellChecker.Text, "Incorrect Text");
            // event check
            Assert.AreEqual(EventNames.DeletedWord, _lastEvent, "Incorrect Event");
            Assert.IsNotNull(_lastSpellingEvent, "Null Event object fired");
            Assert.AreEqual(2, _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.AreEqual(8, _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.AreEqual("is ", _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.SpellCheck();
            //spelling check
            Assert.AreEqual(3, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("tst", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            // event check
            Assert.AreEqual(EventNames.MisspelledWord, _lastEvent, "Incorrect Event");
            Assert.IsNotNull(_lastSpellingEvent, "Null Event object fired");
            Assert.AreEqual(3, _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.AreEqual(10, _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.AreEqual("tst", _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.IgnoreWord();
            //spelling check
            Assert.AreEqual("this is a tst.", _SpellChecker.Text, "Incorrect Text");
            // event check
            Assert.AreEqual(EventNames.IgnoredWord, _lastEvent, "Incorrect Event");
            Assert.IsNotNull(_lastSpellingEvent, "Null Event object fired");
            Assert.AreEqual(3, _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.AreEqual(10, _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.AreEqual("tst", _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.SpellCheck();
            // event check
            Assert.AreEqual(EventNames.EndOfText, _lastEvent, "Incorrect Event");
        }
예제 #17
0
        public void TestEvents()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "ths is is a tst.";

            ResetEvents();
            _SpellChecker.SpellCheck();
            //spelling check
            Assert.True(0 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("ths" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            // event check
            Assert.True(EventNames.MisspelledWord == _lastEvent, "Incorrect Event");
            Assert.NotNull(_lastSpellingEvent);            //, "Event not fired");
            Assert.True(0 == _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.True(0 == _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.True("ths" == _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.ReplaceWord("this");
            //spelling check
            Assert.True("this is is a tst." == _SpellChecker.Text, "Incorrect Text");
            // event check
            Assert.True(EventNames.ReplacedWord == _lastEvent, "Incorrect Event");
            Assert.NotNull(_lastReplaceEvent);            //, "Null Event object fired");
            Assert.True(0 == _lastReplaceEvent.WordIndex, "Incorrect Event Word Index");
            Assert.True(0 == _lastReplaceEvent.TextIndex, "Incorrect Event Text Index");
            Assert.True("ths" == _lastReplaceEvent.Word, "Incorrect Event Word");
            Assert.True("this" == _lastReplaceEvent.ReplacementWord, "Incorrect Event Replacement Word");

            ResetEvents();
            _SpellChecker.SpellCheck();
            //spelling check
            Assert.True(2 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("is" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            // event check
            Assert.True(EventNames.DoubledWord == _lastEvent, "Incorrect Event");
            Assert.NotNull(_lastSpellingEvent);            //, "Null Event object fired");
            Assert.True(2 == _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.True(8 == _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.True("is" == _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.DeleteWord();
            //spelling check
            Assert.True("this is a tst." == _SpellChecker.Text, "Incorrect Text");
            // event check
            Assert.True(EventNames.DeletedWord == _lastEvent, "Incorrect Event");
            Assert.NotNull(_lastSpellingEvent);            //, "Null Event object fired");
            Assert.True(2 == _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.True(8 == _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.True("is " == _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.SpellCheck();
            //spelling check
            Assert.True(3 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("tst" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            // event check
            Assert.True(EventNames.MisspelledWord == _lastEvent, "Incorrect Event");
            Assert.NotNull(_lastSpellingEvent);            //, "Null Event object fired");
            Assert.True(3 == _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.True(10 == _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.True("tst" == _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.IgnoreWord();
            //spelling check
            Assert.True("this is a tst." == _SpellChecker.Text, "Incorrect Text");
            // event check
            Assert.True(EventNames.IgnoredWord == _lastEvent, "Incorrect Event");
            Assert.NotNull(_lastSpellingEvent);            //, "Null Event object fired");
            Assert.True(3 == _lastSpellingEvent.WordIndex, "Incorrect Event Word Index");
            Assert.True(10 == _lastSpellingEvent.TextIndex, "Incorrect Event Text Index");
            Assert.True("tst" == _lastSpellingEvent.Word, "Incorrect Event Word");

            ResetEvents();
            _SpellChecker.SpellCheck();
            // event check
            Assert.True(EventNames.EndOfText == _lastEvent, "Incorrect Event");
        }
예제 #18
0
        public void ReplaceWord()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "ths is an errr tst";

            _SpellChecker.SpellCheck();
            Assert.True(0 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("ths" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplacementWord = "this";
            _SpellChecker.ReplaceWord();
            Assert.True("this is an errr tst" == _SpellChecker.Text, "Incorrect Text");

            //replace with empty string
            _SpellChecker.SpellCheck();
            Assert.True(3 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("errr" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("");
            Assert.True("this is an tst" == _SpellChecker.Text, "Incorrect Text");


            _SpellChecker.Text = "Becuase people are realy bad spelers, \r\nths produc was desinged to prevent spelling errors in a text area like ths.";

            _SpellChecker.SpellCheck();
            Assert.True(0 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.True("Becuase" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("because");
            Assert.True("Because people are realy bad spelers, \r\nths produc was desinged to prevent spelling errors in a text area like ths." == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(3 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("realy" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            //_SpellChecker.ReplaceWord("really");
            //Assert.True("Because people are really bad spelers, \r\nths produc was desinged to prevent spelling errors in a text area like ths." == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(5 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("spelers" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            //_SpellChecker.ReplaceWord("spellers");
            //Assert.True("Because people are really bad spellers, \r\nths produc was desinged to prevent spelling errors in a text area like ths." == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(6 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("ths" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            //_SpellChecker.ReplaceWord("this");
            //Assert.True("Because people are really bad spellers, \r\nthis produc was desinged to prevent spelling errors in a text area like ths." == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(7 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("produc" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            //_SpellChecker.ReplaceWord("product");
            //Assert.True("Because people are really bad spellers, \r\nthis product was desinged to prevent spelling errors in a text area like ths." == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(9 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("desinged" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            //_SpellChecker.ReplaceWord("designed");
            //Assert.True("Because people are really bad spellers, \r\nthis product was designed to prevent spelling errors in a text area like ths." == _SpellChecker.Text, "Incorrect Text");

            //_SpellChecker.SpellCheck();
            //Assert.True(19 == _SpellChecker.WordIndex, "Incorrect WordOffset");
            //Assert.True("ths" == _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            //_SpellChecker.ReplaceWord("this");
            //Assert.True("Because people are really bad spellers, \r\nthis product was designed to prevent spelling errors in a text area like this." == _SpellChecker.Text, "Incorrect Text");
        }
예제 #19
0
        public void ReplaceWord()
        {
            Spelling _SpellChecker = NewSpellChecker();

            _SpellChecker.Text = "ths is an errr tst";

            _SpellChecker.SpellCheck();
            Assert.AreEqual(0, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("ths", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplacementWord = "this";
            _SpellChecker.ReplaceWord();
            Assert.AreEqual("this is an errr tst", _SpellChecker.Text, "Incorrect Text");

            //replace with empty string
            _SpellChecker.SpellCheck();
            Assert.AreEqual(3, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("errr", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("");
            Assert.AreEqual("this is an tst", _SpellChecker.Text, "Incorrect Text");


            _SpellChecker.Text = "Becuase people are realy bad spelers, \r\nths produc was desinged to prevent spelling errors in a text area like ths.";

            _SpellChecker.SpellCheck();
            Assert.AreEqual(0, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("Becuase", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("because");
            Assert.AreEqual("Because people are realy bad spelers, \r\nths produc was desinged to prevent spelling errors in a text area like ths.", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(3, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("realy", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("really");
            Assert.AreEqual("Because people are really bad spelers, \r\nths produc was desinged to prevent spelling errors in a text area like ths.", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(5, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("spelers", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("spellers");
            Assert.AreEqual("Because people are really bad spellers, \r\nths produc was desinged to prevent spelling errors in a text area like ths.", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(6, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("ths", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("this");
            Assert.AreEqual("Because people are really bad spellers, \r\nthis produc was desinged to prevent spelling errors in a text area like ths.", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(7, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("produc", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("product");
            Assert.AreEqual("Because people are really bad spellers, \r\nthis product was desinged to prevent spelling errors in a text area like ths.", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(9, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("desinged", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("designed");
            Assert.AreEqual("Because people are really bad spellers, \r\nthis product was designed to prevent spelling errors in a text area like ths.", _SpellChecker.Text, "Incorrect Text");

            _SpellChecker.SpellCheck();
            Assert.AreEqual(19, _SpellChecker.WordIndex, "Incorrect WordOffset");
            Assert.AreEqual("ths", _SpellChecker.CurrentWord, "Incorrect CurrentWord");
            _SpellChecker.ReplaceWord("this");
            Assert.AreEqual("Because people are really bad spellers, \r\nthis product was designed to prevent spelling errors in a text area like this.", _SpellChecker.Text, "Incorrect Text");
        }
예제 #20
0
        public void SuggestionRank()
        {
            string invalidFile = @"..\src\NetSpell.Tests\Data\SuggestionTest.txt";

            // open file
            FileStream   fs = new FileStream(invalidFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            StreamReader sr = new StreamReader(fs, Encoding.UTF7);

            int totalFound         = 0;
            int totalChecked       = 0;
            int totalFirst         = 0;
            int totalTopFive       = 0;
            int totalTopTen        = 0;
            int totalTopTwentyFive = 0;

            Console.WriteLine("Misspelled\tCorrect\tPosition\tCount");

            // read line by line
            while (sr.Peek() >= 0)
            {
                string tempLine = sr.ReadLine().Trim();
                if (tempLine.Length > 0)
                {
                    string[] parts          = tempLine.Split();
                    string   misSpelled     = parts[0];
                    string   correctSpelled = parts[1];
                    if (parts.Length > 2)
                    {
                        correctSpelled += " " + parts[2];
                    }

                    bool found = false;

                    if (_SpellChecker.SpellCheck(misSpelled))
                    {
                        totalChecked++;
                        _SpellChecker.Suggest();
                        int position = 0;
                        foreach (string suggestion in _SpellChecker.Suggestions)
                        {
                            position++;
                            if (suggestion.ToLower() == correctSpelled.ToLower())
                            {
                                Console.WriteLine("{0}\t{1}\t{2}\t{3}",
                                                  misSpelled, correctSpelled, position.ToString(), _SpellChecker.Suggestions.Count.ToString());
                                found = true;

                                totalFound++;

                                if (position == 1)
                                {
                                    totalFirst++;
                                }
                                else if (position <= 5)
                                {
                                    totalTopFive++;
                                }
                                else if (position <= 10)
                                {
                                    totalTopTen++;
                                }
                                else if (position <= 25)
                                {
                                    totalTopTwentyFive++;
                                }

                                break;
                            }
                        }

                        if (!found)
                        {
                            if (_SpellChecker.Suggestions.Count > 0)
                            {
                                Console.WriteLine("{0}\t{1}\t{2}\t{3}",
                                                  misSpelled, correctSpelled, "0", _SpellChecker.Suggestions.Count.ToString());
                            }
                            else
                            {
                                Console.WriteLine("{0}\t{1}\t{2}\t{3}",
                                                  misSpelled, correctSpelled, "-1", "-1");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0}\t{1}\t{2}\t{3}",
                                          misSpelled, correctSpelled, "1", "1");
                    }
                }
            }


            totalTopFive       += totalFirst;
            totalTopTen        += totalTopFive;
            totalTopTwentyFive += totalTopTen;

            Console.WriteLine("Total Tested\t{0}", totalChecked);
            Console.WriteLine("Total Found\t{0}\t{1}%", totalFound, ((float)totalFound / (float)totalChecked * 100f));
            Console.WriteLine("First Suggestions\t{0}\t{1}%", totalFirst, ((float)totalFirst / (float)totalChecked * 100f));
            Console.WriteLine("Top 5 Suggestions\t{0}\t{1}%", totalTopFive, ((float)totalTopFive / (float)totalChecked * 100f));
            Console.WriteLine("Top 10 Suggestions\t{0}\t{1}%", totalTopTen, ((float)totalTopTen / (float)totalChecked * 100f));
            Console.WriteLine("Top 25 Suggestions\t{0}\t{1}%", totalTopTwentyFive, ((float)totalTopTwentyFive / (float)totalChecked * 100f));

            sr.Close();
            fs.Close();
        }
예제 #21
0
 public void SpellCheck()
 {
     _loggingController.Log(MessageType.information, " load spell check");
     SpellChecker.Text = GetSelectedTextControl().Text;
     SpellChecker.SpellCheck();
 }