This repository was archived by the owner on Apr 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbatch_example.cs
More file actions
64 lines (47 loc) · 2 KB
/
batch_example.cs
File metadata and controls
64 lines (47 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
public class Detection
{
public string language { get; set; }
public bool isReliable { get; set; }
public float confidence { get; set; }
}
public class BatchResultData
{
public List<List<Detection>> detections { get; set; }
}
public class BatchResult
{
public BatchResultData data { get; set; }
}
class Program
{
static void Main(string[] args)
{
var client = new RestClient("http://ws.detectlanguage.com");
// replace "demo" with your API key
client.Authenticator = new HttpBasicAuthenticator("demo", "");
string[] texts = new String[2];
texts[0] = "Hello world";
texts[1] = "Buenos dias, señor";
var batchRequest = new RestRequest("/0.2/detect", Method.POST);
batchRequest.RequestFormat = DataFormat.Json;
batchRequest.AddBody(new { q = texts });
IRestResponse batchResponse = client.Execute(batchRequest);
RestSharp.Deserializers.JsonDeserializer deserializer = new RestSharp.Deserializers.JsonDeserializer();
var batchResult = deserializer.Deserialize<BatchResult>(batchResponse);
Detection batchDetection0 = batchResult.data.detections[0][0];
Console.WriteLine("Language: {0}", batchDetection0.language);
Console.WriteLine("Reliable: {0}", batchDetection0.isReliable);
Console.WriteLine("Confidence: {0}", batchDetection0.confidence);
Detection batchDetection1 = batchResult.data.detections[1][0];
Console.WriteLine("Language: {0}", batchDetection1.language);
Console.WriteLine("Reliable: {0}", batchDetection1.isReliable);
Console.WriteLine("Confidence: {0}", batchDetection1.confidence);
}
}
}