Exemple #1
0
        internal void load(Inflector inflect)
        {
            try {
                this.inflect = inflect;
                mainIndex = new ConcurrentDictionary<string, EdictMatch>();
                kanaIndex = new Dictionary<string, EdictMatch>();
                definitions = null;
                nameDefinitions = null;
                entities = new Dictionary<string, string>();

                using (XmlTextReader xml = new XmlTextReader(Settings.app.JMdictPath)) {
                    xml.DtdProcessing = DtdProcessing.Parse;
                    xml.WhitespaceHandling = WhitespaceHandling.None;
                    xml.EntityHandling = EntityHandling.ExpandCharEntities;
                    while (xml.Read()) {
                        switch (xml.NodeType) {
                            case XmlNodeType.Element:
                                if (xml.Name == "entry") {
                                    readEntry(xml);
                                }
                                break;
                        }
                    }
                }

                /* todo HACK */
                EdictEntry ore = mainIndex["俺"].entries[0].entry;
                addToIndex(mainIndex, "オレ", 2.0, ore);
                RatedEntry tachi = kanaIndex["たち"].entries.First((re) => re.entry.kanji[0].text == "達");
                tachi.rate = 2.0F;
                //RatedEntry ii = kanaIndex["い"].entries.First((re) => re.entry.kanji[0].text == "良い");
                //addToIndex(kanaIndex, "いい", 2.0, ii.entry);
                mainIndex.Remove("もの");
                var haji = mainIndex["初めまして"].entries[0];
                haji.rate = 2.0F;
                var dake = kanaIndex["だけ"].entries.First((re) => re.entry.kanji[0].text == "丈");
                dake.rate = 2.0F;
                /*var tai = mainIndex["た"].entries.First((re) => re.entry.kanji.Count == 0 && re.entry.kana[0].text == "たい");
                tai.rate = 3.0F;*/
                var gozaimasu = mainIndex["御座います"].entries[0].entry;
                gozaimasu.POS.Add("v-imasu");
                addToIndex(gozaimasu, 2.0F, 2.0F);
                mainIndex.Remove("御座います");
                kanaIndex.Remove("ございます");
                var go = mainIndex["御"].entries[0].entry;
                addToIndex(kanaIndex, "ご", 2.0, go);
                addToIndex(kanaIndex, "お", 2.0, go);
                mainIndex["って"].entries[0].rate = 2.0F;

                zeroStemForms = new Dictionary<string, EdictMatch>();
                EdictMatch zeroStem = mainIndex[""];
                foreach (RatedEntry re in zeroStem.entries) {
                    foreach (string suffix in inflect.getAllSuffixes(re.entry.POS)) {
                        zeroStemForms[suffix] = zeroStem;
                    }
                }

                addFrequencyEntities();

                definitions = entities;
                entities = new Dictionary<string, string>();

                Task.Factory.StartNew(() => {
                    if (Settings.app.nameDict != NameDictLoading.NONE) {
                        using (XmlTextReader xml = new XmlTextReader(Settings.app.JMnedictPath)) {
                            xml.DtdProcessing = DtdProcessing.Parse;
                            xml.WhitespaceHandling = WhitespaceHandling.None;
                            xml.EntityHandling = EntityHandling.ExpandCharEntities;
                            while (xml.Read()) {
                                switch (xml.NodeType) {
                                    case XmlNodeType.Element:
                                        if (xml.Name == "entry") {
                                            readNameEntry(xml);
                                        }
                                        break;
                                }
                            }
                        }
                    }
                    nameDefinitions = entities;
                    entities = null;
                    mainIndex = new Dictionary<string, EdictMatch>(mainIndex); // no concurrency needed at this point
                    GC.Collect();
                });

            } catch (Exception ex) {
                Logger.logException(ex);
            }
        }
Exemple #2
0
 protected override void doInitialize()
 {
     inflect = new Inflector();
     inflect.load();
     dict = new EdictDictionary();
     dict.load(inflect);
 }