我目前正在开发一个自然语言处理程序,我在其中访问Google Translate作为我的字典,以便翻译用户输入.
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的命名空间.任何有关此事的帮助将不胜感激!
最佳答案 你下载并引用了HtmlAgilityPack dll吗?您似乎正在尝试使用(第三方)库而不在项目/解决方案中的任何位置引用它.
您可以使用Nu-Get安装库.
Install-Package HtmlAgilityPack