2012-09-25 299 views
4

我目前正在研究自然语言处理程序,在该程序中,我正在访问Google翻译以查找我的字典以翻译用户输入。错误CS0246:找不到类型或名称空间名称`HtmlAgilityPack'

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使用的命名空间。任何关于此事的帮助将不胜感激!

+1

你导入了dll吗?像,你记得添加一个DLL到你的解决方案? – Thousand

+0

您是否添加了对HTML敏捷包DLL的引用?您应该考虑使用NuGet在您的项目中下载并安装HAP! – Zachary

+0

您是否添加了对正确dll的引用? http://stackoverflow.com/questions/846994/how-to-use-html-agility-pack –

回答

1

您是否下载并引用了HtmlAgilityPack dll?看起来您正尝试使用(第三方)库,而无需在项目/解决方案中的任何地方引用它。

您可以使用Nu-Get安装库。

Install-Package HtmlAgilityPack 
+0

感谢您的帮助! –

相关问题