예제 #1
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 == "و"))
                        )
                    {
                        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
                }
            }
        }
예제 #2
0
        public void ApplyWordStopmarks(string original_text)
        {
            int word_number = 0;

            string[] word_texts = original_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 == "و"))
                        )
                    {
                        continue; // skip stopmarks/quranmarks
                    }
                    else // proper word
                    {
                        Stopmark word_stopmark = Stopmark.None;
                        word_number++;

                        // 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)
                            {
                                word_stopmark = this.stopmark;
                            }
                        }

                        // apply word stopmark
                        int word_index = word_number - 1;
                        if ((word_index >= 0) && (word_index < this.words.Count))
                        {
                            this.words[word_number - 1].Stopmark = word_stopmark;
                        }
                    }
                }
            }
        }