我目前正在開發一個自然語言處理程序,我在其中訪問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