我目前正在开发一个自然语言处理程序,在该程序中,我正在访问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;
}
}当我用汇编语言编译这个程序时,我实际上是在使用Unity,但它是用汇编语言编译的,我得到了返回错误:
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的名称空间是什么。在这个问题上的任何帮助都将不胜感激!
发布于 2012-09-26 01:15:37
你下载并引用HtmlAgilityPack动态链接库了吗?似乎您正在尝试使用(第三方)库,而没有在项目/解决方案中的任何地方引用它。
您可以使用Nu-Get安装库。
Install-Package HtmlAgilityPackhttps://stackoverflow.com/questions/12587848
复制相似问题