protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string[] responses = UlifHelper.GetPhrasesPages(phrase, networkSetting);
            if (responses.Length == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            foreach (string str in responses)
            {
                string responseFromServer = str;
                responseFromServer = StringParser.Parse("<div class=\"p_cl\">", "</div>", responseFromServer);
                responseFromServer = StringParser.RemoveAll("<A ondblclick", ">", responseFromServer);
                responseFromServer = responseFromServer.Replace("</A>", "");
                responseFromServer = responseFromServer.Replace("<B>", "");
                responseFromServer = responseFromServer.Replace("</B>", "");
                responseFromServer = responseFromServer.Replace("<I>", "");
                responseFromServer = responseFromServer.Replace("</I>", "");
                StringParser parser       = new StringParser(responseFromServer);
                string[]     translations = parser.ReadItemsList("<P>", "</P>", "3495783-4572385");

                foreach (string subtranslation in translations)
                {
                    Result subres = CreateNewResult("", languagesPair, subject);
                    result.Childs.Add(subres);
                    subres.Translations.Add(subtranslation);
                }
            }
        }
Beispiel #2
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://openthesaurus.caixamagica.pt/suggestions.php?word={0}&search=1";

            query = string.Format(CultureInfo.InvariantCulture, query,
                                  HttpUtility.UrlEncode(phrase, encoding)
                                  );

            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet, encoding);


            string responseFromServer = helper.GetResponse();

            string[] translations = StringParser.ParseItemsList("<li>", "</li>", responseFromServer);

            if (translations.Length == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string subtranslation;

            foreach (string translation in translations)
            {
                subtranslation = StringParser.RemoveAll("<", ">", translation);
                result.Translations.Add(subtranslation);
            }
        }
Beispiel #3
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            Encoding         encoding = Encoding.GetEncoding("iso-8859-1");
            string           query    = "http://wordnetweb.princeton.edu/perl/webwn?s=" + HttpUtility.UrlEncode(phrase, encoding);
            WebRequestHelper helper   =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet, encoding);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("<h3>Your search did not return any results.</h3>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }


            if (responseFromServer.Contains("<h3>Sorry(?) your search can only contain letters(?)"))
            {
                throw new TranslationException("Query contains extraneous symbols");
            }

            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            string[] nodes = StringParser.ParseItemsList("<h3>", "</ul>", responseFromServer);

            bool   first = true;
            string nodename;

            Result child = result;

            string[] subnodes;
            string   translation;

            foreach (string node in nodes)
            {
                nodename = StringParser.ExtractLeft("</h3>", node);
                if (first && nodes.Length == 1)
                {
                    child.Abbreviation = nodename;
                }
                else
                {
                    child = new Result(result.ServiceItem, nodename, result.LanguagePair, result.Subject);
                    result.Childs.Add(child);
                }

                first = false;

                subnodes = StringParser.ParseItemsList("<li>", "</li>", node);
                foreach (string subnode in subnodes)
                {
                    translation = StringParser.RemoveAll("<", ">", subnode);
                    translation = StringParser.ExtractRight(")", translation);
                    child.Translations.Add(translation);
                }
            }
        }
Beispiel #4
0
        public static void SetResult(Result result, string responseFromServer)
        {
            string[] translations = StringParser.ParseItemsList("<li class=\"synsetlist\">", "</li>", responseFromServer);

            if (translations.Length == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string subtranslation;

            foreach (string translation in translations)
            {
                subtranslation = StringParser.RemoveAll("<", ">", translation);
                result.Translations.Add(subtranslation);
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://sa.dir.bg/cgi/sabig.cgi?word={0}&translate=Translate&encin=windows-1251&encout=windows-1251";

            query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase, encoding));


            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            helper.Encoding = encoding;

            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            string responseFromServer = helper.GetResponse();
            string translation        = StringParser.Parse("<TD valign=\"top\" width=\"95%\">", "</TD>", responseFromServer);

            translation = StringParser.RemoveAll("<font", "</font>", translation);
            translation = "html!<p>" + translation.Replace("<BR><BR>", "<BR>") + "</p>";
            result.Translations.Add(translation);
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://dict.tu-chemnitz.de/dings.cgi?lang=en&service={0}&opterrors=0&optpro=0&query={1}&iservice=&dlink=self&comment=";
            query = string.Format(CultureInfo.InvariantCulture, query,
                ConvertLanguagesPair(languagesPair),
                HttpUtility.UrlEncode(phrase, encoding)
                );

            result.ArticleUrl = query;
            result.ArticleUrlCaption = phrase;

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                    networkSetting,
                    WebRequestContentType.UrlEncodedGet);
            helper.Encoding = encoding;

            string responseFromServer = helper.GetResponse();

            if(responseFromServer.Contains(">0 <span class=\"h\">similar</span> results for "))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string[] translations = StringParser.ParseItemsList("<td align=\"right\"><br", "</tr>", responseFromServer);

            if(translations.Length == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            if(responseFromServer.Contains("<td class=\"tip b \" width=\"45%\" align=\"left\" valign=\"top\">"))
            {
                string full_count = StringParser.Parse("<td class=\"tip b \" width=\"45%\" align=\"left\" valign=\"top\">", " ", responseFromServer);
                if(!string.IsNullOrEmpty(full_count))
                {
                    int count;
                    if(int.TryParse(full_count, out count))
                        result.MoreEntriesCount = count - translations.Length;
                }
            }

            string en_string, ge_string, en_url, ge_url;
            bool en_audio, ge_audio;
            Result child = result;
            string subphrase = "";
            foreach(string translation in translations)
            {
                string[] subtranslations = StringParser.ParseItemsList("<td class=\"", "</td>", translation);
                if(subtranslations.Length != 2)
                    throw new TranslationException("Can't found translations in string : " + translation);

                en_string = StringParser.ExtractRight(">", subtranslations[1]);
                if(en_string.Contains("<a href=\""))
                    en_url = StringParser.Parse("<a href=\"", "\"", en_string);
                else
                    en_url = "";
                en_audio = en_string.Contains("href=\"/dings.cgi?speak=");

                en_string = StringParser.RemoveAll("<", ">", en_string);

                ge_string = StringParser.ExtractRight(">", subtranslations[0]);
                if(ge_string.Contains("<a href=\""))
                    ge_url = StringParser.Parse("<a href=\"", "\"", ge_string);
                else
                    ge_url = "";
                ge_audio = ge_string.Contains("href=\"/dings.cgi?speak=");
                ge_string = StringParser.RemoveAll("<", ">", ge_string);

                if(languagesPair.From == Language.German)
                {
                    if(subphrase != ge_string)
                    {
                        child = new Result(result.ServiceItem, ge_string, result.LanguagePair, result.Subject);
                        subphrase = ge_string;
                        if(!string.IsNullOrEmpty(ge_url))
                            child.ArticleUrl = "http://dict.tu-chemnitz.de" + ge_url;
                        child.HasAudio = ge_audio;
                        result.Childs.Add(child);
                    }
                    child.Translations.Add(en_string);
                }
                else
                {
                    if(subphrase != en_string)
                    {
                        child = new Result(result.ServiceItem, en_string, result.LanguagePair, result.Subject);
                        subphrase = en_string;
                        if(!string.IsNullOrEmpty(en_url))
                            child.ArticleUrl = "http://dict.tu-chemnitz.de" + en_url;
                        child.HasAudio = en_audio;
                        result.Childs.Add(child);
                    }

                    child.Translations.Add(ge_string);
                }

            }
        }
        public string GetServiceTooltipText()
        {
            StringBuilder sb = new StringBuilder();

            string name = "";

            if (!string.IsNullOrEmpty(setting.ServiceItem.Description))
            {
                name = LangPack.TranslateString(setting.ServiceItem.Description) + " - ";
            }

            name += LangPack.TranslateString(setting.ServiceItem.Service.FullName);

            sb.AppendLine(name);
            sb.AppendLine(GetServiceItemType(setting.ServiceItem));

            string languagePair = LangPack.TranslateLanguage(Setting.LanguagePair.From) +
                                  "->" +
                                  LangPack.TranslateLanguage(Setting.LanguagePair.To);

            sb.AppendLine(languagePair);

            if (setting.Subject != SubjectConstants.Common)
            {
                sb.AppendLine(LangPack.TranslateString(setting.Subject));
            }

            if (setting.ServiceItem.CharsLimit != -1)
            {
                sb.AppendLine(string.Format(LangPack.TranslateString("Limit {0} : {1} characters"),
                                            "", setting.ServiceItem.CharsLimit));
            }

            if (setting.ServiceItem.LinesLimit != -1)
            {
                sb.AppendLine(string.Format(LangPack.TranslateString("Limit {0} : {1} lines"),
                                            "", setting.ServiceItem.LinesLimit));
            }

            if (setting.ServiceItem.WordsLimit != -1)
            {
                sb.AppendLine(string.Format(LangPack.TranslateString("Limit {0} : {1} words"),
                                            "", setting.ServiceItem.WordsLimit));
            }

            if (IsAsteriskMaskSupported || IsQuestionMaskSupported)
            {
                sb.Append(LangPack.TranslateString("Masks") + " : ");
                if (IsAsteriskMaskSupported)
                {
                    sb.Append("'*'");
                }

                if (IsAsteriskMaskSupported && IsQuestionMaskSupported)
                {
                    sb.Append(",");
                }

                if (IsQuestionMaskSupported)
                {
                    sb.Append("'?'");
                }
                sb.AppendLine();
            }

            sb.AppendLine("---");
            if (DisabledByUser)
            {
                sb.AppendLine(StringParser.RemoveAll("<", ">", LangPack.TranslateString("<b>Status</b> : Disabled")));
            }
            else if (Enabled)
            {
                sb.AppendLine(StringParser.RemoveAll("<", ">", LangPack.TranslateString("<b>Status</b> : Enabled")));
            }
            else
            {
                sb.Append(StringParser.RemoveAll("<", ">", LangPack.TranslateString("<b>Status</b> : Error")));
                sb.AppendLine(" - " + Error);
            }

            return(sb.ToString().Trim());
        }
Beispiel #8
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.google.com/dictionary?aq=f&langpair={1}&q={0}&hl=en";

            query = string.Format(query, HttpUtility.UrlEncode(phrase, System.Text.Encoding.UTF8), GoogleUtils.ConvertLanguagesPair(languagesPair));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("No dictionary translations were found for: <strong>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            if (responseFromServer.Contains("No dictionary definitions were found for: <strong>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            result.HasAudio    = responseFromServer.Contains("<object data=\"/dictionary/flash");
            responseFromServer = StringParser.Parse("<div class=\"dct-srch-otr\">", "<div class=\"dct-rt-sct\">", responseFromServer);

            //pronuncation
            if (responseFromServer.Contains("<span class=\"dct-tp\">/"))
            {
                string pronuncation = StringParser.Parse("<span class=\"dct-tp\">/", "/</span>", responseFromServer);
                pronuncation        = pronuncation.Trim();
                result.Abbreviation = pronuncation;
            }


            //translations
            //string translations = StringParser.Parse("<div class=\"dct-srch-rslt\">", "</div>", responseFromServer);



            string translations = "";

            //TODO: additional sences like in "water" - "water down" not supported

            if (responseFromServer.Contains("<div class=\"sen\">"))
            {
                translations = StringParser.Parse("<ul class=\"dct-e2\" id=\"pr-root\" >", "</ul>\n<div class=\"sen\">", responseFromServer);
            }
            else if (responseFromServer.Contains("<h3>Related phrases</h3>"))
            {
                translations = StringParser.Parse("<ul class=\"dct-e2\" id=\"pr-root\" >", "</ul>\n<h3>Related phrases</h3>", responseFromServer);
            }
            else if (responseFromServer.Contains("<h3>Web definitions</h3>"))
            {
                translations = StringParser.Parse("<ul class=\"dct-e2\" id=\"pr-root\" >", "</ul>\n<h3>Web definitions</h3>", responseFromServer);
            }
            else
            {
                translations = StringParser.Parse("<ul class=\"dct-e2\" id=\"pr-root\" >", "</ul>", responseFromServer);
            }


            StringParser  parser          = null;
            List <string> subtranslations = new List <string>();

            if (translations.Contains("<li class=\"dct-ec\""))
            {
                //"</li>\n</ul>\n</li>"
                parser = new StringParser(translations);
                string[] subtranslation_list = parser.ReadItemsList("<li class=\"dct-ec\"", "</li>\n</ul>\n</li>", "3485730457203");
                subtranslations.AddRange(subtranslation_list);
            }
            else if (translations.Contains("<div style=\"font-weight:bold\">Synonyms:</div>"))
            {
                Result synonyms_tr = CreateNewResult("Synonyms", languagesPair, subject);
                result.Childs.Add(synonyms_tr);

                string synonyms = StringParser.Parse("<div style=\"font-weight:bold\">Synonyms:</div>", "</div>", translations);
                parser = new StringParser(synonyms);
                string[] syn_group_list = parser.ReadItemsList("<li>", "</li>", "3485730457203");
                foreach (string syngroup in syn_group_list)
                {
                    string syn_group_name = StringParser.Parse("title=\"Part-of-speech\">", "</span>", syngroup);
                    Result syn_tr         = CreateNewResult(syn_group_name, languagesPair, subject);
                    synonyms_tr.Childs.Add(syn_tr);
                    parser = new StringParser(syngroup);
                    string[] syn_list = parser.ReadItemsList("<a", "</a>", "3485730457203");
                    foreach (string syn in syn_list)
                    {
                        string synonym = StringParser.ExtractRight(">", syn);
                        syn_tr.Translations.Add(synonym);
                    }
                }

                subtranslations.Add(translations);
            }
            else
            {
                subtranslations.Add(translations);
            }

            Result subres_tr  = result;
            Result sub2res_tr = null;
            Result sub3res_tr = null;
            string abbr_str;

            foreach (string subtranslation in subtranslations)
            {
                if (subtranslation.Contains("<div  class=\"dct-ec\">"))
                {
                    abbr_str  = StringParser.Parse("title=\"Part-of-speech\">", "</span>", subtranslation);
                    subres_tr = CreateNewResult(abbr_str, languagesPair, subject);
                    result.Childs.Add(subres_tr);
                }

                parser = new StringParser(subtranslation.Replace("<li class=\"dct-em\"", "<end><begin>") + "<end>");
                string[] subsubtranslation_list = parser.ReadItemsList("<begin>", "<end>", "3485730457203");

                foreach (string subsubtanslation in subsubtranslation_list)
                {
                    sub2res_tr = CreateNewResult("", languagesPair, subject);
                    subres_tr.Childs.Add(sub2res_tr);

                    if (subsubtanslation.Contains(">See also</span>"))
                    {
                        sub2res_tr.Translations.Add("See also");
                    }

                    StringParser parser2 = new StringParser(subsubtanslation.Replace("<span class=\"dct-tt\">", "<end><begin>") + "<end>");
                    string[]     sub3translation_list = parser2.ReadItemsList("<begin>", "<end>", "3485730457203");

                    foreach (string sub3tanslation in sub3translation_list)
                    {
                        string text_translation = "";
                        string text_abbr        = "";
                        if (sub3tanslation.Contains("<span"))
                        {
                            text_translation = StringParser.ExtractLeft("<span", sub3tanslation);
                            if (text_translation.Contains("</span"))
                            {
                                text_translation = StringParser.ExtractLeft("</span", text_translation);
                            }
                            text_abbr = StringParser.Parse("<span", "</span", sub3tanslation);
                            text_abbr = StringParser.ExtractRight(">", text_abbr);
                        }
                        else
                        {
                            text_translation = StringParser.ExtractLeft("</span>", sub3tanslation);
                        }

                        text_translation = StringParser.RemoveAll("<", ">", text_translation);

                        if (sub2res_tr.Translations.Count == 0)
                        {
                            sub2res_tr.Translations.Add(text_translation);
                            sub2res_tr.Abbreviation = text_abbr;
                        }
                        else
                        {
                            sub3res_tr = CreateNewResult("", languagesPair, subject);
                            sub3res_tr.Translations.Add(text_translation);
                            //sub3res_tr.Phrase = text_abbr;
                            sub2res_tr.Childs.Add(sub3res_tr);
                        }
                    }
                }
            }


            //related words
            if (responseFromServer.Contains("<h3>Related phrases</h3>"))
            {
                string related = StringParser.Parse("<ul class=\"rlt-snt\">", "</ul>", responseFromServer);
                if (!string.IsNullOrEmpty(related))
                {
                    parser = new StringParser(related);
                    string[] related_list = parser.ReadItemsList("<li>", "</li>");

                    foreach (string related_s in related_list)
                    {
                        string related_str = related_s.Replace("\n", "").Trim();
                        string subphrase   = StringParser.Parse("<div>", "</div>", related_str);
                        subphrase = StringParser.RemoveAll("<", ">", subphrase);
                        subphrase = subphrase.Replace("&nbsp", " ").Replace("\n", "").Trim();


                        string subphrasetrans = StringParser.ExtractRight("</div>", related_str);

                        subphrasetrans = StringParser.RemoveAll("<", ">", subphrasetrans);
                        subphrasetrans = subphrasetrans.Replace("&nbsp", " ").Replace("\n", "").Trim();

                        Result subres = CreateNewResult(subphrase, languagesPair, subject);
                        subres.Translations.Add(subphrasetrans);
                        result.Childs.Add(subres);
                    }
                }
            }

            //Web definitions
            if (responseFromServer.Contains("<h3>Web definitions</h3>"))
            {
                string related = StringParser.ExtractRight("<ul class=\"gls\">", responseFromServer);
                if (!string.IsNullOrEmpty(related))
                {
                    {
                        Result subres_wd = CreateNewResult(phrase, languagesPair, subject);
                        result.Childs.Add(subres_wd);

                        parser = new StringParser(related);
                        string[] related_list = parser.ReadItemsList("<li>", "</li>");

                        foreach (string related_s in related_list)
                        {
                            string related_str = related_s;
                            related_str = related_str.Replace("<br/>", "").Trim();
                            related_str = StringParser.RemoveAll("<", ">", related_str);
                            related_str = related_str.Replace("&nbsp", " ").Replace("\n", "").Trim();
                            subres_wd.Translations.Add(related_str);
                        }
                    }
                }
            }
        }
Beispiel #9
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //query = string.Format(query, HttpUtility.UrlEncode(phrase, Encoding.GetEncoding(1251)));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://r2u.org.ua/krym/krym_search.php"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);
            string query = "word_str={0}&type={1}";

            //types
            //"all" - all words
            //"rusb" - general rus words
            //"rus" - all rus words
            //"ukr" - ukr words without quotations
            //"ukrq" - all ukr words
            if (languagesPair.From == Language.Russian)
            {
                query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase), "rus");
            }
            else
            {
                query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase), "ukrq");
            }
            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("нічого не знайдено!</h3>") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.IndexOf("Запит сприймає лише кирилицю") >= 0 || responseFromServer.Contains("<br>Помилка: неправильні символи в запиті"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Only cyrillic characters supported");
            }
            else if (responseFromServer.IndexOf("українські літери в запиті по російських позиціях") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Ukrainian characters in russian query");
            }
            else if (responseFromServer.IndexOf("нічого не знайдено!</h4>") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                result.ArticleUrl        = "http://r2u.org.ua/krym/krym_search.php?" + query;
                result.ArticleUrlCaption = phrase;

                string translation = StringParser.Parse("<table class=\"main_tbl\">", "</table>", responseFromServer);
                translation = translation.Replace("</span>", "");
                translation = translation.Replace("<span class=\"KrymUkr\">", "");
                translation = translation.Replace("<span class=\"KrymRusBold\">", "");
                translation = translation.Replace("<span class=\"KrymRusItalic\">", "");
                translation = translation.Replace("<span class=\"KrymRusItalic\">", "");
                translation = translation.Replace("<span class=\"KrymUkAux\">", "");
                translation = translation.Replace("<span class=\"KrymLat\">", "");
                translation = StringParser.RemoveAll("<a href=\"?word_str=", "\">", translation);
                translation = StringParser.RemoveAll("<b title=\"", "</a></b>", translation);
                translation = translation.Replace("</a>", "");
                translation = translation.Replace("<u class=\"quote\">", "");
                translation = translation.Replace("</u>", "");
                translation = translation.Replace("<span class=\"num\">", "");



                StringParser parser       = new StringParser(translation);
                string[]     translations = parser.ReadItemsList("<tr><td class=\"result_row", "</td></tr>", "787654323");

                int    idx = 0;
                string subpart;
                string subphrase;
                foreach (string part in translations)
                {
                    subpart = part;
                    if (subpart.StartsWith("\">"))
                    {
                        subpart = subpart.Substring(2);
                    }
                    else
                    {
                        subpart = subpart.Substring(8);
                    }

                    int idxOfMinus = subpart.IndexOf("–");
                    if (idxOfMinus > 0)
                    {
                        subphrase = subpart.Substring(0, idxOfMinus).Trim();
                        subpart   = subpart.Substring(idxOfMinus + 1).Trim();
                    }
                    else
                    {
                        subphrase = subpart;
                        subpart   = "";
                    }

                    if (idx == 0 && string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) == 0 && translations.Length == 1)
                    {
                        //single answer
                        result.Translations.Add(subpart);
                        return;
                    }

                    Result subres = CreateNewResult(subphrase, languagesPair, subject);
                    subres.Translations.Add(subpart);
                    result.Childs.Add(subres);

                    idx++;
                }
            }
        }
Beispiel #10
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string responseFromServer = UlifHelper.GetAntonymsPage(phrase, networkSetting);

            if (string.IsNullOrEmpty(responseFromServer))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            responseFromServer = StringParser.Parse("<div class=\"p_cl\">", "</div>", responseFromServer);
            responseFromServer = StringParser.RemoveAll("<a ondblclick", ">", responseFromServer);
            responseFromServer = StringParser.RemoveAll("<font color", ">", responseFromServer);
            responseFromServer = StringParser.RemoveAll("<p align", ">", responseFromServer);


            responseFromServer = responseFromServer.Replace("</a>", "");
            responseFromServer = responseFromServer.Replace("<b>", "");
            responseFromServer = responseFromServer.Replace("</b>", "");
            responseFromServer = responseFromServer.Replace("<i>", "");
            responseFromServer = responseFromServer.Replace("</i>", "");
            responseFromServer = responseFromServer.Replace("◘", "");
            responseFromServer = responseFromServer.Replace("◊", "");
            responseFromServer = responseFromServer.Replace("○", "");
            responseFromServer = responseFromServer.Replace("□", "");
            responseFromServer = responseFromServer.Replace("</font>", "");
            responseFromServer = responseFromServer.Replace("</p>", "");


            StringParser parser = new StringParser(responseFromServer);

            string[] blocks = parser.ReadItemsList("<tr>", "</tr>", "3495783-4572385");

            Result subres;

            string left  = "";
            string right = "";

            if (blocks.Length > 0)
            {
                parser = new StringParser(blocks[0].ToLowerInvariant());
                string[] first_line = parser.ReadItemsList("<td>", "</td>", "3495783-4572385");
                result.Translations.Add(first_line[0] + " - " + first_line[1]);
                left  = first_line[0];
                right = first_line[1];
            }

            for (int i = 1; i < blocks.Length; i++)
            {
                if (blocks[i].Contains("<td>"))
                {
                    subres = CreateNewResult("html!<hr style=\"width: 100%; height: 1px;\">", languagesPair, subject);
                    result.Childs.Add(subres);

                    parser = new StringParser(blocks[i].ToLowerInvariant());
                    string[] second_line = parser.ReadItemsList("<td>", "</td>", "3495783-4572385");

                    subres = CreateNewResult(left, languagesPair, subject);
                    result.Childs.Add(subres);
                    subres.Translations.Add(second_line[0]);

                    subres = CreateNewResult(right, languagesPair, subject);
                    result.Childs.Add(subres);
                    subres.Translations.Add(second_line[1]);

                    subres = CreateNewResult("html!<hr style=\"width: 100%; height: 1px;\">", languagesPair, subject);
                    result.Childs.Add(subres);
                }
                else
                {
                    string line = StringParser.Parse("<td colspan=\"2\">", "</td>", blocks[i]);
                    subres = CreateNewResult("", languagesPair, subject);
                    result.Childs.Add(subres);
                    subres.Translations.Add(line);
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.cybermova.com/cgi-bin/olenuapro.pl";

            if (languagesPair.From == Language.Ukrainian)
            {
                query = "http://www.cybermova.com/cgi-bin/oluaenpro.pl";
            }
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);

            helper.Encoding = Encoding.GetEncoding(1251);

            query = "Word={0}&EnUaBtn=En+--%3E+Ua";
            query = string.Format(query, HttpUtility.UrlEncode(phrase, helper.Encoding));
            helper.AddPostData(query);
            //"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.- "
            //"АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦЧШЩЬЮЯабвгґдеєжзиіїйклмнопрстуфхцчшщьюя'.- !?/,:;()\'\"\""

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("<span id=result><B>") == -1)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("<body bgColor=LightSkyBlue>", "<FORM ACTION=", responseFromServer);

                StringParser phrasesParser = new StringParser(translation);
                string[]     phrases       = phrasesParser.ReadItemsList("<span id=result><B>", "</span>", "787654323");

                string subphrase;
                string subtranslation;
                Result subres = null;
                foreach (string data in phrases)
                {
                    int idx = data.IndexOf("</B>");
                    if (idx < 0)
                    {
                        throw new TranslationException("Can't found </B> tag");
                    }
                    subphrase = data.Substring(0, idx);
                    bool   has_root = subphrase.IndexOf("||") > 0;
                    string root     = "";
                    if (has_root)
                    {
                        root      = subphrase.Substring(0, subphrase.IndexOf("||"));
                        subphrase = subphrase.Replace("||", "");
                    }

                    subtranslation = data.Substring(idx + 4);

                    subtranslation = StringParser.RemoveAll("<IMG", ">", subtranslation);

                    if (subphrase.Length > 1)
                    {
                        subtranslation = subtranslation.Replace(subphrase.Substring(0, 1) + ". ", subphrase + " ");
                        subtranslation = subtranslation.Replace(subphrase.Substring(0, 1) + "</B>. ", subphrase + "</B> ");
                    }

                    if (has_root)
                    {
                        subtranslation = subtranslation.Replace("~", root);
                        subtranslation = subtranslation.Replace("||", "");
                    }

                    subtranslation = subtranslation.Replace("<B>", "");
                    subtranslation = subtranslation.Replace("</B>", "");
                    subtranslation = subtranslation.Replace("<I>", "");
                    subtranslation = subtranslation.Replace("</I>", "");


                    if (subtranslation.IndexOf("1.") < 0 && subtranslation.IndexOf("1)") < 0)
                    {
                        if (string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) == 0 && phrases.Length == 1)
                        {
                            //single answer
                            result.Translations.Add(subtranslation);
                            return;
                        }

                        subres = CreateNewResult(subphrase, languagesPair, subject);
                        subres.Translations.Add(subtranslation);
                        result.Childs.Add(subres);
                    }
                    else
                    {                     //parsing on parts
                        if (subtranslation.IndexOf("1.") < 0)
                        {
                            int    subsubdefinitionIdx = subtranslation.IndexOf("1)");
                            string abbr = subtranslation.Substring(0, subsubdefinitionIdx).Trim();
                            subtranslation = subtranslation.Substring(subsubdefinitionIdx + 2);
                            List <string> subsubsubtranslations = new List <string>();
                            for (int i = 2; i < 100; i++)
                            {
                                int numIdx = subtranslation.IndexOf(i.ToString(CultureInfo.InvariantCulture) + ")");
                                if (numIdx < 0)
                                {                                  //last def
                                    if (subtranslation.Trim() != ".")
                                    {
                                        subsubsubtranslations.Add(subtranslation.Trim());
                                    }
                                    else
                                    {
                                        subsubsubtranslations.Add(abbr);
                                        abbr = "";
                                    }
                                    break;
                                }
                                else
                                {
                                    string Definition = subtranslation.Substring(0, numIdx);
                                    subtranslation = subtranslation.Substring(numIdx + 2);
                                    subsubsubtranslations.Add(Definition.Trim());
                                }
                            }

                            if (string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) == 0 && phrases.Length == 1)
                            {
                                //single answer
                                result.Abbreviation = abbr;
                                foreach (string s in subsubsubtranslations)
                                {
                                    result.Translations.Add(s);
                                }
                                return;
                            }


                            subres = CreateNewResult(subphrase, languagesPair, subject);
                            subres.Abbreviation = abbr;
                            foreach (string s in subsubsubtranslations)
                            {
                                subres.Translations.Add(s);
                            }
                            result.Childs.Add(subres);
                        }
                        else
                        {
                            int    subdefinitionIdx   = subtranslation.IndexOf("1.");
                            string tmp_subtranslation = subtranslation.Substring(subdefinitionIdx + 2).Trim();
                            if (string.IsNullOrEmpty(tmp_subtranslation))
                            {
                                subtranslation = subtranslation.Substring(0, subdefinitionIdx).Trim();
                            }
                            else
                            {
                                subtranslation = tmp_subtranslation;
                            }
                            List <string> subsubtranslations = new List <string>();
                            for (int i = 2; i < 100; i++)
                            {
                                int numIdx = subtranslation.IndexOf(i.ToString(CultureInfo.InvariantCulture) + ".");
                                if (numIdx < 0)
                                {                                  //last def
                                    subsubtranslations.Add(subtranslation.Trim());
                                    break;
                                }
                                else
                                {
                                    string Definition = subtranslation.Substring(0, numIdx);
                                    subtranslation = subtranslation.Substring(numIdx + 2);
                                    subsubtranslations.Add(Definition.Trim());
                                }
                            }

                            subres = CreateNewResult(subphrase, languagesPair, subject);
                            //subres.Translations.Add(" ");
                            result.Childs.Add(subres);
                            Result subsubres;

                            foreach (string subsubtranslation in subsubtranslations)
                            {
                                if (subsubtranslation.IndexOf("1)") < 0)
                                {
                                    subsubres = CreateNewResult("", languagesPair, subject);
                                    subsubres.Translations.Add(subsubtranslation);
                                    subres.Childs.Add(subsubres);
                                }
                                else
                                {
                                    string subdata             = subsubtranslation;
                                    int    subsubdefinitionIdx = subdata.IndexOf("1)");
                                    string abbr = subdata.Substring(0, subsubdefinitionIdx).Trim();
                                    subdata = subdata.Substring(subsubdefinitionIdx + 2);
                                    List <string> subsubsubtranslations = new List <string>();
                                    for (int i = 2; i < 100; i++)
                                    {
                                        int numIdx = subdata.IndexOf(i.ToString(CultureInfo.InvariantCulture) + ")");
                                        if (numIdx < 0)
                                        {                                          //last def
                                            if (subdata.Trim() != ".")
                                            {
                                                subsubsubtranslations.Add(subdata.Trim());
                                            }
                                            else
                                            {
                                                subsubsubtranslations.Add(abbr);
                                                abbr = "";
                                            }
                                            break;
                                        }
                                        else
                                        {
                                            string Definition = subdata.Substring(0, numIdx);
                                            subdata = subdata.Substring(numIdx + 2);
                                            subsubsubtranslations.Add(Definition.Trim());
                                        }
                                    }

                                    subsubres = CreateNewResult(abbr, languagesPair, subject);
                                    foreach (string s in subsubsubtranslations)
                                    {
                                        subsubres.Translations.Add(s);
                                    }
                                    subres.Childs.Add(subsubres);
                                }
                            }
                        }
                    }
                }
            }
        }
        static void SetResult(Result result, string data)
        {
            string firstInfo = "";
            string cat       = "<font class=\"categoria\">";
            string translation;
            int    idx = data.IndexOf(cat);

            if (idx >= 0)
            {
                firstInfo = data.Substring(0, idx);
                firstInfo = StringParser.RemoveAll("<", ">", firstInfo);
                firstInfo = firstInfo.Replace("\r\n", "");
                firstInfo = firstInfo.Replace("\n", "");
                firstInfo = firstInfo.Replace("&lt;", "<");
                result.Translations.Add(firstInfo);
                translation = data.Substring(idx + cat.Length);
            }
            else
            {
                cat = "<div style=\"padding-left:20px; line-height:16px;\">";
                idx = data.IndexOf(cat);
                if (idx < 0)
                {
                    throw new TranslationException("Can't found start tag : " + cat + " in string : " + data);
                }

                firstInfo = data.Substring(0, idx);
                firstInfo = StringParser.RemoveAll("<", ">", firstInfo);
                firstInfo = firstInfo.Replace("\r\n", "");
                firstInfo = firstInfo.Replace("\n", "");
                firstInfo = firstInfo.Replace("&lt;", "<");
                result.Translations.Add(firstInfo);
                translation = data.Substring(idx);
                cat         = "<font class=\"categoria\">";
            }


            translation = translation.Replace("<font class=\"propriedade\">", cat);

            translation = "<begin>" + translation.Replace(cat, "<end><begin>") + "<end>";
            StringParser parser = new StringParser(translation);

            string[] blocks = parser.ReadItemsList("<begin>", "<end>");
            cat = "<div style=\"padding-left:20px; line-height:16px;\">";
            foreach (string block in blocks)
            {
                Result child = new Result(result.ServiceItem, "", result.LanguagePair, result.Subject);
                result.Childs.Add(child);


                idx = block.IndexOf(cat);
                if (idx >= 0)
                {
                    firstInfo          = block.Substring(0, idx);
                    firstInfo          = StringParser.RemoveAll("<", ">", firstInfo);
                    firstInfo          = firstInfo.Replace("\r\n", "");
                    firstInfo          = firstInfo.Replace("\n", "");
                    firstInfo          = firstInfo.Replace("&lt;", "<");
                    child.Abbreviation = firstInfo;

                    parser = new StringParser(block);
                    string[] translations = parser.ReadItemsList(cat, "</div>");
                    foreach (string subtrans in translations)
                    {
                        child.Translations.Add(StringParser.RemoveAll("<", ">", subtrans));
                    }
                }
            }
        }
        void InternalDoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting, string post_data)
        {
            WebRequestHelper helper = null;

            if (string.IsNullOrEmpty(post_data))
            {
                string query = "http://www.merriam-webster.com/dictionary/{0}";
                query             = string.Format(query, HttpUtility.UrlEncode(phrase));
                result.ArticleUrl = query;

                helper =
                    new WebRequestHelper(result, new Uri(query),
                                         networkSetting,
                                         WebRequestContentType.UrlEncodedGet);
                //helper.UseGoogleCache = true;
            }
            else
            {
                helper =
                    new WebRequestHelper(result, new Uri("http://www.merriam-webster.com/dictionary"),
                                         networkSetting,
                                         WebRequestContentType.UrlEncoded);
                helper.AddPostData(post_data);
            }

            string responseFromServer = helper.GetResponse();

            helper = null;

            if (responseFromServer.IndexOf("The word you've entered isn't in the dictionary.") >= 0)
            {
                if (responseFromServer.IndexOf("<PRE>") < 0)
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }
                else
                {                  //get suggestions
                    StringParser parser = new StringParser("<PRE>", "</PRE>", responseFromServer);
                    string[]     items  = parser.ReadItemsList("\">", "<", "345873409587");
                    foreach (string item in items)
                    {
                        string part = item;
                        string link = "html!<p><a href=\"http://www.merriam-webster.com/dictionary/{0}\" title=\"http://www.merriam-webster.com/dictionary/{0}\">{0}</a></p>";
                        link = string.Format(link,
                                             part);
                        result.Translations.Add(link);
                    }
                    return;
                }
            }

            if (!(responseFromServer.Contains("One entry found.\n<br/>") || responseFromServer.Contains("One entry found.\n<br />")))
            {
                if (string.IsNullOrEmpty(post_data) && responseFromServer.Contains("'list' value=\"va:"))
                {
                    string count_str = StringParser.Parse("'list' value=\"va:", ",", responseFromServer);
                    int    count;
                    if (int.TryParse(count_str, out count))
                    {
                        result.MoreEntriesCount = count;
                    }
                }

                StringParser parser = new StringParser("<ol class=\"results\"", "</ol>", responseFromServer);
                string[]     items  = parser.ReadItemsList("href=\"/dictionary/", "</a>");

                foreach (string item in items)
                {
                    string part = StringParser.ExtractLeft("\">", item);
                    string name = StringParser.ExtractRight("\">", item);
                    name = StringParser.RemoveAll("<sup>", "</sup>", name);
                    string link = "html!<p><a href=\"http://www.merriam-webster.com/dictionary/{0}\" title=\"http://www.merriam-webster.com/dictionary/{0}\">{1}</a></p>";
                    link = string.Format(link,
                                         part, name);
                    result.Translations.Add(link);
                }

                if (result.Translations.Count < 50 && responseFromServer.IndexOf("name='incr'") > 0)
                {                 //we has more items
                    //incr=Next+5&jump=dragon%27s+blood&book=Dictionary&quer=blood&list=45%2C31%2C3602592%2C0%3Bdragon%27s+blood%3D2000318535%3Bflesh+and+blood%3D2000400359%3Bfull-blood%5B1%2Cadjective%5D%3D2000425490%3Bfull-blood%5B2%2Cnoun%5D%3D2000425517%3Bhalf-blood%3D2000475964%3Bhalf+blood%3D2000475978%3Bhigh+blood+pressure%3D2000498596%3Blow+blood+pressure%3D2000629024%3Bnew+blood%3D2000712110%3Bpure-blooded%3D2000860991
                    string incr_value      = StringParser.Parse("<input type='submit' value='", "'", responseFromServer);
                    string quer_value      = StringParser.Parse("<input type='hidden' name='quer' value=\"", "\"", responseFromServer);
                    string list_value      = StringParser.Parse("<input type='hidden' name='list' value=\"", "\"", responseFromServer);
                    string post_data_value = "incr={0}&jump={1}&book=Dictionary&quer={2}&list={3}";
                    post_data_value = string.Format(post_data_value,
                                                    incr_value,
                                                    HttpUtility.UrlEncode(items[0]),
                                                    HttpUtility.UrlEncode(quer_value),
                                                    HttpUtility.UrlEncode(list_value)
                                                    );

                    //some cleaning
                    responseFromServer = null;

                    InternalDoTranslate(phrase, languagesPair, subject, result, networkSetting, post_data_value);
                }

                if (result.MoreEntriesCount != 0 && string.IsNullOrEmpty(post_data))
                {
                    result.MoreEntriesCount -= result.Translations.Count;
                }
            }
            else if (responseFromServer.Contains("<span class=\"variant\">"))
            {
                string part = StringParser.Parse("<span class=\"variant\">", "</span>", responseFromServer);

                string link = "html!<p><a href=\"http://www.merriam-webster.com/dictionary/{0}\" title=\"http://www.merriam-webster.com/dictionary/{0}\">{0}</a></p>";
                link = string.Format(link,
                                     part);
                result.Translations.Add(link);
            }
        }
Beispiel #14
0
        public static void DoTranslateSentences(ServiceItem serviceItem, string url, string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = string.Format(url, HttpUtility.UrlEncode(phrase, Encoding.GetEncoding(1251)));

            query += ConvertLanguagesPair(languagesPair);


            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet, Encoding.GetEncoding(1251));

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("</form>") < 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                result.EditArticleUrl = query;
                string translation = StringParser.Parse("</form>", "<table", responseFromServer);

                translation  = translation.Replace("<p>", "<end><begin>");
                translation += "<end>";


                StringParser parser       = new StringParser(translation);
                string[]     translations = parser.ReadItemsList("<begin>", "<end>");

                string subpart;
                string subphrase = "";
                string subtranslation;
                Result subsubres = null;
                foreach (string part in translations)
                {
                    subpart = part;
                    if (subpart.Contains("title=\""))
                    {
                        subphrase = StringParser.Parse("title=\"", "\"", subpart);
                    }
                    else
                    {
                        subphrase = phrase;
                    }

                    subtranslation = StringParser.RemoveAll("<span", ">", subpart);
                    subtranslation = StringParser.RemoveAll("<a", ">", subtranslation);
                    subtranslation = subtranslation.Replace("</a>", "");
                    subtranslation = subtranslation.Replace("<i>", "");
                    subtranslation = subtranslation.Replace("</i>", "");
                    subtranslation = subtranslation.Replace("</span>", "");
                    subtranslation = subtranslation.Replace("<sub>", "");
                    subtranslation = subtranslation.Replace("</sub>", "");
                    subtranslation = subtranslation.Replace("<b>", "");
                    subtranslation = subtranslation.Replace("</b>", "");
                    subtranslation = subtranslation.Replace(">>", "");


                    subsubres = serviceItem.CreateNewResult(subphrase, languagesPair, subject);
                    result.Childs.Add(subsubres);
                    int idx = subtranslation.IndexOf("\n");
                    if (idx < 0)
                    {
                        subsubres.Translations.Add("Parse error. Can't found '\\n' in " + subtranslation);
                    }
                    else
                    {
                        subsubres.Translations.Add(subtranslation.Substring(0, idx));
                        subsubres.Translations.Add(subtranslation.Substring(idx + 1).Trim());
                    }
                }
            }
        }
Beispiel #15
0
        public static void DoTranslatePhrases(ServiceItem serviceItem, string url, string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = string.Format(url, EncodePhrase(phrase, languagesPair));

            query += ConvertLanguagesPair(languagesPair);


            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet, GetEncoding(languagesPair));

            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            if (languagesPair.From == Language.Japanese || languagesPair.To == Language.Japanese)
            {
                helper.StreamConvertor = new EucJPStreamFixer();
            }

            string responseFromServer = helper.GetResponse();

            if ((responseFromServer.IndexOf("ask in forum</a>") >= 0 &&
                 responseFromServer.IndexOf("&nbsp;single words found") < 0)
                ||
                (responseFromServer.IndexOf("спросить в форуме</a>") >= 0 &&
                 responseFromServer.IndexOf("&nbsp; найдены отдельные слова") < 0)
                ||
                responseFromServer.IndexOf("<table cellspacing=\"0\" border=\"0\" width=\"100%\">") < 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("createAutoComplete();", "<script><!--", responseFromServer);

                translation = translation.Replace("</TD>", "</td>");
                translation = translation.Replace("<TD width", "<td width");

                translation = translation.Replace("</td><tr>", "</td></tr><tr>");
                translation = translation.Replace("</a><tr>", "</a></td></tr><tr>");
                translation = translation.Replace("\"><tr>", "\"></td></tr><tr>");
                translation = translation.Replace("</tr></td>", "</td></tr>");



                StringParser parser       = new StringParser(translation);
                string[]     translations = parser.ReadItemsList("<tr>", "</td></tr>");

                string subpart;
                string subphrase = "";
                string subtranslation;
                string abbreviation;
                Result subsubres = null;
                string subres_url;
                foreach (string part in translations)
                {
                    if (!part.Contains("<td width=\"5%\">"))
                    {
                        continue;
                    }
                    subpart    = part;
                    subphrase  = StringParser.Parse("<td width=\"5%\">", "</td>", subpart);
                    subres_url = StringParser.Parse("href=\"", "\"", subphrase);

                    subphrase = StringParser.RemoveAll("<span", ">", subphrase);
                    subphrase = StringParser.RemoveAll("<a", ">", subphrase);
                    subphrase = subphrase.Replace("</a>", "");
                    subphrase = subphrase.Replace("<i>", "");
                    subphrase = subphrase.Replace("</i>", "");
                    subphrase = subphrase.Replace("</span>", "");
                    subphrase = subphrase.Replace("<sub>", "");
                    subphrase = subphrase.Replace("</sub>", "");
                    subphrase = subphrase.Replace("<b>", "");
                    subphrase = subphrase.Replace("</b>", "");

                    abbreviation = StringParser.Parse("<i>", "</i>", subpart);

                    subsubres = serviceItem.CreateNewResult(subphrase, languagesPair, subject);
                    subsubres.Abbreviation = abbreviation;
                    subsubres.ArticleUrl   = "http://www.multitran.ru/c/" + subres_url;

                    result.Childs.Add(subsubres);

                    subtranslation = subpart + "<end>";
                    subtranslation = StringParser.Parse("<td width=\"20%\">", "</td>", subtranslation);
                    subtranslation = StringParser.RemoveAll("<span", ">", subtranslation);
                    subtranslation = StringParser.RemoveAll("<a", ">", subtranslation);
                    subtranslation = StringParser.RemoveAll("<td", ">", subtranslation);
                    subtranslation = subtranslation.Replace("</td>", " ");
                    subtranslation = subtranslation.Replace("</a>", "");
                    subtranslation = subtranslation.Replace("<i>", "");
                    subtranslation = subtranslation.Replace("</i>", "");
                    subtranslation = subtranslation.Replace("</span>", "");
                    subtranslation = subtranslation.Replace("<sub>", "");
                    subtranslation = subtranslation.Replace("</sub>", "");
                    subtranslation = subtranslation.Replace("<b>", "");
                    subtranslation = subtranslation.Replace("</b>", "");

                    subsubres.Translations.Add(subtranslation);


                    subtranslation = subpart + "<end>";
                    subtranslation = StringParser.Parse("<td width=\"75%\">", "<end>", subtranslation);
                    subtranslation = StringParser.RemoveAll("<span", ">", subtranslation);
                    subtranslation = StringParser.RemoveAll("<a", ">", subtranslation);
                    subtranslation = StringParser.RemoveAll("<td", ">", subtranslation);
                    subtranslation = subtranslation.Replace("</td>", " ");
                    subtranslation = subtranslation.Replace("</a>", "");
                    subtranslation = subtranslation.Replace("<i>", "");
                    subtranslation = subtranslation.Replace("</i>", "");
                    subtranslation = subtranslation.Replace("</span>", "");
                    subtranslation = subtranslation.Replace("<sub>", "");
                    subtranslation = subtranslation.Replace("</sub>", "");
                    subtranslation = subtranslation.Replace("<b>", "");
                    subtranslation = subtranslation.Replace("</b>", "");

                    subsubres.Translations.Add(subtranslation);
                }
            }
        }
Beispiel #16
0
        public static void DoTranslateDictionary(ServiceItem serviceItem, string url, string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = string.Format(url, EncodePhrase(phrase, languagesPair));

            query += ConvertLanguagesPair(languagesPair);

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet, GetEncoding(languagesPair));

            if (languagesPair.From == Language.Japanese || languagesPair.To == Language.Japanese)
            {
                helper.StreamConvertor = new EucJPStreamFixer();
            }

            string responseFromServer = helper.GetResponse();

            if ((responseFromServer.IndexOf("ask in forum</a>") >= 0 &&
                 responseFromServer.IndexOf("&nbsp;single words found") < 0)
                ||
                (responseFromServer.IndexOf("спросить в форуме</a>") >= 0 &&
                 responseFromServer.IndexOf("&nbsp; найдены отдельные слова") < 0)
                ||
                responseFromServer.IndexOf("<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">") < 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("createAutoComplete();", "</table>", responseFromServer);
                translation = translation.Replace("</TD>", "</td>");
                translation = translation.Replace("<TD width", "<td width");
                translation = translation.Replace("</td><tr>", "</td></tr><tr>");
                translation = translation.Replace("</a><tr>", "</a></td></tr><tr>");
                translation = translation.Replace("\"><tr>", "\"></td></tr><tr>");
                translation = translation.Replace("</td>\r\n  </tr>", "</td></tr>");


                StringParser parser       = new StringParser(translation);
                string[]     translations = parser.ReadItemsList("<tr>", "</td></tr>");

                string subpart;
                string subphrase = "";
                string subtranslation;
                string abbreviation;
                Result subres    = null;
                Result subsubres = null;
                foreach (string part in translations)
                {
                    subpart = part;

                    if (subpart.StartsWith("<td bgcolor=\"#DBDBDB\" width=\"100%\" colspan=\"2\">"))
                    {                     //new subres
                        subpart   = subpart.Replace("<td bgcolor=\"#DBDBDB\" width=\"100%\" colspan=\"2\">", "");
                        subphrase = StringParser.Parse("\">", "</a>", subpart);
                        subphrase = StringParser.RemoveAll("<span", ">", subphrase);
                        subphrase = StringParser.RemoveAll("<a", ">", subphrase);
                        subphrase = subphrase.Replace("<FONT SIZE=2>", "");
                        subphrase = subphrase.Replace("</FONT>", "");


                        if (subpart.Contains("<em>"))
                        {
                            abbreviation = StringParser.Parse("<em>", "</em>", subpart);
                        }
                        else
                        {
                            abbreviation = "";
                        }
                        subres = serviceItem.CreateNewResult(subphrase, languagesPair, subject);
                        subres.Abbreviation = abbreviation;
                        subres.ArticleUrl   = query;
                        //subres.ArticleUrlCaption = phrase;

                        result.Childs.Add(subres);
                    }
                    else
                    {
                        if (!subpart.Contains("title=\""))
                        {
                            result.ResultNotFound = true;
                            throw new TranslationException("Nothing found");
                        }


                        abbreviation  = StringParser.Parse("title=\"", "\"", subpart);
                        abbreviation += "(";
                        abbreviation += StringParser.Parse("<i>", "</i>", subpart);
                        abbreviation += ")";
                        //subsubres = serviceItem.CreateNewResult("", languagesPair, subject);
                        //subsubres.Abbreviation = abbreviation;
                        subsubres            = serviceItem.CreateNewResult(abbreviation, languagesPair, subject);
                        subsubres.ArticleUrl = "http://www.multitran.ru/c/" + StringParser.Parse("href=\"", "\"", subpart);
                        subres.Childs.Add(subsubres);
                        subtranslation = subpart.Substring(subpart.IndexOf("<td>") + 4);
                        subtranslation = StringParser.RemoveAll("<span", ">", subtranslation);
                        subtranslation = subtranslation.Replace("<a href=\"m.exe?t=", "<end><begin><a");
                        subtranslation = StringParser.RemoveAll("<a", ">", subtranslation);
                        subtranslation = subtranslation.Replace("</a>", "");
                        subtranslation = subtranslation.Replace("<i>", "");
                        subtranslation = subtranslation.Replace("</i>", "");
                        subtranslation = subtranslation.Replace("</span>", "");
                        subtranslation = subtranslation.Replace("<sub>", "");
                        subtranslation = subtranslation.Replace("</sub>", "");
                        subtranslation = subtranslation.Replace("<b>", "");
                        subtranslation = subtranslation.Replace("</b>", "");

                        subtranslation += "<end>";
                        parser          = new StringParser(subtranslation);
                        string[] subtranslations = parser.ReadItemsList("<begin>", "<end>");
                        foreach (string sub in subtranslations)
                        {
                            subtranslation = sub.Trim();
                            if (subtranslation.EndsWith(";"))
                            {
                                subtranslation = subtranslation.Substring(0, subtranslation.Length - 1);
                            }
                            subsubres.Translations.Add(subtranslation);
                        }
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            lock (cookieContainer)
            {
                if (coockieTime < DateTime.Now.AddHours(-1))
                {
                    coockieTime = DateTime.Now;
                    WebRequestHelper helper_cookie =
                        new WebRequestHelper(result, new Uri("http://multiwordnet.itc.it/online/multiwordnet-head.php"),
                                             networkSetting,
                                             WebRequestContentType.UrlEncodedGet);

                    helper_cookie.CookieContainer = cookieContainer;
                    helper_cookie.GetResponse();
                }
            }

            string query = "http://multiwordnet.itc.it/online/mwn-main.php?language={0}&field=word&word={1}&wntype=Overview&pos=";

            query = string.Format(query,
                                  ConvertLanguage(languagesPair.From),
                                  HttpUtility.UrlEncode(phrase));

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            helper.CookieContainer = cookieContainer;

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("<b> No data found </b>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string table = StringParser.Parse("<table border=1 WIDTH=100% CELLPADDING=1 class=bgpos>", "</table>", responseFromServer);

            string[] nodes = StringParser.ParseItemsList("<tr>", "</tr>", table);

            string nodename, nodeval;

            Result child = result;

            foreach (string node in nodes)
            {
                if (node.Contains("<td class=bg_posbody COLSPAN=2 >"))
                {
                    nodename = StringParser.RemoveAll("<", ">", node);
                    child    = new Result(result.ServiceItem, nodename, result.LanguagePair, result.Subject);
                    result.Childs.Add(child);
                }
                else
                {
                    nodeval = StringParser.RemoveAll("<", ">", node);
                    child.Translations.Add(nodeval);
                }
            }
        }
Beispiel #18
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.slovnyk.net/?swrd={0}";

            query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase, Encoding.GetEncoding(1251)));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            helper.Encoding = Encoding.GetEncoding(1251);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("<td align='center' class='art_body'>Не знайдено...<br />") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                result.ArticleUrl        = query;
                result.ArticleUrlCaption = phrase;

                string translation = StringParser.Parse("<tr><td class= 'art_body' >", "</td></tr>", responseFromServer);

                translation = translation.Replace("<span style=\"color:red\">", "");
                translation = translation.Replace("</span>", "́");

                translation = translation.Replace("</FONT><FONT COLOR=\"#ff0000\">", "");
                translation = translation.Replace("</FONT>", "́");


                translation = translation.Replace("<i>", "");
                translation = translation.Replace("<I>", "");
                translation = translation.Replace("</i>", "");
                translation = translation.Replace("</I>", "");
                translation = translation.Replace("<p>", "");
                translation = translation.Replace("</p>", "");
                translation = translation.Replace("<P>", "");
                translation = translation.Replace("</P>", "");
                translation = translation.Replace("<B>", "<b>");
                translation = translation.Replace("</B>", "</b>");


                //get definition
                int startIdx = translation.IndexOf("<b>");
                int endIdx   = translation.IndexOf("</b>");
                if (startIdx < 0 || endIdx <= startIdx)
                {
                    throw new TranslationException("Parse error, start tags not found");
                }
                result.Translations.Add(translation.Substring(startIdx + 3, endIdx - startIdx - 3).ToLower(CultureInfo.GetCultureInfo(0x0422)));
                translation = translation.Substring(endIdx + 4);
                if (translation[0] == '\'')
                {                  //apostrophe
                    startIdx = translation.IndexOf("<b>");
                    endIdx   = translation.IndexOf("</b>");
                    if (startIdx < 0 || endIdx <= startIdx)
                    {
                        throw new TranslationException("Parse error, start tags not found");
                    }
                    result.Translations[0] = result.Translations[0] + "'" + translation.Substring(startIdx + 3, endIdx - startIdx - 3).ToLower(CultureInfo.GetCultureInfo(0x0422));
                    translation            = translation.Substring(endIdx + 4);
                }

                if (translation.StartsWith(", "))
                {
                    translation = translation.Substring(2);
                }

                translation = translation.Replace("<b>", "");
                translation = translation.Replace("</b>", "");
                translation = translation.Replace("**", "");

                //links
                translation = StringParser.RemoveAll("<a href=\"http://www.slovnyk.net/?swrd=", "\">", translation);
                translation = translation.Replace("</a>", "");

                //spans
                translation = StringParser.RemoveAll("<span", ">", translation);

                //sups
                translation = StringParser.RemoveAll("<sup>", "</sup>", translation);

                //Abbreviation
                int definitionIdx = translation.IndexOf("1.");
                endIdx = translation.IndexOf(".");
                if (endIdx < 0 && definitionIdx < 0)
                {
                    throw new TranslationException("Parse error, start of definition not found");
                }

                if (definitionIdx > 0)
                {
                    result.Abbreviation = translation.Substring(0, definitionIdx);
                    translation         = translation.Substring(definitionIdx);
                }
                else
                {
                    result.Abbreviation = translation.Substring(0, endIdx);
                    translation         = translation.Substring(endIdx + 2);
                }

                if (!translation.StartsWith("1."))
                {
                    result.Translations.Add(translation);
                    return;
                }
                else
                {
                    for (int i = 2; i < 100; i++)
                    {
                        int numIdx = translation.IndexOf(i.ToString(CultureInfo.InvariantCulture) + ".");
                        if (numIdx < 0)
                        {                          //last def
                            Result defResult = CreateNewResult("", languagesPair, subject);
                            defResult.Translations.Add(translation.Substring(2).Trim());
                            result.Childs.Add(defResult);
                            return;
                        }
                        else
                        {
                            string Definition = translation.Substring(2, numIdx - 2);
                            translation = translation.Substring(numIdx);
                            Result defResult = CreateNewResult("", languagesPair, subject);
                            defResult.Translations.Add(Definition.Trim());
                            result.Childs.Add(defResult);
                        }
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.dict.cc/?s={0}";

            query                    = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase, encoding));
            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            helper.Encoding = encoding;


            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("<b>Sorry, no results!</b>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string[] translations = StringParser.ParseItemsList("<tr id='tr", "</tr>", responseFromServer);

            if (translations.Length == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            if (responseFromServer.Contains("</b> von&nbsp;<b>"))
            {
                string full_count = StringParser.Parse("</b> von&nbsp;<b>", "</b>", responseFromServer);
                if (!string.IsNullOrEmpty(full_count))
                {
                    int count;
                    if (int.TryParse(full_count, out count))
                    {
                        result.MoreEntriesCount = count - translations.Length;
                    }
                }
            }

            string en_string, ge_string, en_url, ge_url;
            Result child     = result;
            string subphrase = "";

            foreach (string translation in translations)
            {
                string[] subtranslations = StringParser.ParseItemsList("<td class=td7nl>", "</td>", translation);
                if (subtranslations.Length != 2)
                {
                    throw new TranslationException("Can't found translations in string : " + translation);
                }

                en_string = subtranslations[0];
                if (en_string.Contains("<a href=\""))
                {
                    en_url = StringParser.Parse("<a href=\"", "\"", en_string);
                }
                else
                {
                    en_url = "";
                }

                en_string = StringParser.RemoveAll("<", ">", en_string);


                ge_string = subtranslations[1];
                if (ge_string.Contains("<a href=\""))
                {
                    ge_url = StringParser.Parse("<a href=\"", "\"", ge_string);
                }
                else
                {
                    ge_url = "";
                }
                ge_string = StringParser.RemoveAll("<", ">", ge_string);

                if (languagesPair.From == Language.German)
                {
                    if (subphrase != ge_string)
                    {
                        child     = new Result(result.ServiceItem, ge_string, result.LanguagePair, result.Subject);
                        subphrase = ge_string;
                        if (!string.IsNullOrEmpty(ge_url))
                        {
                            child.ArticleUrl = "http://www.dict.cc" + ge_url;
                        }
                        result.Childs.Add(child);
                    }
                    child.Translations.Add(en_string);
                }
                else
                {
                    if (subphrase != en_string)
                    {
                        child     = new Result(result.ServiceItem, en_string, result.LanguagePair, result.Subject);
                        subphrase = en_string;
                        if (!string.IsNullOrEmpty(en_url))
                        {
                            child.ArticleUrl = "http://www.dict.cc" + en_url;
                        }
                        result.Childs.Add(child);
                    }

                    child.Translations.Add(ge_string);
                }
            }
        }
Beispiel #20
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://www.dep.pl/dict?word=test&words=&lang=DE
            string query = "http://www.dep.pl/dict?word={0}&words=&lang=DE";

            query                    = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase));
            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("has not been found - please post it to the") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("<table cellspacing=", "</table>", responseFromServer);

                StringParser parser       = new StringParser(translation);
                string[]     translations = parser.ReadItemsList("<td align=\"left\">", "</td>", "787654323");

                int    cnt = translations.Length;
                string tmp;
                for (int i = 0; i < cnt; i++)
                {
                    tmp             = translations[i];
                    tmp             = StringParser.RemoveAll("<a href=", ">", tmp);
                    tmp             = StringParser.RemoveAll("<font", ">", tmp);
                    tmp             = tmp.Replace("</font>", "");
                    tmp             = tmp.Replace("</a>", "");
                    translations[i] = tmp;
                }

                cnt = translations.Length / 2;
                string polish, german;
                string subphrase, subtranslation;
                Result subres = null;
                for (int i = 0; i < cnt; i++)
                {
                    polish = translations[i * 2];
                    german = translations[i * 2 + 1];

                    if (languagesPair.From == Language.German)
                    {
                        subphrase      = german;
                        subtranslation = polish;
                    }
                    else
                    {
                        subphrase      = polish;
                        subtranslation = german;
                    }

                    if (translations.Length == 2 && string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) == 0)
                    {
                        result.Translations.Add(subtranslation);
                        return;
                    }

                    subres = CreateNewResult(subphrase, languagesPair, subject);
                    subres.Translations.Add(subtranslation);
                    result.Childs.Add(subres);
                }
            }
        }
        public static void SetResult(Result result, string data, string host)
        {
            if (data.IndexOf("</strong> can be found at Merriam-WebsterUnabridged.com.") > 0)
            {
                result.Translations.Add(result.Phrase);
                return;
            }

            if (data.Contains("No entries found that match "))
            {
                result.Translations.Add(result.Phrase);
                return;
            }

            result.HasAudio = data.Contains("title=\"Listen to the pronunciation of");

            if (data.IndexOf("<div>Function: ") > 0)
            {
                string abbr = StringParser.Parse("<div>Function: ", "</div>", data);
                abbr = abbr.Replace("<em>", "");
                abbr = abbr.Replace("</em>", "");
                abbr = abbr.Replace("<span class=\"fl\">", "");
                abbr = abbr.Replace("</span>", "");

                result.Abbreviation = abbr;
            }

            if (data.IndexOf("<div>Pronunciation: ") > 0)
            {
                string abbr = StringParser.Parse("<div>Pronunciation: ", "</div>", data);
                abbr = StringParser.RemoveAll("<span", ">", abbr);
                abbr = abbr.Replace("</span>", "");
                abbr = abbr.Replace("<em>", "");
                abbr = abbr.Replace("</em>", "");
                if (!string.IsNullOrEmpty(result.Abbreviation))
                {
                    result.Abbreviation += ", ";
                }
                result.Abbreviation += abbr;
            }

            if (data.IndexOf("<dd class=\"use\">") > 0)
            {
                string abbr = StringParser.Parse("<dd class=\"use\">", "</dd>", data);
                abbr = abbr.Replace("<em>", "");
                abbr = abbr.Replace("</em>", "");
                if (!string.IsNullOrEmpty(result.Abbreviation))
                {
                    result.Abbreviation += ", ";
                }
                result.Abbreviation += "Usage: " + abbr;
            }

            if (data.IndexOf("<div>Etymology: ") > 0)
            {
                string abbr = StringParser.Parse("<div>Etymology: ", "</div>", data);
                abbr = abbr.Replace("<em>", "(");
                abbr = abbr.Replace("</em>", ")");
                abbr = StringParser.RemoveAll("<a href", ">", abbr);
                abbr = abbr.Replace("</a>", "");

                if (!string.IsNullOrEmpty(result.Abbreviation))
                {
                    result.Abbreviation += ", ";
                }
                result.Abbreviation += "Etymology: " + abbr;
            }

            if (data.IndexOf("<div>Date: ") > 0)
            {
                string abbr = StringParser.Parse("<div>Date: ", "</div>", data);
                abbr = abbr.Replace("<em>", "(");
                abbr = abbr.Replace("</em>", ")");
                if (!string.IsNullOrEmpty(result.Abbreviation))
                {
                    result.Abbreviation += ", ";
                }
                result.Abbreviation += "Date: " + abbr;
            }

            if (!data.Contains("class=\"d\">") && data.Contains("<span class=\"variant\">"))
            {              //variant, like a blew - past of blow
                string variant = StringParser.Parse("<span class=\"variant\">", "</div>", data);
                SetAdditionalLinks(result, variant, host);
                variant = StringParser.RemoveAll("<span", ">", variant);
                variant = StringParser.RemoveAll("<a href", ">", variant);
                variant = variant.Replace("</a>", "");
                variant = variant.Replace("</span>", "");
                variant = variant.Replace("<em>", "");
                variant = variant.Replace("</em>", "");
                variant = variant.Replace("</dd>", " ");
                variant = variant.Replace("</dl>", "");

                result.Translations.Add(variant.Trim());
                return;
            }

            string defs = StringParser.Parse("class=\"d\">", "<script", data);

            defs = defs.Replace(" a</span>", " a ");
            defs = defs.Replace("</span>", "");
            defs = defs.Replace("<em>", "");
            defs = defs.Replace("</em>", "");
            defs = defs.Replace("<strong>Synonyms</strong>", "Synonyms: ");
            defs = defs.Replace("<strong>Related Words</strong>", "Related Words: ");
            defs = defs.Replace("<strong>Antonyms</strong>", "Antonyms: ");
            //defs = defs.Replace("<strong>", "");
            //defs = defs.Replace("</strong>", "");
            defs = defs.Replace(":�<a", "- <a");

            defs = defs.Replace("<span class=\"dxn\">", "");
            SetAdditionalLinks(result, defs, host);
            defs = StringParser.RemoveAll("<a href", ">", defs);
            defs = defs.Replace("</a>", "");
            defs = defs.Replace("<span class=\"sense_content\">", "");
            //defs = StringParser.RemoveAll("<span class=\"sense_label\">", ">", defs);
            defs = defs.Replace("<span>", "");
            defs = defs.Replace("�", "");
            defs = defs.Replace("<span class=\"vi\">", "");
            defs = defs.Replace("<span class=\"text\">", "");

            defs = defs.Replace("<span class=\"\n            sense_label", "<span class=\"sense_label");
            defs = defs.Replace("<span class=\"unicode\">", "");
            defs = defs.Replace("ʼ", "'");



            if (defs.IndexOf("<br/>") < 0)
            {             //single def
                if (defs.IndexOf("<span class=\"syn\">") < 0 &&
                    defs.IndexOf("<span class=\"rel\">") < 0 &&
                    defs.IndexOf("<span class=\"ant\">") < 0
                    )
                {
                    defs = StringParser.RemoveAll("<", ">", defs);
                    result.Translations.Add(defs.Trim());
                    return;
                }
            }


            defs = "<start>" + defs;
            {
                defs  = defs.Replace("<span class=\"verb_class\">", "<end><start>");
                defs  = defs.Replace("<div class=\"synonym\">", "<end><start>");
                defs  = defs.Replace("<span class=\"syn\">", "<end><start>");
                defs  = defs.Replace("<span class=\"rel\">", "<end><start>");
                defs  = defs.Replace("<span class=\"ant\">", "<end><start>");
                defs  = defs.Replace("<br/>", "<end><start>");
                defs += "<end>";                 //ending mark

                StringParser parser     = new StringParser(defs);
                string[]     defs_items = parser.ReadItemsList("<start>", "<end>");
                string       translation;
                foreach (string item in defs_items)
                {
                    translation = item.Trim();

                    /*if(translation[0] <= '9' && translation[0] >= '0')
                     *      translation = item.Substring(1).Trim(); //skip idx
                     *
                     * if(translation[0] <= '9' && translation[0] >= '0')
                     *      translation = translation.Substring(1).Trim(); //skip idx
                     *
                     * if(translation.StartsWith(":"))
                     *      translation = translation.Substring(1);
                     */

                    if (translation.StartsWith("<strong>"))
                    {
                        translation = StringParser.ExtractRight("</strong>", translation);
                    }

                    string subsense_tag = "<em class=\"su\">";
                    if (false && translation.IndexOf(subsense_tag) > 0)
                    {                     //extract senses
                        string toptranslaton = translation.Substring(0, translation.IndexOf(subsense_tag));
                        toptranslaton = StringParser.RemoveAll("<", ">", toptranslaton);
                        if (toptranslaton.StartsWith("a :"))
                        {
                            toptranslaton = toptranslaton.Substring(3);
                        }

                        result.Translations.Add(toptranslaton.Trim());

                        translation  = translation.Substring(translation.IndexOf(subsense_tag));
                        translation  = translation.Replace(subsense_tag, "<end>" + subsense_tag);
                        translation += "<end>";

                        StringParser subparser      = new StringParser(translation);
                        string[]     sub_defs_items = subparser.ReadItemsList(subsense_tag, "<end>");
                        foreach (string subtranslation in sub_defs_items)
                        {
                            translation = subtranslation.Substring(1).Trim();                             //skip idx
                            if (translation.StartsWith(":"))
                            {
                                translation = translation.Substring(1);                                 //skip idx
                            }
                            translation = StringParser.RemoveAll("<", ">", translation);
                            result.Translations.Add(translation.Trim());
                        }
                    }
                    else
                    {
                        translation = StringParser.RemoveAll("<", ">", translation);
                        result.Translations.Add(translation.Trim());
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.dicts.info/ud.php"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);

            string fromLanguage = ConvertLanguage(languagesPair.From);
            string toLanguage   = ConvertLanguage(languagesPair.To);

            int    fromLangColumn, toLangColumn;
            string lang_query = "lan1={0}&lan2={1}";

            if (string.IsNullOrEmpty(fromLanguage))
            {
                fromLangColumn = 0;
                toLangColumn   = 1;
                lang_query     = string.Format(lang_query, toLanguage, "");
            }
            else if (string.IsNullOrEmpty(toLanguage))
            {
                fromLangColumn = 1;
                toLangColumn   = 0;
                lang_query     = string.Format(lang_query, fromLanguage, "");
            }
            else
            {
                fromLangColumn = 1;
                toLangColumn   = 2;
                lang_query     = string.Format(lang_query, fromLanguage, toLanguage);
            }

            string query = "{0}&word={1}&rad=ftsearch&go=Search";

            query = string.Format(CultureInfo.InvariantCulture,
                                  query,
                                  lang_query,
                                  HttpUtility.UrlEncode(phrase)
                                  );
            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            if (!responseFromServer.Contains("<table class=\"t1\""))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            //offcet
            fromLangColumn += 2;
            toLangColumn   += 2;

            string translation = StringParser.Parse("<table class=\"t1\"", "</table>", responseFromServer);

            string[] translations = StringParser.ParseItemsList("<tr bgcolor=\"", "</tr>", translation);

            if (translations.Length == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string sub_phrase, sub_translation;
            Result subres = null;

            foreach (string subtranslation in translations)
            {
                string[] columns = StringParser.ParseItemsList("<td", "</td>", subtranslation);

                sub_phrase      = StringParser.ExtractRight(">", columns[fromLangColumn]).Trim();
                sub_phrase      = StringParser.RemoveAll("<", ">", sub_phrase);
                sub_translation = StringParser.ExtractRight(">", columns[toLangColumn]).Trim();
                sub_translation = StringParser.RemoveAll("<", ">", sub_translation);

                if (!string.IsNullOrEmpty(sub_phrase) && !string.IsNullOrEmpty(sub_translation))
                {
                    if (subres == null ||
                        subres.Phrase != sub_phrase)
                    {
                        subres = CreateNewResult(sub_phrase, languagesPair, subject);
                        result.Childs.Add(subres);
                    }

                    if (!subres.Translations.Contains(sub_translation))
                    {
                        subres.Translations.Add(sub_translation);
                    }
                }
            }

            if (result.Childs.Count == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
        }
        public static void DoTranslate(ServiceItem serviceItem, string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            bool   synonimsDictionary = languagesPair.From == Language.Polish && languagesPair.To == Language.Polish;
            string query = "http://megaslownik.pl/slownik/{0}/,{1}";

            query = string.Format(query,
                                  MegaslownikTools.ConvertLanguagePair(languagesPair),
                                  HttpUtility.UrlEncode(phrase));

            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("<div class=\"slowo\">\r\n             Szukanego słowa nie ma w MEGAsłowniku.\r\n"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            result.HasAudio = responseFromServer.Contains("class=\"ikona_sluchaj2\">");

            string[] translations = StringParser.ParseItemsList("<div class=\"definicja\">", "</div>", responseFromServer);

            if (translations.Length == 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string subsubtranslation;

            string[] subtranslations;
            foreach (string translation in translations)
            {
                subtranslations = StringParser.ParseItemsList("<a href=\"/slownik", "</a>", translation);
                foreach (string subtranslation in subtranslations)
                {
                    subsubtranslation = StringParser.ExtractRight(">", subtranslation);
                    subsubtranslation = StringParser.RemoveAll("<", ">", subsubtranslation);
                    result.Translations.Add(subsubtranslation);
                }
            }

            //synonims
            translations = StringParser.ParseItemsList("<div class=\"synonim\">synonimy:", "</div>", responseFromServer);

            foreach (string translation in translations)
            {
                subtranslations = StringParser.ParseItemsList("<a href=\"/slownik", "</a>", translation);
                foreach (string subtranslation in subtranslations)
                {
                    subsubtranslation = StringParser.ExtractRight(">", subtranslation);
                    subsubtranslation = StringParser.RemoveAll("<", ">", subsubtranslation);
                    if (!result.Translations.Contains(subsubtranslation))
                    {
                        result.Translations.Add(subsubtranslation);
                    }
                }
            }

            //additional links
            if (!synonimsDictionary)
            {
                string[] links = StringParser.ParseItemsList("<li ><a href=\"/slownik/", "</li>", responseFromServer);
                string   linkUrl, linkText, subphrase, subtrans;
                Result   child;
                foreach (string link in links)
                {
                    linkUrl  = "http://megaslownik.pl/slownik/" + StringParser.ExtractLeft("\"", link);
                    linkText = StringParser.ExtractRight(">", link);
                    linkText = StringParser.RemoveAll("<", ">", linkText);
                    if (linkText.Contains("»") && linkText.Contains(phrase))
                    {
                        subphrase = StringParser.ExtractLeft("»", linkText);
                        subtrans  = StringParser.ExtractRight("»", linkText);
                        child     = serviceItem.CreateNewResult(subphrase, languagesPair, subject);
                        result.Childs.Add(child);
                        child.Translations.Add(subtrans);
                        child.ArticleUrl        = linkUrl;
                        child.ArticleUrlCaption = subphrase;
                    }
                }

                links = StringParser.ParseItemsList("<li><a href=\"/slownik/", "</li>", responseFromServer);
                foreach (string link in links)
                {
                    linkUrl  = "http://megaslownik.pl/slownik/" + StringParser.ExtractLeft("\"", link);
                    linkText = StringParser.ExtractRight(">", link);
                    linkText = StringParser.RemoveAll("<", ">", linkText);
                    if (linkText.Contains("»") && linkText.Contains(phrase))
                    {
                        subphrase = StringParser.ExtractLeft("»", linkText);
                        subtrans  = StringParser.ExtractRight("»", linkText);
                        child     = serviceItem.CreateNewResult(subphrase, languagesPair, subject);
                        result.Childs.Add(child);
                        child.Translations.Add(subtrans);
                        child.ArticleUrl        = linkUrl;
                        child.ArticleUrlCaption = subphrase;
                    }
                    //result.RelatedLinks.Add(linkText, linkUrl);
                }
            }
            else
            {             //synonyms
                string[] links = StringParser.ParseItemsList("<li ><a href=\"/slownik/", "</li>", responseFromServer);
                string   linkUrl, linkText;
                foreach (string link in links)
                {
                    linkUrl  = "http://megaslownik.pl/slownik/" + StringParser.ExtractLeft("\"", link);
                    linkText = StringParser.ExtractRight(">", link);
                    linkText = StringParser.RemoveAll("<", ">", linkText);
                    if (linkText.Contains(phrase))
                    {
                        result.RelatedLinks.Add(linkText, linkUrl);
                    }
                }

                links = StringParser.ParseItemsList("<li><a href=\"/slownik/", "</li>", responseFromServer);
                foreach (string link in links)
                {
                    linkUrl  = "http://megaslownik.pl/slownik/" + StringParser.ExtractLeft("\"", link);
                    linkText = StringParser.ExtractRight(">", link);
                    linkText = StringParser.RemoveAll("<", ">", linkText);
                    if (linkText.Contains(phrase))
                    {
                        result.RelatedLinks.Add(linkText, linkUrl);
                    }
                }
            }
        }
Beispiel #24
0
        public static void DoTranslate(ServiceItem searchEngine, string searchHost, string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string link_f = "http://{0}.{1}/wiki/{2}";
            string lang   = WikiUtils.ConvertLanguage(languagesPair.To);

            string link = string.Format(link_f, lang,
                                        searchHost,
                                        phrase);

            result.EditArticleUrl = link;

            Result searchResult = searchEngine.Translate(phrase, languagesPair, subject, networkSetting);

            if (!searchResult.IsHasData() || searchResult.Translations.Count < 1)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string url           = StringParser.Parse("<a href=\"", "\">", searchResult.Translations[0]);
            string searched_name = url.Substring(url.LastIndexOf("/") + 1);

            if (string.Compare(phrase, searched_name, true) != 0)
            {
                //check second line
                if (searchResult.Translations.Count < 2)
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }
                else
                {
                    url           = StringParser.Parse("<a href=\"", "\">", searchResult.Translations[1]);
                    searched_name = url.Substring(url.LastIndexOf("/") + 1);
                    if (string.Compare(phrase, searched_name, true) != 0)
                    {
                        result.ResultNotFound = true;
                        throw new TranslationException("Nothing found");
                    }
                }
            }


            link = string.Format(link_f, lang,
                                 searchHost,
                                 searched_name,
                                 searched_name);
            result.EditArticleUrl = link;

            //http://en.wikipedia.org/w/api.php?action=parse&prop=text&format=xml&page=Ukraine
            string query = "http://{0}.{1}/w/api.php?action=parse&prop=text|revid&format=xml&page={2}";

            query = string.Format(query, lang,
                                  searchHost,
                                  HttpUtility.UrlEncode(searched_name));

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("<parse revid=\"0\">") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string res = StringParser.Parse("<text", "</text>", responseFromServer);

            res = StringParser.ExtractRight(">", res);
            res = res.Replace("width: 100%", "width: 95%");
            res = res.Replace("float:right;", "float: right;margin-right: 0.5em;");

            res = "html!<div style='width:{allowed_width}px;overflow:scroll;overflow-y:hidden;overflow-x:auto;'>" + HttpUtility.HtmlDecode(res) + "&nbsp</div>";

            res = res.Replace("<h1>", "");
            res = res.Replace("</h1>", "");
            res = res.Replace("<h2>", "");
            res = res.Replace("</h2>", "");
            res = res.Replace("<h3>", "");
            res = res.Replace("</h3>", "");
            res = res.Replace("<h4>", "");
            res = res.Replace("</h4>", "");

            res = StringParser.RemoveAll("<span class=\"editsection\">[<a", "</a>]", res);
            res = StringParser.RemoveAll("href=\"#", "\"", res);
            res = StringParser.RemoveAll("<script type=", "</script>", res);
            res = StringParser.RemoveAll("<button onclick=", "</button>", res);



            url = string.Format("a href=\"http://{0}.{1}/", lang, searchHost);
            res = res.Replace("a href=\"/", url);

            url = string.Format("img src=\"http://{0}.{1}/", lang, searchHost);
            res = res.Replace("img src=\"/", url);
            result.Translations.Add(res);
        }
Beispiel #25
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://dict.linux.org.ua/dict/db/table_adv.php?word_str=help&expr=any&A=on&P=on&O=on
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://dict.linux.org.ua/db/table_adv.php"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);
            //helper.Encoding = Encoding.GetEncoding(21866); //koi8-u
            string query = "word={0}&expr=any&A=on&P=on&O=on";

            query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase, helper.Encoding));
            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("не знайдено<br>") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.EndsWith("Рядок пошуку містить недозволені символи."))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Query contains extraneous symbols");
            }
            else if (!responseFromServer.Contains("</html>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("<table BORDER WIDTH=", "</table>", responseFromServer);
                translation = translation.Replace("<B>", "");
                translation = translation.Replace("</B>", "");

                StringParser parser       = new StringParser(translation);
                string[]     translations = parser.ReadItemsList("<tr>", "</td></tr>", "787654323");

                string subpart;
                string subphrase;
                string subtranslation;
                Result subres = null;
                foreach (string part in translations)
                {
                    subpart = part;
                    subpart = StringParser.RemoveAll("<td width=\"2%\">", "</td><td width=\"40%\">", subpart);
                    subpart = subpart.Replace("<td></td><td>", "");

                    if (subpart.StartsWith("<A HREF"))
                    {
                        subphrase      = StringParser.Parse("\">", "</A>", subpart);
                        subtranslation = StringParser.Parse("\"40%\">", "</td>", subpart);

                        if (translations.Length == 1 && string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) == 0)
                        {
                            result.Translations.Add(subtranslation);
                            return;
                        }

                        subres = CreateNewResult(subphrase, languagesPair, subject);
                        subres.Translations.Add(subtranslation);
                        result.Childs.Add(subres);
                    }
                    else if (!subpart.StartsWith(" "))
                    {
                        int idx = subpart.IndexOf("</td>");
                        if (idx < 0)
                        {
                            subphrase      = "Parse Error";
                            subtranslation = "Parse Error";
                        }
                        else
                        {
                            subphrase      = subpart.Substring(0, idx);
                            subpart        = subpart.Substring(idx + 5);
                            subpart        = subpart.Replace("<td width=\"40%\">", "");
                            subtranslation = StringParser.Parse("\">", "</A>", subpart);
                        }

                        if (translations.Length == 1 && string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) == 0)
                        {
                            result.Translations.Add(subtranslation);
                            return;
                        }

                        subres = CreateNewResult(subphrase, languagesPair, subject);
                        subres.Translations.Add(subtranslation);
                        result.Childs.Add(subres);
                    }
                    else
                    {
                        subtranslation = StringParser.Parse("\"40%\">", "</td>", subpart);
                        if (subres != null)
                        {
                            subres.Translations.Add(subtranslation);
                        }
                    }
                }
            }
        }
        void TranslateWord(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            lock (sederetCode)
            {
                if (string.IsNullOrEmpty(sederetCode) || coockieTime < DateTime.Now.AddHours(-1))
                {                  //emulate first access to site
                    WebRequestHelper helpertop =
                        new WebRequestHelper(result, new Uri("http://www.sederet.com/translate.php"),
                                             networkSetting,
                                             WebRequestContentType.UrlEncodedGet, encoding);
                    helpertop.CookieContainer = cookieContainer;
                    coockieTime = DateTime.Now;
                    string responseFromServertop = helpertop.GetResponse();
                    sederetCode = StringParser.Parse("<input type=\"hidden\" name=\"var\" value=\"", "\"", responseFromServertop);
                }
            }



            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.sederet.com/translate.php"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded, encoding);

            helper.CookieContainer = cookieContainer;

            //eng2indo, indo2eng
            string query = "from_to={0}&kata={1}&var={2}";

            if (languagesPair.From == Language.Indonesian)
            {
                query = string.Format(CultureInfo.InvariantCulture, query, "indo2eng", HttpUtility.UrlEncode(phrase), sederetCode);
            }
            else
            {
                query = string.Format(CultureInfo.InvariantCulture, query, "eng2indo", HttpUtility.UrlEncode(phrase), sederetCode);
            }
            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            lock (sederetCode)
            {
                sederetCode = StringParser.Parse("<input type=\"hidden\" name=\"var\" value=\"", "\"", responseFromServer);
            }

            string translation = StringParser.Parse("<span id=\"result_title\"", "id=\"part_right\">", responseFromServer);

            Result       child;
            StringParser subparser;

            if (translation.Contains("<b id=\"match_title\">Exact Match:</b>"))
            {
                child = CreateNewResult(phrase, languagesPair, subject);
                result.Childs.Add(child);
                string subblock = StringParser.Parse("<b id=\"match_title\">Exact Match:</b>", "</table>", translation);
                subparser = new StringParser(subblock);
                string[] subtranslation_list = subparser.ReadItemsList("<td id='result_td'>", "</td>");
                for (int i = 0; i < subtranslation_list.Length; i += 2)
                {
                    string subtranslation = subtranslation_list[i + 1];
                    subtranslation = StringParser.RemoveAll("<", ">", subtranslation);
                    child.Translations.Add(HttpUtility.HtmlDecode(subtranslation));
                }
            }

            if (translation.Contains("<b id=\"match_title\">Other Match(es):</b>"))
            {
                string subblock = StringParser.Parse("<b id=\"match_title\">Other Match(es):</b>", "</table>", translation);
                subparser = new StringParser(subblock);
                string[] subtranslation_list = subparser.ReadItemsList("<td id='result_td'>", "</td>");
                for (int i = 0; i < subtranslation_list.Length; i += 2)
                {
                    string subphrase = subtranslation_list[i];
                    subphrase = StringParser.RemoveAll("<", ">", subphrase);

                    child = CreateNewResult(subphrase, languagesPair, subject);
                    result.Childs.Add(child);

                    string subtranslation = subtranslation_list[i + 1];
                    subtranslation = StringParser.RemoveAll("<", ">", subtranslation);
                    child.Translations.Add(HttpUtility.HtmlDecode(subtranslation));
                }
            }

            result.ResultNotFound = result.Childs.Count == 0;
        }
        public static void DoTranslate(ServiceItem serviceItem, string host, string bookName, string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = host + "/{0}";

            //ISO-8859-1
            query = string.Format(query, HttpUtility.UrlEncode(phrase, System.Text.Encoding.UTF8));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);
            //helper.UseGoogleCache = true;

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("The word you've entered isn't in the dictionary.") >= 0 ||
                responseFromServer.IndexOf("No entries found.\n<br/>") >= 0 ||
                responseFromServer.IndexOf("The word you've entered isn't in the thesaurus.") >= 0
                )
            {
                if (responseFromServer.IndexOf("<PRE>") >= 0)
                {                       //suggestions
                    StringParser suggestions_parser = new StringParser("<PRE>", "</PRE>", responseFromServer);
                    string[]     suggestions        = suggestions_parser.ReadItemsList(">", "</a>");
                    foreach (string item in suggestions)
                    {
                        string part = item;
                        string link = "html!<p><a href=\"" + host + "/{0}\" title=\"" + host + "/{0}\">{0}</a></p>";
                        link = string.Format(link,
                                             part);
                        result.Translations.Add(link);
                    }
                    return;
                }
                else
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }
            }

            result.ArticleUrl = host + "/" + phrase;
            if (responseFromServer.Contains("One entry found.\n<br/>") || responseFromServer.Contains("One entry found.\n<br />"))
            {
                SetResult(result, responseFromServer, host + "/");
            }
            else
            {
                if (responseFromServer.Contains("'list' value=\"va:"))
                {
                    string count_str = StringParser.Parse("'list' value=\"va:", ",", responseFromServer);
                    int    count;
                    if (int.TryParse(count_str, out count))
                    {
                        result.MoreEntriesCount = count;
                    }
                }

                StringParser parser = new StringParser("<ol class=\"results\"", "</ol>", responseFromServer);
                string[]     items  = parser.ReadItemsList("href=\"/" + bookName.ToLower() + "/", "\"");

                bool first = true;
                foreach (string item in items)
                {
                    string part = item;

                    string part_name = StringParser.RemoveAll("[", "]", part);
                    if (string.Compare(part_name, phrase, true) == 0)
                    {
                        Result subres = serviceItem.CreateNewResult(part_name, languagesPair, subject);
                        result.Childs.Add(subres);

                        subres.ArticleUrl = host + "/" + part;

                        if (first)
                        {
                            SetResult(subres, responseFromServer, host + "/");
                            first = false;
                        }
                        else
                        {                         //get translation
                            //jump=blood%5B1%2Cnoun%5D&book=Dictionary&quer=blood&list=45%2C1%2C3602592%2C0%3Bblood%5B1%2Cnoun%5D%3D113554%3Bblood%5B2%2Ctransitive+verb%5D%3D113572%3BABO+blood+group%3D2000002431%3Bbad+blood%3D2000074812%3Bblood-and-guts%3D2000113598%3Bblood-brain+barrier%3D2000113627%3Bblood+brother%3D2000113664%3Bblood+cell%3D2000113685%3Bblood+count%3D2000113697%3Bblood+doping%3D2000113725

                            /*string quer_value = StringParser.Parse("<input type='hidden' name='quer' value=\"", "\"", responseFromServer);
                             * string list_value = StringParser.Parse("<input type='hidden' name='list' value=\"", "\"", responseFromServer);
                             * string post_data_value = "jump={0}&book=" + bookName + "&quer={1}&list={2}";
                             * post_data_value = string.Format(post_data_value ,
                             *      HttpUtility.UrlEncode(part),
                             *      HttpUtility.UrlEncode(quer_value),
                             *      HttpUtility.UrlEncode(list_value)
                             *      );
                             */

                            helper =
                                new WebRequestHelper(result, new Uri(subres.ArticleUrl),
                                                     networkSetting,
                                                     WebRequestContentType.UrlEncodedGet);
                            //helper.AddPostData(post_data_value);
                            //helper.UseGoogleCache = true;
                            responseFromServer = helper.GetResponse();
                            SetResult(subres, responseFromServer, host + "/");
                        }
                    }
                }

                if (result.MoreEntriesCount != 0)
                {
                    result.MoreEntriesCount -= result.Childs.Count;
                }
            }
        }