0
アナライザーリストを取得する要求がハングするだけです。特に> Client.ListAnalyzersAsync()を返します。結果 これは最終的にhttpクライアント要求を呼び出します。要求がハングするだけです
私のコードは、サンプルアプリケーションから直接です。まだ愛はありません。ここで
がLinquisticClientライブラリ
民間のconst文字列DefaultServiceHost = "https://api.projectoxford.ai/linguistics/v1.0" のデフォルトのURLで助けに感謝。これは、C#のクライアントライブラリではなく、サービスの問題であることが判明し
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);
}
}
}