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); }
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); } } } } }
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); }