public ITrans GetTrans() { if (Trans.Strategy == Strategy) { return(Trans); } switch (Strategy) { case TransStrategy.Baidu: Trans = new BaiduTrans(); break; case TransStrategy.Tencent: Trans = new TencentTrans(); break; case TransStrategy.Google: Trans = new GoogleTrans(); break; case TransStrategy.Microsoft: Trans = new MicrosoftTrans(); break; case TransStrategy.Custom: Trans = new CustomTrans(); break; default: Trans = new BaiduTrans(); break; } return(Trans); }
public static void RefreshOldVersionInfo() { var Items = new Dictionary <string, LangMatrixRow>(); //SqlServerReg.Parse(Items, LangsDesignDirs.other + "sqlserver.reg", LangsDesignDirs.other + "sqlserver-clsids.reg"); //SqlServerQuery.Parse(Items, LangsDesignDirs.other + "sqlserver.query"); //ByHand.Parse(Items, LangsDesignDirs.other + "by-hand.xml"); GoogleTrans.Parse(Items); //SpellCheck.Parse(Items); foreach (var kv in Items) { var ci = CultureInfo.GetCultureInfo(kv.Value.lang); var lcid = ci.LCID; if (lcid != 4096) { kv.Value.row[6] = lcid.ToString(); } kv.Value.row[9] = ci.EnglishName; } var fullText = new LangMatrix( Items.Select(kv => kv.Value) ); fullText.save(LangsDesignDirs.otherappdata + "oldVersionInfo.csv"); var wrongs = LangMatrix.readLangs(LangsDesignDirs.otherappdata + "oldVersionInfo.csv").Where(l => !Langs.nameToMeta.ContainsKey(l)).ToArray(); if (wrongs.Length > 1) // "", LCID 127 { throw new Exception(); } }
public async Task <string> googleTranslator(string contain) { GoogleTrans googleTransJson = new GoogleTrans(); googleTransJson = await _clientDictionaryService.startGoogleTrans(contain); return(googleTransJson.sentences[0].trans); }
//Google detail translator //Google translator public async Task <GoogleTrans> startGoogleDetailTrans(string voca) { string result = ""; var url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=vi&hl=vi&dt=t&dt=bd&dj=1&source=icon&tk=827698.827698&q=" + voca; var webRequest = WebRequest.Create(url); using (var response = webRequest.GetResponse()) using (var content = response.GetResponseStream()) using (var reader = new StreamReader(content)) { result = reader.ReadToEnd(); } GoogleTrans googleTransJson = JsonConvert.DeserializeObject <GoogleTrans>(result); return(googleTransJson); }
public async Task <string> searchDictViaBot(string contain, string id = "1554844547918927", string userid = null) { bool multiLetters = false; contain = contain.ToString().ToLower().Trim(); //Tim trong cache nếu ko có thì request crawler var dictTemp = _dictCache.findWordCache(contain); //post // bool isSaveCached = true; DictCache cacheDict = new DictCache(); OxfordDict dict = new OxfordDict(); GoogleTrans googleTransJson = new GoogleTrans(); GoogleTrans detailVietnamese = new GoogleTrans(); //Explain main of letter MessJson messExplaintion = new MessJson(); //Pron MessJson messPron = new MessJson(); //Vietnamese MessJson messVietnamese = new MessJson(); // ChatfuelJson hello = new ChatfuelJson(); AttachmentJson sound = new AttachmentJson(); sound.attachment.type = "audio"; Attachment2 attach = new Attachment2(); //Json is returned Customer AttachmentJson soundDic = new AttachmentJson(); MessJson messExplaintionDict = new MessJson(); MessJson resultGoogle = new MessJson(); // JsonMessengerText jsonTextMessenger = new JsonMessengerText(); jsonTextMessenger.recipient.id = id; JsonMessengerText jsonSoundMessenger = new JsonMessengerText(); jsonSoundMessenger.recipient.id = id; messExplaintionDict.text += "*" + ToTitleCase(contain) + "*"; Payload2 payload = new Payload2(); // if (dictTemp != null) { messPron.text = dictTemp.Pron; messExplaintion.text = dictTemp.MeanEn; messVietnamese.text = dictTemp.MeanVi; sound.attachment.payload.url = dictTemp.SoundUrl; // messExplaintionDict.text += "\r\n" + dictTemp.Pron; messExplaintionDict.text += "\r\n" + dictTemp.MeanEn; messExplaintionDict.text += "\r\n" + dictTemp.MeanVi; soundDic.attachment.payload.url = dictTemp.SoundUrl; } else { int size = contain.Split(' ').Length; if (size > 1) { multiLetters = true; googleTransJson = await _clientDictionaryService.startGoogleTrans(contain); foreach (var sentence in googleTransJson.sentences) { messExplaintion.text += sentence.trans; resultGoogle.text += sentence.trans; } // resultGoogle.text = googleTransJson.sentences[0].trans; //messExplaintionDict.text +="\r\n" + googleTransJson.sentences[0].trans; } else { try { dict = await _clientDictionaryService.startCrawlerOxford(contain); messPron.text = dict.m_Pron; messExplaintion.text = dict.m_Explanation.First().m_UseCase; // messExplaintionDict.text += "\r\n" + dict.m_Pron; messExplaintionDict.text += "\r\n" + dict.m_Explanation.First().m_UseCase; } catch { isSaveCached = false; messExplaintion.text = contain; messExplaintionDict.text += "\r\n" + contain; } try { detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(contain); } catch { detailVietnamese = null; } try { messVietnamese.text = detailVietnamese.dict.First().pos + ": "; foreach (var item in detailVietnamese.dict.First().terms) { messVietnamese.text += item + ", "; } messExplaintionDict.text += "\r\n" + messVietnamese.text; } catch { isSaveCached = false; messVietnamese.text = detailVietnamese.sentences.FirstOrDefault().trans; messExplaintionDict.text += "\r\n" + detailVietnamese.sentences.FirstOrDefault().trans; } } sound.attachment.payload.url = dict.m_SoundUrl; soundDic.attachment.payload.url = dict.m_SoundUrl; //Add database cacheDict = new DictCache(); cacheDict.VocaID = contain; cacheDict.Pron = messPron.text; cacheDict.MeanEn = messExplaintion.text; cacheDict.MeanVi = messVietnamese.text; cacheDict.SoundUrl = dict.m_SoundUrl; _dictCache.Add(cacheDict); if (isSaveCached) { _dictCache.Save(); } dictTemp = cacheDict; } //DetailOurWord detailWord = _detailOutWordService.findDetailOurWord(userid, dictTemp.Id); //if (detailWord == null) //{ // hello.Selected = false; //} //else //{ // hello.Selected = true; //} hello.messages.Add(messPron); hello.messages.Add(messVietnamese); hello.messages.Add(messExplaintion); hello.messages.Add(sound); try { hello.strVoca = ToTitleCase(contain); ApplicationUser currentUser = _service.listUserID().Where(x => x.Id_Messenger == id).FirstOrDefault(); NotificationHub.sendNoti(currentUser.Email, JsonConvert.SerializeObject(hello)); } catch { } if (multiLetters) { jsonTextMessenger.message = messExplaintionDict; jsonSoundMessenger.message = resultGoogle; PostRaw("", JsonConvert.SerializeObject(jsonTextMessenger)); PostRaw("", JsonConvert.SerializeObject(jsonSoundMessenger)); return(""); } jsonTextMessenger.message = messExplaintionDict; jsonSoundMessenger.message = soundDic; PostRaw("", JsonConvert.SerializeObject(jsonTextMessenger)); PostRaw("", JsonConvert.SerializeObject(jsonSoundMessenger)); return(JsonConvert.SerializeObject(hello)); }
public async Task <string> getDictToExtension(string contain) { bool isVN = false; string userid = User.Identity.GetUserId(); contain = contain.ToString().ToLower().Trim(); DictCache dictTemp = new DictCache(); //Tim trong cache nếu ko có thì request crawler try { dictTemp = _dictCache.findWordCache(contain); } catch (Exception e) { } //post // bool isSaveCached = true; DictCache cacheDict; OxfordDict dict = new OxfordDict(); GoogleTrans googleTransJson = new GoogleTrans(); GoogleTrans detailVietnamese = new GoogleTrans(); //Explain main of letter MessJson messExplaintion = new MessJson(); //Pron MessJson messPron = new MessJson(); //Vietnamese MessJson messVietnamese = new MessJson(); // ChatfuelJson hello = new ChatfuelJson(); AttachmentJson sound = new AttachmentJson(); sound.attachment.type = "audio"; Attachment2 attach = new Attachment2(); if (contain.LastOrDefault() == '.') { messPron.text = ""; hello.messages.Add(messPron); return(JsonConvert.SerializeObject(hello)); } Payload2 payload = new Payload2(); // if (dictTemp != null) { messPron.text = dictTemp.Pron; messExplaintion.text = dictTemp.MeanEn; messVietnamese.text = dictTemp.MeanVi; sound.attachment.payload.url = dictTemp.SoundUrl; } else { int size = contain.Split(' ').Length; if (size > 1) { isSaveCached = false; googleTransJson = await _clientDictionaryService.startGoogleTrans(contain); hello.strVietnamese = googleTransJson.src; if (googleTransJson.src == "vi") { isVN = true; } messExplaintion.text = googleTransJson.sentences[0].trans; } else { try { dict = await _clientDictionaryService.startCrawlerOxford(contain); messPron.text = dict.m_Pron; messExplaintion.text = dict.m_Explanation.First().m_UseCase; } catch { isSaveCached = false; messExplaintion.text = contain; } detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(contain); hello.strVietnamese = detailVietnamese.src; if (detailVietnamese.src == "vi") { isVN = true; } try { messVietnamese.text = detailVietnamese.dict.First().pos + ": "; foreach (var item in detailVietnamese.dict.First().terms) { messVietnamese.text += item + ", "; } } catch { isSaveCached = false; messVietnamese.text = detailVietnamese.sentences.FirstOrDefault().trans; } } sound.attachment.payload.url = dict.m_SoundUrl; //Add database cacheDict = new DictCache(); cacheDict.VocaID = contain; cacheDict.Pron = messPron.text; cacheDict.MeanEn = messExplaintion.text; cacheDict.MeanVi = messVietnamese.text; cacheDict.SoundUrl = dict.m_SoundUrl; _dictCache.Add(cacheDict); if (isSaveCached) { _dictCache.Save(); } dictTemp = cacheDict; } DetailOurWord detailWord = _detailOutWordService.findDetailOurWord(userid, dictTemp.Id); if (detailWord == null) { hello.Selected = false; } else { hello.Selected = true; } hello.messages.Add(messPron); hello.messages.Add(messVietnamese); hello.messages.Add(messExplaintion); hello.messages.Add(sound); if (isVN) { return(null); } return(JsonConvert.SerializeObject(hello)); }
public async Task <string> callChatBot(string contain, string id, string userid) { contain = contain.ToString().ToLower().Trim(); //Tim trong cache nếu ko có thì request crawler var dictTemp = _dictCache.findWordCache(contain); //post // bool isSaveCached = true; DictCache cacheDict = new DictCache(); OxfordDict dict = new OxfordDict(); GoogleTrans googleTransJson = new GoogleTrans(); GoogleTrans detailVietnamese = new GoogleTrans(); //Explain main of letter MessJson messExplaintion = new MessJson(); //Pron MessJson messPron = new MessJson(); //Vietnamese MessJson messVietnamese = new MessJson(); // ChatfuelJson hello = new ChatfuelJson(); AttachmentJson sound = new AttachmentJson(); sound.attachment.type = "audio"; Attachment2 attach = new Attachment2(); if (contain.LastOrDefault() == '.') { messPron.text = ""; hello.messages.Add(messPron); return(JsonConvert.SerializeObject(hello)); } Payload2 payload = new Payload2(); // if (dictTemp != null) { messPron.text = dictTemp.Pron; messExplaintion.text = dictTemp.MeanEn; messVietnamese.text = dictTemp.MeanVi; sound.attachment.payload.url = dictTemp.SoundUrl; } else { int size = contain.Split(' ').Length; if (size > 1) { googleTransJson = await _clientDictionaryService.startGoogleTrans(contain); messExplaintion.text = googleTransJson.sentences[0].trans; } else { try { dict = await _clientDictionaryService.startCrawlerOxford(contain); messPron.text = dict.m_Pron; messExplaintion.text = dict.m_Explanation.First().m_UseCase; } catch { isSaveCached = false; messExplaintion.text = contain; } detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(contain); try { messVietnamese.text = detailVietnamese.dict.First().pos + ": "; foreach (var item in detailVietnamese.dict.First().terms) { messVietnamese.text += item + ", "; } } catch { isSaveCached = false; messVietnamese.text = detailVietnamese.sentences.FirstOrDefault().trans; } } sound.attachment.payload.url = dict.m_SoundUrl; //Add database cacheDict = new DictCache(); cacheDict.VocaID = contain; cacheDict.Pron = messPron.text; cacheDict.MeanEn = messExplaintion.text; cacheDict.MeanVi = messVietnamese.text; cacheDict.SoundUrl = dict.m_SoundUrl; _dictCache.Add(cacheDict); if (isSaveCached) { _dictCache.Save(); } dictTemp = cacheDict; } DetailOurWord detailWord = _detailOutWordService.findDetailOurWord(userid, dictTemp.Id); if (detailWord == null) { hello.Selected = false; } else { hello.Selected = true; } hello.messages.Add(messPron); hello.messages.Add(messVietnamese); hello.messages.Add(messExplaintion); hello.messages.Add(sound); try { hello.strVoca = ToTitleCase(contain); ApplicationUser currentUser = _service.listUserID().Where(x => x.Id_Messenger == id).FirstOrDefault(); NotificationHub.sendNoti(currentUser.Email, JsonConvert.SerializeObject(hello)); } catch { } return(JsonConvert.SerializeObject(hello)); }
public async Task <PartialViewResult> Dictionaries(string keyword) { bool isVN = false; OxfordDict dict = new OxfordDict(); GoogleTrans googleTransJson = new GoogleTrans(); keyword = keyword.Trim(); _viewModel = new DictionariesViewModel(); bool downloadSucceeded = false; if (keyword != "") { int size = keyword.Split(' ').Length; if (size > 1) { googleTransJson = await _clientDictionaryService.startGoogleTrans(keyword); DictionariesViewModel.isGoogleTrans = true; DictionariesViewModel.m_GoogleTrans = googleTransJson; } else { try { dict = await _clientDictionaryService.startCrawlerOxford(keyword); downloadSucceeded = true; } catch (Exception e) { downloadSucceeded = false; } if (!downloadSucceeded) { googleTransJson = await _clientDictionaryService.startGoogleTrans(keyword); if (googleTransJson.src == "vi") { isVN = true; } DictionariesViewModel.isGoogleTrans = true; DictionariesViewModel.m_GoogleTrans = googleTransJson; } try { GoogleTrans detailVietnamese = new GoogleTrans(); detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(keyword); if (detailVietnamese.src == "vi") { isVN = true; } string meanVN = detailVietnamese.dict.First().pos + ": "; foreach (var item in detailVietnamese.dict.First().terms) { meanVN += item + ", "; } DictionariesViewModel.m_MeanVn = meanVN; } catch { } DictionariesViewModel.m_Explanation = dict.m_Explanation; DictionariesViewModel.m_SoundUrl = dict.m_SoundUrl; DictionariesViewModel.m_Type = dict.m_Type; DictionariesViewModel.m_Voca = dict.m_Voca; DictionariesViewModel.m_Pron = dict.m_Pron.Replace("BrE", ""); } DictionariesViewModel.m_ExaTraCau = await _clientDictionaryService.startCrawlerTraCau(keyword); } try { DictCache dictCache = _dictCache.findWordCache(keyword); if (dictCache == null) { dictCache = new DictCache(); dictCache.VocaID = keyword; dictCache.Pron = DictionariesViewModel.m_Pron; dictCache.MeanEn = DictionariesViewModel.m_Explanation.FirstOrDefault().m_UseCase; dictCache.MeanVi = DictionariesViewModel.m_MeanVn; dictCache.SoundUrl = DictionariesViewModel.m_SoundUrl; _dictCache.Add(dictCache); _dictCache.Save(); } else { if (_detailOutWordService.findDetailOurWord(User.Identity.GetUserId(), dictCache.Id) != null) { DictionariesViewModel.love = true; } } } catch (Exception e) { } return(PartialView("_Dictionaries", DictionariesViewModel)); }