public static List <Result1> GetData(int languageId)
        {
            EnglishWords3Entities entity = new EnglishWords3Entities();

            entity.Database.CommandTimeout = int.MaxValue;

            List <Result1> allData = new List <Result1>();

            Console.WriteLine("Fetching before lock Data...");
            lock (ob1)
            {
                Console.WriteLine("Fetching Data...");
                allData = (from f in entity.AllWordFromPaymons
                           join t in entity.WordTranslates on f.ID equals t.WordID
                           where t.LanguageId == languageId &&
                           t.Proccessed == null       //f.IsPrimary == true && t.LanguageId == lan.ID
                           orderby f.Word

                           select new Result1
                {
                    WordId = t.WordID,
                    LanId = t.LanguageId,
                    Word = f.Word,
                    AllData = t.AllData,
                    First = "",
                }).Take(10000).ToList();
            }
            Console.WriteLine("Fetched Data");
            return(allData);
        }
        public static void ProcessAll()
        {
            Console.Clear();
            Console.WriteLine("Start ProcessAll");
            EnglishWords3Entities entity = new EnglishWords3Entities();
            var langauages = entity.WordTranslates.Where(x => x.Proccessed == null).Select(x => (int?)x.LanguageId).Distinct()
                             .Take(1).FirstOrDefault();
            List <Task> taskList = new List <Task>();

            if (!langauages.HasValue)
            {
                return;
            }
            var dataList = GetData(langauages.Value);
            var count    = dataList.Count / 10;

            for (var id = 0; id < 10; id++)
            {
                var forLast = dataList.Count - (id * count);
                var range   = dataList.GetRange(count * id,
                                                id + 1 == 10 ? forLast : count);
                Console.WriteLine("Start Thread " + id + $" List: {range.Count}");
                taskList.Add(Task.Factory.StartNew(() => ProcessTranslateFiles(langauages.Value, range)));
            }
            Task.WaitAll(taskList.ToArray());
            ProcessAll();
        }
        public static void ImportWords()
        {
            var wordText = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "\\Import_Word.txt");
            var words    = wordText.Split(new char[] { ',', '\"', ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            var lists    = words.Select(x => new AllWordFromPaymon
            {
                Word = x.Trim(),
            }).Where(x => !string.IsNullOrEmpty(x.Word)).ToList();

            Console.WriteLine("Intering..");
            var entity = new EnglishWords3Entities();

            entity.BulkInsert(lists);
            Console.WriteLine("Inserted");
        }
Пример #4
0
        public static void ConvertToSQL2()
        {
            var path = Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\JsonFileMerged");


            var pathSQL = AppDomain.CurrentDomain.BaseDirectory + "\\" + "InsertTranslated2.sql";

            File.Delete(pathSQL);
            Console.WriteLine("Gettting");

            EnglishWords3Entities entity = new EnglishWords3Entities();

            var data = (from f in entity.AllWordFromPaymons
                        join t in entity.WordTranslates on f.ID equals t.WordID
                        join l in entity.Languages on t.LanguageId equals l.ID
                        orderby l.LanguageCode
                        select new {
                f.Word,
                t.AllWords,
                l.LanguageCode
            }).ToList();


            Console.WriteLine("Geted");



            List <string> codes   = new List <string>();
            string        lastLan = "";

            foreach (var f in data)
            {
                var d = $"\r\nINSERT INTO [dbo].[Translations] ([Word] ,[Language] ,[Meaning]) VALUES " +
                        $"('{f.Word.Replace("'", "''")}','{f.LanguageCode}',N'{f.AllWords.Replace("'", "''")}')";


                File.AppendAllText(pathSQL, d);

                if (lastLan != f.LanguageCode)
                {
                    Console.WriteLine("Code " + f.LanguageCode + " finished");
                }

                lastLan = f.LanguageCode;
            }
        }
Пример #5
0
 public ResourceService3()
 {
     entity = new EnglishWords3Entities();
 }
        private static void ProcessTranslateFiles(int languageId, List <Result1> allData)
        {
            EnglishWords3Entities entity = new EnglishWords3Entities();

            entity.Database.CommandTimeout = int.MaxValue;
            Console.WriteLine("Processing...");

            foreach (var result1 in allData)
            {
                var dicAll = new List <string>();

                var objectT = JsonConvert.DeserializeObject <CallBankService>(result1.AllData);
                var body    = JsonConvert.DeserializeObject <JArray>(objectT.Raw);

                if (body.Count > 0)
                {
                    var first = body.First <JToken>();
                    var item  = first.FirstOrDefault();
                    if (item != null)
                    {
                        result1.Verified = item[4].Value <int>() == 1;
                        result1.First    = item[0].Value <string>();
                    }
                }


                if (body.Count > 5 && body[5].HasValues && !result1.Verified)
                {
                    var item = body[5].FirstOrDefault();
                    if (item != null && item[3].HasValues && item[2].HasValues && item[3].Any())
                    {
                        var googleWord = item[0].Value <string>().ToLower();
                        var myword     = result1.Word.ToLower();
                        if (googleWord != myword)
                        {
                            File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "\\DeffWords.txt",
                                               "\r\n" + myword + "\t" + googleWord);
                        }
                        var goodRank = item[3][0].Values <int>().Select((r, i) => new
                        {
                            Index = i,
                            Rank  = r,
                        }).OrderByDescending(x => x.Rank).FirstOrDefault();
                        if (goodRank != null)
                        {
                            if (item[2].Count() > goodRank.Index)
                            {
                                result1.First = item[2][goodRank.Index][0].Value <string>();
                            }
                            else
                            {
                                result1.First = item[2].FirstOrDefault()?[0].Value <string>();
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(result1.First) && result1.First.Length > 0)
                {
                    dicAll.Add(result1.First.Trim());
                }

                if (body.Count > 1 && body[1].HasValues)
                {
                    foreach (var v in body[1])
                    {
                        if (v.HasValues && v.Count() > 1)
                        {
                            var dic = v[1].Select(x => x.Value <string>()).ToList();
                            dicAll.AddRange(dic);
                        }
                    }
                }

                dicAll = dicAll.Distinct().ToList();
                var proceessd = dicAll.Aggregate((x, y) => x + ", " + y).Trim(' ', ',');

                entity.WordTranslates.Where(x => x.WordID == result1.WordId && x.LanguageId == result1.LanId)
                .UpdateFromQuery(x => new WordTranslate {
                    AllWords = proceessd, Translated = result1.First, Proccessed = true
                });

                Console.WriteLine($"Update {result1.WordId}\t{result1.LanId}\t{result1.Word}");
            }
        }