コード例 #1
0
        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>();
        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
ファイル: InflectionTrie.cs プロジェクト: wareya/chiitrans
 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);
     }
 }
コード例 #4
0
ファイル: InflectionState.cs プロジェクト: wareya/chiitrans
 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 + " &rarr; " + tense;
         }
     }
     this.tense = tense;
     this.POS = new HashSet<string>();
 }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
ファイル: Inflector.cs プロジェクト: wareya/chiitrans
 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);
     }
 }