コード例 #1
0
        public void ShouldReturnCorrectResultText_WhenParametersIsOnlyLetters()
        {
            var service  = new FindWordsProcessor();
            var result   = service.Process("Lol");
            var expected = new WordsResult(new List <WordItem>
            {
                new WordItem(true, "Lol")
            });

            Assert.AreEqual(expected, result);
        }
コード例 #2
0
        public void ShouldReturnCorrectResultText_WhenParametersIsCommonCase()
        {
            var service  = new FindWordsProcessor();
            var result   = service.Process("I love.");
            var expected = new WordsResult(new List <WordItem>
            {
                new WordItem(true, "I"),
                new WordItem(false, " "),
                new WordItem(true, "love"),
                new WordItem(false, ".")
            });

            Assert.AreEqual(expected, result);
        }
コード例 #3
0
        void GetWords(int offset, int range, WordsResult result)
        {
            if (m_DBLock)
            {
                return;
            }
            if (result == null)
            {
                Debug.LogError("Called GetWords without a result callback");
                return;
            }
            m_DBLock = true;
            //Not sure what the current deal is with threads. Hopefully this is OK?
            new Thread(() =>
            {
                try
                {
                    DictionaryListItemData[] words = new DictionaryListItemData[range];
                    IDbCommand dbcmd   = m_DBConnection.CreateCommand();
                    string sqlQuery    = string.Format("SELECT lemma, definition FROM word as W JOIN sense as S on W.wordid=S.wordid JOIN synset as Y on S.synsetid=Y.synsetid ORDER BY W.wordid limit {0} OFFSET {1}", range, offset);
                    dbcmd.CommandText  = sqlQuery;
                    IDataReader reader = dbcmd.ExecuteReader();
                    int count          = 0;
                    while (reader.Read())
                    {
                        string lemma      = reader.GetString(0);
                        string definition = reader.GetString(1);
                        words[count]      = new DictionaryListItemData {
                            template = defaultTemplate
                        };

                        //truncate word if necessary
                        if (lemma.Length > maxWordCharacters)
                        {
                            lemma = lemma.Substring(0, maxWordCharacters - 3) + "...";
                        }
                        words[count].word = lemma;

                        //Wrap definition
                        string[] wrds = definition.Split(' ');
                        int charCount = 0;
                        int lineCount = 0;
                        foreach (var wrd in wrds)
                        {
                            charCount += wrd.Length + 1;
                            if (charCount > definitionCharacterWrap)
                            { //Guesstimate
                                if (++lineCount >= maxDefinitionLines)
                                {
                                    words[count].definition += "...";
                                    break;
                                }
                                words[count].definition += "\n";
                                charCount = 0;
                            }
                            words[count].definition += wrd + " ";
                        }
                        count++;
                    }
                    if (count < batchSize)
                    {
                        Debug.LogWarning("reached end");
                    }
                    reader.Close();
                    dbcmd.Dispose();
                    result(words);
                } catch (Exception e)
                {
                    Debug.LogError("Exception reading from DB: " + e.Message);
                }
                m_DBLock  = false;
                m_Loading = false;
            }).Start();
        }