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

            filePathes = GetRealPath(filePathes);

            foreach (string file in filePathes)
            {
                WordLibraryList wlList = import.Import(file);
                wlList = Filter(wlList);
                allWlList.AddRange(wlList);
            }
            isImportProgress = false;
            if (selectedTranslate != ChineseTranslate.NotTrans)
            {
                allWlList = ConvertChinese(allWlList);
            }
            GenerateWordRank(allWlList);
            if (import.CodeType != export.CodeType)
            {
                GenerateDestinationCode(allWlList, export.CodeType);
            }
            count = allWlList.Count;
            if (export.CodeType != CodeType.NoCode)
            {
                allWlList = RemoveEmptyCodeData(allWlList);
            }
            ExportContents = export.Export(allWlList);
            return(string.Join("\r\n", ExportContents.ToArray()));
        }
Exemplo n.º 2
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)
            {
                WordLibraryList wlList = import.Import(file);
                wlList = Filter(wlList);
                allWlList.AddRange(wlList);
            }
            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()));
        }
Exemplo n.º 3
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)
            {
                WordLibraryList wlList = import.Import(file);
                wlList = Filter(wlList);
                allWlList.AddRange(wlList);
            }
            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);
            ExportContents = export.Export(allWlList);
            this.timer.Stop();
            return(string.Join("\r\n", ExportContents.ToArray()));
        }
Exemplo n.º 4
0
 /// <summary>
 /// 转换多个文件成一个文件
 /// </summary>
 /// <param name="filePathes"></param>
 /// <returns></returns>
 public string Convert(IList <string> filePathes)
 {
     allWlList.Clear();
     isImportProgress = true;
     foreach (string file in filePathes)
     {
         WordLibraryList wlList = import.Import(file);
         wlList = Filter(wlList);
         allWlList.AddRange(wlList);
     }
     isImportProgress = false;
     if (selectedTranslate != ChineseTranslate.NotTrans)
     {
         allWlList = ConvertChinese(allWlList);
     }
     GenerateWordRank(allWlList);
     if (import.CodeType != export.CodeType)
     {
         GenerateDestinationCode(allWlList, export.CodeType);
     }
     count = allWlList.Count;
     return(export.Export(RemoveEmptyCodeData(allWlList)));
 }
Exemplo n.º 5
0
 public string Convert(IList <string> filePathes)
 {
     foreach (string file in filePathes)
     {
         WordLibraryList wlList = import.Import(file);
         wlList = Filter(wlList);
         allWlList.AddRange(wlList);
     }
     if (selectedTranslate != ChineseTranslate.NotTrans)
     {
         allWlList = ConvertChinese(allWlList);
     }
     count = allWlList.Count;
     return(export.Export(allWlList));
 }
Exemplo n.º 6
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)
        {
            var allWlList = new WordLibraryList();

            this.timer.Start();
            ExportContents   = new List <string>();
            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) + ")处理出现异常:\n\t" + ex.Message);
                    isImportProgress = false;
                    this.timer.Stop();
                    return("");
                }
            }
            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()));
        }