forked from rosette-api/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage.cs
More file actions
49 lines (47 loc) · 1.72 KB
/
language.cs
File metadata and controls
49 lines (47 loc) · 1.72 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using rosette_api;
namespace rosette_apiExamples
{
class language
{
/// <summary>
/// Example code to call Rosette API to detect possible languages for a piece of text.
/// Requires Nuget Package:
/// rosette_api
/// </summary>
static void Main(string[] args)
{
//To use the C# API, you must provide an API key
string apikey = "Your API key";
string alturl = string.Empty;
//You may set the API key via command line argument:
//language yourapikeyhere
if (args.Length != 0)
{
apikey = args[0];
alturl = args.Length > 1 ? args[1] : string.Empty;
}
try
{
CAPI LanguageCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
string language_data = @"Por favor Señorita, says the man.";
//The results of the API call will come back in the form of a Dictionary
LanguageCAPI.SetCustomHeaders("X-RosetteAPI-App", "csharp-app");
RosetteResponse response = LanguageCAPI.Language(language_data);
foreach (KeyValuePair<string, string> h in response.Headers) {
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
}
Console.WriteLine(response.ContentAsJson);
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
}
}