我目前正在开发一个自然语言处理程序,在该程序中我正在访问我的字典的谷歌翻译,以便翻译用户输入。
using UnityEngine;
using System.Collections;
using System.Text;
using System.Net;
public class GoogleTranslate : MonoBehaviour {
public static string Translate(string input, string languagePair, Encoding encoding)
{
string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text= {0}&langpair={1}", input, languagePair);
string result = String.Empty;
using (WebClient webClient = new WebClient())
{
webClient.E ncoding = encoding;
result = webClient.DownloadString(url);
}
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(result);
return doc.DocumentNode.SelectSingleNode("//textarea[@name='utrans']").InnerText;
}
}
当我在 Assembly 中编译这个程序时,我实际上是在使用 Unity 但它使用 Assembly 编译时,我得到了返回错误:
Assets/GoogleTranslate.cs(17,13): error CS0246: The type or namespace name `HtmlDocument' could not be found. Are you missing a using directive or an assembly reference?
我开始在网上查找 HtmlDocument 的正确命名空间,并读到我应该写:
using HtmlAgilityPack;
将其放入我的程序后,我收到错误:
Assets/GoogleTranslate.cs(5,7): error CS0246: The type or namespace name `HtmlAgilityPack' could not be found. Are you missing a using directive or an assembly reference?
我在网上读到我必须更具体并使用:
using HtmlAgilityPack.HtmlDocument;
现在我把它放进去,我仍然继续收到错误:
Assets/GoogleTranslate.cs(5,7): error CS0246: The type or namespace name `HtmlAgilityPack' could not be found. Are you missing a using directive or an assembly reference?
我想知道 HtmlDocument 使用什么命名空间。对此事的任何帮助将不胜感激!