Exemple #1
0
            public string[] wrong_word;     //массив неверных слов

            public TestWord(string eng_word
                            , Word.WordType type
                            , string ru_word
                            , string[] str
                            )
            {
                this.eng_word   = eng_word;
                this.word_type  = type;
                this.rus_word   = ru_word;
                this.wrong_word = str;
            }
Exemple #2
0
        private static int ComputeWords(MySqlConnection conn)
        {
            int row      = 0;
            int rowCount = DatabaseManager.QuerySqlInt(conn, "SELECT COUNT(*) FROM wn_synset");
            int rowStep  = Math.Max(1, rowCount / 100); // 1%

            string word;
            string type;
            int    synSetId;
            int    wNum;

            List <Noun>      nounBuffer      = new List <Noun>();
            List <Verb>      verbBuffer      = new List <Verb>();
            List <Adjective> adjectiveBuffer = new List <Adjective>();

            List <long> ts = new List <long>
            {
                TimeUtils.Now()
            };

            while (row < rowCount)
            {
                nounBuffer.Clear();
                verbBuffer.Clear();
                adjectiveBuffer.Clear();
                DatabaseManager.QuerySql(conn, "SELECT * FROM wn_synset LIMIT @rowStep OFFSET @row", reader =>
                {
                    while (reader.Read())
                    {
                        row++;

                        word     = reader.GetString("word");
                        type     = reader.GetString("ss_type");
                        synSetId = reader.GetInt32("synset_id");
                        wNum     = reader.GetInt32("w_num");

                        Word.WordType wordType = Word.WordType.Undef;

                        if (word.Contains("_") || word == null)
                        {
                            continue;
                        }

                        word = word.Split("(")[0];
                        switch (type)
                        {
                        case "n":
                            wordType     = Word.WordType.Noun;
                            string word1 = word;
                            if (nounBuffer.All(w => w.Base != word1) && !DbContext.NounExists(word) &&
                                !DbContext.FemaleNounExists(word))
                            {
                                nounBuffer.AddIfNotNull(ComputeNewNoun(word));
                            }
                            break;

                        case "v":
                            wordType     = Word.WordType.Verb;
                            string word2 = word;
                            if (verbBuffer.All(w => w.Base != word2) && !DbContext.VerbExists(word))
                            {
                                verbBuffer.Add(ComputeNewVerb(word));
                            }
                            break;

                        case "a":
                        case "s":
                            wordType     = Word.WordType.Adjective;
                            string word3 = word;
                            if (adjectiveBuffer.All(w => w.Base != word3) && !DbContext.AdjectiveExists(word))
                            {
                                adjectiveBuffer.Add(ComputeNewAdjective(word));
                            }
                            break;

                        case "r":
                            wordType = Word.WordType.Adverb;
                            break;

                        default:
                            continue;
                        }

                        DbContext.Add(new Word(word, (int)wordType, GetSynSetId(synSetId), wNum));
                    }
                }, ("@rowstep", rowStep), ("@row", row));
                DbContext.AddRange(nounBuffer);
                DbContext.AddRange(verbBuffer);
                DbContext.AddRange(adjectiveBuffer);
                DbContext.SaveChanges();
                if (_verbose)
                {
                    Logger.Write("\r\tComputed {0}/{1} words ({2}%) (ETA {3})         ", row, rowCount,
                                 Math.Round(100 * row / (decimal)rowCount), TimeUtils.GetEta(ts, rowStep, rowCount));
                }
            }

            return(row);
        }