private void saveWord(WordParseResult wordParseResult) { EdictEntry entry = wordParseResult.getSelectedEntry(); string kanji = string.Join(",", (from k in entry.kanji select k.text)); string kana = string.Join(",", (from k in entry.kana select k.text)); string meaning = string.Join("/", (from m in entry.sense select m.glossary.First()).Take(3)); string fn = Settings.app.SaveWordPath; if (File.Exists(fn)) { foreach (string s in File.ReadAllLines(fn)) { if (kanji != "") { if (s.StartsWith(kanji)) { return; } } else { if (s.StartsWith("\t" + kana)) { return; } } } } File.AppendAllText(fn, kanji + "\t" + kana + "\t" + meaning + "\n"); }
public void showHint(int parseId, int num, double x, double y, double h, double browserW, double browserH) { WordParseResult part = TranslationService.instance.getParseResult(parseId, num); if (part != null) { Invoke(new Action(() => { double qx = browserW == 0 ? 1 : webBrowser1.Width / browserW; double qy = browserH == 0 ? 1 : webBrowser1.Height / browserH; hintForm.display(part, webBrowser1.PointToScreen(new Point((int)Math.Round(x * qx), (int)Math.Round(y * qy))), (int)Math.Round(h * qy)); })); } }
internal void display(WordParseResult part, Point where, int anchorHeight) { if (!definitionsSent) { if (Edict.instance.getDefinitions() != null) { webBrowser1.callScript("setDefinitions", Utils.toJson(Edict.instance.getDefinitions())); definitionsSent = true; } } if (!nameDefinitionsSent) { if (Edict.instance.getNameDefinitions() != null) { webBrowser1.callScript("setNameDefinitions", Utils.toJson(Edict.instance.getNameDefinitions())); nameDefinitionsSent = true; } } lastData = part; webBrowser1.callScript("show", part.asJsonFull(), Settings.app.getSelectedPage(part.getMatchStem()), Settings.app.transparentMode, Settings.app.fontSize); this.Width = (int)(350 * Settings.app.fontSize / 100); Location = getRealPos(where.X, where.Y, anchorHeight); showNoActivate(); }
private void exportWord(WordParseResult wordParseResult) { EdictEntry entry = wordParseResult.getSelectedEntry(); var kanjiUsed = new HashSet <char>(wordParseResult.asText().Where(FuriganaUtils.isKanji)); var indices = Enumerable.Zip(entry.kanji, Enumerable.Range(0, entry.kanji.Count), (e, i) => new { entry = e, index = i }) .Where(x => new HashSet <char>(x.entry.text.Where(FuriganaUtils.isKanji)).SetEquals(kanjiUsed)) .Select(x => x.index); if (indices.Count() == 0) { indices = Enumerable.Range(0, entry.kanji.Count); } string formatted = Regex.Replace(Settings.app.ankiSaveFormat, "\\$.", f => { switch (f.Value) { case "$t": return("\t"); case "$d": // Dictionary form if (kanjiUsed.Count() == 0) { return(string.Join(", ", entry.kana.Select(k => k.text))); } else { return(string.Join(", ", indices.Select(i => entry.kanji.ElementAt(i).text))); } case "$r": // Reading return(string.Join(", ", indices.Select(i => entry.kana.ElementAt(i).text))); case "$n": // Definition return(string.Join(";<br />", entry.sense.Select(m => string.Join(", ", m.glossary)))); case "$s": // Sentence return(Regex.Replace(lastParseResult.asText(), "\\n|\\r|\\r\\n|\\n\\r", "<br />")); case "$f": // Furigana if (entry.kanji.Count == 0) { return(string.Join(", ", indices.Select(i => entry.kana.ElementAt(i).text))); } else { string kana = entry.kana.First().text; return(string.Join(", ", indices.Select(i => FuriganaUtils.generateFurigana(entry.kanji.ElementAt(i).text, kana)))); } case "$i": // Title return(Text); default: return(f.Value); } }); string fn = "anki-rt.txt"; // TODO: Anki realtime export file in settings/temp folder string fieldNames = Settings.app.ankiFieldNames.Replace(' ', '\t'); File.WriteAllText(fn, $"add\t1\n{fieldNames}\n\n{formatted}"); using (UdpClient client = new UdpClient("127.0.0.1", ANKI_REALTIME_IMPORT_PORT)) { string fullPath = Path.GetFullPath(fn); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(fullPath); client.Send(bytes, bytes.Length); } }
internal string replaceNames(ParseResult parseData) { StringBuilder sb = new StringBuilder(); IEnumerable <ParseResult> parts; if (parseData.type == ParseResult.ParseResultType.COMPLEX) { parts = (parseData as ComplexParseResult).parts; } else { parts = Enumerable.Repeat(parseData, 1); } bool prevName = false; foreach (var part in parts) { if (part.type == ParseResult.ParseResultType.UNPARSED) { prevName = false; sb.Append(part.asText()); } else if (part.type == ParseResult.ParseResultType.WORD) { WordParseResult wp = part as WordParseResult; bool found = false; bool isName = wp.isName(); bool isReplacement = wp.isReplacement(); if (isName || isReplacement) { var entry = wp.getSelectedEntry(); DictionarySense sense = entry.sense.FirstOrDefault(); if (sense != null && sense.glossary.Count > 0) { if (prevName) { sb.Append(' '); } sb.Append(sense.glossary.First()); found = true; } else { if (entry.kana.Count > 0) { if (prevName) { sb.Append(' '); } sb.Append(entry.kana.First().text); found = true; } } } else if (prevName) { foreach (EdictEntry entry in wp.getEntries()) { if (nameSuffixes.ContainsKey(part.asText())) { string reading = nameSuffixes[part.asText()]; sb.Append(reading); found = true; break; } else if (nameSuffixes.ContainsKey(entry.getText())) { string reading = nameSuffixes[entry.getText()]; sb.Append(reading); found = true; break; } } } if (found) { prevName = isName || prevName; } else { prevName = false; sb.Append(part.asText()); } } } return(sb.ToString()); }