Skip to content

Commit 7fe02f6

Browse files
Merge pull request #99 from Katsuya-Tomioka/DEVOPS-247-address-sample
DEVOPS-247: add address-similarity example
2 parents 8dce74b + 8cb5941 commit 7fe02f6

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Web.Script.Serialization;
7+
using rosette_api;
8+
9+
namespace rosette_apiExamples
10+
{
11+
class address_similarity
12+
{
13+
/// <summary>
14+
/// Example code to call Rosette API to get match score (similarity) for two addresses.
15+
/// Requires Nuget Package:
16+
/// rosette_api
17+
/// </summary>
18+
static void Main(string[] args)
19+
{
20+
//To use the C# API, you must provide an API key
21+
string apikey = "Your API key";
22+
string alturl = string.Empty;
23+
24+
//You may set the API key via command line argument:
25+
//address_similarity yourapikeyhere
26+
if (args.Length != 0)
27+
{
28+
apikey = args[0];
29+
alturl = args.Length > 1 ? args[1] : string.Empty;
30+
}
31+
try
32+
{
33+
CAPI cAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
34+
//The results of the API call will come back in the form of a Dictionary
35+
AddressSimilarityResponse response = cAPI.AddressSimilarity(new Address(city:"Cambridge", state:"MA"), new Address(city:"cambridge", road:"one kendall sq", state:"massachusetts"));
36+
foreach (KeyValuePair<string, string> h in response.Headers) {
37+
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
38+
}
39+
Console.WriteLine(response.ToString());
40+
}
41+
catch (Exception e)
42+
{
43+
Console.WriteLine("Exception: " + e.Message);
44+
}
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)