日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#编写的日英字典程序 - 基于EDict

發布時間:2024/1/1 C# 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#编写的日英字典程序 - 基于EDict 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

關于EDict, 詳細資料可以訪問?http://www.csse.monash.edu.au/~jwb/edict_doc_old.html


EDict的文件組織形式:

FORMAT

EDICT's format is that of the original "EDICT" format used by the early PC Japanese word-processor MOKE (Mark's Own Kanji Editor). It uses EUC-JP coding for kana and kanji, however this can be converted to JIS (ISO-2022-JP) or Shift-JIS by any of the several conversion programs around. It is a text file with one entry per line. The format of entries is:

KANJI [KANA] /English_1/English_2/.../

or

KANA /English_1/.../

(NB: Only the KANJI and KANA are in EUC; all the other characters, including spaces, must be ASCII.)

The English translations were initially deliberately brief, as the application of the dictionary was expected to be primarily on-line look-ups, etc. Over time the translations have become more extended.

The EDICT file is not intended to have its entries in any particular order. In fact it almost always is in order as a by-product of the update method I use, however there is no guarantee of this. (The order is almost always JIS + alphabetical, starting with the head-word.)


主要代碼:

MainForm.cs

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO;namespace EdictLookup {public partial class MainForm : Form{private Edict myEdict;public MainForm(){InitializeComponent();}private void MainForm_Load(object sender, EventArgs e){myEdict = new Edict();try{myEdict.EdictLoad(this.cb_fulldic.Checked);}catch (Exception ex){MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);this.Close();}this.edit_input.Focus();}private void btn_lookup_Click(object sender, EventArgs e){myEdict.EdictLookup(this.edit_input.Text, this.list_result, this.cb_exact.Checked);}private void cb_fulldic_CheckedChanged(object sender, EventArgs e){try{myEdict.EdictLoad(this.cb_fulldic.Checked);}catch (Exception ex){MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);this.Close();}myEdict.EdictLookup(this.edit_input.Text, this.list_result, this.cb_exact.Checked);}private void cb_exact_CheckedChanged(object sender, EventArgs e){myEdict.EdictLookup(this.edit_input.Text, this.list_result, this.cb_exact.Checked);}}public class Edict{private const string DIC_SUB_FILENAME = "edict_sub"; // filename of the edit_sub fileprivate const string DIC_FILENAME = "edict"; // filename of the edit fileprivate int dicFileSize; // edict file sizeprivate char[] dicBuffer; // buffer of edict file, contains all text of edictprivate string dicText; // text of edict, a copy of dicBufferprivate void EdictLoad_Sub(){FileInfo fi = new FileInfo(DIC_SUB_FILENAME);this.dicFileSize = (int)fi.Length;FileStream fs = new FileStream(DIC_SUB_FILENAME, FileMode.Open);StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("EUC-JP"));this.dicBuffer = new char[this.dicFileSize + 1];sr.Read(this.dicBuffer, 0, this.dicFileSize);sr.Close();fs.Close();this.dicText = new string(this.dicBuffer);}private void EdictLoad_Full(){FileInfo fi = new FileInfo(DIC_FILENAME);this.dicFileSize = (int)fi.Length;FileStream fs = new FileStream(DIC_FILENAME, FileMode.Open);StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("EUC-JP"));this.dicBuffer = new char[this.dicFileSize + 1];sr.Read(this.dicBuffer, 0, this.dicFileSize);sr.Close();fs.Close();this.dicText = new string(this.dicBuffer);}public void EdictLoad(bool full){GC.Collect();if (full){this.EdictLoad_Full();}else{this.EdictLoad_Sub();}}private void EdictLookup_Fuzzy(string search, ListBox result){result.Items.Clear();if (search.Length > 0){int index = -1;int pos1 = -2;int pos2;while ((index = this.dicText.IndexOf(search, index + 1)) != -1){pos1 = this.dicText.LastIndexOf('\n', index) + 1;pos2 = this.dicText.IndexOf('\n', index);result.Items.Add(this.dicText.Substring(pos1, pos2 - pos1));}if (pos1 == -2){result.Items.Add("Not Found!");}}else{result.Items.Add("Empty Input!");}}private void EdictLookup_Exact(string search, ListBox result){try{result.Items.Clear();if (search.Length > 0){int index = -1;int pos1 = -2;int pos2;// kanji matchstring temp = '\n' + search + ' ';while ((index = this.dicText.IndexOf(temp, index + 1)) != -1){pos1 = index + 1;pos2 = this.dicText.IndexOf('\n', pos1);result.Items.Add(this.dicText.Substring(pos1, pos2 - pos1));}// kana matchindex = -1;temp = '[' + search + ']';while ((index = this.dicText.IndexOf(temp, index + 1)) != -1){pos1 = this.dicText.LastIndexOf('\n', index) + 1;pos2 = this.dicText.IndexOf('\n', index);result.Items.Add(this.dicText.Substring(pos1, pos2 - pos1));}if (pos1 == -2){result.Items.Add("Not Found!");}}else{result.Items.Add("Empty Input!");}}catch (Exception ex){MessageBox.Show(ex.ToString());}}public void EdictLookup(string search, ListBox result, bool exact){if (exact){this.EdictLookup_Exact(search, result);}else{this.EdictLookup_Fuzzy(search, result);}}}}

完整源代碼:

EdictLookup.rar

在bin\Release中已包含 edict(完整字典文件) 和 edict_sub(常用字典文件) 文件


總結

以上是生活随笔為你收集整理的C#编写的日英字典程序 - 基于EDict的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。