请求获取分析器列表。具体而言>返回Client.ListAnalyzersAsync()。结果 这最终会调用http客户端请求。
我的代码直接来自示例应用。仍然没有爱。感谢帮助
以下是LinquisticClient库中的默认网址
私有const字符串DefaultServiceHost =" https://api.projectoxford.ai/linguistics/v1.0&#34 ;;
以下是我创建的课程
我的呼吁是这个方法 - Parse()
public static class LinguisticAnalyzer
{
private static readonly LinguisticsClient Client = new LinguisticsClient("Removed_id");
public static string Parse(string line)
{
// List analyzers
Analyzer[] supportedAnalyzers = null;
try
{
supportedAnalyzers = ListAnalyzers();
var analyzersAsJson = JsonConvert.SerializeObject(supportedAnalyzers, Formatting.Indented, jsonSerializerSettings);
Console.WriteLine("Supported analyzers: " + analyzersAsJson);
}
catch (Exception e)
{
Console.Error.WriteLine("Failed to list supported analyzers: " + e.ToString());
Environment.Exit(1);
}
// Analyze text with all available analyzers
var analyzeTextRequest = new AnalyzeTextRequest()
{
Language = "en",
AnalyzerIds = supportedAnalyzers.Select(analyzer => analyzer.Id).ToArray(),
Text = line //"Welcome to Microsoft Linguistic Analysis!"
};
try
{
var analyzeTextResults = AnalyzeText(analyzeTextRequest);
var resultsAsJson = JsonConvert.SerializeObject(analyzeTextResults, Formatting.Indented, jsonSerializerSettings);
Console.WriteLine("Analyze text results: " + resultsAsJson);
return resultsAsJson;
}
catch (Exception e)
{
Console.Error.WriteLine("Failed to list supported analyzers: " + e.ToString());
Environment.Exit(1);
}
return "";
}
/// <summary>
/// Default jsonserializer settings
/// </summary>
private static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings()
{
DateFormatHandling = DateFormatHandling.IsoDateFormat,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
/// <summary>
/// List analyzers synchronously.
/// </summary>
/// <returns>An array of supported analyzers.</returns>
private static Analyzer[] ListAnalyzers()
{
try
{
return Client.ListAnalyzersAsync().Result;
}
catch (Exception exception)
{
throw new Exception("Failed to gather list of analyzers", exception as ClientException);
}
}
/// <summary>
/// Analyze text synchronously.
/// </summary>
/// <param name="request">Analyze text request.</param>
/// <returns>An array of analyze text result.</returns>
private static AnalyzeTextResult[] AnalyzeText(AnalyzeTextRequest request)
{
try
{
return Client.AnalyzeTextAsync(request).Result;
}
catch (Exception exception)
{
throw new Exception("Failed to analyze text", exception as ClientException);
}
}
}