forked from rosette-api/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64_input.cs
More file actions
47 lines (45 loc) · 1.8 KB
/
base64_input.cs
File metadata and controls
47 lines (45 loc) · 1.8 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
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 entities
{
/// <summary>
/// Example code to call Rosette API to get entities from 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:
//entities yourapikeyhere
if (args.Length != 0)
{
apikey = args[0];
alturl = args.Length > 1 ? args[1] : string.Empty;
}
try
{
CAPI EntitiesCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
string entities_text_data = @"Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS";
var exampleBytes = System.Text.Encoding.UTF8.GetBytes(entities_text_data);
String exampleText = System.Convert.ToBase64String(exampleBytes);
//The results of the API call will come back in the form of a Dictionary
Dictionary<string, Object> EntitiesResult = EntitiesCAPI.Entity(exampleText, null, "application/octet-stream");
Console.WriteLine(new JavaScriptSerializer().Serialize(EntitiesResult));
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
}
}