コード例 #1
0
        /// <summary>
        /// Performs stress assignment and related processing on a word, and adds it to the queue of produced segments.
        /// </summary>
        /// <param name="w">The word obtained from the segmentation step.</param>
        void AddAndProcessWord(Word w)
        {
            if ((curSyl != null) && !w.Syllables.Contains(curSyl))
            {
                w.Syllables.Add(curSyl);
                curSyl = null;
            }
            SyllablePattern?sp = w.PlaceStress(StressHeuristics, DefaultStress);
//            Log(LogLevel.Debug, sp);
            bool beforeStress = true;

            foreach (Syllable syl in w.Syllables)
            {
                bool stressed = syl.IsStressed;
                if (stressed)
                {
                    beforeStress = false;
                }
                for (int i = 0; i < syl.Phonemes.Count; i++)
                {
                    SpeechElement e = syl.Phonemes[i];
                    if (e is Vowel)
                    {
                        Vowel v = (Vowel)e;
                        if (v.vowel == Vowels.KamatzIndeterminate)
                        {
                            if (beforeStress && (syl.Coda == SyllableCoda.Closed) && (syl.Phonemes[syl.Phonemes.Count - 1] is Consonant) /*&& ((w.Tag&TagTypes.Origin)!=TagTypes.Foreign)*/ && !stressed)
                            {
                                v.vowel = Vowels.KamatzKatan;
                            }
                            else
                            {
                                v.vowel = Vowels.KamatzGadol;
                            }
                        }
                        else if (v.vowel == Vowels.AudibleSchwa)
                        {
                            if ((w.Tag & TagTypes.Origin) == TagTypes.Foreign)
                            {
                                v.vowel = Vowels.SilentSchwa;
                            }
                            else
                            {
                                int j = w.Phonemes.IndexOf(e);
                                if ((j + 1 < w.Phonemes.Count) &&
                                    (w.Phonemes[j + 1] is Consonant) &&
                                    (j - 1 >= 0) &&
                                    (w.Phonemes[j - 1] is Consonant) &&
                                    (w.Phonemes[j + 1].Latin != w.Phonemes[j - 1].Latin))
                                {
                                    switch (w.Phonemes[j - 1].Latin)
                                    {
                                    /*											case "k":
                                     * case "l":
                                     * case "b":
                                     * case "m":
                                     *  break;*/
                                    case Consonants.Vav:
                                    case Consonants.Lamed:
                                        break;

                                    default:
                                        if (!relaxAudibleSchwa)
                                        {
                                            break;
                                        }
                                        int son = ((Consonant)w.Phonemes[j + 1]).Sonority -
                                                  ((Consonant)w.Phonemes[j - 1]).Sonority;
                                        if (son >= 0)
                                        {
                                            v.Silent = true;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (sp != null)
            {
                Log(LogLevel.Info, "/{0}/ from pattern {1}", w.TranslitSyllablesStress, sp.ToString());
            }
            else
            {
                Log(LogLevel.Info, "/{0}/", w.TranslitSyllablesStress);
            }
            Emit(w);
        }
コード例 #2
0
        void AddAndProcessWord(Word w)
        {
            if ((curSyl != null) && !w.Syllables.Contains(curSyl))
            {
                w.Syllables.Add(curSyl);
                curSyl = null;
            }
            Console.WriteLine("segmenter: /{0}/", w.TranslitSyllables);
            w.PlaceStress(StressHeuristics, DefaultStress);
            foreach (Syllable syl in w.Syllables)
            {
                bool stressed = syl.IsStressed;
                for (int i = 0; i < syl.Phonemes.Count; i++)
                {
                    SpeechElement e = syl.Phonemes[i];
                    if (e is Vowel)
                    {
                        Vowel v = (Vowel)e;
                        if (v.vowel == Vowels.KamatzIndeterminate)
                        {
                            if ((syl.Coda == SyllableCoda.Closed) && (syl.Phonemes[syl.Phonemes.Count - 1] is Consonant) /*&& ((w.Tag&TagTypes.Origin)!=TagTypes.Foreign)*/ && !stressed)
                            {
                                v.vowel = Vowels.KamatzKatan;
                            }
                            else
                            {
                                v.vowel = Vowels.KamatzGadol;
                            }
//							Log.Analyzer.WriteLine("Kamatz determined to be "+v.vowel.ToString());
                        }
                        else if (v.vowel == Vowels.AudibleSchwa)
                        {
                            if ((w.Tag & TagTypes.Origin) == TagTypes.Foreign)
                            {
                                v.vowel = Vowels.SilentSchwa;
                            }
                            else
                            {
                                int j = w.Phonemes.IndexOf(e);
                                if ((j + 1 < w.Phonemes.Count) &&
                                    (w.Phonemes[j + 1] is Consonant) &&
                                    (j - 1 >= 0) &&
                                    (w.Phonemes[j - 1] is Consonant) &&
                                    (w.Phonemes[j + 1].Latin != w.Phonemes[j - 1].Latin))
                                {
                                    switch (w.Phonemes[j - 1].Latin)
                                    {
                                    /*											case "k":
                                     * case "l":
                                     * case "b":
                                     * case "m":
                                     *      break;*/
                                    case Consonants.Vav:
                                    case Consonants.Lamed:
                                        break;

                                    default:
                                        if (!relaxAudibleSchwa)
                                        {
                                            break;
                                        }
                                        int son = ((Consonant)w.Phonemes[j + 1]).Sonority -
                                                  ((Consonant)w.Phonemes[j - 1]).Sonority;
                                        if (son >= 0)
                                        {
                                            v.Silent = true;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Emit(w);
        }