private bool FindUIElements(DictResult dictResult, out ListBox listBox, out TabItem tabItem, out string engineName) { bool hasFound = false; switch (dictResult.DictionaryType) { case DictionaryType.Dict_cn: { hasFound = true; listBox = _parent.DictcnOutputListBox; tabItem = _parent.DictcnTabItem; engineName = "Dictcn"; break; } default: { hasFound = false; listBox = null; tabItem = null; engineName = "Unknown"; break; } } return(hasFound); }
public DictResult GetDictcnResult(object sender) { DictResult dictResult = null; if (sender != null) { bool hasFound = FindDictcnResult(sender, out dictResult); } return(dictResult); }
private bool FindDictcnResult(object sender, out DictResult dictResult) { bool hasFound = false; DictResult result = null; if (sender is ListBox) { ListBox sourceListBox = sender as ListBox; hasFound = FindDictcnResult(_currentQueryResult, DictionaryType.Dict_cn, out result); } dictResult = result; return(hasFound); }
private void DictcnOutputListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { int index = DictcnOutputListBox.SelectedIndex; DictResult result = _resultHandler.GetDictcnResult(sender); //SearchEngineResult result = _resultHandler.GetSearchEngineResult( sender ); if (result != null && ((index & 1) == 0)) { string uri = string.Format("{0}", result.SearchUrl); Shell shell = new Shell(); shell.DoOpenWebBrowser(uri); } } }
public SmartMe.Core.Data.DictResult Parse(string html, Encoding encoding) { dictResult = new DictResult(); HTMLparser oP = HtmlParserFactory.GetInstance(); dictResult.DictionaryType = DictionaryType.Dict_cn; oP.Init(encoding.GetBytes(html)); oP.SetEncoding(encoding); HTMLchunk oChunk = null; int state = 0; bool bEncodingSet = false; while ((oChunk = oP.ParseNext()) != null) { switch (oChunk.oType) { case HTMLchunkType.OpenTag: HandleOpenTag(oChunk, ref state); printParams: if (oChunk.sTag == "meta") { HandleMetaEncoding(oP, oChunk, ref bEncodingSet); } ; HandleParam(oChunk, ref state); break; case HTMLchunkType.CloseTag: HandleCloseTag(oChunk, ref state); break; case HTMLchunkType.Text: HandleText(oChunk, ref state); break; default: break; } } return(dictResult); }
/// <summary> /// 查询单词翻译结果 /// </summary> /// <param name="context"></param> /// <param name="word"></param> /// <param name="isChinese"></param> /// <param name="part"></param> /// <param name="extendQuery"></param> private static void Query(DataContext context, string word, bool isChinese, DictQuery.ResultPart part, bool extendQuery) { DictRecord dictRecord = MaterialBiz.GetDictRecord(word, isChinese); #region 查询有结果 if (null != dictRecord) { DictResultBasic resultBase = new DictResultBasic { Text = dictRecord.Word.Trim(), PhonicsEn = dictRecord.PhonicsEn.Trim(), PhonicsUs = dictRecord.PhonicsUs.Trim(), AudioEn = dictRecord.AudioEn.Trim().ImageUrlFixed(), AudioUs = dictRecord.AudioUs.Trim().ImageUrlFixed(), Meaning = new List <DictResultPackage>(0), Explication = new List <DictResultPackage>(0), Example = new List <DictResultPackage>(0) }; if ((part == DictQuery.ResultPart.All || part == DictQuery.ResultPart.Meaning) && dictRecord.TransBase != null && dictRecord.TransBase.Length > 0) { resultBase.Meaning = dictRecord.TransBase.ProtoBufDeserialize <List <DictResultPackage> >(); } if ((part == DictQuery.ResultPart.All || part == DictQuery.ResultPart.Explication) && dictRecord.Explication != null && dictRecord.Explication.Length > 0) { resultBase.Explication = dictRecord.Explication.ProtoBufDeserialize <List <DictResultPackage> >(); } if ((part == DictQuery.ResultPart.All || part == DictQuery.ResultPart.Example) && dictRecord.Example != null && dictRecord.Example.Length > 0) { resultBase.Example = dictRecord.Example.ProtoBufDeserialize <List <DictResultPackage> >(); } DictResult result = new DictResult { Basic = resultBase }; context.Flush <DictResult>(result); return; } #endregion #region 查询无结果,需要联想查询 if (extendQuery) { if (isChinese) { #region 中文查询 //分词 List <string> wordList = word.Participle(isChinese).ToList(); if (wordList.Count > 0) { List <DictRecord> extendWords = MaterialBiz.DictC2eExtendQuery(wordList, 20).ToList(); DictResult extendResult = GetExtendDictResult(extendWords); if (null != extendResult) { context.Flush <DictResult>(extendResult); return; } } #endregion } else { #region 英文查询 List <string> wordList = new List <string>(0); if (!word.IsFullEnglish()) { wordList = word.Participle(isChinese).ToList(); } else { wordList = new List <string> { word } }; if (wordList.Count > 0) { List <DictRecord> extendWords = MaterialBiz.DictE2cExtendQueryWithWords(wordList, 20).ToList(); if (extendWords.Count > 0) { DictResult extendResult = GetExtendDictResult(extendWords); if (null != extendResult) { context.Flush <DictResult>(extendResult); return; } } } #endregion } } #endregion #region 查询无结果,并且无需联想查询 context.Flush(); return; #endregion }
private bool FindDictcnResult(QueryResult queryResult, DictionaryType targetType, out DictResult dictResult) { bool hasFound = false; dictResult = null; if (queryResult != null) { if (queryResult.DictResultItems != null) { foreach (DictResult resultItem in queryResult.DictResultItems) { if (resultItem != null && resultItem.DictionaryType == targetType) { dictResult = resultItem; hasFound = true; break; } } } } return(hasFound); }