-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
548 additions
and
218 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System.Net.Http; | ||
|
||
namespace rosette_api { | ||
/// <summary> | ||
/// A class to represent the results from the Name Deduplication endpoint of the Rosette API | ||
/// </summary> | ||
[JsonObject(MemberSerialization.OptOut)] | ||
public class NameDeduplicationResponse : RosetteResponse { | ||
private const string nameDeduplicationKey = "results"; | ||
|
||
/// <summary> | ||
/// The transliterated string | ||
/// </summary> | ||
[JsonProperty(nameDeduplicationKey)] | ||
public List<string> Results; | ||
|
||
/// <summary> | ||
/// Creates a NameDeduplicationResponse from the given apiResults | ||
/// </summary> | ||
/// <param name="apiResults">The message from the API</param> | ||
public NameDeduplicationResponse(HttpResponseMessage apiResults) : base(apiResults) { | ||
if (this.ContentDictionary.ContainsKey(nameDeduplicationKey)) { | ||
this.Results = this.ContentDictionary[nameDeduplicationKey] as List<string>; | ||
JArray resultsArr = this.ContentDictionary.ContainsKey(nameDeduplicationKey) ? this.ContentDictionary[nameDeduplicationKey] as JArray : null; | ||
this.Results = resultsArr != null ? new List<string>(resultsArr.Select<JToken, string>((jToken) => jToken != null ? jToken.ToString() : null)) : null; | ||
|
||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a NameDeduplicationResponse from its headers | ||
/// </summary> | ||
/// <param name="responseHeaders">The response headers from the API</param> | ||
/// <param name="content">The content of the response (the score) in dictionary form</param> | ||
/// <param name="contentAsJSON">The content in JSON</param> | ||
public NameDeduplicationResponse(Dictionary<string, string> responseHeaders, Dictionary<string, object> content, string contentAsJSON) : base(responseHeaders, content, contentAsJSON) { | ||
if (this.ContentDictionary.ContainsKey(nameDeduplicationKey)) { | ||
this.Results = this.ContentDictionary[nameDeduplicationKey] as List<string>; | ||
JArray resultsArr = this.ContentDictionary.ContainsKey(nameDeduplicationKey) ? this.ContentDictionary[nameDeduplicationKey] as JArray : null; | ||
this.Results = resultsArr != null ? new List<string>(resultsArr.Select<JToken, string>((jToken) => jToken != null ? jToken.ToString() : null)) : null; | ||
|
||
} | ||
} | ||
|
||
/// <summary> | ||
/// Equals override. | ||
/// </summary> | ||
/// <param name="obj">The object to compare against</param> | ||
/// <returns>True if equal.</returns> | ||
public override bool Equals(object obj) { | ||
if (obj is NameDeduplicationResponse) { | ||
NameDeduplicationResponse other = obj as NameDeduplicationResponse; | ||
return this.Results == other.Results && this.ResponseHeaders.Equals(other.ResponseHeaders); | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// HashCode override | ||
/// </summary> | ||
/// <returns>The hashcode</returns> | ||
public override int GetHashCode() { | ||
return this.Results.GetHashCode() ^ this.ResponseHeaders.GetHashCode(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using System.Net.Http; | ||
|
||
namespace rosette_api { | ||
/// <summary> | ||
/// A class to represnt the results from the Name Deduplication endpoint of the Rosette API | ||
/// </summary> | ||
[JsonObject(MemberSerialization.OptOut)] | ||
public class TransliterationResponse : RosetteResponse { | ||
private const string transliterationKey = "transliteration"; | ||
|
||
/// <summary> | ||
/// The transliterated string | ||
/// </summary> | ||
[JsonProperty(transliterationKey)] | ||
public string Transliteration; | ||
|
||
/// <summary> | ||
/// Creates a TransliterationResponse from the given apiResults | ||
/// </summary> | ||
/// <param name="apiResults">The message from the API</param> | ||
public TransliterationResponse(HttpResponseMessage apiResults) : base(apiResults) { | ||
if (this.ContentDictionary.ContainsKey("transliteration")) { | ||
this.Transliteration = this.ContentDictionary["transliteration"] as string; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a TransliterationResponse from its headers | ||
/// </summary> | ||
/// <param name="responseHeaders">The response headers from the API</param> | ||
/// <param name="content">The content of the response (the score) in dictionary form</param> | ||
/// <param name="contentAsJSON">The content in JSON</param> | ||
public TransliterationResponse(Dictionary<string, string> responseHeaders, Dictionary<string, object> content, string contentAsJSON) : base(responseHeaders, content, contentAsJSON) { | ||
if (this.ContentDictionary.ContainsKey("transliteration")) { | ||
this.Transliteration = this.ContentDictionary["transliteration"] as string; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Equals override. | ||
/// </summary> | ||
/// <param name="obj">The object to compare against</param> | ||
/// <returns>True if equal.</returns> | ||
public override bool Equals(object obj) { | ||
if (obj is TransliterationResponse) { | ||
TransliterationResponse other = obj as TransliterationResponse; | ||
return this.Transliteration == other.Transliteration && this.ResponseHeaders.Equals(other.ResponseHeaders); | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// HashCode override | ||
/// </summary> | ||
/// <returns>The hashcode</returns> | ||
public override int GetHashCode() { | ||
return this.Transliteration.GetHashCode() ^ this.ResponseHeaders.GetHashCode(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="System.Numerics.Vectors" version="4.1.1" targetFramework="net45" /> | ||
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" /> | ||
<package id="System.Numerics.Vectors" version="4.3.0" targetFramework="net45" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.