private void addToIndex(IDictionary <string, EdictMatch> dict, string key, double rate, EdictEntry entry)
        {
            if (key.Length > maxKeyLength)
            {
                return;
            }
            if (key.Length == 0)
            {
                rate = 1.5;
            }
            EdictMatch entries;
            RatedEntry newEntry = new RatedEntry {
                entry = entry, rate = (float)rate
            };

            if (dict.TryGetValue(key, out entries))
            {
                entries.addEntry(newEntry);
            }
            else
            {
                entries = new EdictMatch(key);
                entries.addEntry(newEntry);
                dict.Add(key, entries);
            }
        }
        internal EdictMatch findName(string name)
        {
            EdictMatch m = Settings.session.userNames.GetOrDefault(name);

            if (m == null)
            {
                m = mainIndex.GetOrDefault(name);
            }
            return(m);
        }
Exemple #3
0
 private void addToIndex(IDictionary<string, EdictMatch> dict, string key, double rate, EdictEntry entry)
 {
     if (key.Length > maxKeyLength) {
         return;
     }
     if (key.Length == 0) {
         rate = 1.5;
     }
     EdictMatch entries;
     RatedEntry newEntry = new RatedEntry { entry = entry, rate = (float)rate };
     if (dict.TryGetValue(key, out entries)) {
         entries.addEntry(newEntry);
     } else {
         entries = new EdictMatch(key);
         entries.addEntry(newEntry);
         dict.Add(key, entries);
     }
 }
Exemple #4
0
 public void addUserName(string key, string sense, string nameType)
 {
     lock (this) {
         Settings.app.removeBannedWord(key);
         EdictMatch match = new EdictMatch(key);
         EdictEntryBuilder eb = new EdictEntryBuilder();
         eb.addKanji(new DictionaryKeyBuilder(key));
         eb.addKana(new DictionaryKeyBuilder(sense));
         DictionarySense ds = new DictionarySense();
         ds.addGloss(null, sense);
         eb.addSense(ds);
         if (nameType != "notname") {
             eb.addPOS("name");
         } else {
             eb.addPOS("n");
         }
         eb.nameType = nameType;
         match.addEntry(new RatedEntry { entry = eb.build(), rate = 5.0F });
         userNames[key] = match;
         this.isDirty = true;
     }
 }
Exemple #5
0
 public EdictMatchWithType(EdictMatch match, EdictMatchType matchType)
 {
     this.match     = match;
     this.matchType = matchType;
 }
 public EdictMatchWithType(EdictMatch match, EdictMatchType matchType)
 {
     this.match = match;
     this.matchType = matchType;
 }
        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);
            }
        }