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

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

                foreach (string subtranslation in translations)
                {
                    Result subres = CreateNewResult("", languagesPair, subject);
                    result.Childs.Add(subres);
                    subres.Translations.Add(subtranslation);
                }
            }
        }
示例#2
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string responseFromServer = UlifHelper.GetAntonymsPage(phrase, networkSetting);

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

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


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


            StringParser parser = new StringParser(responseFromServer);

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

            Result subres;

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

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

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

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

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

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

                    subres = CreateNewResult("html!<hr style=\"width: 100%; height: 1px;\">", languagesPair, subject);
                    result.Childs.Add(subres);
                }
                else
                {
                    string line = StringParser.Parse("<td colspan=\"2\">", "</td>", blocks[i]);
                    subres = CreateNewResult("", languagesPair, subject);
                    result.Childs.Add(subres);
                    subres.Translations.Add(line);
                }
            }
        }