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);
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            lock (viewState)
            {
                if (string.IsNullOrEmpty(viewState))
                {                  //emulate first access to site
                    WebRequestHelper helpertop =
                        new WebRequestHelper(result, new Uri("http://www.online-translator.com/Default.aspx/Text"),
                                             networkSetting,
                                             WebRequestContentType.UrlEncodedGet);

                    string responseFromServertop = helpertop.GetResponse();
                    viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServertop);
                    prevPage  = StringParser.Parse("id=\"__PREVIOUSPAGE\" value=\"", "\"", responseFromServertop);
                }
            }

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.online-translator.com/Default.aspx/Text"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);

            //query
            lock (viewState)
            {
                //string query = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={0}&ctl00%24SiteContent%24ucTextTranslator%24tbFromAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbToAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbCCAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbSubject=&ctl00%24SiteContent%24ucTextTranslator%24tbBody=&ctl00%24SiteContent%24ucTextTranslator%24templates={1}&ctl00%24SiteContent%24ucTextTranslator%24checkShowVariants=on&ctl00%24SiteContent%24ucTextTranslator%24dlTemplates=General&ctl00%24SiteContent%24ucTextTranslator%24sourceText={2}&resultText=&ctl00%24SiteContent%24ucTextTranslator%24dlDirections={3}&ctl00%24SiteContent%24ucTextTranslator%24bTranslate=Translate&ctl00%24tbEmail=&ctl00%24tbName=&ctl00%24tbComment=&ctl00%24pollDiv%24tbSiteLang=en";
                string query = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={0}&ctl00%24SiteContent%24MA_trasnlform%24selected_tab=text&chLangs=true&ctl00%24SiteContent%24MA_trasnlform%24rblTemplates=General&ctl00%24SiteContent%24MA_trasnlform%24otherTemplatesInput={1}&ctl00%24SiteContent%24MA_trasnlform%24sourceText={2}&ctl00%24SiteContent%24MA_trasnlform%24sLang={3}&ctl00%24SiteContent%24MA_trasnlform%24rLang={4}&ctl00%24SiteContent%24MA_trasnlform%24bTranslate=Translate&ctl00%24SiteContent%24MA_trasnlform%24changedFieldToAddr=&ctl00%24SiteContent%24MA_trasnlform%24hiddenDir=&ctl00%24SiteContent%24MA_trasnlform%24hiddenTranid=&ctl00%24changedField=&__PREVIOUSPAGE={5}";
                query = string.Format(query,
                                      HttpUtility.UrlEncode(viewState),
                                      PromtUtils.GetSubject(subject),
                                      HttpUtility.UrlEncode(phrase),
                                      PromtUtils.ConvertLanguage(languagesPair.From),
                                      PromtUtils.ConvertLanguage(languagesPair.To),
                                      prevPage);
                helper.AddPostData(query);
            }



            string responseFromServer = helper.GetResponse();

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

            result.Translations.Add(translation);
            lock (viewState)
            {
                viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServer);
                prevPage  = StringParser.Parse("id=\"__PREVIOUSPAGE\" value=\"", "\"", responseFromServer);
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            lock(viewState)
            {
                if(string.IsNullOrEmpty(viewState))
                {  //emulate first access to site
                    WebRequestHelper helpertop =
                        new WebRequestHelper(result, new Uri("http://www.online-translator.com/Default.aspx/Text"),
                            networkSetting,
                            WebRequestContentType.UrlEncodedGet);

                    string responseFromServertop = helpertop.GetResponse();
                    viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServertop);
                    prevPage = StringParser.Parse("id=\"__PREVIOUSPAGE\" value=\"", "\"", responseFromServertop);
                }
            }

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.online-translator.com/Default.aspx/Text"),
                    networkSetting,
                    WebRequestContentType.UrlEncoded);

            //query
            lock(viewState)
            {
            //string query = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={0}&ctl00%24SiteContent%24ucTextTranslator%24tbFromAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbToAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbCCAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbSubject=&ctl00%24SiteContent%24ucTextTranslator%24tbBody=&ctl00%24SiteContent%24ucTextTranslator%24templates={1}&ctl00%24SiteContent%24ucTextTranslator%24checkShowVariants=on&ctl00%24SiteContent%24ucTextTranslator%24dlTemplates=General&ctl00%24SiteContent%24ucTextTranslator%24sourceText={2}&resultText=&ctl00%24SiteContent%24ucTextTranslator%24dlDirections={3}&ctl00%24SiteContent%24ucTextTranslator%24bTranslate=Translate&ctl00%24tbEmail=&ctl00%24tbName=&ctl00%24tbComment=&ctl00%24pollDiv%24tbSiteLang=en";
            string query =   "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={0}&ctl00%24SiteContent%24MA_trasnlform%24selected_tab=text&chLangs=true&ctl00%24SiteContent%24MA_trasnlform%24rblTemplates=General&ctl00%24SiteContent%24MA_trasnlform%24otherTemplatesInput={1}&ctl00%24SiteContent%24MA_trasnlform%24sourceText={2}&ctl00%24SiteContent%24MA_trasnlform%24sLang={3}&ctl00%24SiteContent%24MA_trasnlform%24rLang={4}&ctl00%24SiteContent%24MA_trasnlform%24bTranslate=Translate&ctl00%24SiteContent%24MA_trasnlform%24changedFieldToAddr=&ctl00%24SiteContent%24MA_trasnlform%24hiddenDir=&ctl00%24SiteContent%24MA_trasnlform%24hiddenTranid=&ctl00%24changedField=&__PREVIOUSPAGE={5}";
            query = string.Format(query,
                HttpUtility.UrlEncode(viewState),
                PromtUtils.GetSubject(subject),
                HttpUtility.UrlEncode(phrase),
                PromtUtils.ConvertLanguage(languagesPair.From),
                PromtUtils.ConvertLanguage(languagesPair.To),
                prevPage);
                helper.AddPostData(query);
            }

            string responseFromServer = helper.GetResponse();

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

            result.Translations.Add(translation);
            lock(viewState)
            {
            viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServer);
            prevPage = StringParser.Parse("id=\"__PREVIOUSPAGE\" value=\"", "\"", responseFromServer);
            }
        }
Exemple #4
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.online-translator.com/text/references.aspx?prmtlang=en&direction={0}&word={1}";

            query = string.Format(query, PromtUtils.ConvertLanguagesPair(languagesPair),
                                  HttpUtility.UrlEncode(phrase));

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

            string responseFromServer = helper.GetResponse();

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

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


            StringParser parser = new StringParser(responseFromServer);

            string[] translation_list = parser.ReadItemsList("<span class=\"ref_source\"", "</table>");

            string       subphrase;
            string       abbreviation;
            Result       child;
            StringParser subparser;

            foreach (string translation in translation_list)
            {
                subphrase          = StringParser.Parse(">", "</span>", translation);
                abbreviation       = StringParser.Parse("<span class=\"ref_psp\">", "</span>", translation);
                child              = CreateNewResult(subphrase, languagesPair, subject);
                child.Abbreviation = abbreviation;
                result.Childs.Add(child);
                subparser = new StringParser(translation);
                string[] subtranslation_list = subparser.ReadItemsList("<span class=\"ref_result\">", "</span>");
                foreach (string subtranslation in subtranslation_list)
                {
                    child.Translations.Add(HttpUtility.HtmlDecode(subtranslation));
                }
            }
        }
Exemple #5
0
        public static void DoSearch(string searchHost, string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://{0}.{1}/w/api.php?action=query&list=search&srsearch={2}&srlimit={3}&format=xml&srwhat=text";
            string lang  = WikiUtils.ConvertLanguage(languagesPair.To);

            query = string.Format(query, lang,
                                  searchHost,
                                  HttpUtility.UrlEncode(phrase),
                                  MonolingualSearchEngine.ResultsLimit);

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

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("info=\"") >= 0)
            {
                string error = StringParser.Parse("info=\"", "\"", responseFromServer);
                throw new TranslationException(error);
            }

            if (responseFromServer.IndexOf("<p ns=\"0\" title=\"") < 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            StringParser parser = new StringParser(responseFromServer);

            string[] items = parser.ReadItemsList("<p ns=\"0\" title=\"", "\"", "787654323");

            string link;

            foreach (string part in items)
            {
                //link = "html!";
                link = "html!<p><a href=\"http://{0}.{1}/wiki/{2}\" title=\"http://{0}.{1}/wiki/{2}\">{3}</a></p>";
                link = string.Format(link, lang,
                                     searchHost,
                                     part,
                                     part);
                result.Translations.Add(link);
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://pere.org.ua/cgi-bin/pere.cgi"),
                    networkSetting,
                    WebRequestContentType.Multipart);

            helper.AddPostKey("lng", "uk-ua");
            helper.AddPostKey("han", "text");
            helper.AddPostKey("wht", "text");
            helper.AddPostKey("cod", ConvertLangsPair(languagesPair));
            helper.AddPostKey("par", "1");
            helper.AddPostKey("txt", phrase);
            helper.AddPostKey("don", "Відправити запит");

            string responseFromServer = helper.GetResponse();
            result.Translations.Add(StringParser.Parse("<nopere><TEXTAREA ROWS=20 COLS=80>", "</TEXTAREA></nopere>", responseFromServer));
        }
Exemple #7
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://pere.org.ua/cgi-bin/pere.cgi"),
                                     networkSetting,
                                     WebRequestContentType.Multipart);

            helper.AddPostKey("lng", "uk-ua");
            helper.AddPostKey("han", "text");
            helper.AddPostKey("wht", "text");
            helper.AddPostKey("cod", ConvertLangsPair(languagesPair));
            helper.AddPostKey("par", "1");
            helper.AddPostKey("txt", phrase);
            helper.AddPostKey("don", "Відправити запит");


            string responseFromServer = helper.GetResponse();

            result.Translations.Add(StringParser.Parse("<nopere><TEXTAREA ROWS=20 COLS=80>", "</TEXTAREA></nopere>", responseFromServer));
        }
Exemple #8
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://193.2.66.133:85/overview.php?search=1&word={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, encoding);


            string responseFromServer = helper.GetResponse();

            OpenthesaurusDeDictionary.SetResult(result, responseFromServer);
        }
Exemple #9
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.opentaal.org/opentaalbank/thesaurus/multimatch.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();

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

            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);
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.trident.com.ua/translation_online/"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);

            //query
            //?SrcTxt=test&Subject=**&LangFrom=Detect&LangTo=Rus&Translate=++Translate+++&DstTxt=&DlgLang=english
            string lang_to   = ConvertLanguage(languagesPair.To);
            string lang_from = ConvertLanguage(languagesPair.From);
            string query     = "SrcTxt={2}&Subject={1}&LangFrom={3}&LangTo={0}&Translate=++Translate+++&DstTxt=&DlgLang=english";

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

            string responseFromServer = helper.GetResponse();

            string translation = StringParser.Parse("<textarea rows=\"7\" cols=\"50\" name=\"DstTxt\"", "</textarea>", responseFromServer);

            translation = StringParser.ExtractRight(">", translation).Trim();
            if (!String.IsNullOrEmpty(translation))
            {
                result.Translations.Add(translation);
            }
            else
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
        }
Exemple #11
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://en.sozlukte.com/AjaxSearch/?word={0}&lang={1}";

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

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

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("<h3>-</h3>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("<h3>", "</h3>", responseFromServer);
                result.Translations.Add(translation);
            }
        }
        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);
        }
Exemple #13
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);
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://intertran.tranexp.com/Translate/result.shtml"),
                    networkSetting,
                    WebRequestContentType.UrlEncoded);
            helper.Encoding = GetEncoding(languagesPair.From, languagesPair.To);//Encoding.GetEncoding(GetEncoding(languagesPair.To));
            string query = "Submit.x=56&Submit.y=10&from={0}&keyb=non&text={1}&to={2}&translation=";

            query = string.Format(CultureInfo.InvariantCulture,
                    query,
                    ConvertLanguage(languagesPair.From),
                    HttpUtility.UrlEncode(phrase, Encoding.GetEncoding(GetEncoding(languagesPair.From))),
                    ConvertLanguage(languagesPair.To)
                );
            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            if(string.IsNullOrEmpty(responseFromServer))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if(responseFromServer.Contains("there was no translation for your original query.</center>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if(responseFromServer.Contains("name=\"translation\">An error occurred during translation. Please try again later.</textarea>"))
            {
                //result.ResultNotFound = true;
                throw new TranslationException("An error occurred during translation. Please try again later.");
            }
            else if(responseFromServer.Contains("<center>Warning:<br> Could not open"))
            {
                //result.ResultNotFound = true;
                throw new TranslationException("An error occurred during translation. Please try again later.");
            }
            else if(responseFromServer.Contains("<center>Warning:</strong><br> Could not open"))
            {
                //result.ResultNotFound = true;
                throw new TranslationException("An error occurred during translation. Please try again later.");
            }
            else
            {
                string translation = StringParser.Parse("<INPUT TYPE=\"hidden\" NAME=\"alltrans\" VALUE=\"", "\">",  responseFromServer).Trim();
                if(string.IsNullOrEmpty(translation))
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }

                string subphrase;
                bool firstRun = true;
                Result subres = result;
                StringParser parser = new StringParser(translation);
                string[] translations = parser.ReadItemsList("{{", "}}");

                foreach(string subtranslation in translations)
                {
                    string subtrans = "|" + subtranslation + "|";
                    parser = new StringParser(subtrans);
                    string[] subtranslations = parser.ReadItemsList("|", "|");
                    if(subtranslations.Length > 1)
                    {
                        subphrase = subtranslations[0];
                        if(firstRun && translation.Length == 1 && string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) ==0)
                        {
                            for(int i = 1; i < subtranslations.Length; i++)
                                result.Translations.Add(subtranslations[i]);
                            return;
                        }
                        firstRun = false;

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

                        for(int i = 1; i < subtranslations.Length; i++)
                            subres.Translations.Add(subtranslations[i]);
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string from = ConvertLanguage(languagesPair.From);
            string to = ConvertLanguage(languagesPair.To);

            string query = "http://{0}.{1}.open-tran.eu/json/suggest/{2}";
            query = string.Format(query, from, to, HttpUtility.UrlEncode(phrase));

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

            helper.Referer = "http://translate-net.appspot.com/";
            string responseFromServer = helper.GetResponse();
            JsonArray parsed = (JsonArray)JsonParser.Parse(responseFromServer);
            string count;
            string translation = "";
            string subphrase, servicename;
            Result subres;

            foreach(JsonObject item in parsed)
            {
                translation = ((JsonValue)item["text"]).Value;
                count = ((JsonValue)item["count"]).Value;

                if(translation.StartsWith("&") ||
                    translation.StartsWith("_") ||
                    translation.StartsWith("$") ||
                    translation.StartsWith("~")
                    )
                    translation = translation.Substring(1);

                subres = CreateNewResult(translation, languagesPair, subject);
                if(count != "1")
                    subres.Abbreviation = " {" + count.ToString() + "}";
                result.Childs.Add(subres);

                foreach(JsonObject project in (JsonArray)item["projects"])
                {
                    count = ((JsonValue)project["count"]).Value;
                    servicename = ((JsonValue)project["path"]).Value.Substring(2);
                    servicename = ((JsonValue)project["name"]).Value + " " + servicename;
                    subphrase = ((JsonValue)project["orig_phrase"]).Value;
                    if(subphrase.StartsWith("&") ||
                            subphrase.StartsWith("_") ||
                            subphrase.StartsWith("$") ||
                            subphrase.StartsWith("~")
                        )
                        subphrase = subphrase.Substring(1);

                        subphrase += " - " + servicename + " - ";
                        subphrase += " {" + count.ToString() + "}";
                        subres.Translations.Add(subphrase);
                }
            }

            if(result.Childs.Count > 0)
            {
                result.ArticleUrl = "http://" + from + "." + to + ".open-tran.eu/suggest/" + phrase;
                result.ArticleUrlCaption = phrase;
            }
            else
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.slovnenya.com/dictionary/{0}";
            query = string.Format(query, HttpUtility.UrlEncode(phrase).Replace("+", "%20"));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                    networkSetting,
                    WebRequestContentType.UrlEncodedGet);

            helper.AcceptLanguage = "en-us,en";
            string responseFromServer = helper.GetResponse();

            if(responseFromServer.Contains("did not return any results</div>") ||
                responseFromServer.Contains("</span>` did not return any results"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if(responseFromServer.IndexOf("Query contains extraneous symbol(s)<") >= 0)
            {
                throw new TranslationException("Query contains extraneous symbols");
            }
            else
            {
                result.ArticleUrl = query;
                result.ArticleUrlCaption = phrase;

                string translation = StringParser.Parse("<hr style=\"border:0;background-color:grey;height:1px;width:92%;text-align:center\" />", "<hr style=\"border:0;background-color:grey;height:1px;width:92%;text-align:center\" />", responseFromServer);
                StringsTree tree = StringParser.ParseTreeStructure("<table", "</table>", translation);
                if(tree.Childs.Count != 1)
                        throw new TranslationException("Wrong data structure");

                tree = tree.Childs[0];

                if(tree.Childs.Count != 1)
                        throw new TranslationException("Wrong data structure");

                tree = tree.Childs[0];

                Result wordres = result;

                if(tree.Childs.Count == 0)
                        throw new TranslationException("Wrong data structure");

                //get word
                if(tree.Childs[0].Childs.Count != 1)
                    throw new TranslationException("Wrong data structure");

                string word = StringParser.Parse("font-size:14pt\">", "<", tree.Childs[0].Childs[0].Data);

                for(int i = 1; i < tree.Childs.Count; i++)
                {
                    StringsTree abbr_tree = tree.Childs[i];
                    Result abbrres = null;

                    string abbr = StringParser.Parse("font-size:12pt\">", "<", abbr_tree.Data);
                    Result tmpRes = CreateNewResult(abbr, languagesPair, subject);
                    wordres.Childs.Add(tmpRes);
                    abbrres = tmpRes;

                    StringParser parser = new StringParser(abbr_tree.Childs[0].Data);
                    string[] translations = parser.ReadItemsList("font-size:12pt\">", "<");
                    foreach(string trans in translations)
                        abbrres.Translations.Add(trans);
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://slovnyk.org/fcgi-bin/dic.fcgi?iw={0}&hn=pre&il={1}&ol={2}&ul=en-us";
            query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase), ConvertLanguage(languagesPair.From), ConvertLanguage(languagesPair.To));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                    networkSetting,
                    WebRequestContentType.UrlEncodedGet);

            string responseFromServer = helper.GetResponse().Trim();
            if(string.IsNullOrEmpty(responseFromServer))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("<PRE>", "</PRE>",  responseFromServer).Trim();
                if(string.IsNullOrEmpty(translation))
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }

                string subphrase, subtranslation;
                int startIdx = 0;
                int newLineIdx = 0;
                int tabIdx = translation.IndexOf('\t', startIdx);
                bool firstRun = true;
                Result subres = result;

                while(tabIdx >= 0)
                {
                    newLineIdx = translation.IndexOf('\n', startIdx);
                    if(newLineIdx < 0)
                        newLineIdx = translation.Length;
                    subphrase = translation.Substring(startIdx, tabIdx - startIdx);
                    subtranslation = translation.Substring(tabIdx + 1, newLineIdx - tabIdx - 1);
                    startIdx = newLineIdx + 1;
                    if(startIdx < translation.Length)
                        tabIdx = translation.IndexOf('\t', startIdx);
                    else
                        tabIdx = -1;
                    if(firstRun && tabIdx < 0 && string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) ==0)
                    {
                        result.Translations.Add(subtranslation);
                        return;
                    }

                    if(firstRun)
                    {
                        subres = CreateNewResult(subphrase, languagesPair, subject);
                        result.Childs.Add(subres);
                    }

                    firstRun = false;

                    if(string.Compare(subphrase, subres.Phrase, true, CultureInfo.InvariantCulture) !=0)
                    {
                        subres = CreateNewResult(subphrase, languagesPair, subject);
                        result.Childs.Add(subres);
                    }

                    subres.Translations.Add(subtranslation);
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://rosukrdic.iatp.org.ua/search.php?fullname=%E0%E2%EE%F1%FC
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.rosukrdic.ho.ua/search.php"),
                    networkSetting,
                    WebRequestContentType.UrlEncoded);
            helper.Encoding = Encoding.GetEncoding(1251); //koi8-u
            string query = "fullname={0}";

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

            string responseFromServer = helper.GetResponse();
            if(responseFromServer.IndexOf("</b>������ � ��������.") >= 0 ||
                responseFromServer.IndexOf("</b> ������ � ��������.") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("<body>", "</body>", responseFromServer);
                translation = translation.Replace("</u>", "");
                translation = translation.Replace("</span>", "");
                translation = translation.Replace("<span class=\"examples_class\">", "");
                translation = translation.Replace("<em>", "");
                translation = translation.Replace("</em>", "");
                translation = translation.Replace("<p>\n", "<p>");
                translation = translation.Replace("<p>\r\n", "<p>");
                translation = translation.Replace("<h2>", "\n<h2>");
                translation = translation.Replace("</p>", "\n</p>");
                translation = translation.Replace("<span class='examples_class'>", "");

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

                StringParser translationsParser = new StringParser(translation);
                string[] translations = translationsParser.ReadItemsList("<p", "\n", "787654323");

                string subphrase;
                string subtranslation;
                Result subres = null;
                for(int i = 0; i < phrases.Length; i++)
                {
                    subphrase = phrases[i].Trim();
                    if(subphrase.EndsWith("."))
                        subphrase = subphrase.Substring(0, subphrase.Length-1);
                    subtranslation = translations[i].Substring(1).Trim();
                    subtranslation = subtranslation.Replace("<span class=\"style1\">", "");
                    subtranslation = subtranslation.Replace("lass=\"style1\">", "");
                    subtranslation = subtranslation.Replace("</p>", "");

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

                }

            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            lock (cookieContainer)
            {
                if (coockieTime < DateTime.Now.AddHours(-1))
                {                  //emulate first access to site
                    WebRequestHelper helpertop =
                        new WebRequestHelper(result, new Uri("http://translate.meta.ua/"),
                                             networkSetting,
                                             WebRequestContentType.UrlEncodedGet);
                    helpertop.CookieContainer = cookieContainer;
                    string responseFromServertop = helpertop.GetResponse();
                    coockieTime = DateTime.Now;
                }
            }

            string lang_from = ConvertLanguage(languagesPair.From);
            string lang_to   = ConvertLanguage(languagesPair.To);

            string responseFromServer = null;

            lock (cookieContainer)
            {
                WebRequestHelper helper =
                    new WebRequestHelper(result, new Uri("http://translate.meta.ua/ajax/?sn=save_source"),
                                         networkSetting,
                                         WebRequestContentType.UrlEncoded);
                helper.CookieContainer = cookieContainer;

                //query
                //text_source=проверка&lang_to=ua&lang_from=ru&dict=**
                StringBuilder queryBuilder = new StringBuilder();
                queryBuilder.AppendFormat("text_source={0}&", phrase);
                queryBuilder.AppendFormat("lang_to={0}&lang_from={1}&", lang_to, lang_from);
                queryBuilder.AppendFormat("dict=", GetSubject(subject));
                string query = queryBuilder.ToString();
                helper.AddPostData(query);
                responseFromServer = helper.GetResponse();
                coockieTime        = DateTime.Now;
            }

            if (!String.IsNullOrEmpty(responseFromServer))
            {
                //{"r":true,"pc":1,"ui":"4c1ea0e46198f"}
                string code = StringParser.Parse("ui\":\"", "\"}", responseFromServer);
                //http://translate.meta.ua/ajax/?sn=get_translate&translate_uniqid=4c1ea0e46198f&lang_to=ua&lang_from=ru&translate_part=0
                string query = "http://translate.meta.ua/ajax/?sn=get_translate&translate_uniqid={0}&lang_to={1}&lang_from={2}&translate_part=0";
                string url   = String.Format(query, code, lang_to, lang_from);
                lock (cookieContainer)
                {
                    WebRequestHelper helper =
                        new WebRequestHelper(result, new Uri(url),
                                             networkSetting,
                                             WebRequestContentType.UrlEncodedGet);
                    helper.CookieContainer = cookieContainer;
                    responseFromServer     = helper.GetResponse();
                    coockieTime            = DateTime.Now;
                }
                if (!String.IsNullOrEmpty(responseFromServer))
                {
                    //{"source":"\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430","translate":" \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u043a\u0430","translate_part":"0","type":"p","index":0,"r":true}
                    string translation = StringParser.Parse("translate\":\"", "\"", responseFromServer);
                    result.Translations.Add(HttpUtilityEx.HtmlDecode(translation));
                }
                else
                {
                    throw new TranslationException("Nothing returned from call to " + url);
                }
            }
            else
            {
                throw new TranslationException("Nothing returned from call to http://translate.meta.ua/ajax/?sn=save_source");
            }
        }
        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);
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://en.sozlukte.com/AjaxSearch/?word={0}&lang={1}";
            query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase), ConvertLanguagesPair(languagesPair));

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

            string responseFromServer = helper.GetResponse();
            if(responseFromServer.Contains("<h3>-</h3>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                string translation = StringParser.Parse("<h3>", "</h3>", responseFromServer);
                result.Translations.Add(translation);
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://www.urduenglishdictionary.org/English-To-Urdu-Translation/test/Page-1.htm
            string query = "http://www.urduenglishdictionary.org/English-To-Urdu-Translation/{0}/Page-1.htm";

            if (languagesPair.From == Language.Urdu)
            {
                query = "http://www.urduenglishdictionary.org/Urdu-To-English-Translation/{0}/Page-1.htm";
            }

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

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

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("</B> could not be found!</h2>") &&
                responseFromServer.Contains("<U>Suggestions:</U><BR><BR><BR><BR><BR><BR></div>")
                )
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.Contains("</B> could not be found!</h2>") &&
                     responseFromServer.Contains("<U>Suggestions:</U><BR><BR><a")
                     )
            {
                //suggestions exists
                string       suggestions      = StringParser.Parse("<U>Suggestions:</U><BR><BR>", "</div>", responseFromServer);
                StringParser parser           = new StringParser(suggestions);
                string[]     suggestions_list = parser.ReadItemsList("<a href='", "</a>");
                foreach (string str in suggestions_list)
                {
                    result.Translations.Add("html!<p><a href='http://www.urduenglishdictionary.org" + str + "</a></p>");
                }
            }
            else
            {
                if (responseFromServer.Contains("<tr class='head-row'>"))
                {
                    result.ArticleUrl        = query;
                    result.ArticleUrlCaption = phrase;

                    string       translation  = StringParser.Parse("<tr class='head-row'>", "</table>", responseFromServer);
                    StringParser parser       = new StringParser(translation);
                    string[]     translations = parser.ReadItemsList("<tr class='data-row'>", "</tr>");
                    Result       subres       = null;
                    foreach (string str in translations)
                    {
                        string word = "";
                        if (str.Contains("align=left valign=top nowrap>"))
                        {
                            word = StringParser.Parse("align=left valign=top nowrap>", "<sup>", str).Trim();
                        }
                        else
                        {
                            word = StringParser.Parse("<td class='data-cell' align=left valign=top>", "<",
                                                      StringParser.Parse("<td class='data-cell' align=left valign=top>", "sup>", str)).Trim();
                        }

                        string abbr = StringParser.Parse("<span class='feature'>", "</span>", str).Trim();
                        translation = StringParser.Parse("<td class='urdu-cell' align=right valign=top>", "<", str).Trim();

                        if (translations.Length == 1)
                        {
                            subres = result;
                        }
                        else if (languagesPair.From == Language.Urdu)
                        {
                            subres = CreateNewResult(translation, languagesPair, subject);
                            result.Childs.Add(subres);
                        }
                        else
                        {
                            subres = CreateNewResult(word, languagesPair, subject);
                            result.Childs.Add(subres);
                        }

                        subres.Abbreviation = abbr;
                        if (languagesPair.From == Language.Urdu)
                        {
                            subres.Translations.Add(word);
                        }
                        else
                        {
                            subres.Translations.Add(translation);
                        }
                    }
                }

                //more
                if (responseFromServer.Contains("Page-2.htm"))
                {
                    query = "http://www.urduenglishdictionary.org/English-To-Urdu-Translation/{0}/Page-2.htm";
                    if (languagesPair.From == Language.Urdu)
                    {
                        query = "http://www.urduenglishdictionary.org/Urdu-To-English-Translation/{0}/Page-2.htm";
                    }

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

                    string link = "html!<p><a href=\"{0}\" title=\"{0}\">{1}</a></p>";
                    link = string.Format(link,
                                         query,
                                         "More ...");
                    Result subres = CreateNewResult(link, languagesPair, subject);
                    result.Childs.Add(subres);
                }

                if (result.Childs.Count == 0 && result.Translations.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);
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://babelfish.yahoo.com/translate_txt"),
                    networkSetting,
                    WebRequestContentType.UrlEncoded);
            helper.AcceptCharset = "utf-8";

            //query
            //ei=UTF-8&doit=done&fr=bf-res&intl=1&tt=urltext&trtext=test+it&lp=en_ru&btnTrTxt=Translate

            string langpair= ConvertTranslatorLanguagesPair(languagesPair);
            string query = "ei=UTF-8&doit=done&fr=bf-res&intl=1&tt=urltext&trtext=" +
                HttpUtility.UrlEncode(phrase, System.Text.Encoding.UTF8 ) +
                "&lp=" + langpair +
                "&btnTrTxt=Translate";

            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();
            result.Translations.Add(StringParser.Parse("<div style=\"padding:0.6em;\">", "</div>", responseFromServer));
        }
        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);
                                }

                            }

                        }
                    }
                }

            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://slovnik.seznam.cz/?q=test&lang=en_cz
            string query = "http://slovnik.seznam.cz/?q={0}&lang={1}";
            query = string.Format(CultureInfo.InvariantCulture, query, HttpUtility.UrlEncode(phrase), ConvertLanguagesPair(languagesPair));

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

            string responseFromServer = helper.GetResponse();
            if(responseFromServer.Contains("</strong>&quot; nebylo ve Slovníku nic nalezeno.</h2>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                result.ArticleUrl = query;
                result.ArticleUrlCaption = phrase;

                //translation by self
                if(responseFromServer.Contains("<table id=\"words\">"))
                {
                    string translation = StringParser.Parse("<table id=\"words\">", "</table>", responseFromServer);
                    StringParser parser = new StringParser(translation);
                    string[] translations = parser.ReadItemsList("<tr>", "</tr>");
                    Result subres = null;
                    foreach(string str in translations)
                    {
                        string word = StringParser.Parse(">", "<", StringParser.Parse("<a", "/a>", str));
                        subres = CreateNewResult(word, languagesPair, subject);
                        result.Childs.Add(subres);

                        StringParser subparser = new StringParser("<td class=\"translated\">", "</td>", str);
                        string[] subtranslations = subparser.ReadItemsList("<a", "/a>") ;
                        foreach(string sub_str in subtranslations)
                        {
                            if(!sub_str.Contains("<img src"))
                                subres.Translations.Add(StringParser.Parse(">", "<", sub_str));
                        }
                    }
                }

                //phrases
                if(responseFromServer.Contains("<div id=\"collocations\">"))
                {
                    string translation = StringParser.Parse("<div id=\"collocations\">", "</div>", responseFromServer);
                    StringParser parser = new StringParser(translation);
                    string[] translations = parser.ReadItemsList("<dt>", "</dd>");
                    Result subres = null;
                    foreach(string str in translations)
                    {
                        string word = StringParser.Parse(">", "<", StringParser.Parse("<a", "/a>", str));
                        subres = CreateNewResult(word, languagesPair, subject);
                        result.Childs.Add(subres);

                        StringParser subparser = new StringParser("<dd>", "</dd>", str + "</dd>");
                        string[] subtranslations = subparser.ReadItemsList("<a", "/a>") ;
                        foreach(string sub_str in subtranslations)
                        {
                                subres.Translations.Add(StringParser.Parse(">", "<", sub_str));
                        }

                    }

                    if(responseFromServer.Contains("&amp;from=31\">2</a></span>"))
                    { //more phrases

                        string link = "html!<p><a href=\"{0}\" title=\"{0}\">{1}</a></p>";
                        link = string.Format(link,
                            query + "&from=31",
                            "More phrases ...");
                        subres = CreateNewResult(link, languagesPair, subject);
                        result.Childs.Add(subres);
                    }
                }

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

            }
        }
        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);
                    }

                }

            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://slovnik.tiscali.cz/index.php?od=0&slovnik=dict_ac&dotaz=test
            string query = "http://slovnik.tiscali.cz/index.php?od=0&slovnik={0}&dotaz={1}";
            query = string.Format(CultureInfo.InvariantCulture, query, ConvertLanguagesPair(languagesPair), HttpUtility.UrlEncode(phrase));

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

            string responseFromServer = helper.GetResponse();
            if(responseFromServer.Contains("<strong>Zadané slovo nebylo nalezeno !!!</strong>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                if(responseFromServer.Contains("<div class=\"vysledek\">"))
                {
                    result.ArticleUrl = query;
                    result.ArticleUrlCaption = phrase;

                    string translation = StringParser.Parse("<div class=\"vysledek\">", "</div>", responseFromServer);
                    StringParser parser = new StringParser(translation);
                    string[] translations = parser.ReadItemsList("<a", "<br />");
                    Result subres = null;
                    foreach(string str in translations)
                    {
                        string word = StringParser.Parse("<strong>", "</strong>", str);
                        string subtranslation = StringParser.Parse(">", "<", StringParser.Parse("<a", "/a>", str));

                        if (subres == null || subres.Phrase != word )
                        {
                            subres = CreateNewResult(word, languagesPair, subject);
                            result.Childs.Add(subres);
                        }
                        subres.Translations.Add(subtranslation);

                    }
                }

                //more
                if(responseFromServer.Contains("<strong>Další >></strong>"))
                {
                    query = "http://slovnik.tiscali.cz/index.php?od=24&slovnik={0}&dotaz={1}";
                    query = string.Format(CultureInfo.InvariantCulture, query, ConvertLanguagesPair(languagesPair), HttpUtility.UrlEncode(phrase));

                    string link = "html!<p><a href=\"{0}\" title=\"{0}\">{1}</a></p>";
                    link = string.Format(link,
                        query,
                        "More phrases ...");
                    Result subres = CreateNewResult(link, languagesPair, subject);
                    result.Childs.Add(subres);
                }

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

            }
        }
Exemple #29
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://slovnik.tiscali.cz/index.php?od=0&slovnik=dict_ac&dotaz=test
            string query = "http://slovnik.tiscali.cz/index.php?od=0&slovnik={0}&dotaz={1}";

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

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

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("<strong>Zadané slovo nebylo nalezeno !!!</strong>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                if (responseFromServer.Contains("<div class=\"vysledek\">"))
                {
                    result.ArticleUrl        = query;
                    result.ArticleUrlCaption = phrase;

                    string       translation  = StringParser.Parse("<div class=\"vysledek\">", "</div>", responseFromServer);
                    StringParser parser       = new StringParser(translation);
                    string[]     translations = parser.ReadItemsList("<a", "<br />");
                    Result       subres       = null;
                    foreach (string str in translations)
                    {
                        string word           = StringParser.Parse("<strong>", "</strong>", str);
                        string subtranslation = StringParser.Parse(">", "<", StringParser.Parse("<a", "/a>", str));

                        if (subres == null || subres.Phrase != word)
                        {
                            subres = CreateNewResult(word, languagesPair, subject);
                            result.Childs.Add(subres);
                        }
                        subres.Translations.Add(subtranslation);
                    }
                }

                //more
                if (responseFromServer.Contains("<strong>Další >></strong>"))
                {
                    query = "http://slovnik.tiscali.cz/index.php?od=24&slovnik={0}&dotaz={1}";
                    query = string.Format(CultureInfo.InvariantCulture, query, ConvertLanguagesPair(languagesPair), HttpUtility.UrlEncode(phrase));

                    string link = "html!<p><a href=\"{0}\" title=\"{0}\">{1}</a></p>";
                    link = string.Format(link,
                                         query,
                                         "More phrases ...");
                    Result subres = CreateNewResult(link, languagesPair, subject);
                    result.Childs.Add(subres);
                }

                if (result.Childs.Count == 0)
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }
            }
        }
Exemple #30
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);
                        }
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.systranet.com/tt?gui=www.systran.co.uk;/snetcom/text/ts&lp={0}&MAX_TRANSLATED_WORDS=500&service=translate";
            query = string.Format(query, ConvertLanguagesPair(languagesPair));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                    networkSetting,
                    WebRequestContentType.UrlEncoded);

            helper.AddPostData(phrase);

            string responseFromServer = helper.GetResponse();

            string status = responseFromServer.Substring(6);
            result.Translations.Add(status);
            /*
            if(status != "2")
            {
                throw new TranslationException(responseFromServer.Substring(10));
            }
            else
            {	if(responseFromServer.Substring(17) == "Translation direction is not correct")
                    throw new TranslationException("Translation direction is not correct");
                result.Translations.Add(responseFromServer.Substring(17));
            }
            */
        }
        string DoInternalTranslate(string query, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                    networkSetting,
                    WebRequestContentType.UrlEncodedGet,
                    true);
            helper.Referer = "http://translate-net.appspot.com/";

            string responseFromServer = helper.GetResponse();

            if(responseFromServer.Contains(", \"responseStatus\": 200}"))
            {
                string translation = StringParser.Parse("\"translatedText\":\"", "\"", responseFromServer);
                translation = HttpUtilityEx.HtmlDecode(translation);
                return translation;
            }
            else
            {
                string error = StringParser.Parse("\"responseDetails\": \"", "\"", responseFromServer);
                string code = StringParser.Parse("\"responseStatus\":", "}", responseFromServer);
                throw new TranslationException(error + ", error code : " + code);
            }
        }
        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);
            }
        }
        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://web.cecs.pdx.edu/~bule/bahasa/search.php"),
                            networkSetting,
                            WebRequestContentType.UrlEncodedGet, encoding);
                    helpertop.CookieContainer = cookieContainer;
                    coockieTime = DateTime.Now;
                    string responseFromServertop = helpertop.GetResponse();
                    sederetCode = StringParser.Parse("<input type=\"hidden\" name=\"id\" value=\"", "\"", responseFromServertop);
                }
            }

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://web.cecs.pdx.edu/~bule/bahasa/search.php"),
                    networkSetting,
                    WebRequestContentType.UrlEncoded, encoding);
            helper.CookieContainer = cookieContainer;

            //English to Indonesian, Indonesian to English
            string query = "id={0}&language={1}&method=fuzzy&stoken={2}";

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

            string responseFromServer = helper.GetResponse();

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

            if(!responseFromServer.Contains("<th colspan=\"6\"><hr>"))
            {
                result.ResultNotFound = result.Childs.Count == 0;
                return;
            }

            string translation = StringParser.Parse("<th colspan=\"6\"><hr>", "<tr><td colspan=\"6\"><hr>", responseFromServer);

            Result child;
            StringParser subparser;

            {
                subparser = new StringParser(translation);
                string[] subtranslation_list = subparser.ReadItemsList("<td", "</td>");
                for(int i = 0; i < subtranslation_list.Length; i+=6)
                {
                    string subphrase = subtranslation_list[i];
                    subphrase = StringParser.ExtractRight(">", subphrase);

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

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

                    string abbr = subtranslation_list[i+2];
                    abbr = StringParser.ExtractRight(">", abbr);
                    child.Abbreviation = abbr;
                }
            }

            result.ResultNotFound = result.Childs.Count == 0;
        }
Exemple #35
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++;
                }
            }
        }
        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);
                }

            }
        }
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.trident.com.ua/translation_online/"),
                    networkSetting,
                    WebRequestContentType.UrlEncoded);

            //query
            //?SrcTxt=test&Subject=**&LangFrom=Detect&LangTo=Rus&Translate=++Translate+++&DstTxt=&DlgLang=english
            string lang_to = ConvertLanguage(languagesPair.To);
            string lang_from = ConvertLanguage(languagesPair.From);
            string query = "SrcTxt={2}&Subject={1}&LangFrom={3}&LangTo={0}&Translate=++Translate+++&DstTxt=&DlgLang=english";
            query = string.Format(CultureInfo.InvariantCulture,
                query,
                lang_to,
                GetSubject(subject),
                HttpUtility.UrlEncode(phrase, helper.Encoding),
                lang_from);
            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            string translation = StringParser.Parse("<textarea rows=\"7\" cols=\"50\" name=\"DstTxt\"", "</textarea>", responseFromServer);
            translation = StringParser.ExtractRight(">",translation).Trim();
            if(!String.IsNullOrEmpty(translation))
                result.Translations.Add(translation);
            else
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
        }
        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);
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://openthes-es.berlios.de/multimatch.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();

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

            OpenthesaurusDeDictionary.SetResult(result, responseFromServer);
        }
Exemple #41
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string from = ConvertLanguage(languagesPair.From);
            string to   = ConvertLanguage(languagesPair.To);

            string query = "http://{0}.{1}.open-tran.eu/json/suggest/{2}";

            query = string.Format(query, from, to, HttpUtility.UrlEncode(phrase));

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

            helper.Referer = "http://translate-net.appspot.com/";
            string    responseFromServer = helper.GetResponse();
            JsonArray parsed             = (JsonArray)JsonParser.Parse(responseFromServer);
            string    count;
            string    translation = "";
            string    subphrase, servicename;
            Result    subres;

            foreach (JsonObject item in parsed)
            {
                translation = ((JsonValue)item["text"]).Value;
                count       = ((JsonValue)item["count"]).Value;

                if (translation.StartsWith("&") ||
                    translation.StartsWith("_") ||
                    translation.StartsWith("$") ||
                    translation.StartsWith("~")
                    )
                {
                    translation = translation.Substring(1);
                }

                subres = CreateNewResult(translation, languagesPair, subject);
                if (count != "1")
                {
                    subres.Abbreviation = " {" + count.ToString() + "}";
                }
                result.Childs.Add(subres);

                foreach (JsonObject project in (JsonArray)item["projects"])
                {
                    count       = ((JsonValue)project["count"]).Value;
                    servicename = ((JsonValue)project["path"]).Value.Substring(2);
                    servicename = ((JsonValue)project["name"]).Value + " " + servicename;
                    subphrase   = ((JsonValue)project["orig_phrase"]).Value;
                    if (subphrase.StartsWith("&") ||
                        subphrase.StartsWith("_") ||
                        subphrase.StartsWith("$") ||
                        subphrase.StartsWith("~")
                        )
                    {
                        subphrase = subphrase.Substring(1);
                    }

                    subphrase += " - " + servicename + " - ";
                    subphrase += " {" + count.ToString() + "}";
                    subres.Translations.Add(subphrase);
                }
            }

            if (result.Childs.Count > 0)
            {
                result.ArticleUrl        = "http://" + from + "." + to + ".open-tran.eu/suggest/" + phrase;
                result.ArticleUrlCaption = phrase;
            }
            else
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
        }
Exemple #42
0
        protected override void DoGuess(string phrase, GuessResult result, NetworkSetting networkSetting)
        {
            string query_base = "http://ajax.googleapis.com/ajax/services/language/detect?" +
                                "v=1.0&hl=en&q=";
            int allowed_length = 2070 - query_base.Length;

            string query = SplitQuery(phrase, allowed_length);

            if (query.Length > 500)
            {
                throw new InvalidOperationException("The length of string is greater of 500 characters." +
                                                    " string : " + query +
                                                    ", full phrase : " + phrase
                                                    );
            }

            string real_query = query_base + HttpUtility.UrlEncode(query);

            if (real_query.Length > 2070)
            {
                throw new InvalidOperationException("The length of query is greater of 2070 characters." +
                                                    " query : " + real_query +
                                                    " full phrase : " + phrase
                                                    );
            }

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

            helper.Referer = "http://translate-net.appspot.com/";

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains(", \"responseStatus\": 200}"))
            {
                string languageString   = StringParser.Parse("\"language\":\"", "\"", responseFromServer);
                string isReliableString = StringParser.Parse("\"isReliable\":", ",", responseFromServer);
                string confidenceString = StringParser.Parse("\"confidence\":", "}", responseFromServer);

                Language language;
                if (languageString == "pt-PT")
                {
                    language = Language.Portuguese;
                }
                else
                {
                    if (!keyToLang.TryGetValue(languageString, out language))
                    {
                        throw new TranslationException("Language : " + languageString + " not supported");
                    }
                }

                bool isReliable = isReliableString == "true";
                //if(phrase.Length < 30)
                //	isReliable = false;

                NumberFormatInfo num = NumberFormatInfo.InvariantInfo;
                confidenceString = confidenceString.Replace(",", num.NumberDecimalSeparator);
                confidenceString = confidenceString.Replace(".", num.NumberDecimalSeparator);

                double confidence;
                if (!double.TryParse(confidenceString, NumberStyles.Number | NumberStyles.AllowExponent, num, out confidence))
                {
                    throw new TranslationException("Can't parse string : " + confidenceString + " to float");
                }

                result.AddScore(language, confidence * 100, isReliable);
            }
            else
            {
                string error = StringParser.Parse("\"responseDetails\": \"", "\"", responseFromServer);
                string code  = StringParser.Parse("\"responseStatus\":", "}", responseFromServer);
                throw new TranslationException(error + ", error code : " + code);
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://www.urduenglishdictionary.org/English-To-Urdu-Translation/test/Page-1.htm
            string query = "http://www.urduenglishdictionary.org/English-To-Urdu-Translation/{0}/Page-1.htm";
            if(languagesPair.From == Language.Urdu)
                query = "http://www.urduenglishdictionary.org/Urdu-To-English-Translation/{0}/Page-1.htm";

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

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

            string responseFromServer = helper.GetResponse();
            if(responseFromServer.Contains("</B> could not be found!</h2>") &&
                responseFromServer.Contains("<U>Suggestions:</U><BR><BR><BR><BR><BR><BR></div>")
            )
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if(responseFromServer.Contains("</B> could not be found!</h2>") &&
                responseFromServer.Contains("<U>Suggestions:</U><BR><BR><a")
            )
            {
                //suggestions exists
                string suggestions = StringParser.Parse("<U>Suggestions:</U><BR><BR>", "</div>", responseFromServer);
                StringParser parser = new StringParser(suggestions);
                string[] suggestions_list = parser.ReadItemsList("<a href='", "</a>");
                foreach(string str in suggestions_list)
                {
                    result.Translations.Add("html!<p><a href='http://www.urduenglishdictionary.org" + str + "</a></p>");
                }
            }
            else
            {
                if(responseFromServer.Contains("<tr class='head-row'>"))
                {
                    result.ArticleUrl = query;
                    result.ArticleUrlCaption = phrase;

                    string translation = StringParser.Parse("<tr class='head-row'>", "</table>", responseFromServer);
                    StringParser parser = new StringParser(translation);
                    string[] translations = parser.ReadItemsList("<tr class='data-row'>", "</tr>");
                    Result subres = null;
                    foreach(string str in translations)
                    {
                        string word = "";
                        if(str.Contains("align=left valign=top nowrap>"))
                            word = StringParser.Parse("align=left valign=top nowrap>", "<sup>", str).Trim();
                        else
                            word = StringParser.Parse("<td class='data-cell' align=left valign=top>", "<",
                                StringParser.Parse("<td class='data-cell' align=left valign=top>", "sup>", str)).Trim();

                        string abbr = StringParser.Parse("<span class='feature'>", "</span>", str).Trim();
                        translation  = StringParser.Parse("<td class='urdu-cell' align=right valign=top>", "<", str).Trim();

                        if(translations.Length == 1)
                            subres = result;
                        else if(languagesPair.From == Language.Urdu)
                        {
                            subres = CreateNewResult(translation, languagesPair, subject);
                            result.Childs.Add(subres);
                        }
                        else
                        {
                            subres = CreateNewResult(word, languagesPair, subject);
                            result.Childs.Add(subres);
                        }

                        subres.Abbreviation = abbr;
                        if(languagesPair.From == Language.Urdu)
                            subres.Translations.Add(word);
                        else
                            subres.Translations.Add(translation);

                    }
                }

                //more
                if(responseFromServer.Contains("Page-2.htm"))
                {
                    query = "http://www.urduenglishdictionary.org/English-To-Urdu-Translation/{0}/Page-2.htm";
                    if(languagesPair.From == Language.Urdu)
                        query = "http://www.urduenglishdictionary.org/Urdu-To-English-Translation/{0}/Page-2.htm";

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

                    string link = "html!<p><a href=\"{0}\" title=\"{0}\">{1}</a></p>";
                    link = string.Format(link,
                        query,
                        "More ...");
                    Result subres = CreateNewResult(link, languagesPair, subject);
                    result.Childs.Add(subres);
                }

                if(result.Childs.Count == 0 && result.Translations.Count == 0)
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }

            }
        }
        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);
            }
        }
        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://web.cecs.pdx.edu/~bule/bahasa/search.php"),
                                             networkSetting,
                                             WebRequestContentType.UrlEncodedGet, encoding);
                    helpertop.CookieContainer = cookieContainer;
                    coockieTime = DateTime.Now;
                    string responseFromServertop = helpertop.GetResponse();
                    sederetCode = StringParser.Parse("<input type=\"hidden\" name=\"id\" value=\"", "\"", responseFromServertop);
                }
            }



            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://web.cecs.pdx.edu/~bule/bahasa/search.php"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded, encoding);

            helper.CookieContainer = cookieContainer;

            //English to Indonesian, Indonesian to English
            string query = "id={0}&language={1}&method=fuzzy&stoken={2}";

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

            string responseFromServer = helper.GetResponse();

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

            if (!responseFromServer.Contains("<th colspan=\"6\"><hr>"))
            {
                result.ResultNotFound = result.Childs.Count == 0;
                return;
            }

            string translation = StringParser.Parse("<th colspan=\"6\"><hr>", "<tr><td colspan=\"6\"><hr>", responseFromServer);

            Result       child;
            StringParser subparser;


            {
                subparser = new StringParser(translation);
                string[] subtranslation_list = subparser.ReadItemsList("<td", "</td>");
                for (int i = 0; i < subtranslation_list.Length; i += 6)
                {
                    string subphrase = subtranslation_list[i];
                    subphrase = StringParser.ExtractRight(">", subphrase);

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

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

                    string abbr = subtranslation_list[i + 2];
                    abbr = StringParser.ExtractRight(">", abbr);
                    child.Abbreviation = abbr;
                }
            }

            result.ResultNotFound = result.Childs.Count == 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);
                        }
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.online-translator.com/text/references.aspx?prmtlang=en&direction={0}&word={1}";
            query = string.Format(query, PromtUtils.ConvertLanguagesPair(languagesPair),
                HttpUtility.UrlEncode(phrase));

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

            string responseFromServer = helper.GetResponse();

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

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

            StringParser parser = new StringParser(responseFromServer);
            string[] translation_list = parser.ReadItemsList("<span class=\"ref_source\"", "</table>");

            string subphrase;
            string abbreviation;
            Result child;
            StringParser subparser;

            foreach(string translation in translation_list)
            {
                subphrase = StringParser.Parse(">","</span>",translation);
                abbreviation = StringParser.Parse("<span class=\"ref_psp\">","</span>",translation);
                child = CreateNewResult(subphrase, languagesPair, subject);
                child.Abbreviation = abbreviation;
                result.Childs.Add(child);
                subparser = new StringParser(translation);
                string[] subtranslation_list = subparser.ReadItemsList("<span class=\"ref_result\">", "</span>");
                foreach(string subtranslation in subtranslation_list)
                {
                    child.Translations.Add(HttpUtility.HtmlDecode(subtranslation));
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://193.2.66.133:85/overview.php?search=1&word={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, encoding);

            string responseFromServer = helper.GetResponse();

            OpenthesaurusDeDictionary.SetResult(result, responseFromServer);
        }
Exemple #49
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);
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.slovnenya.com/dictionary/{0}";

            query = string.Format(query, HttpUtility.UrlEncode(phrase).Replace("+", "%20"));
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            helper.AcceptLanguage = "en-us,en";
            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("did not return any results</div>") ||
                responseFromServer.Contains("</span>` did not return any results"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.IndexOf("Query contains extraneous symbol(s)<") >= 0)
            {
                throw new TranslationException("Query contains extraneous symbols");
            }
            else
            {
                result.ArticleUrl        = query;
                result.ArticleUrlCaption = phrase;

                string      translation = StringParser.Parse("<hr style=\"border:0;background-color:grey;height:1px;width:92%;text-align:center\" />", "<hr style=\"border:0;background-color:grey;height:1px;width:92%;text-align:center\" />", responseFromServer);
                StringsTree tree        = StringParser.ParseTreeStructure("<table", "</table>", translation);
                if (tree.Childs.Count != 1)
                {
                    throw new TranslationException("Wrong data structure");
                }

                tree = tree.Childs[0];

                if (tree.Childs.Count != 1)
                {
                    throw new TranslationException("Wrong data structure");
                }

                tree = tree.Childs[0];

                Result wordres = result;

                if (tree.Childs.Count == 0)
                {
                    throw new TranslationException("Wrong data structure");
                }


                //get word
                if (tree.Childs[0].Childs.Count != 1)
                {
                    throw new TranslationException("Wrong data structure");
                }


                string word = StringParser.Parse("font-size:14pt\">", "<", tree.Childs[0].Childs[0].Data);

                for (int i = 1; i < tree.Childs.Count; i++)
                {
                    StringsTree abbr_tree = tree.Childs[i];
                    Result      abbrres   = null;

                    string abbr   = StringParser.Parse("font-size:12pt\">", "<", abbr_tree.Data);
                    Result tmpRes = CreateNewResult(abbr, languagesPair, subject);
                    wordres.Childs.Add(tmpRes);
                    abbrres = tmpRes;

                    StringParser parser       = new StringParser(abbr_tree.Childs[0].Data);
                    string[]     translations = parser.ReadItemsList("font-size:12pt\">", "<");
                    foreach (string trans in translations)
                    {
                        abbrres.Translations.Add(trans);
                    }
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://www.urduword.com/search.php?English=test
            string query = "http://www.urduword.com/search.php?English={0}";

            if (languagesPair.From == Language.Urdu)
            {
                query = "http://www.urduword.com/search.php?Roman={0}";
            }

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

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

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.Contains("<p>Could not find translation for <b>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                if (responseFromServer.Contains("<table border=\"0\" width=\"100%\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" >"))
                {
                    result.ArticleUrl        = query;
                    result.ArticleUrlCaption = phrase;

                    string       translation  = StringParser.Parse("<table border=\"0\" width=\"100%\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" >", "</table>", responseFromServer);
                    StringParser parser       = new StringParser(translation);
                    string[]     translations = parser.ReadItemsList("<tr>", "</tr>");
                    Result       subres       = null;
                    foreach (string str in translations)
                    {
                        if (str.Contains("class=\"tablehead\""))
                        {
                            continue;
                        }

                        string word = StringParser.Parse(">", "<", StringParser.Parse("<a", "/a>", str));
                        translation = StringParser.Parse("align=\"center\">", "<", str);

                        if (languagesPair.From == Language.Urdu)
                        {
                            if (subres == null || subres.Phrase != translation)
                            {
                                subres = CreateNewResult(translation, languagesPair, subject);
                                result.Childs.Add(subres);
                            }
                        }
                        else
                        {
                            if (subres == null || subres.Phrase != word)
                            {
                                subres = CreateNewResult(word, languagesPair, subject);
                                result.Childs.Add(subres);
                            }
                        }

                        if (languagesPair.From == Language.Urdu)
                        {
                            subres.Translations.Add(word);
                        }
                        else
                        {
                            subres.Translations.Add(translation);
                        }
                    }
                }

                //more
                if (responseFromServer.Contains("page=2\">Next"))
                {
                    query = "http://www.urduword.com/search.php?English={0}&page=2";
                    if (languagesPair.From == Language.Urdu)
                    {
                        query = "http://www.urduword.com/search.php?Roman={0}&page=2";
                    }

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

                    string link = "html!<p><a href=\"{0}\" title=\"{0}\">{1}</a></p>";
                    link = string.Format(link,
                                         query,
                                         "More ...");
                    Result subres = CreateNewResult(link, languagesPair, subject);
                    result.Childs.Add(subres);
                }

                if (result.Childs.Count == 0)
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }
            }
        }
Exemple #52
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            if (string.IsNullOrEmpty(viewState))
            {              //emulate first access to site
                WebRequestHelper helpertop =
                    new WebRequestHelper(result, new Uri("http://www.prolingoffice.com/page.aspx?l1=43"),
                                         networkSetting,
                                         WebRequestContentType.UrlEncodedGet,
                                         Encoding.GetEncoding(1251));

                string responseFromServertop = helpertop.GetResponse();
                viewState       = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServertop);
                eventValidation = StringParser.Parse("id=\"__EVENTVALIDATION\" value=\"", "\"", responseFromServertop);
            }

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.prolingoffice.com/page.aspx?l1=43"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded,
                                     Encoding.GetEncoding(1251));

            //__EVENTTARGET=_ctl1%24Menu1&__EVENTARGUMENT=1&
            //__VIEWSTATE={0}&q={1}&_ctl1%3AtsLang=rbLangU&LanguageH=RUS&
            //__EVENTVALIDATION={2}
            string query = "__EVENTTARGET=_ctl1%24Menu1&__EVENTARGUMENT=1&__VIEWSTATE={0}&q={1}&_ctl1%3AtsLang=rbLangU&LanguageH=RUS&__EVENTVALIDATION={2}";

            query = string.Format(query,
                                  HttpUtility.UrlEncode(viewState, helper.Encoding),
                                  HttpUtility.UrlEncode(phrase, helper.Encoding),
                                  HttpUtility.UrlEncode(eventValidation, helper.Encoding));

            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            viewState       = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServer);
            eventValidation = StringParser.Parse("id=\"__EVENTVALIDATION\" value=\"", "\"", responseFromServer);


            if (responseFromServer.IndexOf("Перекладу цього слова не знайдено. Спробуйте записати слово інакше, або ознайомтеся з інформацією, яка міститься у <a") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.IndexOf("В слове содержатся ошибки. Возможно имелось в виду:</b>") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.IndexOf("Синонімів для цього слова не знайдено. Спробуйте записати слово інакше, або ознайомтеся з інформацією, яка міститься у <") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.IndexOf("В слове содержатся ошибки.</b>") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }



            string translation = StringParser.Parse("<span class=\"wrd\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\">", "</TABLE></span>", responseFromServer);
            string abbr        = StringParser.Parse("title=\"", "\"", translation);

            abbr += " " + StringParser.Parse("xslt\">", "</span>", translation).Trim();
            //result.Abbreviation = abbr;

            StringParser parser = new StringParser(translation);

            string[] translations = parser.ReadItemsList("<span class=\"tolk\"", "</td><td></td></tr>", "3495783-4572385");

            foreach (string subtranslation in translations)
            {
                translation = StringParser.Parse(">", "</span>", subtranslation);
                Result subres;
                subres = CreateNewResult(translation, languagesPair, subject);
                result.Childs.Add(subres);

                parser = new StringParser(subtranslation);
                string[] subtranslations = parser.ReadItemsList("<a ", "/a>", "3495783-4572385");
                foreach (string s in subtranslations)
                {
                    subres.Translations.Add(StringParser.Parse(">", "<", s));
                }
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            if(string.IsNullOrEmpty(viewState))
            {  //emulate first access to site
                WebRequestHelper helpertop =
                    new WebRequestHelper(result, new Uri("http://www.prolingoffice.com/page.aspx?l1=43"),
                        networkSetting,
                        WebRequestContentType.UrlEncodedGet,
                        Encoding.GetEncoding(1251));

                string responseFromServertop = helpertop.GetResponse();
                viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServertop);
                eventValidation = StringParser.Parse("id=\"__EVENTVALIDATION\" value=\"", "\"", responseFromServertop);
            }

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.prolingoffice.com/page.aspx?l1=43"),
                    networkSetting,
                    WebRequestContentType.UrlEncoded,
                        Encoding.GetEncoding(1251));

            //__EVENTTARGET=_ctl1%24Menu1&__EVENTARGUMENT=1&
            //__VIEWSTATE={0}&q={1}&_ctl1%3AtsLang=rbLangU&LanguageH=RUS&
            //__EVENTVALIDATION={2}
            string query = "__EVENTTARGET=_ctl1%24Menu1&__EVENTARGUMENT=1&__VIEWSTATE={0}&q={1}&_ctl1%3AtsLang=rbLangU&LanguageH=RUS&__EVENTVALIDATION={2}";

            query = string.Format(query,
                HttpUtility.UrlEncode(viewState, helper.Encoding),
                HttpUtility.UrlEncode(phrase, helper.Encoding),
                HttpUtility.UrlEncode(eventValidation, helper.Encoding));

            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServer);
            eventValidation = StringParser.Parse("id=\"__EVENTVALIDATION\" value=\"", "\"", responseFromServer);

            if(responseFromServer.IndexOf("��������� ����� ����� �� ��������. ��������� �������� ����� ������, ��� ����������� � �����������, ��� �������� � <a") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if(responseFromServer.IndexOf("� ����� ���������� ������. �������� ������� � ����:</b>") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if(responseFromServer.IndexOf("������� ��� ����� ����� �� ��������. ��������� �������� ����� ������, ��� ����������� � �����������, ��� �������� � <") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if(responseFromServer.IndexOf("� ����� ���������� ������.</b>") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            string translation = StringParser.Parse("<span class=\"wrd\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\">", "</TABLE></span>", responseFromServer);
            string abbr = StringParser.Parse("title=\"", "\"", translation);
            abbr += " " + StringParser.Parse("xslt\">", "</span>", translation).Trim();
            //result.Abbreviation = abbr;

            StringParser parser = new StringParser(translation);
            string[] translations = parser.ReadItemsList("<span class=\"tolk\"", "</td><td></td></tr>", "3495783-4572385");

            foreach(string subtranslation in translations)
            {
                translation = StringParser.Parse(">", "</span>", subtranslation);
                Result subres;
                subres = CreateNewResult(translation, languagesPair, subject);
                result.Childs.Add(subres);

                parser = new StringParser(subtranslation);
                string[] subtranslations = parser.ReadItemsList("<a ", "/a>", "3495783-4572385");
                foreach(string s in subtranslations)
                    subres.Translations.Add(StringParser.Parse(">", "<", s));
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.pcdigest.net/cgi-bin/u/book/sis.pl?Qry={0}&found=10&action=search";

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

            string responseFromServer = helper.GetResponse();

            responseFromServer = StringParser.Parse("<!-- START CONTENT -->", "<!-- RIGHT SHORT TABLE -->", responseFromServer);
            responseFromServer = StringParser.Parse("<P align=justify>", "</table>", responseFromServer);
            responseFromServer = responseFromServer.Replace("<font color=darkgreen>", "");
            responseFromServer = responseFromServer.Replace("<font color=red>", "");
            responseFromServer = responseFromServer.Replace("</font>", "");

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

            responseFromServer = responseFromServer.Replace("<i>", "");
            responseFromServer = responseFromServer.Replace("</i>", "");

            responseFromServer = responseFromServer.Replace("<u>", "");
            responseFromServer = responseFromServer.Replace("</u>", "");


            StringParser parser = new StringParser(responseFromServer);

            string[] translations = parser.ReadItemsList("<P align=justify>", "</P>", "3495783-4572385");

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

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

            string translation, abrr, data;
            int    idx;

            foreach (string subtranslation in translations)
            {
                idx = subtranslation.IndexOf("(");
                if (idx < 0)
                {
                    idx = subtranslation.IndexOf("-");
                }

                translation = subtranslation.Substring(0, idx);

                if (subtranslation.IndexOf("(") >= 0)
                {
                    abrr = StringParser.Parse("(", ")", subtranslation);
                }
                else
                {
                    abrr = "";
                }

                idx = subtranslation.IndexOf("-");
                if (idx >= 0)
                {
                    data = subtranslation.Substring(idx + 1);
                }
                else
                {
                    data = "";
                }

                Result subres;
                if (translations.Length > 1)
                {
                    subres = CreateNewResult(translation, languagesPair, subject);
                    result.Childs.Add(subres);
                }
                else
                {
                    subres = result;
                }

                if (!string.IsNullOrEmpty(abrr))
                {
                    subres.Abbreviation = abrr;
                }
                if (!string.IsNullOrEmpty(data))
                {
                    subres.Translations.Add(data);
                }
            }
        }
        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;
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            if (string.IsNullOrEmpty(viewState))
            {              //emulate first access to site
                WebRequestHelper helpertop =
                    new WebRequestHelper(result, new Uri("http://www.priberam.pt/dlpo/dlpo.aspx"),
                                         networkSetting,
                                         WebRequestContentType.UrlEncodedGet,
                                         Encoding.GetEncoding("iso-8859-1"));

                string responseFromServertop = helpertop.GetResponse();
                viewState = StringParser.Parse("name=\"__VIEWSTATE\" value=\"", "\"", responseFromServertop);
            }

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.priberam.pt/dlpo/definir_resultados.aspx"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded,
                                     Encoding.GetEncoding("iso-8859-1"));

            string queryStr = "__EVENTTARGET=&__EVENTARGUMENT=&NOTVIEWSTATE={0}" +
                              "&definActionTarget=%2Fdlpo%2Fdefinir_resultados.aspx" +
                              "&pesqActionTarget=%2Fdlpo%2Fpesquisar_resultados.aspx" +
                              "&conjugaActionTarget=%2Fdlpo%2Fconjugar_resultados.aspx" +
                              "&CVdefinActionTarget=%2Fdcvpo%2Fdefinir_resultados.aspx" +
                              "&CVpesqActionTarget=%2Fdcvpo%2Fpesquisar_resultados.aspx" +
                              "&CVconjugaActionTarget=%2Fdcvpo%2Fconjugar_resultados.aspx" +
                              "&h_seccao_index=&h_vista=&h_abrev_cat=1&h_abrev_flex=1&h_abrev_dom=1" +
                              "&h_abrev_exemp=1&h_abrev_etim=1&h_abrev_outras=1&h_filtro=&h_dominio=" +
                              "&h_var_geografica=&h_categoria=&h_reg_linguistico=&h_etimologia=" +
                              "&h_desc_dominio=&h_desc_var_geografica=&h_desc_categoria=" +
                              "&h_desc_reg_linguistico=&h_desc_etimologia=&accao=" +
                              "&h_texto_pesquisa={1}&h_n={2}&accao=" +
                              "&pal={1}&Dicionario%3ApalVisible={3}";



            string query = string.Format(queryStr,
                                         HttpUtility.UrlEncode(viewState, helper.Encoding),
                                         HttpUtility.UrlEncode(phrase, helper.Encoding),
                                         0,
                                         HttpUtility.UrlEncode(phrase, helper.Encoding)
                                         );

            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            viewState = StringParser.Parse("name=\"__VIEWSTATE\" value=\"", "\"", responseFromServer);

            if (responseFromServer.Contains("A palavra não foi encontrada.</span>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            if (responseFromServer.Contains("<blockquote>"))
            {
                StringParser parser    = new StringParser(responseFromServer);
                string[]     subblocks = parser.ReadItemsList("<blockquote>", "</blockquote>");
                if (subblocks.Length == 1)
                {
                    SetResult(result, subblocks[0]);
                }
                else
                {
                    foreach (string block in subblocks)
                    {
                        Result child = new Result(result.ServiceItem, phrase, result.LanguagePair, result.Subject);
                        result.Childs.Add(child);
                        SetResult(child, block);
                    }
                }
            }
            else if (responseFromServer.Contains("javascript:SeleccionaEntrada(&quot"))
            {
                StringParser parser   = new StringParser(responseFromServer);
                string[]     sublinks = parser.ReadItemsList("javascript:SeleccionaEntrada(&quot;", "&quot;)\"");
                if (sublinks.Length <= 1)
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }

                string key = "&quot;,&quot;";
                foreach (string sublink in sublinks)
                {
                    int idx = sublink.IndexOf(key);
                    if (idx < 0)
                    {
                        throw new TranslationException("Can't found start tag : \"&quot;,&quot;\" in string : " + sublink);
                    }

                    string val = sublink.Substring(0, idx);
                    string num = sublink.Substring(idx + key.Length);
                    query = string.Format(queryStr,
                                          HttpUtility.UrlEncode(viewState, helper.Encoding),
                                          HttpUtility.UrlEncode(val, helper.Encoding),
                                          num,
                                          HttpUtility.UrlEncode(phrase, helper.Encoding));

                    helper =
                        new WebRequestHelper(result, new Uri("http://www.priberam.pt/dlpo/definir_resultados.aspx"),
                                             networkSetting,
                                             WebRequestContentType.UrlEncoded,
                                             Encoding.GetEncoding("iso-8859-1"));
                    helper.AddPostData(query);

                    responseFromServer = helper.GetResponse();

                    viewState = StringParser.Parse("name=\"__VIEWSTATE\" value=\"", "\"", responseFromServer);

                    if (responseFromServer.Contains("<blockquote>"))
                    {
                        parser = new StringParser(responseFromServer);
                        string[] subblocks = parser.ReadItemsList("<blockquote>", "</blockquote>");
                        foreach (string block in subblocks)
                        {
                            Result child = new Result(result.ServiceItem, val, result.LanguagePair, result.Subject);
                            result.Childs.Add(child);
                            SetResult(child, block);
                        }
                    }
                }

                if (result.Childs.Count == 0)
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }
            }
            else
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
        }
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            //http://www.urduword.com/search.php?English=test
            string query = "http://www.urduword.com/search.php?English={0}";
            if(languagesPair.From == Language.Urdu)
                query = "http://www.urduword.com/search.php?Roman={0}";

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

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

            string responseFromServer = helper.GetResponse();
            if(responseFromServer.Contains("<p>Could not find translation for <b>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else
            {
                if(responseFromServer.Contains("<table border=\"0\" width=\"100%\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" >"))
                {
                    result.ArticleUrl = query;
                    result.ArticleUrlCaption = phrase;

                    string translation = StringParser.Parse("<table border=\"0\" width=\"100%\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" >", "</table>", responseFromServer);
                    StringParser parser = new StringParser(translation);
                    string[] translations = parser.ReadItemsList("<tr>", "</tr>");
                    Result subres = null;
                    foreach(string str in translations)
                    {
                        if(str.Contains("class=\"tablehead\""))
                            continue;

                        string word = StringParser.Parse(">", "<", StringParser.Parse("<a", "/a>", str));
                        translation  = StringParser.Parse("align=\"center\">", "<", str);

                        if(languagesPair.From == Language.Urdu)
                        {
                            if(subres == null || subres.Phrase != translation)
                            {
                                subres = CreateNewResult(translation, languagesPair, subject);
                                result.Childs.Add(subres);
                            }
                        }
                        else
                        {
                            if(subres == null || subres.Phrase != word)
                            {
                                subres = CreateNewResult(word, languagesPair, subject);
                                result.Childs.Add(subres);
                            }
                        }

                        if(languagesPair.From == Language.Urdu)
                            subres.Translations.Add(word);
                        else
                            subres.Translations.Add(translation);

                    }
                }

                //more
                if(responseFromServer.Contains("page=2\">Next"))
                {
                    query = "http://www.urduword.com/search.php?English={0}&page=2";
                    if(languagesPair.From == Language.Urdu)
                        query = "http://www.urduword.com/search.php?Roman={0}&page=2";

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

                    string link = "html!<p><a href=\"{0}\" title=\"{0}\">{1}</a></p>";
                    link = string.Format(link,
                        query,
                        "More ...");
                    Result subres = CreateNewResult(link, languagesPair, subject);
                    result.Childs.Add(subres);
                }

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

            }
        }
        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);
                }
            }
        }
        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)
        {
            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://intertran.tranexp.com/Translate/result.shtml"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);

            helper.Encoding = GetEncoding(languagesPair.From, languagesPair.To);            //Encoding.GetEncoding(GetEncoding(languagesPair.To));
            string query = "Submit.x=56&Submit.y=10&from={0}&keyb=non&text={1}&to={2}&translation=";

            query = string.Format(CultureInfo.InvariantCulture,
                                  query,
                                  ConvertLanguage(languagesPair.From),
                                  HttpUtility.UrlEncode(phrase, Encoding.GetEncoding(GetEncoding(languagesPair.From))),
                                  ConvertLanguage(languagesPair.To)
                                  );
            helper.AddPostData(query);

            string responseFromServer = helper.GetResponse();

            if (string.IsNullOrEmpty(responseFromServer))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.Contains("there was no translation for your original query.</center>"))
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }
            else if (responseFromServer.Contains("name=\"translation\">An error occurred during translation. Please try again later.</textarea>"))
            {
                //result.ResultNotFound = true;
                throw new TranslationException("An error occurred during translation. Please try again later.");
            }
            else if (responseFromServer.Contains("<center>Warning:<br> Could not open"))
            {
                //result.ResultNotFound = true;
                throw new TranslationException("An error occurred during translation. Please try again later.");
            }
            else if (responseFromServer.Contains("<center>Warning:</strong><br> Could not open"))
            {
                //result.ResultNotFound = true;
                throw new TranslationException("An error occurred during translation. Please try again later.");
            }
            else
            {
                string translation = StringParser.Parse("<INPUT TYPE=\"hidden\" NAME=\"alltrans\" VALUE=\"", "\">", responseFromServer).Trim();
                if (string.IsNullOrEmpty(translation))
                {
                    result.ResultNotFound = true;
                    throw new TranslationException("Nothing found");
                }

                string       subphrase;
                bool         firstRun     = true;
                Result       subres       = result;
                StringParser parser       = new StringParser(translation);
                string[]     translations = parser.ReadItemsList("{{", "}}");

                foreach (string subtranslation in translations)
                {
                    string subtrans = "|" + subtranslation + "|";
                    parser = new StringParser(subtrans);
                    string[] subtranslations = parser.ReadItemsList("|", "|");
                    if (subtranslations.Length > 1)
                    {
                        subphrase = subtranslations[0];
                        if (firstRun && translation.Length == 1 && string.Compare(subphrase, phrase, true, CultureInfo.InvariantCulture) == 0)
                        {
                            for (int i = 1; i < subtranslations.Length; i++)
                            {
                                result.Translations.Add(subtranslations[i]);
                            }
                            return;
                        }
                        firstRun = false;

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

                        for (int i = 1; i < subtranslations.Length; i++)
                        {
                            subres.Translations.Add(subtranslations[i]);
                        }
                    }
                }
            }
        }