protected override void Consume(Queue <Segment> InQueue)
        {
            if (InQueue.Count == 0)
            {
                return;
            }
            Segment seg = InQueue.Dequeue();

            _ItemConsumed(seg);
            Segment nextSeg = null;

            if (InQueue.Count > 0)
            {
                nextSeg = InQueue.Peek();
            }
            if (seg is SeparatorSegment)
            {
                if (HebrewChar.IsPunctuation((seg[0] as Separator).Latin[0]))
                {
                    Phone phn = Phone.Create(seg[0]);
                    if (phn == null)
                    {
                        phn = new Phone("_", 1);
                    }
                    Emit(phn);
                }
                firstStressInClause = true;
            }
            else if (seg is Word)
            {
                /*bool nextIsPunctuation = false;
                 * if (nextSeg is SeparatorSegment)
                 *  nextIsPunctuation = HebrewChar.IsPunctuation(nextSeg[0].Latin[0]);*/

                Word w = (Word)seg;

                bool          beforeStress     = true;
                SpeechElement HintStrongDagesh = null;
                for (int sylIndex = 0; sylIndex < w.Syllables.Count; sylIndex++)
                {
                    Syllable syl = w.Syllables[sylIndex];

                    bool stressed = syl.IsStressed;
                    if (beforeStress && stressed)
                    {
                        beforeStress = false;
                    }
                    bool beforeNucleus = true;

                    //bool heavySyl = ((syl.Coda == SyllableCoda.Closed) ^ ((syl.Nucleus!=null) && syl.Nucleus.IsVowelIn(Vowels.Long)));
                    //					bool sylStart=true;
                    //foreach (SpeechElement e in	w.Phonemes.GetRange(syl.Start,syl.End-syl.Start+1)) {
                    for (int elemIndex = 0; elemIndex < syl.Phonemes.Count; elemIndex++)
                    {
                        SpeechElement e     = syl.Phonemes[elemIndex];
                        Phone         phone = null;
//                        bool sylEnd = (elemIndex == syl.Phonemes.Count - 1);
                        if ((e is Consonant) && ((((Consonant)e).Flags & ConsonantFlags.StrongDagesh) != 0) && (e == HintStrongDagesh))
                        {
                            continue;
                        }

                        phone = Phone.Create(e);
                        if (phone == null)
                        {
                            continue;
                        }
                        phone.Context.SylIndex        = sylIndex;
                        phone.Context.SylReverseIndex = w.Syllables.Count - sylIndex - 1;
                        phone.Context.IsNucleus       = (syl.Nucleus == e);
                        phone.Context.IsAccented      = stressed;
                        if (nextSeg is SeparatorSegment)
                        {
                            phone.Context.NextSeparator = (nextSeg as SeparatorSegment)[0].Latin;
                        }
                        if (!stressed)
                        {
                            if (Options.Akanye)
                            {
                                if (phone.Symbol == "o")
                                {
                                    phone.Symbol = "a";
                                }
                            }
                            if (Options.Ikanye)
                            {
                                if (phone.Symbol == "e")
                                {
                                    phone.Symbol = "i";
                                }
                            }
                        }
                        else
                        {
                            phone.Context.AccentStrength = 1;
                        }
                        if (phone.PitchCurve.Count > 0)
                        {
                            phone.PitchCurve.Clear();
                        }

                        phone.Duration = 80;
                        if (e is Vowel)
                        {
                            Vowel v = (Vowel)e;
                            if (v.IsVowelIn(Vowels.VeryShort))
                            {
                                if (v.vowel == Vowels.AudibleSchwa)
                                {
                                    phone.Duration = 28;
                                }
                                else
                                {
                                    phone.Duration = 40;
                                }
                            }
                            else if (v.IsVowelIn(Vowels.Short))
                            {
                                phone.Duration = 90;
                            }
                            else if (v.IsVowelIn(Vowels.Long))
                            {
                                phone.Duration = 94;
                            }
                            else if (v.IsVowelIn(Vowels.VeryLong))
                            {
                                phone.Duration = 97;
                            }
                            if (v.IsVowelIn(Vowels.HighVowels))
                            {
                                phone.Duration += 25;
                            }
                            else
                            {
                                phone.Duration += 30;
                            }
                        }
                        else if (e is Consonant)
                        {
                            phone.Duration = (((Consonant)e).Sonority) * 1.6 + 60;
                        }
                        else
                        {
                            phone.Duration = 100;
                        }

                        if (stressed)
                        {
                            if (firstStressInClause)
                            {
                                firstStressInClause = false;
                            }
                            if (e == syl.Nucleus)
                            {
                                beforeNucleus = false;
                            }
                            phone.Duration *= 1;
                            if (beforeNucleus && (e is Consonant) && ((Consonant)e).IsLiquid)
                            {
                                phone.Duration *= 1.2;
                            }
                        }
                        else
                        {
                            if (e is Vowel)
                            {
                                if (beforeStress)
                                {
                                    phone.Duration *= 0.85;
                                }
                                else
                                {
                                    phone.Duration *= 0.9;
                                }
                            }
                        }
                        if ((e is Consonant) && ((((Consonant)e).Flags & ConsonantFlags.StrongDagesh) != 0))
                        {
                            HintStrongDagesh = e;
                            if (Options.DistinguishStrongDagesh)
                            {
                                phone.Duration *= 1.4;
                            }
                            else
                            {
                                phone.Duration *= 1.1F;
                            }
                        }

                        /* if ((!nextIsPunctuation) && !heavySyl)
                         *   phone.Duration *= 0.7;*/

                        //                        if ((nextSeg is SeparatorSegment) && (sylIndex == w.Syllables.Count - 1))
                        //                            phone.Duration *= 1.6;
                        Emit(phone);



                        //						sylStart=false;
                    }
                }

                /*					if (w.CantillationMarks.Contains('֑'))
                 *      silpr.Phones.Add(new Phone("_",200));*/
                #region cantillation stuff
                if (Options.SingCantillation)
                {
                    foreach (char ch in w.CantillationMarks)
                    {
                        int i = HebrewChar.DisjunctiveRank(ch), len = 0;

                        if (i < 5)
                        {
                            switch (i)
                            {
                            case 1:
                                len = 230;
                                break;

                            case 2:
                                len = 165;
                                break;

                            case 3:
                                len = 60;
                                break;

                            case 4:
                                len = 30;
                                break;
                            }
                            Emit(new Phone("_", len));
                        }
                    }
                }
                #endregion
            }
        }
        protected override void Consume(Queue <SpeechElement> InQueue)
        {
            SpeechElement curElement = InQueue.Dequeue();

            _ItemConsumed(curElement);
            Console.WriteLine("segmenter: Current element is a {0} ({1})", curElement.GetType(), curElement.Latin);
            SpeechElement nextElement = null;

            if (InQueue.Count > 0)
            {
                nextElement = InQueue.Peek();
            }
            if (curSegment == null)
            {
                if ((curElement is Phoneme) || (curElement is WordTag))
                {
                    curSegment = new Word();
                }
                else
                {
                    curSegment = new SeparatorSegment();
                }
                curElementIndex = -1;
            }
            if (curSegment is Word)
            {
                curWord = (curSegment as Word);
                if (curElement is Phoneme)
                {
                    curWord.Add(curElement);
                    curElementIndex++;
                    if (curSyl == null)
                    {
                        curSyl       = new Syllable(curWord);
                        curSyl.Start = curElementIndex;
                        curSyl.End   = curElementIndex;
                    }
                    else if (curSyl.Nucleus == null)
                    {
                        curSyl.End++;
                        if ((curElement is Vowel) &&
                            (curElement as Vowel).IsVowelIn(Vowels.LegalNuclei))
                        {
                            curSyl.Nucleus = curElement as Vowel;
                        }
                    }
                    else if (curElement is Consonant)
                    {
                        if ((nextElement != null) && (nextElement is Vowel) && (nextElement as Vowel).IsVowelIn(Vowels.Inaudible))
                        {
                            curSyl.End++;
                            nextElement = InQueue.Dequeue();
                            Console.WriteLine("segmenter: About to chomp a {0} ({1})", nextElement.GetType(), nextElement.Latin);
                        }
                        else if ((nextElement == null) || (nextElement is Separator))
                        {
                            curSyl.End++;
//							curWord.Syllables.Add(curSyl);
//							curSyl=null;
                        }
                        else
                        {
                            if (((curElement as Consonant).Flags & ConsonantFlags.StrongDagesh) != 0)
                            {
                                curSyl.End++;
                                curSyl.HintStrongDagesh = true;
                            }
                            curWord.Syllables.Add(curSyl);
                            curSyl       = new Syllable(curWord);
                            curSyl.Start = curElementIndex;
                            curSyl.End   = curElementIndex;
                        }
                    }
                    else
                    {
                        // non-nucleic vowel, move on
                        curSyl.End++;
                    }
                }
                else if (curElement is WordTag)
                {
                    curWord.Tag = (curElement as WordTag).Tag;
                }
                else if (curElement is Qaryan.Core.Cantillation)
                {
                    curWord.CantillationMarks.Add((curElement as Cantillation).Mark);
                }
                else if (curElement is Separator)
                {
                    AddAndProcessWord(curSegment as Word);
                    curSegment = null;
                }
            }
            if (curElement is Separator)
            {
                if (curSegment != null)
                {
                    if (curSegment is SeparatorSegment)
                    {
                        curSegment.Add(curElement);
                    }
                    else
                    {
                        if (curSegment is Word)
                        {
                            AddAndProcessWord(curSegment as Word);
                        }
                        else
                        {
                            Emit(curSegment);
                        }
                        curSegment = new SeparatorSegment(curElement as Separator);
                    }
                    Emit(curSegment);
                    Console.WriteLine("segmenter: Added separator segment");
                    curSegment = null;
                }
                else
                {
                    Emit(curSegment = new SeparatorSegment(curElement as Separator));
                    Console.WriteLine("segmenter: Added separator segment");
                    curSegment = null;
                }
            }
        }
예제 #3
0
 public Syllable(Word parent)
 {
     Parent = parent;
 }
        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);
        }