Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Park committed Jun 14, 2017
2 parents c52c70f + f1da599 commit 91caa5b
Show file tree
Hide file tree
Showing 19 changed files with 548 additions and 218 deletions.
188 changes: 130 additions & 58 deletions rosette_api/CAPI.cs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion rosette_api/EntitiesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class EntitiesResponse : RosetteResponse
private const String normalizedKey = "normalized";
private const String entityIDKey = "entityId";
private const String countKey = "count";
private const String confidenceKey = "confidence";

/// <summary>
/// Creates a CategoriesResponse from the API's raw output
Expand All @@ -46,7 +47,8 @@ public EntitiesResponse(HttpResponseMessage apiResult) : base(apiResult)
EntityID entityID = entityIDStr != null ? new EntityID(entityIDStr) : null;
String normalized = result.Properties().Where((p) => String.Equals(p.Name, normalizedKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[normalizedKey].ToString() : null;
Nullable<int> count = result.Properties().Where((p) => String.Equals(p.Name, countKey)).Any() ? result[countKey].ToObject<int?>() : null;
entities.Add(new RosetteEntity(mention, normalized, entityID, type, count));
Nullable<double> confidence = result.Properties().Where((p) => String.Equals(p.Name, confidenceKey)).Any() ? result[confidenceKey].ToObject<double?>() : null;
entities.Add(new RosetteEntity(mention, normalized, entityID, type, count, confidence));
}
this.Entities = entities;
}
Expand Down
73 changes: 73 additions & 0 deletions rosette_api/NameDeduplicationResponse.cs
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();
}
}
}

4 changes: 0 additions & 4 deletions rosette_api/NameSimilarityResponse.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Net.Http;

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.5.0.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
// [assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
14 changes: 12 additions & 2 deletions rosette_api/RosetteEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public class RosetteEntity
[JsonProperty("count")]
public Nullable<int> Count { get; set; }

/// <summary>
/// Gets or sets the confidence of the extracted entity
/// </summary>
[JsonProperty("confidence")]
public Nullable<double> Confidence { get; set; }

/// <summary>
/// Creates an entity
/// </summary>
Expand All @@ -122,13 +128,15 @@ public class RosetteEntity
/// <param name="id">The mention's id</param>
/// <param name="entityType">The entity type</param>
/// <param name="count">The number of times this entity appeared in the input to the API</param>
public RosetteEntity(String mention, String normalizedMention, EntityID id, String entityType, Nullable<int> count)
/// <param name="confidence">The confidence of this entity appeared in the input to the API</param>
public RosetteEntity(String mention, String normalizedMention, EntityID id, String entityType, Nullable<int> count, Nullable<double> confidence)
{
this.Mention = mention;
this.NormalizedMention = normalizedMention;
this.ID = id;
this.Count = count;
this.EntityType = entityType;
this.Confidence = confidence;
}

/// <summary>
Expand All @@ -147,6 +155,7 @@ public override bool Equals(object obj)
this.EntityType == other.EntityType,
this.Mention == other.Mention,
this.NormalizedMention == other.NormalizedMention,
this.Confidence == other.Confidence,
this.GetHashCode() == other.GetHashCode()
};
return conditions.All(condition => condition);
Expand All @@ -168,7 +177,8 @@ public override int GetHashCode()
int h2 = this.ID != null ? this.ID.GetHashCode() : 1;
int h3 = this.Count != null ? this.Count.GetHashCode() : 1;
int h4 = this.EntityType != null ? this.EntityType.GetHashCode() : 1;
return h0 ^ h1 ^ h2 ^ h3 ^ h4;
int h5 = this.Confidence != null ? this.Confidence.GetHashCode() : 1;
return h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5;
}

/// <summary>
Expand Down
20 changes: 11 additions & 9 deletions rosette_api/SentimentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SentimentResponse(HttpResponseMessage apiResult)
List<RosetteSentimentEntity> entitySentiments = new List<RosetteSentimentEntity>();
JObject docResult = this.ContentDictionary.ContainsKey(docKey) ? this.ContentDictionary[docKey] as JObject : new JObject();
string docSentiment = docResult.Properties().Where((p) => p.Name == labelKey).Any() ? docResult[labelKey].ToString() : null;
decimal? docSentimentConfidence = docResult.Properties().Where((p) => p.Name == confidenceKey).Any() ? docResult[confidenceKey].ToObject<decimal?>() : new decimal?();
double? docSentimentConfidence = docResult.Properties().Where((p) => p.Name == confidenceKey).Any() ? docResult[confidenceKey].ToObject<double?>() : new double?();
this.DocSentiment = docSentiment != null && docSentimentConfidence != null ? new RosetteSentiment(docSentiment, docSentimentConfidence) : null;
JArray enumerableResults = this.ContentDictionary.ContainsKey(entitiesKey) ? this.ContentDictionary[entitiesKey] as JArray : new JArray();
foreach (JObject result in enumerableResults)
Expand All @@ -61,12 +61,12 @@ public SentimentResponse(HttpResponseMessage apiResult)
EntityID entityID = entityIDStr != null ? new EntityID(entityIDStr) : null;
Nullable<int> count = result.Properties().Where((p) => p.Name == countKey).Any() ? result[countKey].ToObject<int?>() : null;
string sentiment = null;
Nullable<decimal> confidence = null;
Nullable<double> confidence = null;
if (result.Properties().Where((p) => p.Name == sentimentKey).Any())
{
JObject entitySentiment = result[sentimentKey].ToObject<JObject>();
sentiment = entitySentiment.Properties().Where((p) => p.Name == labelKey).Any() ? entitySentiment[labelKey].ToString() : null;
confidence = entitySentiment.Properties().Where((p) => p.Name == confidenceKey).Any() ? entitySentiment[confidenceKey].ToObject<decimal?>() : new decimal?();
confidence = entitySentiment.Properties().Where((p) => p.Name == confidenceKey).Any() ? entitySentiment[confidenceKey].ToObject<double?>() : new double?();
}
entitySentiments.Add(new RosetteSentimentEntity(mention, normalizedMention, entityID, type, count, sentiment, confidence));
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public enum SentimentLabel
/// On a scale of 0-1, the confidence in the Label's correctness.
/// </summary>
[JsonProperty(confidenceKey)]
public Nullable<decimal> Confidence;
public Nullable<double> Confidence;
/// <summary>
/// The label indicating the sentiment
/// </summary>
Expand All @@ -168,14 +168,14 @@ public enum SentimentLabel
/// </summary>
/// <param name="sentiment">The sentiment label: "pos", "neu", or "neg"</param>
/// <param name="confidence">An indicator of confidence in the label being correct. A range from 0-1.</param>
public RosetteSentiment(String sentiment, Nullable<decimal> confidence)
public RosetteSentiment(String sentiment, Nullable<double> confidence)
{
switch (sentiment)
{
case "pos": this.Label = SentimentLabel.pos; break;
case "neu": this.Label = SentimentLabel.neu; break;
case "neg": this.Label = SentimentLabel.neg; break;
default: throw new ArgumentException("The sentiment label returned by the API has been changed. The binding needs to be updated.", "sentiment");
default: this.Label = SentimentLabel.neu; break;
}
this.Confidence = confidence;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public class RosetteSentimentEntity : RosetteEntity
/// <param name="count">The number of times the entity appeared in the text</param>
/// <param name="sentiment">The contextual sentiment of the entity</param>
/// <param name="confidence">The confidence that the sentiment was correctly identified</param>
public RosetteSentimentEntity(String mention, String normalizedMention, EntityID id, String entityType, Nullable<int> count, String sentiment, Nullable<decimal> confidence) : base(mention, normalizedMention, id, entityType, count)
public RosetteSentimentEntity(String mention, String normalizedMention, EntityID id, String entityType, Nullable<int> count, String sentiment, Nullable<double> confidence) : base(mention, normalizedMention, id, entityType, count, confidence)
{
this.Sentiment = new SentimentResponse.RosetteSentiment(sentiment, confidence);
}
Expand All @@ -265,7 +265,8 @@ public bool EntityEquals(RosetteEntity other)
this.Mention != null && other.Mention != null ? this.Mention.Equals(other.Mention) : this.Mention == other.Mention,
this.ID != null && other.ID != null ? this.ID.Equals(other.ID) : this.ID == other.ID,
this.EntityType != null && other.EntityType != null ? this.EntityType.Equals(other.EntityType) : this.EntityType == other.EntityType,
this.Count != null && other.Count != null ? this.Count.Equals(other.Count) : this.Count == other.Count
this.Count != null && other.Count != null ? this.Count.Equals(other.Count) : this.Count == other.Count,
this.Confidence != null && other.Confidence != null ? this.Confidence.Equals(other.Confidence) : this.Confidence == other.Confidence
};
return conditions.All(condition => condition);
}
Expand Down Expand Up @@ -305,7 +306,8 @@ public override int GetHashCode()
int h3 = this.Mention != null ? this.Mention.GetHashCode() : 1;
int h4 = this.NormalizedMention != null ? this.NormalizedMention.GetHashCode() : 1;
int h5 = this.Sentiment != null ? this.Sentiment.GetHashCode() : 1;
return h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5;
int h6 = this.Confidence != null ? this.Confidence.GetHashCode() : 1;
return h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5 ^ h6;
}

/// <summary>
Expand Down
66 changes: 66 additions & 0 deletions rosette_api/TransliterationResponse.cs
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();
}
}
}

3 changes: 2 additions & 1 deletion rosette_api/packages.config
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>
10 changes: 7 additions & 3 deletions rosette_api/rosette_api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics.Vectors, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -61,6 +63,7 @@
<Compile Include="LanguageIdentificationResponse.cs" />
<Compile Include="MorphologyResponse.cs" />
<Compile Include="Name.cs" />
<Compile Include="NameDeduplicationResponse.cs" />
<Compile Include="NameSimilarityResponse.cs" />
<Compile Include="PingResponse.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -79,6 +82,7 @@
<Compile Include="TextEmbeddingResponse.cs" />
<Compile Include="TokenizationResponse.cs" />
<Compile Include="TranslateNamesResponse.cs" />
<Compile Include="TransliterationResponse.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
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.5.0</version>
<version>1.7.0</version>
<authors>basistech</authors>
<owners>basistech</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
Expand Down
Loading

0 comments on commit 91caa5b

Please sign in to comment.