Esempio n. 1
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;
     }
 }
Esempio n. 2
0
 private void readTrans(EdictEntryBuilder entry, XmlReader xml)
 {
     DictionarySense sense = new DictionarySense();
     while (xml.Read()) {
         if (xml.NodeType == XmlNodeType.EndElement && xml.Name == "trans") break;
         if (xml.NodeType == XmlNodeType.Element) {
             if (xml.Name == "trans_det") {
                 string lang = xml.GetAttribute("xml:lang");
                 if (lang == "eng") lang = null;
                 string value = xml.ReadString();
                 sense.addGloss(lang, value);
             } else {
                 switch (xml.Name) {
                     case "name_type":
                         entry.nameType = fromEntity(xml);
                         break;
                 }
             }
         }
     }
     entry.addSense(sense, 1.0, 1.0);
 }
Esempio n. 3
0
 private void readSense(EdictEntryBuilder entry, XmlReader xml)
 {
     DictionarySense sense = new DictionarySense();
     double globalMult = 1.0;
     double kanaMult = 0.8;
     while (xml.Read()) {
         if (xml.NodeType == XmlNodeType.EndElement && xml.Name == "sense") break;
         if (xml.NodeType == XmlNodeType.Element) {
             if (xml.Name == "gloss") {
                 string lang = xml.GetAttribute("xml:lang");
                 if (lang == "eng") lang = null;
                 string value = xml.ReadString();
                 sense.addGloss(lang, value);
             } else {
                 switch (xml.Name) {
                     case "pos":
                         entry.addPOS(fromEntity(xml));
                         break;
                     case "field":
                     case "misc":
                     case "dial":
                         string v = fromEntity(xml);
                         adjustMultipliers(v, ref globalMult, ref kanaMult);
                         sense.addMisc(v);
                         break;
                 }
             }
         }
     }
     entry.addSense(sense, globalMult, kanaMult);
 }
Esempio n. 4
0
 private void readReading(EdictEntryBuilder entry, XmlReader xml)
 {
     string text = null;
     double mult = 1.0;
     List<string> misc = null;
     while (xml.Read()) {
         if (xml.NodeType == XmlNodeType.EndElement) {
             if (xml.Name == "r_ele") {
                 break;
             }
         }
         if (xml.NodeType == XmlNodeType.Element) {
             string name = xml.Name;
             switch (name) {
                 case "reb":
                     text = xml.ReadString();
                     break;
                 case "re_nokanji":
                     mult = 1.5;
                     break;
                 case "re_restr":
                     // ignore for now
                     break;
                 case "re_inf":
                     if (misc == null) misc = new List<string>();
                     misc.Add(fromEntity(xml));
                     break;
                 case "re_pri":
                     string priority = xml.ReadString();
                     entry.addPriority(priority);
                     if (mult > 0) {
                         mult = Math.Max(mult, getMultiplierFromCode(priority));
                     }
                     break;
             }
         }
     }
     if (text != null) {
         DictionaryKeyBuilder s = new DictionaryKeyBuilder(text, mult, misc);
         entry.addKana(s);
     }
 }
Esempio n. 5
0
 private void readNameEntry(XmlReader xml)
 {
     EdictEntryBuilder entry = new EdictEntryBuilder();
     entry.addPOS("name");
     while (xml.Read()) {
         if (xml.NodeType == XmlNodeType.EndElement && xml.Name == "entry") break;
         if (xml.NodeType == XmlNodeType.Element) {
             switch (xml.Name) {
                 case "k_ele":
                     readKanji(entry, xml);
                     break;
                 case "r_ele":
                     readReading(entry, xml);
                     break;
                 case "trans":
                     readTrans(entry, xml);
                     break;
             }
         }
     }
     addToNameIndex(entry);
 }
Esempio n. 6
0
 private void readEntry(XmlReader xml)
 {
     EdictEntryBuilder entry = new EdictEntryBuilder();
     while (xml.Read()) {
         if (xml.NodeType == XmlNodeType.EndElement && xml.Name == "entry") break;
         if (xml.NodeType == XmlNodeType.Element) {
             switch (xml.Name) {
                 case "k_ele":
                     readKanji(entry, xml);
                     break;
                 case "r_ele":
                     readReading(entry, xml);
                     break;
                 case "sense":
                     readSense(entry, xml);
                     break;
             }
         }
     }
     addToIndex(entry);
 }
Esempio n. 7
0
 private void addToNameIndex(EdictEntryBuilder entry)
 {
     bool proceed = true;
     if (Settings.app.nameDict == NameDictLoading.NAMES) {
         string nameType = entry.nameType;
         proceed = nameType == "surname" || nameType == "masc" || nameType == "fem" || nameType == "person" || nameType == "given";
     }
     if (proceed) {
         foreach (DictionaryKeyBuilder key in entry.kanji) {
             addToIndex(mainIndex, key.text, 0.85, entry);
         }
     }
 }
Esempio n. 8
0
 private void addToIndex(EdictEntryBuilder entry)
 {
     foreach (DictionaryKeyBuilder key in entry.kanji) {
         if (key.text.Length == 1 && TextUtils.isAllKatakana(key.text)) {
             continue;
         }
         double rate = entry.globalMultiplier * key.rate;
         string stem = inflect.getStem(key.text, entry.POS);
         int kanjiCount = stem.Count((c) => TextUtils.isKanji(c));
         if (kanjiCount > 1) {
             rate = rate * 2.0; // kanji are good
         }
         addToIndex(mainIndex, stem, rate, entry);
     }
     if (entry.kanji.Count == 0 && entry.kana.Count > 0) {
         foreach (DictionaryKeyBuilder key in entry.kana) {
             if (key.text == "です") { // DESU DESU DESU
                 entry.addPOS("copula");    // DESU DESU DESU
             }
             string stem = inflect.getStem(key.text, entry.POS);
             double rate;
             if (key.text == "は" || key.text == "が" || key.text == "の" || key.text == "に" || key.text == "し") {
                 rate = 2.0; // these are good
             } else {
                 rate = entry.globalMultiplier * Math.Max(key.rate, 1.3);
                 /*if (stem.Length == 1 && rate > 1.0) {
                     rate = 1.0;
                 }*/
             }
             addToIndex(mainIndex, stem, rate, entry);
         }
     } else {
         foreach (DictionaryKeyBuilder key in entry.kana) {
             if (key.text.Length > 1) {
                 string stem = inflect.getStem(key.text, entry.POS);
                 double rate = entry.globalMultiplier * entry.globalKanaMultiplier * key.rate;
                 if (rate > 0) {
                     addToIndex(kanaIndex, stem, rate, entry);
                 }
             }
         }
     }
 }
Esempio n. 9
0
 private void addToIndex(IDictionary<string, EdictMatch> dict, string key, double rate, EdictEntryBuilder entry)
 {
     addToIndex(dict, key, rate, entry.build());
 }
Esempio n. 10
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;
     }
 }