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);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var client  = new RestClient("http://ws.detectlanguage.com");
            var request = new RestRequest("/0.2/detect", Method.POST);

            request.AddParameter("key", "demo"); // replace "demo" with your API key
            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);
        }