public Syllable(Word parent, Vowel nucleus, int start, int end) { Parent = parent; Nucleus = nucleus; Start = start; End = end; }
void AddElement(SpeechElement eElement) { Log("Producing {0} {1}", eElement.GetType().Name, (eElement is Vowel) ? (eElement as Vowel).vowel.ToString() : eElement.Latin); this.Emit(eElement); prevElement = eElement; prevVowel = prevElement as Vowel; // prevConsonant = prevElement as Consonant; }
void AddElement(SpeechElement eElement) { Console.WriteLine("parser: Current element is a {0} ({1})", eElement.GetType(), (eElement is Vowel)?(eElement as Vowel).vowel.ToString():eElement.Latin); this.Emit(eElement); prevElement = eElement; prevVowel = prevElement as Vowel; prevConsonant = prevElement as Consonant; }
protected override void BeforeConsumption() { base.BeforeConsumption(); Log(LogLevel.MajorInfo, "Started"); t = null; newElement = null; lastTag = null; prev = null; isFirstWindow = true; isLastWindow = false; prevVowel = null; // prevConsonant = null; prevElement = null; }
protected override void BeforeConsumption() { base.BeforeConsumption(); Console.WriteLine("parser started"); t = null; newElement = null; lastTag = null; prev = null; isFirstWindow = true; isLastWindow = false; prevVowel = null; prevConsonant = null; prevElement = null; }
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 } }
/// <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); }
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); Console.WriteLine("phonetizer: {0}", phn); } firstStressInClause = true; } else if (seg is Word) { Word w = (Word)seg; bool beforeStress = true; SpeechElement HintStrongDagesh = null; foreach (Syllable syl in w.Syllables) { bool stressed = syl.IsStressed; if (beforeStress && stressed) { beforeStress = false; } bool beforeNucleus = true; // bool sylStart=true; foreach (SpeechElement e in w.Phonemes.GetRange(syl.Start, syl.End - syl.Start + 1)) { Phone phone = null; bool sylEnd = (syl.Phonemes.IndexOf(e) == 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.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)) { phone.Duration = 28; //38 } 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) * 2.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.5; } else { phone.Duration *= 0.6; } } } if ((e is Consonant) && ((((Consonant)e).Flags & ConsonantFlags.StrongDagesh) != 0)) { HintStrongDagesh = e; if (Options.DistinguishStrongDagesh) { phone.Duration *= 1.4; } else { phone.Duration *= 1.1F; } } Emit(phone); Console.WriteLine("phonetizer: {0}", 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; } Phone phone; Emit(phone = new Phone("_", len)); Console.WriteLine("phonetizer: {0}", phone); } } } #endregion } }
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); }