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 Sep 10, 2019
2 parents e7ae204 + 2c28307 commit fc9b48c
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/rosette-api/csharp.svg?branch=master)](https://travis-ci.org/rosette-api/csharp)
[![Build Status](https://travis-ci.org/rosette-api/csharp.svg?branch=master)](https://travis-ci.org/rosette-api/csharp) [![NuGet version](https://badge.fury.io/nu/rosette_api.svg)](https://badge.fury.io/nu/rosette_api)

## .Net (C#) client binding for the Rosette API

Expand Down
8 changes: 6 additions & 2 deletions rosette_api/EntitiesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public class EntitiesResponse : RosetteResponse
private const String countKey = "count";
private const String confidenceKey = "confidence";
private const String dbpediaTypeKey = "dbpediaType";
private const String dbpediaTypesKey = "dbpediaTypes";
private const String mentionOffsetsKey = "mentionOffsets";
private const String linkingConfidenceKey = "linkingConfidence";
private const String salienceKey = "salience";
private const String permIdKey = "permId";

/// <summary>
/// Creates an EntitiesResponse from the API's raw output
Expand All @@ -53,11 +55,13 @@ public EntitiesResponse(HttpResponseMessage apiResult) : base(apiResult)
Nullable<int> count = result.Properties().Where((p) => String.Equals(p.Name, countKey)).Any() ? result[countKey].ToObject<int?>() : null;
Nullable<double> confidence = result.Properties().Where((p) => String.Equals(p.Name, confidenceKey)).Any() ? result[confidenceKey].ToObject<double?>() : null;
String dbpediaType = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypeKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[dbpediaTypeKey].ToString() : null;
JArray mentionOffsetsArr = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypeKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[mentionOffsetsKey] as JArray : null;
List<String> dbpediaTypes = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypesKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[dbpediaTypesKey].ToObject<List<String>>() : null;
JArray mentionOffsetsArr = result.Properties().Where((p) => String.Equals(p.Name, mentionOffsetsKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[mentionOffsetsKey] as JArray : null;
List<MentionOffset> mentionOffsets = mentionOffsetsArr != null ? mentionOffsetsArr.ToObject<List<MentionOffset>>() : null;
Nullable<double> linkingConfidence = result.Properties().Where((p) => String.Equals(p.Name, linkingConfidenceKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[linkingConfidenceKey].ToObject<double?>() : null;
Nullable<double> salience = result.Properties().Where((p) => String.Equals(p.Name, salienceKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[salienceKey].ToObject<double?>() : null;
entities.Add(new RosetteEntity(mention, normalized, entityID, type, count, confidence, dbpediaType, mentionOffsets, linkingConfidence, salience));
String permId = result.Properties().Where((p) => String.Equals(p.Name, permIdKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[permIdKey].ToString() : null;
entities.Add(new RosetteEntity(mention, normalized, entityID, type, count, confidence, dbpediaType, dbpediaTypes, mentionOffsets, linkingConfidence, salience, permId));
}
this.Entities = entities;
}
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.12.2.0")]
[assembly: AssemblyVersion("1.12.2.0")]
[assembly: AssemblyFileVersion("1.12.2.0")]
// [assembly: AssemblyVersion("1.14.0.0")]
[assembly: AssemblyVersion("1.14.0.0")]
[assembly: AssemblyFileVersion("1.14.0.0")]
41 changes: 38 additions & 3 deletions rosette_api/RosetteEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,16 @@ public class RosetteEntity : IEquatable<RosetteEntity>
/// <summary>
/// Gets or sets the dbpediaType of the extracted entity
/// </summary>
[Obsolete("Use dbPediaTypes instead.")]
[JsonProperty("dbpediaType", NullValueHandling = NullValueHandling.Ignore)]
public String DBpediaType { get; set; }

/// <summary>
/// Gets or sets the dbpediaTypes of the extracted entity
/// </summary>
[JsonProperty("dbpediaTypes", NullValueHandling = NullValueHandling.Ignore)]
public List<String> DBpediaTypes { get; set; }

/// <summary>
/// Gets or sets the offsets of the extracted entity
/// </summary>
Expand All @@ -144,6 +151,12 @@ public class RosetteEntity : IEquatable<RosetteEntity>
[JsonProperty("salience", NullValueHandling = NullValueHandling.Ignore)]
public Nullable<double> Salience { get; set; }

/// <summary>
/// Gets or sets the permId of the extracted entity
/// </summary>
[JsonProperty("permId", NullValueHandling = NullValueHandling.Ignore)]
public String PermID { get; set; }

/// <summary>
/// Creates an entity
/// </summary>
Expand All @@ -154,12 +167,14 @@ public class RosetteEntity : IEquatable<RosetteEntity>
/// <param name="count">The number of times this entity appeared in the input to the API</param>
/// <param name="confidence">The confidence of this entity appeared in the input to the API</param>
/// <param name="dbpediaType">The DBpedia type of the entity</param>
/// <param name="dbpediaTypes">A list of DBpedia types of the entitiy</param>
/// <param name="mentionOffsets">The mention offsets of the entity</param>
/// <param name="linkingConfidence">The linking confidence of the entity</param>
/// <param name="salience">The salience of the entity</param>
/// <param name="permId">The Thomson Reuters Permanent Identifier of the entity</param>
public RosetteEntity(string mention, string normalizedMention, EntityID id, string entityType, int? count,
double? confidence, string dbpediaType, List<MentionOffset> mentionOffsets, double? linkingConfidence,
double? salience)
double? confidence, string dbpediaType, List<String> dbpediaTypes, List<MentionOffset> mentionOffsets,
double? linkingConfidence, double? salience, string permId)
{
this.Mention = mention;
this.NormalizedMention = normalizedMention;
Expand All @@ -168,9 +183,25 @@ public RosetteEntity(string mention, string normalizedMention, EntityID id, stri
this.EntityType = entityType;
this.Confidence = confidence;
this.DBpediaType = dbpediaType;
this.DBpediaTypes = dbpediaTypes;
this.MentionOffsets = mentionOffsets;
this.LinkingConfidence = linkingConfidence;
this.Salience = salience;
this.PermID = permId;
}

/// <summary>
/// Method to compare Lists of Strings. SequenceEqual throws an exception
/// if either argument is null.
/// </summary>
/// <param name="list1">List<String></param>
/// <param name="list2">List<String></param>
/// <returns>True if equal or both null</returns>
private bool StringListsAreEqual(List<String> list1, List<String> list2)
{
if(list1 == null && list2 == null) { return true; }
if(list1 == null || list2 == null) { return false; } // only one is null
return list1.SequenceEqual(list2);
}

/// <summary>
Expand All @@ -187,9 +218,11 @@ public bool Equals(RosetteEntity other)
&& Count == other.Count
&& Confidence.Equals(other.Confidence)
&& string.Equals(DBpediaType, other.DBpediaType)
&& StringListsAreEqual(DBpediaTypes, other.DBpediaTypes)
&& MentionOffsets.SequenceEqual(other.MentionOffsets)
&& LinkingConfidence.Equals(other.LinkingConfidence)
&& Salience.Equals(other.Salience);
&& Salience.Equals(other.Salience)
&& string.Equals(PermID, other.PermID);
}

/// <summary>
Expand Down Expand Up @@ -220,9 +253,11 @@ public override int GetHashCode()
hashCode = (hashCode * 397) ^ Count.GetHashCode();
hashCode = (hashCode * 397) ^ Confidence.GetHashCode();
hashCode = (hashCode * 397) ^ (DBpediaType != null ? DBpediaType.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (DBpediaTypes != null ? DBpediaTypes.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (MentionOffsets != null ? MentionOffsets.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (LinkingConfidence != null ? LinkingConfidence.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Salience != null ? Salience.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (PermID != null ? PermID.GetHashCode() : 0);
return hashCode;
}
}
Expand Down
16 changes: 13 additions & 3 deletions rosette_api/SentimentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ public class SentimentResponse : RosetteResponse, IEquatable<SentimentResponse>
internal const string mentionKey = "mention";
internal const string normalizedMentionKey = "normalized";
internal const string dbpediaTypeKey = "dbpediaType";
internal const string dbpediaTypesKey = "dbpediaTypes";
internal const string countKey = "count";
internal const string typeKey = "type";
internal const string entityIDKey = "entityId";
internal const string sentimentKey = "sentiment";
internal const String mentionOffsetsKey = "mentionOffsets";
internal const String linkingConfidenceKey = "linkingConfidence";
internal const String salienceKey = "salience";
internal const String permIdKey = "permId";

/// <summary>
/// Gets or sets the document-level sentiment identified by the Rosette API
Expand Down Expand Up @@ -64,17 +66,19 @@ public SentimentResponse(HttpResponseMessage apiResult)
string entityIDStr = result.Properties().Where((p) => p.Name == entityIDKey).Any() ? result[entityIDKey].ToString() : null;
EntityID entityID = entityIDStr != null ? new EntityID(entityIDStr) : null;
string dbpediaType = result.Properties().Where((p) => p.Name == dbpediaTypeKey).Any() ? result[dbpediaTypeKey].ToString() : null;
List<String> dbpediaTypes = result.Properties().Where((permIdKey) => permIdKey.Name == dbpediaTypesKey).Any() ? result[dbpediaTypesKey].ToObject<List<String>>() : null;
Nullable<int> count = result.Properties().Where((p) => p.Name == countKey).Any() ? result[countKey].ToObject<int?>() : null;
Nullable<double> confidence = result.Properties().Where((p) => String.Equals(p.Name, confidenceKey)).Any() ? result[confidenceKey].ToObject<double?>() : null;
JArray mentionOffsetsArr = result.Properties().Where((p) => p.Name == mentionOffsetsKey).Any() ? result[mentionOffsetsKey] as JArray : null;
List<MentionOffset> mentionOffsets = mentionOffsetsArr != null ? mentionOffsetsArr.ToObject<List<MentionOffset>>() : null;
Nullable<double> linkingConfidence = result.Properties().Where((p) => p.Name == linkingConfidenceKey).Any() ? result[linkingConfidenceKey].ToObject<double?>() : null;
Nullable<double> salience = result.Properties().Where((p) => p.Name == salienceKey).Any() ? result[salienceKey].ToObject<double?>() : null;
String permId = result.Properties().Where((p) => p.Name == permIdKey).Any() ? result[permIdKey].ToString() : null;
RosetteSentiment sentiment = null;
if (result.Properties().Where((p) => p.Name == sentimentKey).Any()) {
sentiment = result[sentimentKey].ToObject<RosetteSentiment>();
}
entitySentiments.Add(new RosetteSentimentEntity(mention, normalizedMention, entityID, type, count, sentiment, confidence, dbpediaType, mentionOffsets, linkingConfidence, salience));
entitySentiments.Add(new RosetteSentimentEntity(mention, normalizedMention, entityID, type, count, sentiment, confidence, dbpediaType, dbpediaTypes, mentionOffsets, linkingConfidence, salience, permId));
}
this.EntitySentiments = entitySentiments;
}
Expand Down Expand Up @@ -282,9 +286,11 @@ public class RosetteSentimentEntity : RosetteEntity, IEquatable<RosetteSentiment
/// <param name="sentiment">The contextual sentiment of the entity</param>
/// <param name="confidence">The confidence that the sentiment was correctly identified</param>
/// <param name="dbpediaType">The DBpedia type of the entity</param>
/// <param name="dbpediaTypes">A list of DBpedia types of the entitiy</param>
/// <param name="mentionOffsets">The mention offsets of the entity</param>
/// <param name="linkingConfidence">The linking confidence of the entity</param>
/// <param name="salience">The salience of the entity</param>
/// <param name="permId">The Thomson Reuters Permanent Identifier of the entity</param>
public RosetteSentimentEntity(string mention,
string normalizedMention,
EntityID id,
Expand All @@ -293,19 +299,23 @@ public RosetteSentimentEntity(string mention,
SentimentResponse.RosetteSentiment sentiment,
double? confidence,
string dbpediaType,
List<String> dbpediaTypes,
List<MentionOffset> mentionOffsets,
double? linkingConfidence,
double? salience
double? salience,
String permId
) : base(mention,
normalizedMention,
id,
entityType,
count,
confidence,
dbpediaType,
dbpediaTypes,
mentionOffsets,
linkingConfidence,
salience
salience,
permId
)
{
this.Sentiment = new SentimentResponse.RosetteSentiment(sentiment.Label, sentiment.Confidence);
Expand Down
4 changes: 2 additions & 2 deletions rosette_api/rosette_api.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<package >
<metadata>
<id>rosette_api</id>
<version>1.12.2</version>
<version>1.14.0</version>
<authors>basistech</authors>
<owners>basistech</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<license type="expression">Apache-2.0</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>.Net (C#) Binding for Rosette API</description>
<releaseNotes>.Net (C#) Binding updated for Rosette API</releaseNotes>
Expand Down
Loading

0 comments on commit fc9b48c

Please sign in to comment.