コード例 #1
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);
     }
 }
コード例 #2
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);
     }
 }