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 pathexample.cs
More file actions
51 lines (39 loc) · 1.43 KB
/
example.cs
File metadata and controls
51 lines (39 loc) · 1.43 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
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 ResultData
{
public List<Detection> detections { get; set; }
}
public class Result
{
public ResultData 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", "");
var request = new RestRequest("/0.2/detect", Method.POST);
request.AddParameter("q", "Some text to detect language");
IRestResponse response = client.Execute(request);
RestSharp.Deserializers.JsonDeserializer deserializer = new RestSharp.Deserializers.JsonDeserializer();
var result = deserializer.Deserialize<Result>(response);
Detection detection = result.data.detections[0];
Console.WriteLine("Language: {0}", detection.language);
Console.WriteLine("Reliable: {0}", detection.isReliable);
Console.WriteLine("Confidence: {0}", detection.confidence);
}
}
}