Example #1
0
        public DataSet ProcessWords(List <string> words)
        {
            originalWordList  = new string[words.Count];
            lowercaseWordList = new string[words.Count];

            words.CopyTo(originalWordList);
            words.CopyTo(lowercaseWordList);

            for (int i = 0; i < words.Count; i++)
            {
                lowercaseWordList[i] = lowercaseWordList[i].ToLower();
            }

            ds = new DataSet();
            DataTable dt = new DataTable("inputWords");

            dt.Columns.Add("class");
            dt.Columns.Add("wordNumber");
            dt.Columns.Add("word");
            dt.Columns.Add("pos");

            for (int i = 0; i < words.Count; i++)
            {
                string[] data = new string[4];

                Definition d = RitchardDataHelper.GetDefinitionCaseSensitive(originalWordList[i]);

                data[1] = string.Format("{0}", i + 1);
                data[2] = originalWordList[i];
                data[3] = "";

                if (d != null)
                {
                    data[0] = "";

                    foreach (var posDef in _db.PartsOfSpeeches.Where(ps => ps.DefinitionID == d.DefinitionID))
                    {
                        if (data[3].Length > 0)
                        {
                            data[3] += ", ";
                        }

                        data[3] += posDef.PartOfSpeechString;
                    }
                }
                else
                {
                    data[0] = "warning";
                    data[3] = "";
                }

                dt.Rows.Add(data);
            }

            ds.Tables.Add(dt);

            return(ds);
        }
Example #2
0
        public void GetPartsOfSpeech()
        {
            foreach (var entry in queue.GetDictionaryEntries())
            {
                if (!_db.PartsOfSpeeches.Any(pos => pos.DefinitionString == entry.Query))
                {
                    List <string> partsOfSpeech = entry.GetPartsOfSpeech();

                    if (partsOfSpeech.Count > 0)
                    {
                        Definition def = RitchardDataHelper.GetDefinitionCaseSensitive(entry.Query);

                        if (def == null)
                        {
                            def = new Definition(Guids.EnglishLanguage, entry.Query);
                            _db.Definitions.InsertOnSubmit(def);
                            _db.SubmitChanges();
                        }

                        foreach (string part in partsOfSpeech)
                        {
                            if (!Strings.PageMapDictionaryPartOfSpeechIgnoreList.Contains(part))
                            {
                                PartsOfSpeech pos = new PartsOfSpeech
                                {
                                    PartOfSpeechID     = Guid.NewGuid(),
                                    DefinitionID       = def.DefinitionID,
                                    DefinitionString   = def.String,
                                    PartOfSpeechDefID  = Guids.GuidDictionary[part],
                                    PartOfSpeechString = part
                                };

                                _db.PartsOfSpeeches.InsertOnSubmit(pos);
                            }
                        }

                        _db.SubmitChanges();
                    }
                }
            }
        }
Example #3
0
        public void ProcessInput(string input)
        {
            /*
             * Creates new queue.
             * Adds each new word to a list to be searched for, removing duplicates.
             */

            // Initialise queue to hold calls to dictionary, thesaurus and conjugator
            queue = new Queue();

            if (words == null)
            {
                words = GetWordsFromInput(input);
            }

            // Queue words we haven't seen before
            foreach (string word in words)
            {
                if (!string.IsNullOrEmpty(word))
                {
                    // Check whether the word is in the definitions table
                    Definition def = RitchardDataHelper.GetDefinitionCaseSensitive(word); // Full def needed for 'else'

                    if (def == null)
                    {
                        // If not, see if we have previously seen a misspelling of this word
                        CorrectedSpelling cs = _db.CorrectedSpellings.SingleOrDefault(crs => crs.OriginalSpelling == word);

                        Guid correctedDefGuid = Guid.Empty;
                        if (cs != null)
                        {
                            correctedDefGuid = cs.ResultingDefinition;
                        }

                        // If not...
                        if (correctedDefGuid == Guid.Empty)
                        {
                            // ...check whether search has already been requested for that word
                            if (!odWords.Contains(word))
                            {
                                // If not, queue it
                                odWords.Add(word, Strings.WordLookupReady);
                                queue.AddDictionaryEntry(word);
                            }
                        }
                    }
                    // If it IS in the definitions table, see if we have part of speech and verb info.
                    else
                    {
                        if (!_db.PartsOfSpeeches.Any(pos => pos.DefinitionID == def.DefinitionID))
                        {
                            // If not, queue it
                            odWords.Add(word, Strings.WordLookupReady);
                            queue.AddDictionaryEntry(word);
                        }
                    }
                }
            }

            ProcessQueue();
            CorrectSpellings();
            GetPartsOfSpeech();

            //ParseSentences();
        }