Example #1
0
 /// <summary>
 /// 直接从数据库删除(测试)
 /// <para>从生词本删除单词(软删除)</para>
 /// </summary>
 /// <param name="word"></param>
 public static void Delete(Word word)
 {
     if (!string.IsNullOrEmpty(word.WordContent))
     {
         WordDAL.Delete(word);
     }
 }
Example #2
0
        public static void Update(Word word)
        {
            string str = word.WordContent.Substring(0, 1);

            SqlHelper.ExecuteNonQuery("Update " + GetTableName(word.WordContent) + " set IsPrefer=@isp where WordContent=@word",
                new SqlParameter("isp", word.IsPrefer),
                new SqlParameter("word", word.WordContent)
                );
        }
Example #3
0
        public static void Insert(Word word)
        {
            string str = word.WordContent.Substring(0, 1);

            SqlHelper.ExecuteNonQuery("insert into " + GetTableName(word.WordContent) + "(WordContent,Phonetic,Meaning,IsPrefer) values(@word,@ph,@mea,@isp)",
                new SqlParameter("word", word.WordContent),
                new SqlParameter("ph", word.Phonetic),
                new SqlParameter("mea", word.Meaning),
                new SqlParameter("isp", word.IsPrefer));
        }
Example #4
0
 /// <summary>
 /// 从数据库查询单词
 /// <para>
 /// 1、从生词本查询
 /// 2、从数据库查询
 /// 3、联机查询并将查询结果添加到数据库
 /// </para>
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static Word Query(string str)
 {
     DataTable table = SqlHelper.ExecuteDataTable("select * from " + GetTableName(str) + " where WordContent=@wordContent", new SqlParameter("wordContent", str));
     Word word = new Word();
     if (table.Rows.Count > 0)
     {
         DataRow row = table.Rows[0];
         word.Phonetic = (string)row["Phonetic"];
         word.WordContent = (string)row["WordContent"];
         word.Meaning = (string)row["Meaning"];
         word.IsPrefer = (bool)row["IsPrefer"];
         //word.IsInDatabase = (bool)row["IsInDatabase"];
     }
     return word;
 }
Example #5
0
 /// <summary>
 /// 添加到数据库
 /// </summary>
 /// <param name="word"></param>
 public static void Add(Word word)
 {
     if (!string.IsNullOrEmpty(word.WordContent))
     {
         if (word.IsInDatabase == false)
         {
             WordDAL.Insert(word);
         }
     }
     //if (WordDAL.Query(word.WordContent) == null)
     //{
     //    WordDAL.Insert(word);
     //}
     //else
     //{
     //    WordDAL.Update(word);
     //}
 }
Example #6
0
        private static Word Query(string str)
        {
            Word word = new Word();
            if (str == "")
            {
                return word;
            }

            str = str.Trim().ToLower();
            //开头不允许输入汉字
#if beta
            //if ((int)str[0] > 127)
            //{
            //    return word;
            //}
#endif
            //带有汉字的词不从数据库中查询
            if (!Character.IsChinese(str))
            {
                word = WordDAL.Query(str);
                if (word.Meaning == "")
                {
                    word = WebBLL.QueryOnline(str);
                }
            }
            else
            {
                word = WebBLL.QueryOnline(str);
            }

#if beta
            //将查询结果添加到数据库中
            if (Character.IsChinese(str) == false)
            {
                Add(word);
            }
#endif
            return word;
        }
Example #7
0
        /// <summary>
        /// 添加到生词本,同时添加到数据库
        /// </summary>
        /// <param name="word"></param>
        public static void AddInNewWrodBook(Word word)
        {

        }
Example #8
0
 public WordPart(Word word, int number_in_word, string buckwalter, string tag)
 {
     this.word = word;
     this.word.Parts.Add(this);
     this.number_in_word = number_in_word;
     this.buckwalter = buckwalter;
     this.text = buckwalter.ToArabic();
     this.tag = tag;
     this.grammar = null;
 }
Example #9
0
 public WordPart(Word word, int number_in_word, string buckwalter, string tag, WordPartGrammar grammar)
     : this(word, number_in_word, buckwalter, tag)
 {
     this.grammar = new WordPartGrammar(grammar);
 }
Example #10
0
        /// <summary>
        /// 在线查询
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static Model.Word QueryOnline(string str)
        {
            Model.Word word = new Model.Word();
            if (IsOnline())
            {
                Searchengine.Word resultWord = new Searchengine.Word();
                if (Character.IsChinese(str))
                {
                    if (Character.IsMixture(str))
                    {
                        resultWord = MixtureSearch.QueryOnline(str);
                    }
                    else
                    {
                        resultWord = WebSearchCN.QueryOnline(str);
                    }
                }
                else
                {
                    resultWord = WebSearchEN.QueryOnline(str);
                }
                word.WordContent = resultWord.WordContent;
                word.Phonetic = resultWord.Phonetic;
                word.Meaning = resultWord.Meaning;
            }

            return word;
        }
Example #11
0
 // get related words and verses
 public List<Word> GetRelatedWords(Word word, bool with_diacritics)
 {
     List<Word> result = new List<Word>();
     if (word != null)
     {
         Dictionary<string, List<Word>> root_words_dictionary = this.RootWords;
         if (root_words_dictionary != null)
         {
             // try all roots in case word_text is a root
             if (root_words_dictionary.ContainsKey(word.Text))
             {
                 List<Word> root_words = root_words_dictionary[word.Text];
                 foreach (Word root_word in root_words)
                 {
                     Verse verse = this.Verses[root_word.Verse.Number - 1];
                     Word verse_word = verse.Words[root_word.NumberInVerse - 1];
                     if (!result.Contains(verse_word))
                     {
                         result.Add(verse_word);
                     }
                 }
             }
             else // if no such root, search for the matching root_word by its verse position and get its root and then get all root_words
             {
                 string root = GetBestRoot(word.Text, with_diacritics);
                 if (!String.IsNullOrEmpty(root))
                 {
                     List<Word> root_words = root_words_dictionary[root];
                     foreach (Word root_word in root_words)
                     {
                         Verse verse = this.Verses[root_word.Verse.Number - 1];
                         Word verse_word = verse.Words[root_word.NumberInVerse - 1];
                         if (!result.Contains(verse_word))
                         {
                             result.Add(verse_word);
                         }
                     }
                 }
             }
         }
     }
     return result;
 }
Example #12
0
 public static void Delete(Word word)
 {
     SqlHelper.ExecuteNonQuery("delete from " + GetTableName(word.WordContent) + " where WordContent=@wordContent",
         new SqlParameter("wordContent", word.WordContent));
 }
Example #13
0
        public void RecreateWordsApplyStopmarks(string waw_text)
        {
            this.text = waw_text;

            this.words = new List <Word>();

            int word_number   = 0;
            int word_position = 0;

            string[] word_texts = waw_text.Split();
            for (int i = 0; i < word_texts.Length; i++)
            {
                string word_text = word_texts[i];
                if (word_text.Length > 0)
                {
                    // build new Words
                    if ((word_text.Length == 1)
                        &&
                        ((word_text[0] == '۩') || (word_text[0] == '⌂'))
                        )
                    {
                        // add stopmark to previous word to stop it interfering with next verse or with chapters 8, 54, 97 as previous ones end with sijood
                        if (((i - 1) >= 0) && ((i - 1) < this.words.Count))
                        {
                            if (this.words[i - 1].Stopmark == Stopmark.None)
                            {
                                this.words[i - 1].Stopmark = Stopmark.MustStop;
                            }
                        }
                    }
                    else if (
                        (word_text.Length == 1)
                        &&
                        !((word_text == "_") || (word_text == "ص") || (word_text == "ق") || (word_text == "ٯ") || (word_text == "ن") || (word_text == "ں") || (word_text == "و"))
                        ) // SimplifiedDots.txt
                    {
                        if ((Constants.STOPMARKS.Contains(word_text[0])) || (Constants.QURANMARKS.Contains(word_text[0])))
                        {
                            // increment word position by stopmarks length in original text
                            word_position += 2; // 2 for stopmark and space after it
                        }
                        continue;               // skip stopmarks/quranmarks
                    }
                    else // proper word
                    {
                        word_number++;
                        Stopmark word_stopmark = Stopmark.None;

                        // lookahead to determine word stopmark
                        // if not last word in verse
                        if (i < word_texts.Length - 1)
                        {
                            word_stopmark = StopmarkHelper.GetStopmark(word_texts[i + 1]);

                            // Quran 36:52 has another stopmark after MustPause, so use that instead
                            if (word_stopmark != Stopmark.None)
                            {
                                if (word_texts.Length > (i + 2))
                                {
                                    Stopmark next_word_stopmark = StopmarkHelper.GetStopmark(word_texts[i + 2]);
                                    if (next_word_stopmark != Stopmark.None)
                                    {
                                        word_stopmark = next_word_stopmark;
                                    }
                                }
                            }

                            // add stopmark.CanStop after بسم الله الرحمن الرحيم except 1:1 and 27:30
                            if (word_number == 4)
                            {
                                if ((word_text.Simplify29() == "الرحيم") || (word_text.Simplify29() == "الررحيم"))
                                {
                                    word_stopmark = Stopmark.CanStop;
                                }
                            }
                        }
                        else // last word in verse
                        {
                            // if no stopmark after word
                            if (word_stopmark == Stopmark.None)
                            {
                                // use verse stopmark
                                word_stopmark = this.stopmark;
                            }
                        }

                        Word word = new Word(this, word_number, word_position, word_text);
                        if (word != null)
                        {
                            word.Stopmark = word_stopmark;
                            this.words.Add(word);
                        }
                    }

                    // in all cases
                    word_position += word_text.Length + 1; // 1 for space
                }
            }
        }
Example #14
0
 public Letter(Word word, char character, int number_in_word)
 {
     this.word = word;
     this.character = character;
     this.number_in_word = number_in_word;
 }
Example #15
0
        /// <summary>
        /// build verse words with appropriate stopmarks regardless of text_mode
        /// </summary>
        /// <param name="text_mode"></param>
        /// <param name="original_text"></param>
        public void BuildWords(string text_mode, string original_text)
        {
            if (String.IsNullOrEmpty(text_mode)) return;
            if (String.IsNullOrEmpty(original_text)) return;
            original_text = original_text.Trim();

            this.words = new List<Word>();
            Stopmark word_stopmark;

            int word_number_in_verse = 0;
            int word_position_in_verse = 0;

            string[] original_word_texts = original_text.Split();
            for (int i = 0; i < original_word_texts.Length; i++)
            {
                word_number_in_verse++;
                word_stopmark = Stopmark.None;

                string original_word_text = original_word_texts[i];
                string word_text = original_word_text;
                if (text_mode.Contains("Simplified"))
                {
                    word_text = original_word_text.SimplifyTo(text_mode);
                }

                // skip stopmarks/quranmarks
                if (
                     (original_word_text.Length == 1)
                     &&
                     !((original_word_text == "ص") || (original_word_text == "ق") || (original_word_text == "ن") || (original_word_text == "و"))
                   )
                {
                    if (text_mode.Contains("Original"))
                    {
                        if (Constants.STOPMARKS.Contains(original_word_text[0]))
                        {
                            // advance position if original and stopmark
                            word_position_in_verse += 2; // 2 for stopmark and space after it
                        }
                        else
                        {
                            // ignore quranmarks
                        }
                    }
                    continue;
                }
                else
                { // lookahead to determine word stopmark

                    // if not last word in verse
                    if (i < original_word_texts.Length - 1)
                    {
                        string next_original_word_text = original_word_texts[i + 1];
                        switch (next_original_word_text)
                        {
                            case "":  // next word is never empty (never comes here)
                                word_stopmark = Stopmark.None;
                                break;
                            case "ۙ": // Laaa
                                word_stopmark = Stopmark.MustContinue;
                                break;
                            case "ۖ": // Sala
                                word_stopmark = Stopmark.ShouldContinue;
                                break;
                            case "ۚ": // Jeem
                                word_stopmark = Stopmark.CanStop;
                                break;
                            case "ۛ": // Dots
                                word_stopmark = Stopmark.CanStopAtOneOnly;
                                break;
                            case "ۗ": // Qala
                                word_stopmark = Stopmark.ShouldStop;
                                break;
                            case "ۜ": // Seen
                                word_stopmark = Stopmark.MustPause;
                                break;
                            case "ۘ": // Meem
                                word_stopmark = Stopmark.MustStop;
                                break;
                            default: // Quran word
                                word_stopmark = Stopmark.None;
                                break;
                        }

                        // add stopmark.CanStop after بسم الله الرحمن الرحيم except 1:1 and 27:30
                        if (word_number_in_verse == 4)
                        {
                            if (word_text.Simplify29() == "الرحيم")
                            {
                                word_stopmark = Stopmark.CanStop;
                            }
                        }
                    }
                    else // last word in verse
                    {
                        // if no stopmark after word
                        if (word_stopmark == Stopmark.None)
                        {
                            // use verse stopmark
                            word_stopmark = this.Stopmark;
                        }
                    }

                    Word word = new Word(this, word_number_in_verse, word_position_in_verse, word_text, word_stopmark);
                    this.words.Add(word);
                }

                // in all cases
                word_position_in_verse += word_text.Length + 1; // 1 for space
            }
        }