// Find the best matching SymbolText. Gender can be null or empty for don't care. Same with nounCase. If // nounCase is empty then the first noun case from the language is chosen if possible. static SymbolText FindBestText(SymbolDB symbolDB, List <SymbolText> texts, string language, bool plural, string gender, string nounCase) { int best = 99999; SymbolText bestSymText = null; if (gender == null) { gender = ""; } string defaultNounCase = ""; SymbolLanguage symbolLanguage = symbolDB.GetLanguage(language); if (symbolLanguage != null && symbolLanguage.CaseModifiers && symbolLanguage.Cases.Length > 0) { defaultNounCase = symbolLanguage.Cases[0]; } // Search for exact match. foreach (SymbolText symtext in texts) { int metric = 0; if (symtext.Lang != language && symtext.Lang != "en") { metric += 100; } if (symtext.Lang != language && symtext.Lang == "en") // english is most preferred if no language match { metric += 50; } if (symtext.Plural != plural) { metric += 10; } if (gender != "" && symtext.Gender != gender) { metric += 5; } if (nounCase != "" && symtext.Case != nounCase) { metric += 3; } if (nounCase == "" && symtext.Case != null && symtext.Case != defaultNounCase) { metric += 1; } if (metric < best) { best = metric; bestSymText = symtext; } } return(bestSymText); }
private void ReadSymbolFile(string filename) { int sortOrder = 1; using (XmlInput xmlinput = new XmlInput(filename)) { xmlinput.CheckElement("symbols"); bool first = true; while (xmlinput.FindSubElement(first, new string[] { "symbol", "language" })) { if (xmlinput.Name == "symbol") { Symbol symbol = new Symbol(this, sortOrder); ++sortOrder; symbol.ReadXml(xmlinput); if (symbols.ContainsKey(symbol.Id)) { symbols[symbol.Id].Add(symbol); } else { symbols[symbol.Id] = new List <Symbol>() { symbol }; } } else if (xmlinput.Name == "language") { SymbolLanguage language = new SymbolLanguage(); language.ReadXml(xmlinput); languages.Add(language.LangId, language); } first = false; } } }
public override bool Equals(object obj) { if (obj is SymbolLanguage) { SymbolLanguage other = (SymbolLanguage)obj; if (other.Name != Name) { return(false); } if (other.LangId != LangId) { return(false); } if (other.PluralNouns != PluralNouns) { return(false); } if (other.PluralModifiers != PluralModifiers) { return(false); } if (other.GenderModifiers != GenderModifiers) { return(false); } if (!Util.ArrayEquals(other.Genders, Genders)) { return(false); } return(true); } else { return(false); } }