public bool Match(SyllableMask pattern) { bool match = true; if (pattern.StartsWith.Length > 0) { match = match && Translit.StartsWith(pattern.StartsWith); } if (pattern.EndsWith.Length > 0) { match = match && Translit.EndsWith(pattern.EndsWith); } return(match && ((Onset & pattern.AllowedOnsets) == Onset) && ((Coda & pattern.AllowedCodas) == Coda) && (Nucleus != null) && (Nucleus.IsVowelIn(pattern.AllowedVowels))); }
static List <SyllablePattern> LoadStressHeuristicsFromXml(string Filename) { List <SyllablePattern> StressHeuristics = new List <SyllablePattern>(); // Log.Analyzer.WriteLine("Loading stress heuristics from XML...."); FileStream fs = File.Open(Filename, FileMode.Open); // XmlReaderSettings xrs=new XmlReaderSettings(); XmlTextReader r = new XmlTextReader(fs); r.ReadStartElement("StressHeuristics"); while (r.ReadToFollowing("Pattern")) { SyllablePattern p; string result = r.GetAttribute("Result"), comment = r.GetAttribute("Description"), anchor = r.GetAttribute("Anchor"); if (result == null) { result = "Milra"; } if (anchor == null) { anchor = "End"; } p = new SyllablePattern((Word.Stress)Enum.Parse(typeof(Word.Stress), result), (SyllablePatternAnchor)EnumParseFlags(typeof(SyllablePatternAnchor), anchor)); if (comment != null) { p.Comment = comment; } // Log.Analyzer.WriteLine("--> Begin pattern"); if (r.ReadToDescendant("Syllable")) { do { string nucleus = r.GetAttribute("Nucleus"), coda = r.GetAttribute("Coda"), onset = r.GetAttribute("Onset"), start = r.GetAttribute("Start"), end = r.GetAttribute("End"), disposition = r.GetAttribute("Disposition"); if (nucleus == null) { nucleus = "Any"; } if (coda == null) { coda = "Any"; } if (onset == null) { onset = "Any"; } if (start == null) { start = ""; } if (end == null) { end = ""; } if (disposition == null) { disposition = "Required"; } SyllableMask m = new SyllableMask((Vowels)EnumParseFlags(typeof(Vowels), nucleus), (SyllableCoda)EnumParseFlags(typeof(SyllableCoda), coda), (SyllableOnset)EnumParseFlags(typeof(SyllableOnset), onset), (SyllableDisposition)EnumParseFlags(typeof(SyllableDisposition), disposition) ); m.StartsWith = start; m.EndsWith = end; p.Syllables.Add(m); // Log.Analyzer.WriteLine("Added mask "+m.ToString()); // r.ReadEndElement(); } while (r.ReadToNextSibling("Syllable")); } //r.ReadEndElement(); StressHeuristics.Add(p); //Log.Analyzer.WriteLine("Loaded pattern "+p.ToString()); } // r.ReadEndElement(); // Log.Analyzer.WriteLine(StressHeuristics.Count + " patterns loaded successfully."); r.Close(); fs.Close(); return(StressHeuristics); }