public override bool Equals(object obj) { if (!(obj is SymbolText)) { return(false); } SymbolText other = obj as SymbolText; if (other.Text != Text) { return(false); } if (other.Lang != Lang) { return(false); } if (other.Plural != Plural) { return(false); } if (other.Gender != Gender) { return(false); } if (other.Case != Case) { return(false); } if (other.CaseOfModified != CaseOfModified) { return(false); } return(true); }
// 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); }
// Get the gender for a item from a list of symbol texts. public static string GetSymbolGender(SymbolDB symbolDB, List <SymbolText> texts, string language) { SymbolText best = FindBestText(symbolDB, texts, language, false, "", ""); if (best != null) { return(best.Gender); } else { return(null); } }
// Get the gender of this item. public string GetGender(string language) { SymbolText best = FindBestText(symbolDB, texts, language, false, null, ""); if (best != null) { return(best.Gender); } else { return(null); } }
/// <summary> /// Get the plural text for the symbol to use in text descriptions. If no plural text is defined, /// the singular text is used instead. /// </summary> /// <param name="language">The language to use.</param> /// <returns>The text string to use.</returns> public string GetPluralText(string language, string gender = null, string nounCase = "") { SymbolText best = FindBestText(symbolDB, texts, language, true, gender, nounCase); if (best != null) { return(best.Text); } else { return(null); } }
// Get the case of what this symbol modifies, or "" if none. public static string GetModifiedCase(SymbolDB symbolDB, List <SymbolText> texts, string language) { SymbolText best = FindBestText(symbolDB, texts, language, false, "", ""); if (best != null) { return(best.CaseOfModified); } else { return(null); } }
// Get the best symbol text for a language from a list of symbol texts. public static string GetBestSymbolText(SymbolDB symbolDB, List <SymbolText> texts, string language, bool plural, string gender, string nounCase) { SymbolText best = FindBestText(symbolDB, texts, language, plural, gender, nounCase); if (best != null) { return(best.Text); } else { return(null); } }
/// <summary> /// Read the state of this symbol from XML. The xmlinput must be on a /// symbol node. /// </summary> public void ReadXml(XmlInput xmlinput) { xmlinput.CheckElement("symbol"); this.kind = xmlinput.GetAttributeString("kind")[0]; this.id = xmlinput.GetAttributeString("id"); this.replacementId = xmlinput.GetAttributeString("replacement-id", null); this.id2018 = xmlinput.GetAttributeString("id-2018", null); this.sizeIsDepth = xmlinput.GetAttributeBool("size-is-depth", false); string standardStrings = xmlinput.GetAttributeString("standard", ""); if (standardStrings != "") { this.standards = standardStrings.Split(','); } bool first = true; List <SymbolStroke> strokes = new List <SymbolStroke>(); while (xmlinput.FindSubElement(first, new string[] { "name", "text", "filled-circle", "circle", "polygon", "filled-polygon", "lines", "beziers", "filled-beziers" })) { SymbolStroke stroke = new SymbolStroke(); bool isStroke = true; switch (xmlinput.Name) { case "name": xmlinput.CheckElement("name"); string language = xmlinput.GetAttributeString("lang"); name.Add(language, xmlinput.GetContentString()); isStroke = false; break; case "text": xmlinput.CheckElement("text"); SymbolText symtext = new SymbolText(); symtext.ReadXml(xmlinput); texts.Add(symtext); isStroke = false; break; case "filled-circle": xmlinput.CheckElement("filled-circle"); stroke.kind = SymbolStrokes.Disc; stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "circle": xmlinput.CheckElement("circle"); stroke.kind = SymbolStrokes.Circle; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "polygon": xmlinput.CheckElement("polygon"); stroke.kind = SymbolStrokes.Polygon; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "filled-polygon": xmlinput.CheckElement("filled-polygon"); stroke.kind = SymbolStrokes.FilledPolygon; break; case "lines": xmlinput.CheckElement("lines"); stroke.kind = SymbolStrokes.Polyline; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "beziers": xmlinput.CheckElement("beziers"); stroke.kind = SymbolStrokes.PolyBezier; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); break; case "filled-beziers": xmlinput.CheckElement("filled-beziers"); stroke.kind = SymbolStrokes.FilledPolyBezier; break; } if (isStroke) { stroke.points = ReadPoints(xmlinput); strokes.Add(stroke); } first = false; } if (this.name == null) { xmlinput.BadXml("Missing name element"); } if (texts.Count == 0) { xmlinput.BadXml("Missing text element"); } this.strokes = strokes.ToArray(); }