public InflectionState(string suffix, ConjugationsVariantJson form = null, string prevTense = null) { this.suffix = suffix; this.form = form; string tense = null; if (form != null && !string.IsNullOrEmpty(form.Tense) && form.Tense != "Remove" && form.Tense != "Stem") { tense = form.Tense; hasOwnTense = true; } else { hasOwnTense = false; } if (!string.IsNullOrEmpty(prevTense) && prevTense != "Remove" && prevTense != "Stem") { if (tense == null) { tense = prevTense; } else { tense = prevTense + " → " + tense; } } this.tense = tense; this.POS = new HashSet <string>(); }
internal void load() { try { conjugations = new Dictionary <string, ConjugationsJson>(); knownPOS = new HashSet <string>(); JavaScriptSerializer json = new JavaScriptSerializer(); string jsonRaw = File.ReadAllText(Settings.app.ConjugationsPath); IList data = (IList)json.DeserializeObject(jsonRaw); foreach (var it in data) { IDictionary conjJson = (IDictionary)it; List <ConjugationsVariantJson> tenses = new List <ConjugationsVariantJson>(); var jsonTenses = (IList)conjJson["Tenses"]; foreach (var form in jsonTenses) { IDictionary formJson = (IDictionary)form; var conjVar = new ConjugationsVariantJson { Formal = (bool)formJson["Formal"], Negative = (bool)formJson["Negative"], Suffix = (string)formJson["Suffix"], Tense = (string)formJson["Tense"], NextType = (string)formJson["Next Type"] ?? ((string)formJson["Tense"] == "Te-form" ? "te-form" : null), Ignore = formJson["Ignore"] != null }; //conjVar.Ignore = conjVar.Ignore || (conjVar.Tense == "Stem" && conjVar.Suffix == ""); tenses.Add(conjVar); } var conj = new ConjugationsJson { Name = (string)conjJson["Name"], PartOfSpeech = (string)conjJson["Part of Speech"], Tenses = tenses }; conj.addBaseFormSuffix(tenses[0].Suffix); ConjugationsJson old; if (conjugations.TryGetValue(conj.Name, out old)) { old.addTenses(conj.Tenses); old.addBaseFormSuffix(tenses[0].Suffix); } else { knownPOS.Add(conj.Name); conjugations.Add(conj.Name, conj); } } rebuildIndex(); } catch (Exception ex) { Logger.logException(ex); } }
public void addForm(ConjugationsVariantJson form, Dictionary<string, ConjugationsJson> conjugations) { var cur = this; if (!form.Ignore) { foreach (char c in form.Suffix) { cur = cur.get(c); } cur.forms.Add(form); } if (form.NextType != null) { string baseSuf = getStem(conjugations, form.Suffix, form.NextType); cur = this; foreach (char c in baseSuf) { cur = cur.get(c); } cur.linkForms.Add(form); } }
public InflectionState(string suffix, ConjugationsVariantJson form = null, string prevTense = null) { this.suffix = suffix; this.form = form; string tense = null; if (form != null && !string.IsNullOrEmpty(form.Tense) && form.Tense != "Remove" && form.Tense != "Stem") { tense = form.Tense; hasOwnTense = true; } else { hasOwnTense = false; } if (!string.IsNullOrEmpty(prevTense) && prevTense != "Remove" && prevTense != "Stem") { if (tense == null) { tense = prevTense; } else { tense = prevTense + " → " + tense; } } this.tense = tense; this.POS = new HashSet<string>(); }
public void addForm(ConjugationsVariantJson form, Dictionary <string, ConjugationsJson> conjugations) { var cur = this; if (!form.Ignore) { foreach (char c in form.Suffix) { cur = cur.get(c); } cur.forms.Add(form); } if (form.NextType != null) { string baseSuf = getStem(conjugations, form.Suffix, form.NextType); cur = this; foreach (char c in baseSuf) { cur = cur.get(c); } cur.linkForms.Add(form); } }
internal void load() { try { conjugations = new Dictionary<string, ConjugationsJson>(); knownPOS = new HashSet<string>(); JavaScriptSerializer json = new JavaScriptSerializer(); string jsonRaw = File.ReadAllText(Settings.app.ConjugationsPath); IList data = (IList)json.DeserializeObject(jsonRaw); foreach (var it in data) { IDictionary conjJson = (IDictionary)it; List<ConjugationsVariantJson> tenses = new List<ConjugationsVariantJson>(); var jsonTenses = (IList)conjJson["Tenses"]; foreach (var form in jsonTenses) { IDictionary formJson = (IDictionary)form; var conjVar = new ConjugationsVariantJson { Formal = (bool)formJson["Formal"], Negative = (bool)formJson["Negative"], Suffix = (string)formJson["Suffix"], Tense = (string)formJson["Tense"], NextType = (string)formJson["Next Type"] ?? ((string)formJson["Tense"] == "Te-form" ? "te-form" : null), Ignore = formJson["Ignore"] != null }; //conjVar.Ignore = conjVar.Ignore || (conjVar.Tense == "Stem" && conjVar.Suffix == ""); tenses.Add(conjVar); } var conj = new ConjugationsJson { Name = (string)conjJson["Name"], PartOfSpeech = (string)conjJson["Part of Speech"], Tenses = tenses }; conj.addBaseFormSuffix(tenses[0].Suffix); ConjugationsJson old; if (conjugations.TryGetValue(conj.Name, out old)) { old.addTenses(conj.Tenses); old.addBaseFormSuffix(tenses[0].Suffix); } else { knownPOS.Add(conj.Name); conjugations.Add(conj.Name, conj); } } rebuildIndex(); } catch (Exception ex) { Logger.logException(ex); } }