字典文件错误吧,字典应该是文本文件,并且每一行用'|'分割后有3段,第一段是关键字。
可以参加下面这段代码
1 private WordDictionaryFile LoadFromTextFile(String fileName) 2 { 3 WordDictionaryFile dictFile = new WordDictionaryFile(); 4 dictFile.Dicts = new List<WordAttribute>(); 5 6 using (StreamReader sr = new StreamReader(fileName, Encoding.UTF8)) 7 { 8 while (!sr.EndOfStream) 9 { 10 string line = sr.ReadLine(); 11 12 string[] strs = line.Split(new char[] { '|' }); 13 14 if (strs.Length == 3) 15 { 16 string word = strs[0].Trim(); 17 18 POS pos = (POS)int.Parse(strs[1].Substring(2, strs[1].Length - 2), System.Globalization.NumberStyles.HexNumber); 19 double frequency = double.Parse(strs[2]); 20 WordAttribute dict = new WordAttribute(word, pos, frequency); 21 22 dictFile.Dicts.Add(dict); 23 } 24 } 25 } 26 27 return dictFile; 28 }
把那句改为Dict.Load(strFileName);在本地测试是可以了
一会试试你这种方法,谢谢
遇到同样问题,一会试试!