Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 42 additions & 43 deletions examples/AddressSimilarity.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
using Rosette.Api;
using Rosette.Api.Models;
using Rosette.Api.Client;
using Rosette.Api.Client.Models;

namespace examples
namespace Rosette.Api.Examples;

class AddressSimilarity
{
class AddressSimilarity
/// <summary>
/// RunEndpoint runs the example. By default the endpoint will be run against the Rosette Cloud Service.
/// An optional alternate URL may be provided, i.e. for an on-premise solution.
/// </summary>
/// <param name="apiKey">Required api key (obtained from Basis Technology)</param>
/// <param name="altUrl">Optional alternate URL</param>
private static void RunEndpoint(string apiKey, string? altUrl = null)
{
/// <summary>
/// RunEndpoint runs the example. By default the endpoint will be run against the Rosette Cloud Service.
/// An optional alternate URL may be provided, i.e. for an on-premise solution.
/// </summary>
/// <param name="apiKey">Required api key (obtained from Basis Technology)</param>
/// <param name="altUrl">Optional alternate URL</param>
private void RunEndpoint(string apiKey, string? altUrl = null)
try
{
try
ApiClient api = new(apiKey);
if (!string.IsNullOrEmpty(altUrl))
{
ApiClient api = new ApiClient(apiKey);
if (!string.IsNullOrEmpty(altUrl))
{
api.UseAlternateURL(altUrl);
}
api.UseAlternateURL(altUrl);
}

var add1 = new UnfieldedAddressRecord { Address = "160 Pennsylvana Avenue, Washington, D.C., 20500" };
var add2 = new FieldedAddressRecord(houseNumber: "1600", road: "Pennsylvania Ave N.W.", city: "Washington", state: "DC", postcode: "20500");
var add1 = new UnfieldedAddressRecord { Address = "160 Pennsylvana Avenue, Washington, D.C., 20500" };
var add2 = new FieldedAddressRecord(houseNumber: "1600", road: "Pennsylvania Ave N.W.", city: "Washington", state: "DC", postcode: "20500");


Rosette.Api.Endpoints.AddressSimilarity endpoint = new(add1, add2);
Rosette.Api.Client.Endpoints.AddressSimilarity endpoint = new(add1, add2);

Response response = endpoint.Call(api);
Response response = endpoint.Call(api);

//The results of the API call will come back in the form of a Dictionary
foreach (KeyValuePair<string, string> h in response.Headers)
{
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
}
Console.WriteLine(response.ContentAsJson(pretty: true));
}
catch (Exception e)
//The results of the API call will come back in the form of a Dictionary
foreach (KeyValuePair<string, string> h in response.Headers)
{
Console.WriteLine(e.Message);
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
}
Console.WriteLine(response.ContentAsJson(pretty: true));
}
/// <summary>
/// Main is a simple entrypoint for command line calling of the endpoint examples
/// </summary>
/// <param name="args">Command line args, expects API Key, (optional) alt URL</param>
static void Main(string[] args)
catch (Exception e)
{
if (args.Length != 0)
{
new AddressSimilarity().RunEndpoint(args[0], args.Length > 1 ? args[1] : null);
}
else
{
Console.WriteLine("An API Key is required");
}
Console.WriteLine(e.Message);
}
}
/// <summary>
/// Main is a simple entrypoint for command line calling of the endpoint examples
/// </summary>
/// <param name="args">Command line args, expects API Key, (optional) alt URL</param>
static void Main(string[] args)
{
if (args.Length != 0)
{
RunEndpoint(args[0], args.Length > 1 ? args[1] : null);
}
else
{
Console.WriteLine("An API Key is required");
}
}
}
129 changes: 90 additions & 39 deletions examples/Categories.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,99 @@
using Rosette.Api;
using Rosette.Api.Models;
using Rosette.Api.Client;
using Rosette.Api.Client.Models;
using System.Text;

namespace examples {
class Categories
{
/// <summary>
/// RunEndpoint runs the example. By default the endpoint will be run against the Rosette Cloud Service.
/// An optional alternate URL may be provided, i.e. for an on-premise solution.
/// </summary>
/// <param name="apiKey">Required api key (obtained from Basis Technology)</param>
/// <param name="altUrl">Optional alternate URL</param>
private void RunEndpoint(string apiKey, string? altUrl =null) {
try {
ApiClient api = new ApiClient(apiKey);
if (!string.IsNullOrEmpty(altUrl)) {
api.UseAlternateURL(altUrl);
}
string categories_text_data = @"Sony Pictures is planning to shoot a good portion of the new ""Ghostbusters"" in Boston as well.";

Rosette.Api.Endpoints.Categories endpoint = new(categories_text_data);

Response response = endpoint.Call(api);
//The results of the API call will come back in the form of a Dictionary
foreach (KeyValuePair<string, string> h in response.Headers)
{
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
}
Console.WriteLine(response.ContentAsJson(pretty: true));
namespace Rosette.Api.Examples;

class Categories
{
/// <summary>
/// RunEndpoint runs the example. By default the endpoint will be run against the Rosette Cloud Service.
/// An optional alternate URL may be provided, i.e. for an on-premise solution.
/// </summary>
/// <param name="apiKey">Required api key (obtained from Basis Technology)</param>
/// <param name="altUrl">Optional alternate URL</param>
private static void RunEndpoint(string apiKey, string? altUrl = null) {
try {
Console.OutputEncoding = Encoding.UTF8;

ApiClient api = new(apiKey);
if (!string.IsNullOrEmpty(altUrl)) {
api.UseAlternateURL(altUrl);
}
catch (Exception e) {
Console.WriteLine(e.Message);
string categories_text_data = @"Sony Pictures is planning to shoot a good portion of the new ""Ghostbusters"" in Boston as well.";

Rosette.Api.Client.Endpoints.Categories endpoint = new(categories_text_data);

Response response = endpoint.Call(api);
//The results of the API call will come back in the form of a Dictionary
foreach (KeyValuePair<string, string> h in response.Headers)
{
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
}
Console.WriteLine(response.ContentAsJson(pretty: true));
}
catch (Exception e) {
Console.WriteLine("Exception: " + e.Message);
}
/// <summary>
/// Main is a simple entrypoint for command line calling of the endpoint examples
/// </summary>
/// <param name="args">Command line args, expects API Key, (optional) alt URL</param>
static void Main(string[] args) {
if (args.Length != 0) {
new Categories().RunEndpoint(args[0], args.Length > 1 ? args[1] : null);
}

/// <summary>
/// RunEndpointAsync runs the example asynchronously. By default the endpoint will be run against the Rosette Cloud Service.
/// An optional alternate URL may be provided, i.e. for an on-premise solution.
/// </summary>
/// <param name="apiKey">Required api key (obtained from Basis Technology)</param>
/// <param name="altUrl">Optional alternate URL</param>
private static async Task RunEndpointAsync(string apiKey, string? altUrl = null)
{
try
{
Console.OutputEncoding = Encoding.UTF8;

ApiClient api = new(apiKey);
if (!string.IsNullOrEmpty(altUrl))
{
api.UseAlternateURL(altUrl);
}
else {
Console.WriteLine("An API Key is required");
string categories_text_data = @"Sony Pictures is planning to shoot a good portion of the new ""Ghostbusters"" in Boston as well.";

Rosette.Api.Client.Endpoints.Categories endpoint = new(categories_text_data);

// Use async call with optional timeout
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
Response response = await endpoint.CallAsync(api, cts.Token);

//The results of the API call will come back in the form of a Dictionary
foreach (KeyValuePair<string, string> h in response.Headers)
{
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
}
Console.WriteLine(response.ContentAsJson(pretty: true));
}
catch (OperationCanceledException)
{
Console.WriteLine("Request was cancelled or timed out");
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}

/// <summary>
/// Main is a simple entrypoint for command line calling of the endpoint examples
/// </summary>
/// <param name="args">Command line args, expects API Key, (optional) alt URL</param>
static async Task Main(string[] args) {
if (args.Length != 0) {

Console.WriteLine("\n=== First Call (Async) ===");
await RunEndpointAsync(args[0], args.Length > 1 ? args[1] : null);

Console.WriteLine("\n=== Second Call (Synchronous) ===");
RunEndpoint(args[0], args.Length > 1 ? args[1] : null);
}
else {
Console.WriteLine("An API Key is required");
}
}
}
96 changes: 48 additions & 48 deletions examples/ConcurrencyTest.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
using Rosette.Api;
using Rosette.Api.Client;

namespace examples {
public class ConcurrencyTest {
private static int threads = 3;
private static int calls = 5;
namespace Rosette.Api.Examples;

/// <summary>
/// RunEndpoint runs the example. By default the endpoint will be run against the Rosette Cloud Service.
/// An optional alternate URL may be provided, i.e. for an on-premise solution.
/// This particular example runs entities on multiple threads to demonstrate
/// concurrency.
/// </summary>
/// <param name="apiKey">Required api key (obtained from Basis Technology)</param>
/// <param name="altUrl">Optional alternate URL</param>
private static async Task TestConcurrency(string apiKey, string altUrl) {
var tasks = new List<Task>();
ApiClient api = new ApiClient(apiKey);
if (!string.IsNullOrEmpty(altUrl)) {
api.UseAlternateURL(altUrl);
}
api = api.AssignConcurrentConnections(2); // 2 is the default. Set to the amount allowed by your plan
public class ConcurrencyTest {
private static readonly int threads = 3;
private static readonly int calls = 5;

foreach (int task in Enumerable.Range(0, threads)) {
Console.WriteLine("Starting task {0}", task);
tasks.Add(Task.Factory.StartNew( () => runLookup(task, api) ));
}
await Task.WhenAll(tasks);
Console.WriteLine("Test complete");
/// <summary>
/// RunEndpoint runs the example. By default the endpoint will be run against the Rosette Cloud Service.
/// An optional alternate URL may be provided, i.e. for an on-premise solution.
/// This particular example runs entities on multiple threads to demonstrate
/// concurrency.
/// </summary>
/// <param name="apiKey">Required api key (obtained from Basis Technology)</param>
/// <param name="altUrl">Optional alternate URL</param>
private static async Task TestConcurrency(string apiKey, string altUrl) {
var tasks = new List<Task>();
ApiClient api = new(apiKey);
if (!string.IsNullOrEmpty(altUrl)) {
api.UseAlternateURL(altUrl);
}
api = api.AssignConcurrentConnections(2); // 2 is the default. Set to the amount allowed by your plan

private static Task runLookup(int taskId, ApiClient api) {
string entities_text_data = @"The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country.";
Rosette.Api.Endpoints.Entities endpoint = new(entities_text_data);
foreach (int call in Enumerable.Range(0, calls)) {
Console.WriteLine("Task ID: {0} call {1}", taskId, call);
try {
Console.WriteLine(endpoint.Call(api).ContentAsJson(pretty: true));
}
catch (Exception ex) {
Console.WriteLine(ex);
}
}
return Task.CompletedTask;
foreach (int task in Enumerable.Range(0, threads)) {
Console.WriteLine("Starting task {0}", task);
tasks.Add(Task.Factory.StartNew( () => RunLookup(task, api) ));
}
await Task.WhenAll(tasks);
Console.WriteLine("Test complete");
}

/// <summary>
/// Main is a simple entrypoint for command line calling of the endpoint examples
/// </summary>
/// <param name="args">Command line args, expects API Key, (optional) alt URL</param>
static void Main(string[] args) {
if (args.Length != 0) {
TestConcurrency(args[0], args.Length > 1 ? args[1] : null).GetAwaiter().GetResult();
private static Task RunLookup(int taskId, ApiClient api) {
string entities_text_data = @"The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country.";
Rosette.Api.Client.Endpoints.Entities endpoint = new(entities_text_data);
foreach (int call in Enumerable.Range(0, calls)) {
Console.WriteLine("Task ID: {0} call {1}", taskId, call);
try {
Console.WriteLine(endpoint.Call(api).ContentAsJson(pretty: true));
}
else {
Console.WriteLine("An API Key is required");
catch (Exception ex) {
Console.WriteLine(ex);
}
}
return Task.CompletedTask;
}

/// <summary>
/// Main is a simple entrypoint for command line calling of the endpoint examples
/// </summary>
/// <param name="args">Command line args, expects API Key, (optional) alt URL</param>
static void Main(string[] args) {
if (args.Length != 0) {
TestConcurrency(args[0], args.Length > 1 ? args[1] : null).GetAwaiter().GetResult();
}
else {
Console.WriteLine("An API Key is required");
}
}
}
Loading