Ejemplo n.º 1
0
        //public List<string> GetRealPath(IList<string> filePathes)
        //{
        //    var list = new List<string>();

        //    filePathes.ToList().ForEach(x =>
        //    {
        //        var dic = Path.GetDirectoryName(x);
        //        var filen = Path.GetFileName(x);
        //        if (filen.Contains("*"))
        //        {
        //            var files = Directory.GetFiles(dic, filen, SearchOption.AllDirectories);
        //            list.AddRange(files);
        //        }
        //        else
        //        {
        //            list.Add(x);
        //        }

        //    });


        //    return list;
        //}

        /// <summary>
        /// 转换多个文件成一个文件
        /// </summary>
        /// <param name="filePathes"></param>
        /// <returns></returns>
        public string Convert(IList <string> filePathes)
        {
            this.timer.Start();
            ExportContents = new List <string>();
            allWlList.Clear();
            isImportProgress = true;

            //filePathes = GetRealPath(filePathes);

            foreach (string file in filePathes)
            {
                if (FileOperationHelper.GetFileSize(file) == 0)
                {
                    ProcessNotice("词库(" + Path.GetFileName(file) + ")为空,请检查");
                    continue;
                }
                Debug.WriteLine("start process file:" + file);
                try
                {
                    WordLibraryList wlList = import.Import(file);
                    wlList = Filter(wlList);
                    allWlList.AddRange(wlList);
                }
                catch (Exception ex)
                {
                    ProcessNotice("词库(" + Path.GetFileName(file) + ")处理出现异常:" + ex.Message);
                }
            }
            isImportProgress = false;
            if (selectedTranslate != ChineseTranslate.NotTrans)
            {
                ProcessNotice("开始繁简转换...");

                allWlList = ConvertChinese(allWlList);
            }
            if (export.CodeType != CodeType.NoCode)
            {
                ProcessNotice("开始生成词频...");
                GenerateWordRank(allWlList);
            }
            if (import.CodeType != export.CodeType)
            {
                ProcessNotice("开始生成目标编码...");

                GenerateDestinationCode(allWlList, export.CodeType);
            }
            if (export.CodeType != CodeType.NoCode)
            {
                allWlList = RemoveEmptyCodeData(allWlList);
            }
            count = allWlList.Count;

            ReplaceAfterCode(allWlList);
            //Sort
            //var wlDict = new Dictionary<string, WordLibrary>();
            //var sorted = allWlList.Distinct().OrderBy(w => w.PinYinString).ToList();
            //allWlList = new WordLibraryList();
            //foreach (var wl in sorted)
            //{
            //    if (!wlDict.ContainsKey(wl.Word))
            //    {
            //        wlDict.Add(wl.Word, wl);
            //        allWlList.Add(wl);
            //    }
            //}
            ExportContents = export.Export(allWlList);

            this.timer.Stop();

            return(string.Join("\r\n", ExportContents.ToArray()));
        }