Skip to content

Commit fc9b48c

Browse files
committed
Merge branch 'develop'
2 parents e7ae204 + 2c28307 commit fc9b48c

File tree

7 files changed

+128
-39
lines changed

7 files changed

+128
-39
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/rosette-api/csharp.svg?branch=master)](https://travis-ci.org/rosette-api/csharp)
1+
[![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)
22

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

rosette_api/EntitiesResponse.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ public class EntitiesResponse : RosetteResponse
3131
private const String countKey = "count";
3232
private const String confidenceKey = "confidence";
3333
private const String dbpediaTypeKey = "dbpediaType";
34+
private const String dbpediaTypesKey = "dbpediaTypes";
3435
private const String mentionOffsetsKey = "mentionOffsets";
3536
private const String linkingConfidenceKey = "linkingConfidence";
3637
private const String salienceKey = "salience";
38+
private const String permIdKey = "permId";
3739

3840
/// <summary>
3941
/// Creates an EntitiesResponse from the API's raw output
@@ -53,11 +55,13 @@ public EntitiesResponse(HttpResponseMessage apiResult) : base(apiResult)
5355
Nullable<int> count = result.Properties().Where((p) => String.Equals(p.Name, countKey)).Any() ? result[countKey].ToObject<int?>() : null;
5456
Nullable<double> confidence = result.Properties().Where((p) => String.Equals(p.Name, confidenceKey)).Any() ? result[confidenceKey].ToObject<double?>() : null;
5557
String dbpediaType = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypeKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[dbpediaTypeKey].ToString() : null;
56-
JArray mentionOffsetsArr = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypeKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[mentionOffsetsKey] as JArray : null;
58+
List<String> dbpediaTypes = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypesKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[dbpediaTypesKey].ToObject<List<String>>() : null;
59+
JArray mentionOffsetsArr = result.Properties().Where((p) => String.Equals(p.Name, mentionOffsetsKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[mentionOffsetsKey] as JArray : null;
5760
List<MentionOffset> mentionOffsets = mentionOffsetsArr != null ? mentionOffsetsArr.ToObject<List<MentionOffset>>() : null;
5861
Nullable<double> linkingConfidence = result.Properties().Where((p) => String.Equals(p.Name, linkingConfidenceKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[linkingConfidenceKey].ToObject<double?>() : null;
5962
Nullable<double> salience = result.Properties().Where((p) => String.Equals(p.Name, salienceKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[salienceKey].ToObject<double?>() : null;
60-
entities.Add(new RosetteEntity(mention, normalized, entityID, type, count, confidence, dbpediaType, mentionOffsets, linkingConfidence, salience));
63+
String permId = result.Properties().Where((p) => String.Equals(p.Name, permIdKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[permIdKey].ToString() : null;
64+
entities.Add(new RosetteEntity(mention, normalized, entityID, type, count, confidence, dbpediaType, dbpediaTypes, mentionOffsets, linkingConfidence, salience, permId));
6165
}
6266
this.Entities = entities;
6367
}

rosette_api/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
//
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
34-
// [assembly: AssemblyVersion("1.12.2.0")]
35-
[assembly: AssemblyVersion("1.12.2.0")]
36-
[assembly: AssemblyFileVersion("1.12.2.0")]
34+
// [assembly: AssemblyVersion("1.14.0.0")]
35+
[assembly: AssemblyVersion("1.14.0.0")]
36+
[assembly: AssemblyFileVersion("1.14.0.0")]

rosette_api/RosetteEntity.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,16 @@ public class RosetteEntity : IEquatable<RosetteEntity>
123123
/// <summary>
124124
/// Gets or sets the dbpediaType of the extracted entity
125125
/// </summary>
126+
[Obsolete("Use dbPediaTypes instead.")]
126127
[JsonProperty("dbpediaType", NullValueHandling = NullValueHandling.Ignore)]
127128
public String DBpediaType { get; set; }
128129

130+
/// <summary>
131+
/// Gets or sets the dbpediaTypes of the extracted entity
132+
/// </summary>
133+
[JsonProperty("dbpediaTypes", NullValueHandling = NullValueHandling.Ignore)]
134+
public List<String> DBpediaTypes { get; set; }
135+
129136
/// <summary>
130137
/// Gets or sets the offsets of the extracted entity
131138
/// </summary>
@@ -144,6 +151,12 @@ public class RosetteEntity : IEquatable<RosetteEntity>
144151
[JsonProperty("salience", NullValueHandling = NullValueHandling.Ignore)]
145152
public Nullable<double> Salience { get; set; }
146153

154+
/// <summary>
155+
/// Gets or sets the permId of the extracted entity
156+
/// </summary>
157+
[JsonProperty("permId", NullValueHandling = NullValueHandling.Ignore)]
158+
public String PermID { get; set; }
159+
147160
/// <summary>
148161
/// Creates an entity
149162
/// </summary>
@@ -154,12 +167,14 @@ public class RosetteEntity : IEquatable<RosetteEntity>
154167
/// <param name="count">The number of times this entity appeared in the input to the API</param>
155168
/// <param name="confidence">The confidence of this entity appeared in the input to the API</param>
156169
/// <param name="dbpediaType">The DBpedia type of the entity</param>
170+
/// <param name="dbpediaTypes">A list of DBpedia types of the entitiy</param>
157171
/// <param name="mentionOffsets">The mention offsets of the entity</param>
158172
/// <param name="linkingConfidence">The linking confidence of the entity</param>
159173
/// <param name="salience">The salience of the entity</param>
174+
/// <param name="permId">The Thomson Reuters Permanent Identifier of the entity</param>
160175
public RosetteEntity(string mention, string normalizedMention, EntityID id, string entityType, int? count,
161-
double? confidence, string dbpediaType, List<MentionOffset> mentionOffsets, double? linkingConfidence,
162-
double? salience)
176+
double? confidence, string dbpediaType, List<String> dbpediaTypes, List<MentionOffset> mentionOffsets,
177+
double? linkingConfidence, double? salience, string permId)
163178
{
164179
this.Mention = mention;
165180
this.NormalizedMention = normalizedMention;
@@ -168,9 +183,25 @@ public RosetteEntity(string mention, string normalizedMention, EntityID id, stri
168183
this.EntityType = entityType;
169184
this.Confidence = confidence;
170185
this.DBpediaType = dbpediaType;
186+
this.DBpediaTypes = dbpediaTypes;
171187
this.MentionOffsets = mentionOffsets;
172188
this.LinkingConfidence = linkingConfidence;
173189
this.Salience = salience;
190+
this.PermID = permId;
191+
}
192+
193+
/// <summary>
194+
/// Method to compare Lists of Strings. SequenceEqual throws an exception
195+
/// if either argument is null.
196+
/// </summary>
197+
/// <param name="list1">List<String></param>
198+
/// <param name="list2">List<String></param>
199+
/// <returns>True if equal or both null</returns>
200+
private bool StringListsAreEqual(List<String> list1, List<String> list2)
201+
{
202+
if(list1 == null && list2 == null) { return true; }
203+
if(list1 == null || list2 == null) { return false; } // only one is null
204+
return list1.SequenceEqual(list2);
174205
}
175206

176207
/// <summary>
@@ -187,9 +218,11 @@ public bool Equals(RosetteEntity other)
187218
&& Count == other.Count
188219
&& Confidence.Equals(other.Confidence)
189220
&& string.Equals(DBpediaType, other.DBpediaType)
221+
&& StringListsAreEqual(DBpediaTypes, other.DBpediaTypes)
190222
&& MentionOffsets.SequenceEqual(other.MentionOffsets)
191223
&& LinkingConfidence.Equals(other.LinkingConfidence)
192-
&& Salience.Equals(other.Salience);
224+
&& Salience.Equals(other.Salience)
225+
&& string.Equals(PermID, other.PermID);
193226
}
194227

195228
/// <summary>
@@ -220,9 +253,11 @@ public override int GetHashCode()
220253
hashCode = (hashCode * 397) ^ Count.GetHashCode();
221254
hashCode = (hashCode * 397) ^ Confidence.GetHashCode();
222255
hashCode = (hashCode * 397) ^ (DBpediaType != null ? DBpediaType.GetHashCode() : 0);
256+
hashCode = (hashCode * 397) ^ (DBpediaTypes != null ? DBpediaTypes.GetHashCode() : 0);
223257
hashCode = (hashCode * 397) ^ (MentionOffsets != null ? MentionOffsets.GetHashCode() : 0);
224258
hashCode = (hashCode * 397) ^ (LinkingConfidence != null ? LinkingConfidence.GetHashCode() : 0);
225259
hashCode = (hashCode * 397) ^ (Salience != null ? Salience.GetHashCode() : 0);
260+
hashCode = (hashCode * 397) ^ (PermID != null ? PermID.GetHashCode() : 0);
226261
return hashCode;
227262
}
228263
}

rosette_api/SentimentResponse.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ public class SentimentResponse : RosetteResponse, IEquatable<SentimentResponse>
2424
internal const string mentionKey = "mention";
2525
internal const string normalizedMentionKey = "normalized";
2626
internal const string dbpediaTypeKey = "dbpediaType";
27+
internal const string dbpediaTypesKey = "dbpediaTypes";
2728
internal const string countKey = "count";
2829
internal const string typeKey = "type";
2930
internal const string entityIDKey = "entityId";
3031
internal const string sentimentKey = "sentiment";
3132
internal const String mentionOffsetsKey = "mentionOffsets";
3233
internal const String linkingConfidenceKey = "linkingConfidence";
3334
internal const String salienceKey = "salience";
35+
internal const String permIdKey = "permId";
3436

3537
/// <summary>
3638
/// Gets or sets the document-level sentiment identified by the Rosette API
@@ -64,17 +66,19 @@ public SentimentResponse(HttpResponseMessage apiResult)
6466
string entityIDStr = result.Properties().Where((p) => p.Name == entityIDKey).Any() ? result[entityIDKey].ToString() : null;
6567
EntityID entityID = entityIDStr != null ? new EntityID(entityIDStr) : null;
6668
string dbpediaType = result.Properties().Where((p) => p.Name == dbpediaTypeKey).Any() ? result[dbpediaTypeKey].ToString() : null;
69+
List<String> dbpediaTypes = result.Properties().Where((permIdKey) => permIdKey.Name == dbpediaTypesKey).Any() ? result[dbpediaTypesKey].ToObject<List<String>>() : null;
6770
Nullable<int> count = result.Properties().Where((p) => p.Name == countKey).Any() ? result[countKey].ToObject<int?>() : null;
6871
Nullable<double> confidence = result.Properties().Where((p) => String.Equals(p.Name, confidenceKey)).Any() ? result[confidenceKey].ToObject<double?>() : null;
6972
JArray mentionOffsetsArr = result.Properties().Where((p) => p.Name == mentionOffsetsKey).Any() ? result[mentionOffsetsKey] as JArray : null;
7073
List<MentionOffset> mentionOffsets = mentionOffsetsArr != null ? mentionOffsetsArr.ToObject<List<MentionOffset>>() : null;
7174
Nullable<double> linkingConfidence = result.Properties().Where((p) => p.Name == linkingConfidenceKey).Any() ? result[linkingConfidenceKey].ToObject<double?>() : null;
7275
Nullable<double> salience = result.Properties().Where((p) => p.Name == salienceKey).Any() ? result[salienceKey].ToObject<double?>() : null;
76+
String permId = result.Properties().Where((p) => p.Name == permIdKey).Any() ? result[permIdKey].ToString() : null;
7377
RosetteSentiment sentiment = null;
7478
if (result.Properties().Where((p) => p.Name == sentimentKey).Any()) {
7579
sentiment = result[sentimentKey].ToObject<RosetteSentiment>();
7680
}
77-
entitySentiments.Add(new RosetteSentimentEntity(mention, normalizedMention, entityID, type, count, sentiment, confidence, dbpediaType, mentionOffsets, linkingConfidence, salience));
81+
entitySentiments.Add(new RosetteSentimentEntity(mention, normalizedMention, entityID, type, count, sentiment, confidence, dbpediaType, dbpediaTypes, mentionOffsets, linkingConfidence, salience, permId));
7882
}
7983
this.EntitySentiments = entitySentiments;
8084
}
@@ -282,9 +286,11 @@ public class RosetteSentimentEntity : RosetteEntity, IEquatable<RosetteSentiment
282286
/// <param name="sentiment">The contextual sentiment of the entity</param>
283287
/// <param name="confidence">The confidence that the sentiment was correctly identified</param>
284288
/// <param name="dbpediaType">The DBpedia type of the entity</param>
289+
/// <param name="dbpediaTypes">A list of DBpedia types of the entitiy</param>
285290
/// <param name="mentionOffsets">The mention offsets of the entity</param>
286291
/// <param name="linkingConfidence">The linking confidence of the entity</param>
287292
/// <param name="salience">The salience of the entity</param>
293+
/// <param name="permId">The Thomson Reuters Permanent Identifier of the entity</param>
288294
public RosetteSentimentEntity(string mention,
289295
string normalizedMention,
290296
EntityID id,
@@ -293,19 +299,23 @@ public RosetteSentimentEntity(string mention,
293299
SentimentResponse.RosetteSentiment sentiment,
294300
double? confidence,
295301
string dbpediaType,
302+
List<String> dbpediaTypes,
296303
List<MentionOffset> mentionOffsets,
297304
double? linkingConfidence,
298-
double? salience
305+
double? salience,
306+
String permId
299307
) : base(mention,
300308
normalizedMention,
301309
id,
302310
entityType,
303311
count,
304312
confidence,
305313
dbpediaType,
314+
dbpediaTypes,
306315
mentionOffsets,
307316
linkingConfidence,
308-
salience
317+
salience,
318+
permId
309319
)
310320
{
311321
this.Sentiment = new SentimentResponse.RosetteSentiment(sentiment.Label, sentiment.Confidence);

rosette_api/rosette_api.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<package >
33
<metadata>
44
<id>rosette_api</id>
5-
<version>1.12.2</version>
5+
<version>1.14.0</version>
66
<authors>basistech</authors>
77
<owners>basistech</owners>
8-
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
8+
<license type="expression">Apache-2.0</license>
99
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1010
<description>.Net (C#) Binding for Rosette API</description>
1111
<releaseNotes>.Net (C#) Binding updated for Rosette API</releaseNotes>

0 commit comments

Comments
 (0)