Build a simple dictionary application
The most essential tool when learning a foreign language is the dictionary. Surely you, as well as me, always feel hard to look up the word on the thick dictionary. A worthwhile solution is to use a computer dictionary application. Although the dictionary applications are now much but they are informatics people, I decided to build them myself
The most essential tool when learning a foreign language is the dictionary. Surely you, as well as me, always feel hard to look up the word on the thick dictionary. A worthwhile solution is to use a computer dictionary application. Although the dictionary applications have a lot but they are informatics people, I decided to build my own dictionary application.
Database
The most important part for a dictionary application is the database (database). Building a database for the dictionary must ensure quick access because the data of the dictionary is often quite large, up to tens of thousands of words. Fortunately, DICT.ORG (www.dict.org) has built a very easy-to-use dictionary format, which has been used to build quite large dictionaries. The format format is described as follows: the entire database is contained in two files, one file containing the meaning of the word and one index file. File index includes the word name, the meaning of the starting word in the file containing the meaning and the length of the meaning. The starting position and length of the meaning are encoded in the following way: Use 64 letters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 + /
letter A is equivalent to 0, letter B is equivalent to number 1, etc. Between words, starting position and meaning length are separated by tab characters (ASCII 9). Each line in the index file contains the data of a word. Lines separated by a carriage return (ASCII 10).
For example, in the index file of the German-Vietnamese dictionary there is one line as follows:
Abdeckung kbpP D3
Thus the meaning of Abdeckung in the meaning file will start at offset kbpP (in 64-character code) and be of length D3.
The conversion from base code 64 to base 10 is done as follows:
For starting position: kbpP. We have k (at base 64) = 36 (at base 10), b = 27, p = 41, P = 15. So switch to base 10, kbpP code is valid: 36 * 643 + 27 * 642 + 41 * 641 + 15 * 640 = 9550415
For meaning length: D3. We have D = 3, 3 = 55. So switch to base 10, code D3 at base number 64 has the value of: 247.
File index is arranged to reduce search time. Encoding as base number 64 above allows index file size to be greatly reduced compared to non-encryption.
The structure of the file contains the meaning of the following sections:
@headword
* tu loai (noun, verb .)
- nutrition 1
= to make the 1 + nostalgic sense of craving
- nutrition 2
= to help the 2 + nostalgic spirit grow
* tu loai
- nutrition 3
The meaning of each word consists of a part like the above, the meanings of each word continue continuously.
Thus, you can completely build your own dictionaries. However, data entry work is not simple at all. But, once again, we are fortunate that some of you have already put in some common dictionaries. You can refer to: www.ttdomain.net/ttdownload/, www.informatik.uni-leipzig.de/~duc/Dict/, huybien.vze.com . There are also many dictionaries. Other specialties, you can refer to the addresses at or at www.dict.org.
Building the program
Here I would like to show you how to use Visual C ++ 6.0 language and MFC library. You can completely use other languages. In the framework of the article, I would like to present only the most essential parts. Parts such as interface design, interface layout, etc. you can refer to the sample program and create more.
1. Basic interface components:
• Edit Box: used to enter words. Settings for controls: 'Variable name: m_word, Category: Value, Type: Cstring;'
• WebBrowser: used to show the meaning of words. The use of WebBrowser is only intended to display a more intuitive and vivid meaning by processing the string (to be mentioned later). You can add the ActiveX Web Browser control to your application by selecting Project-> Add to Project-> Components And Controls, in the Registered ActiveX Controls folder that controls the Microsoft Web Browser. Variable for control: 'Variable name: m_wordmean;'
• Listbox, used to display word list. Variable for control: 'Variable name: m_wordlist; Category: Control; '
• Listbox, used to store data about words. Variable for control: 'Variable name: m_worddata, Category: Control;'
2. Program code:
• Load data into list boxes: you set this code section in the event WM_OnInitDialog () so that the data is loaded right from the start of the program. Here, you replace the index file name with the file name corresponding to the dictionary you use.
FILE * inFile;
inFile = fopen ('mydic.index', 'r');
if (inFile == NULL) {
MessageBox ('Cannot open index file');
} else {
char * line;
char lineBuf [100];
line = (char *) lineBuf;
m_wordlist.ResetContent ();
m_worddata.ResetContent ();
CString word = '';
CString sWord = '';
CString sData = '';
while (! feof (inFile)) {
fgets (line, 99, inFile);
if (strlen (line)> = 2) {
word = line;
int pos = word.Find ('t', 0);
sWord = word.Left (pos);
sData = word.Mid (pos + 1, word.
GetLength () - pos-1);
if (sData.Find ('n', 0)> 0) {
sData = sData.Left (sData.
GetLength () - 1); }
if (sWord.GetLength ()> = 1) {
m_wordlist.AddString (sWord);
m_worddata.AddString (sData);}
}}}
fclose (inFile);
• The function changes from base number 64 to base 10
int GetDemicalValue (CString str) {
CString base64 = 'ABCDEFGHIJKLM-NOPQRSTUVWXYZabcdefghijklmnopqrstu-vwxyz0123456789 + /';
int decValue = 0;
int len = str.GetLength ();
for (int i = 0; i
int pos = base64.Find (str.
GetAt (i), 0);
decValue + = (int) pow (64, len-i-
1) * pos;
}
return decValue;
}
• The function handles the character string meaning. As mentioned above, I use the Web Browser control to display the meaning for more vivid. This function works to treat meaning strings by adding HTML tags so that the meaning is expressed more vividly, for example: child meanings are bold, red, examples are in italics, blue letters, etc. .
CString ChangeStyle (CString wordmean) {
CString meaning = wordmean;
meaning = meaning.Right (meaning.GetLength () - 1);
int pos = meaning.Find ('n', 1);
meaning.Insert (pos, '');
meaning = ' ' + meaning;
meaning.Replace ('n', '
');
meaning.Replace ('{', ' ');
meaning.Replace ('}', ' ');
meaning.Replace ('[', ' ');
meaning.Replace (']', ' ');
meaning.Replace ('+', '');
return meaning;
}
• Function takes the meaning of the word: this function works to read from the file containing the meaning to get the meaning of the word, then process the meaning string and then write the temp.htm file. If the definition is successful, the function returns TRUE value, if it fails, the function returns FALSE. You change the name of mydict.dict file with the name of the corresponding dictionary file.
BOOL CXDictDlg :: GetMeaning () {
CFile f;
CString meaning = '';
if (f.Open ('mydic.dict', CFile :: modeRead) == FALSE) {
meaning = 'Can not open database file!';
} else {
CString sOffLen;
m_worddata.GetText (m_wordlist.GetCurSel (), sOffLen);
int pos = sOffLen.Find ('t', 0);
CString sOff = sOffLen.Left (pos);
CString sLen = sOffLen.Right (sOffLen.GetLength () - pos-1);
int iOff = GetDemicalValue (sOff);
int iLength = GetDemicalValue (sLen);
int temp = f.Seek (iOff, CFile :: begin);
char buff [64];
DWORD dwRead;
due to {
if (iLength> = 64)
dwRead = f.Read (buff, 64);
else
dwRead = f.Read (buff, iLength);
iLength - = dwRead;
CString stemp = buff;
stemp = stemp.Left (dwRead);
meaning + = stemp;
} while (iLength> 0);
f.Close ();
}
meaning = ChangeStyle (meaning);
CString strHtml ('');
strHtml + = 'nn'; strHtml + = 'n'; strHtml + = 'nn';
strHtml + = meaning + 'nn';
CFile f2;
if (f2.Open ('temp.htm', CFile :: modeCreate | CFile :: modeWrite) == FALSE) {
MessageBox ('Cannot write meaning file!', 'Error!');
return 0;
}
f2.Write (strHtml, strHtml.GetLength ());
f2.Close ();
return 1;
}
• Display the meaning of the word, you install this code into the DoubleClick event of the list box control.
BOOL gm = GetMeaning ();
if (gm) {
m_wordlist.GetText (m_wordlist.GetCurSel (), m_word);
UpdateData (FALSE);
// Lay the link to the current account
DWORD cchCurDir;
LPTSTR lpszCurDir;
TCHAR buffer [MAX_PATH];
lpszCurDir = buffer;
GetCurrentDirectory (cchCurDir, lpszCurDir);
CString str = lpszCurDir;
str = 'file: //'+str+'temp.htm';
/ / Hien test of the practice
m_wordmean.Navigate
(str, NULL, NULL, NULL, NULL);
} else {
MessageBox ('không thể lấy nghĩa của từ');
}
• Search the word in the list box corresponding to the change in the input in the Edit control. You install this code into the EN_CHANGE view of the Edit control. So every time you type 1 word into the Edit control, the program will automatically find the most similar word in the list of words.
UpdateData (TRUE);
m_wordlist.SelectString (-1, m_word);
After successful construction, the program will have the interface as shown.
Above, I have presented how to build a simple dictionary application. With the creativity and knowledge already available, you can completely add new capabilities to this dictionary application so that it is not inferior to the commercial dictionary software. In addition, with a fairly simple dictionary format like above, you can easily build an additional application to create a new dictionary automatically.
I would also like to introduce you some addresses of software that use DICT.ORG's standard dictionaries for you to refer to:
• Ho Ngoc Duc's website , www.informatik.uni-leipzig.de/~duc/Dict/, here you can search online dictionaries or download applications written in Java and dictionary files to run directly on the machine.
o PowerClick , www.ttdomain.net/ttdownload. Software has been introduced on TGVT - PCW VN A 7/2004, capable of clicking and Seeing on some applications.
• E-lexicon, www.edusoft.com.vn. Software was introduced on TCVT - PCW VN A 7/2004, working under Client - Server model.
• MultiDictionary , http://huybien.vze.com/. Application of multi-dictionary, beautiful interface, able to pronounce English, Russian, French, German.
Wish you success and satisfaction with your dictionary application.
Tran Binh An
b_v_a_l@yahoo.com
You should read it
- Tips to play Fate/Grand Order gamers need to know
- Create automatic table of contents in Word 2003
- Create automatic table of contents in Word for Word 2007, Word 2010 to Word 2019
- How to create automatic table of contents in Word 2016
- How to do automatic table of contents in Word 2013, 2016
- 10 impressive table of contents for Microsoft Word
- Create table of contents automatically in Word 2007 and 2010
- How to make a table of contents in Word 2010
- How to create an image table of contents in Word?
- How to create automatic table of contents effectively in Word 2007
- How to make a table of contents in Word 2016
- Instructions for creating a table of contents automatically in Word
Maybe you are interested
Difference between WiFi 5, WiFi 6 and WiFi 6E Instructions to turn on 'Rating comments' for posts on Facebook Find anything on Facebook Timeline with the following 5 tools 1000 free music tracks to create Facebook, Instagram videos How to remove the code as a video format on Facebook Messenger How to create a Weibo account with a Vietnamese phone number