Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
seth-mg committed Jan 17, 2018
2 parents 0b6d694 + 6744ff1 commit 1737663
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 15 deletions.
13 changes: 11 additions & 2 deletions rosette_api/CAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ public CAPI(string user_key, string uristring = "https://api.rosette.com/rest/v1
public static string Version {
get { return typeof(CAPI).Assembly.GetName().Version.ToString(); }
}
/// <summary>
/// UserAgent returns the string that will be used for User-Agent
/// </summary>
/// <returns>string User-Agent</returns>
public string UserAgent {
get {
return string.Format("RosetteAPICsharp/{0}/{1}", Version, Environment.Version.ToString());
}
}
/// <summary>MaxRetry
/// <para>
/// Getter, Setter for the MaxRetry
Expand Down Expand Up @@ -1261,7 +1270,7 @@ private void SetupClient(bool forceReset=false) {

// Standard headers, which are required for Rosette API
AddRequestHeader("X-RosetteAPI-Key", UserKey ?? "not-provided");
AddRequestHeader("User-Agent", "RosetteAPICsharp/" + Version);
AddRequestHeader("User-Agent", UserAgent);
AddRequestHeader("X-RosetteAPI-Binding", "csharp");
AddRequestHeader("X-RosetteAPI-Binding-Version", Version);

Expand Down Expand Up @@ -1293,7 +1302,7 @@ private void SetupClient(bool forceReset=false) {
/// <param name="value">Value of header</param>
private void AddRequestHeader(string name, string value) {
if (!Client.DefaultRequestHeaders.Contains(name))
Client.DefaultRequestHeaders.Add(name, value);
Client.DefaultRequestHeaders.TryAddWithoutValidation(name, value);
}

/// <summary>Decompress
Expand Down
6 changes: 3 additions & 3 deletions rosette_api/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyFileVersion("1.8.1.0")]
// [assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
2 changes: 1 addition & 1 deletion rosette_api/rosette_api.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>rosette_api</id>
<version>1.8.1</version>
<version>1.9.0</version>
<authors>basistech</authors>
<owners>basistech</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion rosette_apiExamples/concurrencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static async Task TestConcurrency(string apikey, string alturl) {
Console.WriteLine("Test complete");
}
private static Task runLookup(int taskId, CAPI api) {
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";
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.";

//string contentUri = "http://www.foxsports.com/olympics/story/chad-le-clos-showed-why-you-never-talk-trash-to-michael-phelps-080916";
foreach (int call in Enumerable.Range(0, calls)) {
Expand Down
2 changes: 1 addition & 1 deletion rosette_apiExamples/entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
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";
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.";
//The results of the API call will come back in the form of a Dictionary
EntitiesResponse response = EntitiesCAPI.Entity(entities_text_data, null, null, null, "social-media");
foreach (KeyValuePair<string, string> h in response.Headers) {
Expand Down
52 changes: 52 additions & 0 deletions rosette_apiExamples/language_multilingual.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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_multilingual_data = @"On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة ""د هـ ك ب ج"" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان.";

LanguageCAPI.SetCustomHeaders("X-RosetteAPI-App", "csharp-app");
LanguageCAPI.SetOption("multilingual", "true");

//The results of the API call will come back in the form of a Dictionary
LanguageIdentificationResponse response = LanguageCAPI.Language(language_multilingual_data);
foreach (KeyValuePair<string, string> h in response.Headers) {
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
}
Console.WriteLine(response.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
}
}
2 changes: 1 addition & 1 deletion rosette_apiExamples/morphology_complete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
try
{
CAPI MorphologyCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
string morphology_complete_data = @"The quick brown fox jumped over the lazy dog. Yes he did.";
string morphology_complete_data = @"The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)";
//The results of the API call will come back in the form of a Dictionary
MorphologyResponse response = MorphologyCAPI.Morphology(morphology_complete_data);
foreach (KeyValuePair<string, string> h in response.Headers) {
Expand Down
2 changes: 1 addition & 1 deletion rosette_apiExamples/name_deduplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
try
{
CAPI rosetteApi = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
string name_dedupe_data = @"John Smith,Johnathon Smith,Fred Jones";
string name_dedupe_data = @"Alice Terry,Alice Thierry,Betty Grable,Betty Gable,Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,Julie Halliday";

List<string> dedup_names = name_dedupe_data.Split(',').ToList<string>();
List<Name> names = dedup_names.Select(name => new Name(name, "eng", "Latn")).ToList();
Expand Down
2 changes: 1 addition & 1 deletion rosette_apiExamples/relationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
try
{
CAPI RelationshipsCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
string relationships_text_data = @"Bill Gates, Microsoft's former CEO, is a philanthropist.";
string relationships_text_data = @"FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai.";
//The results of the API call will come back in the form of a Dictionary
RelationshipsResponse response = RelationshipsCAPI.Relationships(relationships_text_data);
foreach (KeyValuePair<string, string> h in response.Headers) {
Expand Down
2 changes: 1 addition & 1 deletion rosette_apiExamples/sentences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
try
{
CAPI SentencesCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
string sentences_data = @"This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me.";
string sentences_data = @"This land is your land. This land is my land, from California to the New York island; from the red wood forest to the Gulf Stream waters. This land was made for you and Me. As I was walking that ribbon of highway, I saw above me that endless skyway: I saw below me that golden valley: This land was made for you and me.";
//The results of the API call will come back in the form of a Dictionary
SentenceTaggingResponse response = SentencesCAPI.Sentences(sentences_data);
foreach (KeyValuePair<string, string> h in response.Headers) {
Expand Down
5 changes: 2 additions & 3 deletions rosette_apiExamples/transliteration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ static void Main(string[] args)
try
{
CAPI rosetteApi = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl);
string transliteration_data = "haza ya7taj fakat ila an takoun ba3dh el-nousous allati na7n ymkn an tata7awal ila al-3arabizi.";
string transliteration_language_data = "ara";
string transliteration_data = "ana r2ye7 el gam3a el sa3a 3 el 3asr";

//The results of the API call will come back in the form of a Dictionary
TransliterationResponse response = rosetteApi.Transliteration(transliteration_data, transliteration_language_data);
TransliterationResponse response = rosetteApi.Transliteration(transliteration_data, "ara");

foreach (KeyValuePair<string, string> h in response.Headers) {
Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value));
Expand Down
9 changes: 9 additions & 0 deletions rosette_apiUnitTests/rosette_apiUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ public void Cleanup() {
_mockHttp.Clear();
}

//------------------------- User-Agent Test ----------------------------------------
[Test]
public void UserAgentTest() {
string uaString = string.Format("RosetteAPICsharp/{0}/{1}", CAPI.Version, Environment.Version.ToString());
Assert.AreEqual(uaString, _rosetteApi.UserAgent);
}



//------------------------- Simple Options Tests ----------------------------------------


Expand Down

0 comments on commit 1737663

Please sign in to comment.