liuying
2024-12-01 ead79c455934f654d4ae5fa6f295160fe0304a0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
using Furion;
using System.Text;
 
namespace Admin.NET.Application
{
    /// <summary>
    /// Éú³ÉÖú¼ÇÂë
    /// </summary>
    public class MnemonicCodeHelper
    {
        private struct ItemWord
        {
            public int numFlag;     //ÊÇ·ñ¶àÒô×Ö
            public char strWord;    //µ±Ç°µ¥´Ê
            public string strSpell1;//ÊäÈëÂë1
            public string strSpell2;//ÊäÈëÂë2
            public string strExt;   //¶àÒô×Ö±£Áô´®
            public string strName;  //ÓÃÓÚ¶¨ÒåÐÕÊÏÂë
        }
 
        private static readonly int INTMAX = 65536;
        private static ItemWord[] stWord = new ItemWord[INTMAX];
        private static Boolean b_LoadData = false;
 
        //¶ÁÈ¡ËùÓкº×Ö
        public static Boolean fun_LoadWords()
        {
            int i, numIndex;
            int numCount1, numCount2;
            string strFileName;
            char[] chrWord;
 
            if (b_LoadData)
                return true;
 
            //ÒÔϳõʼ»¯ËùÓеÄÊý¾Ý
            for (i = 0; i < INTMAX; i++)
            {
                stWord[i].numFlag = 0;
                stWord[i].strSpell1 = "";
                stWord[i].strSpell2 = "";
                stWord[i].strName = "";
                stWord[i].strExt = "|";
            }
 
            var rootPath = System.IO.Path.Combine(App.WebHostEnvironment.WebRootPath, "ChineseSpellFile");
 
            //¶ÁÈ¡ºº×ÖÆ´Òô
            strFileName = rootPath + @"\hzpy1.txt";
            StreamReader srFile = new StreamReader(strFileName, Encoding.ASCII);
            string strInput = null;
 
            numCount1 = 0;
            while ((strInput = srFile.ReadLine()) != null)
            {
                chrWord = strInput.ToCharArray();
                numIndex = (int)chrWord[0];
 
                if (numIndex <= 0) continue;
                if (numIndex >= INTMAX) continue;
 
                stWord[numIndex].strWord = chrWord[0];
                stWord[numIndex].strSpell1 = chrWord[2].ToString();
                numCount1++;
            }
            srFile.Close();
 
            //¶ÁÈ¡¶àÒô×Ö
            strFileName = rootPath + @"\hzpy2.txt";
            srFile = new StreamReader(strFileName, Encoding.ASCII);
 
            while ((strInput = srFile.ReadLine()) != null)
            {
                chrWord = strInput.ToCharArray();
                numIndex = (int)chrWord[0];
 
                if (numIndex <= 0) continue;
                if (numIndex >= INTMAX) continue;
 
                stWord[numIndex].numFlag = 1;
                strInput = strInput.Substring(2);
                strInput = strInput.Replace("\t", " ");
 
                while (strInput.IndexOf("  ") >= 0)
                {
                    strInput = strInput.Replace("  ", " ");
                }
                strInput = strInput.Replace(" ", "/");
                stWord[numIndex].strExt = stWord[numIndex].strExt + strInput + "|";
            }
            srFile.Close();
 
            //¶ÁÈ¡ÐÕÊÏ
            strFileName = rootPath + @"\hzpy3.txt";
            srFile = new StreamReader(strFileName, Encoding.ASCII);
 
            while ((strInput = srFile.ReadLine()) != null)
            {
                chrWord = strInput.ToCharArray();
                numIndex = (int)chrWord[0];
 
                if (numIndex <= 0) continue;
                if (numIndex >= INTMAX) continue;
 
                stWord[numIndex].numFlag = 1;
                strInput = strInput.Substring(2);
                strInput = strInput.Replace("\t", " ");
 
                while (strInput.IndexOf("  ") >= 0)
                {
                    strInput = strInput.Replace("  ", " ");
                }
                stWord[numIndex].strName = strInput;
            }
            srFile.Close();
 
            //ÒÔϲ¿·Ö¶ÁÈ¡Îå±ÊÂëµÄÊ××Ö·û
            strFileName = rootPath + @"\hzwb.txt";
            numCount2 = 0;
            srFile = new StreamReader(strFileName, Encoding.ASCII);
 
            while ((strInput = srFile.ReadLine()) != null)
            {
                chrWord = strInput.ToCharArray();
                numIndex = (int)chrWord[0];
 
                if (numIndex <= 0) continue;
                if (numIndex >= INTMAX) continue;
                stWord[numIndex].strWord = chrWord[0];
                stWord[numIndex].strSpell2 = chrWord[1].ToString();
                numCount2++;
            }
            srFile.Close();
 
            b_LoadData = true;
            return true;
        }
        private static string funFindMulti(int numIndex, char ch1, char ch2)
        {
            int numPos;
            string strWord;
 
            strWord = "|" + ch1 + ch2 + "/";
            numPos = stWord[numIndex].strExt.IndexOf(strWord);
            if (numPos >= 0)
                return stWord[numIndex].strExt.Substring(numPos + strWord.Length, 1);
            return "";
        }
 
        /// <summary>
        /// Öú¼ÇÂë(Æ´Òô)
        /// </summary>
        /// <param name="strChinese"></param>
        /// <param name="IsName"></param>
        /// <returns></returns>
        public static string funChineseSpell(string strChinese, bool IsName)
        {
            if (string.IsNullOrWhiteSpace(strChinese))
            {
                return string.Empty;
            }
            string strSpell, strThis;
            int i, numCount, numIndex;
            char[] chrWord;
 
            strSpell = "";
            chrWord = strChinese.ToCharArray();
            numCount = strChinese.Length;
 
            //2010-03-19 ÒÀ´Î´¦Àí¸÷ºº×ֵį´ÒôÂë
            for (i = 0; i < numCount; i++)
            {
                numIndex = (int)chrWord[i];
 
                if (numIndex <= 0) continue;
                if (numIndex >= INTMAX) continue;
 
 
                //2010-03-19 ÊÇ·ñ¶àÒô×Ö
                strThis = "";
                if (stWord[numIndex].numFlag > 0 && !IsName)
                {
                    if (i > 0)
                    {
                        strThis = funFindMulti(numIndex, chrWord[i - 1], chrWord[i]);
                    }
                    if (strThis.Length == 0)
                    {
                        if (i < numCount - 1)
                            strThis = funFindMulti(numIndex, chrWord[i], chrWord[i + 1]);
                    }
 
                }
 
                //2010-04-02 °´ÐÕÃû½øÐд¦Àí
                if (IsName && i == 0 && stWord[numIndex].strName.Length > 0)
                    strThis = stWord[numIndex].strName;
 
                //2010-03-20 Î´ÕÒ×ÅʱÊDZê×¼Âë
                if (strThis.Length == 0)
                    strThis = stWord[numIndex].strSpell1.ToString();
                strSpell = strSpell + strThis;
            }
            return strSpell;
        }
 
        /// <summary>
        /// Öú¼ÇÂë(Îå±Ê)
        /// </summary>
        /// <param name="strChinese"></param>
        /// <returns></returns>
        public string funWbzxSpell(string strChinese)
        {
            string strSpell = "";
            int i, numCount, numIndex;
            char[] chrWord;
 
            strSpell = "";
            chrWord = strChinese.ToCharArray();
            numCount = strChinese.Length;
 
            //2010-03-19 ÒÀ´Î´¦Àí¸÷ºº×ÖµÄÎå±Ê±àÂë
            for (i = 0; i < numCount; i++)
            {
                numIndex = (int)chrWord[i];
 
                if (numIndex <= 0) continue;
                if (numIndex >= INTMAX) continue;
 
                strSpell = strSpell + stWord[numIndex].strSpell2.ToString();
            }
            return strSpell;
        }
    }
 
}