public WordLibraryList ImportLine(string line) { string[] c = line.Split(' '); var wl = new WordLibrary(); string code = c[0]; wl.Word = c[1]; wl.Count = DefaultRank; wl.PinYin = CollectionHelper.ToArray(pyGenerater.GetCodeOfString(wl.Word)); wl.AddCode(CodeType, code); var wll = new WordLibraryList(); wll.Add(wl); return wll; }
public WordLibraryList ImportLine(string line) { string code = line.Split(' ')[0]; string word = line.Split(' ')[1]; var wl = new WordLibrary(); wl.Word = word; wl.Count = DefaultRank; wl.AddCode(CodeType.Wubi, code); wl.PinYin = CollectionHelper.ToArray(pinyinFactory.GetCodeOfString(word)); var wll = new WordLibraryList(); if (wl.PinYin.Length > 0) { wll.Add(wl); } return wll; }
//private IWordCodeGenerater pyGenerater = new PinyinGenerater(); public WordLibraryList ImportLine(string str) { var list = new WordLibraryList(); string[] words = str.Split(' '); for (int i = 1; i < words.Length; i++) { string word = words[i]; var wl = new WordLibrary(); wl.Word = word; wl.Count = DefaultRank; wl.AddCode(CodeType, words[0]); //wl.PinYin = CollectionHelper.ToArray(pyGenerater.GetCodeOfString(word)); list.Add(wl); } return list; }
////没有什么思路,接下来的代码写得乱七八糟的,但是好像还是对的。zengyi20101114 ////如果wl中提供了拼音数组,而且自定义格式也是拼音格式,那么就只转换格式即可。 //public string BuildWLString(WordLibrary wl) //{ // string py = "", cp = ""; // var sb = new StringBuilder(); // if (ContainCode) // { // if (IsPinyinFormat) // { // py = wl.GetPinYinString(CodeSplitString, CodeSplitType); // } // else // { // selfFactory.MutiWordCodeFormat = MutiWordCodeFormat; // py = selfFactory.GetCodeOfString(wl.Word)[0]; // } // } // if (ContainRank) // { // cp = wl.Count.ToString(); // } // var dic = new Dictionary<int, string>(); // dic.Add(Sort[0], py); // dic.Add(Sort[1], wl.Word); // dic.Add(Sort[2], cp); // var newSort = new List<int>(Sort); // newSort.Sort(); // foreach (int x in newSort) // { // if (dic[x] != "") // { // sb.Append(dic[x] + SplitString); // } // } // string str = sb.ToString(); // return str.Substring(0, str.LastIndexOf(SplitString)); //} public WordLibrary BuildWordLibrary(string line) { var wl = new WordLibrary(); string[] strlist = line.Split(new[] { SplitString }, StringSplitOptions.RemoveEmptyEntries); var newSort = new List<int>(Sort); newSort.Sort(); if (isPinyin) { int index1 = Sort.FindIndex(i => i == newSort[0]); //最小的一个 if (index1 == 0 && ContainCode) //第一个是拼音 { wl.PinYinString = strlist[0]; } if (index1 == 1) { wl.Word = strlist[0]; } if (index1 == 2 && ContainRank) { wl.Count = Convert.ToInt32(strlist[0]); } if (strlist.Length > 1) { int index2 = Sort.FindIndex(i => i == newSort[1]); //中间的一个 if (index2 == 0 && ContainCode) //第一个是拼音 { wl.PinYinString = strlist[1]; } if (index2 == 1) { wl.Word = strlist[1]; } if (index2 == 2 && ContainRank) { wl.Count = Convert.ToInt32(strlist[1]); } } if (strlist.Length > 2) { int index2 = Sort.FindIndex(i => i == newSort[2]); //最大的一个 if (index2 == 0 && ContainCode) //第一个是拼音 { wl.PinYinString = strlist[2]; } if (index2 == 1) { wl.Word = strlist[2]; } if (index2 == 2 && ContainRank) { wl.Count = Convert.ToInt32(strlist[2]); } } wl.PinYin = wl.PinYinString.Split(new[] { CodeSplitString }, StringSplitOptions.RemoveEmptyEntries); } else//不是拼音,那么就抛弃直接加入Unknown Code。 { int index1 = Sort.FindIndex(i => i == newSort[0]); //最小的一个 if (index1 == 0 && ContainCode) //第一个是Code { wl.AddCode(CodeType.Unknown, strlist[0]); } if (index1 == 1) { wl.Word = strlist[0]; } if (index1 == 2 && ContainRank) { wl.Count = Convert.ToInt32(strlist[0]); } if (strlist.Length > 1) { int index2 = Sort.FindIndex(i => i == newSort[1]); //中间的一个 if (index2 == 0 && ContainCode) //第一个是Code { wl.AddCode(CodeType.Unknown, strlist[1]); } if (index2 == 1) { wl.Word = strlist[1]; } if (index2 == 2 && ContainRank) { wl.Count = Convert.ToInt32(strlist[1]); } } if (strlist.Length > 2) { int index2 = Sort.FindIndex(i => i == newSort[2]); //最大的一个 if (index2 == 0 && ContainCode) //第一个是拼音 { wl.AddCode(CodeType.Unknown, strlist[2]); } if (index2 == 1) { wl.Word = strlist[2]; } if (index2 == 2 && ContainRank) { wl.Count = Convert.ToInt32(strlist[2]); } } } return wl; }
public virtual WordLibraryList ImportLine(string line) { var wlList = new WordLibraryList(); string[] strs = line.Split(' '); for (int i = 1; i < strs.Length; i++) { string word = strs[i].Replace(",", ""); //把汉字中带有逗号的都去掉逗号 var list = pinyinFactory.GetCodeOfString(word); for (int j = 0; j < list.Count; j++) { var wl = new WordLibrary(); wl.Word = word; if (IsWubi) { wl.AddCode(CodeType.Wubi, strs[0]); } wl.PinYin = CollectionHelper.ToArray(list); wlList.Add(wl); } } return wlList; }
//private IWordCodeGenerater pyGenerater=new PinyinGenerater(); public WordLibraryList ImportLine(string line) { string[] lineArray = line.Split('\t'); string word = lineArray[0]; string code = lineArray[1]; var wl = new WordLibrary(); wl.Word = word; wl.Count = Convert.ToInt32(lineArray[2]); if (CodeType == CodeType.Pinyin) { wl.PinYin = code.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); } else { //wl.PinYin = CollectionHelper.ToArray(pyGenerater.GetCodeOfString(wl.Word)); wl.AddCode(CodeType, code); } var wll = new WordLibraryList(); wll.Add(wl); return wll; }