Skip to content

Commit e7ae204

Browse files
committed
Merge branch 'develop'
2 parents 6a65de6 + 098c355 commit e7ae204

16 files changed

+838
-135
lines changed

rosette_api/CAPI.cs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,116 @@ public TextEmbeddingResponse TextEmbedding(RosetteFile file)
755755
return Process<TextEmbeddingResponse>(file);
756756
}
757757

758+
/// <summary>SemanticVectors
759+
/// <para>
760+
/// (POST)SemanticVectors Endpoint: Returns an averaged text vector of the input text.
761+
/// </para>
762+
/// </summary>
763+
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
764+
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
765+
/// <param name="contentType">(string, optional): not used at time</param>
766+
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
767+
/// <param name="genre">(string, optional): genre to categorize the input data</param>
768+
/// <returns>
769+
/// A SemanticVectorsResponse:
770+
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
771+
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
772+
/// The text embedding represents the relationships between words in your document in the semantic space.
773+
/// The semantic space is a multilingual network that maps the input based on the words and their context.
774+
/// Words with similar meanings have similar contexts, and Rosette maps them close to each other
775+
/// </returns>
776+
public SemanticVectorsResponse SemanticVectors(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
777+
{
778+
_uri = "semantics/vector";
779+
return Process<SemanticVectorsResponse>(content, language, contentType, contentUri, genre);
780+
}
781+
782+
/// <summary>SemanticVectors
783+
/// <para>
784+
/// (POST)SemanticVectors Endpoint: Returns an averaged text vector of the input text.
785+
/// </para>
786+
/// </summary>
787+
/// <param name="dict">Dictionary&lt;object, object&gt;: Dictionary containing parameters as (key,value) pairs</param>
788+
/// <returns>
789+
/// A SemanticVectorsResponse:
790+
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
791+
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
792+
/// The text embedding represents the relationships between words in your document in the semantic space.
793+
/// The semantic space is a multilingual network that maps the input based on the words and their context.
794+
/// Words with similar meanings have similar contexts, and Rosette maps them close to each other
795+
/// </returns>
796+
public SemanticVectorsResponse SemanticVectors(Dictionary<object, object> dict)
797+
{
798+
_uri = "semantics/vector";
799+
return GetResponse<SemanticVectorsResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
800+
}
801+
802+
/// <summary>SemanticVectors
803+
/// <para>
804+
/// (POST)SemanticVectors Endpoint: Returns an averaged text vector of the input text.
805+
/// </para>
806+
/// </summary>
807+
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
808+
/// <returns>
809+
/// A SemanticVectorsResponse:
810+
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
811+
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
812+
/// The text embedding represents the relationships between words in your document in the semantic space.
813+
/// The semantic space is a multilingual network that maps the input based on the words and their context.
814+
/// Words with similar meanings have similar contexts, and Rosette maps them close to each other
815+
/// </returns>
816+
public SemanticVectorsResponse SemanticVectors(RosetteFile file)
817+
{
818+
_uri = "semantics/vector";
819+
return Process<SemanticVectorsResponse>(file);
820+
}
821+
822+
/// <summary>Similar terms
823+
/// <para>
824+
/// (POST)Similar Terms Endpoint: Returns the terms similar to an input term
825+
/// </para>
826+
/// </summary>
827+
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
828+
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
829+
/// <param name="contentType">(string, optional): not used at time</param>
830+
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
831+
/// <param name="genre">(string, optional): genre to categorize the input data</param>
832+
/// <returns>SimilarTermsResponse containing the results of the request.
833+
/// The response contains a mapping of language to similar terms.
834+
/// </returns>
835+
public SimilarTermsResponse SimilarTerms(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) {
836+
_uri = "semantics/similar";
837+
return Process<SimilarTermsResponse>(content, language, contentType, contentUri, genre);
838+
}
839+
840+
/// <summary>Similar terms
841+
/// <para>
842+
/// (POST)Similar Terms Endpoint: Returns the terms similar to an input term
843+
/// </para>
844+
/// </summary>
845+
/// <param name="dict">Dictionary&lt;object, object&gt;: Dictionary containing parameters as (key,value) pairs</param>
846+
/// <returns>SimilarTermsResponse containing the results of the request.
847+
/// The response contains a mapping of language to similar terms.
848+
/// </returns>
849+
public SimilarTermsResponse SimilarTerms(Dictionary<object, object> dict) {
850+
_uri = "semantics/similar";
851+
return GetResponse<SimilarTermsResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
852+
}
853+
854+
/// <summary>Similar terms
855+
/// <para>
856+
/// (POST)Similar Terms Endpoint: Returns the terms similar to an input term
857+
/// </para>
858+
/// </summary>
859+
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
860+
/// <returns>SimilarTermsResponse containing the results of the request.
861+
/// The response contains a mapping of language to similar terms.
862+
/// </returns>
863+
public SimilarTermsResponse SimilarTerms(RosetteFile file) {
864+
_uri = "semantics/similar";
865+
return Process<SimilarTermsResponse>(file);
866+
}
867+
758868
/// <summary>SyntaxDependencies
759869
/// <para>
760870
/// (POST)SyntaxDependencies Endpoint: Return the syntactic dependencies of the input text.

rosette_api/EntitiesResponse.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ 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 mentionOffsetsKey = "mentionOffsets";
35+
private const String linkingConfidenceKey = "linkingConfidence";
36+
private const String salienceKey = "salience";
3437

3538
/// <summary>
3639
/// Creates an EntitiesResponse from the API's raw output
@@ -50,7 +53,11 @@ public EntitiesResponse(HttpResponseMessage apiResult) : base(apiResult)
5053
Nullable<int> count = result.Properties().Where((p) => String.Equals(p.Name, countKey)).Any() ? result[countKey].ToObject<int?>() : null;
5154
Nullable<double> confidence = result.Properties().Where((p) => String.Equals(p.Name, confidenceKey)).Any() ? result[confidenceKey].ToObject<double?>() : null;
5255
String dbpediaType = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypeKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[dbpediaTypeKey].ToString() : null;
53-
entities.Add(new RosetteEntity(mention, normalized, entityID, type, count, confidence, dbpediaType));
56+
JArray mentionOffsetsArr = result.Properties().Where((p) => String.Equals(p.Name, dbpediaTypeKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[mentionOffsetsKey] as JArray : null;
57+
List<MentionOffset> mentionOffsets = mentionOffsetsArr != null ? mentionOffsetsArr.ToObject<List<MentionOffset>>() : null;
58+
Nullable<double> linkingConfidence = result.Properties().Where((p) => String.Equals(p.Name, linkingConfidenceKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[linkingConfidenceKey].ToObject<double?>() : null;
59+
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));
5461
}
5562
this.Entities = entities;
5663
}
@@ -79,9 +86,8 @@ public override bool Equals(object obj)
7986
{
8087
EntitiesResponse other = obj as EntitiesResponse;
8188
List<bool> conditions = new List<bool>() {
82-
this.Entities != null && other.Entities != null ? this.Entities.SequenceEqual(other.Entities) : this.Entities == other.Entities,
89+
this.Entities != null && other.Entities != null ? this.Entities.SequenceEqual(other.Entities) : ReferenceEquals(this.Entities, other.Entities),
8390
this.ResponseHeaders != null && other.ResponseHeaders != null ? this.ResponseHeaders.Equals(other.ResponseHeaders) : this.ResponseHeaders == other.ResponseHeaders,
84-
this.GetHashCode() == other.GetHashCode()
8591
};
8692
return conditions.All(condition => condition);
8793
}

rosette_api/MentionOffset.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace rosette_api {
5+
/// <summary>
6+
/// Offsets of a piece of text in the document
7+
/// </summary>
8+
[JsonObject(MemberSerialization.OptOut)]
9+
public class MentionOffset : IEquatable<MentionOffset> {
10+
11+
/// <summary>
12+
/// ctor of MentionOffset
13+
/// </summary>
14+
/// <param name="startOffset">offset of the start of text</param>
15+
/// <param name="endOffset">offset of the end of text</param>
16+
public MentionOffset(int startOffset, int endOffset) {
17+
StartOffset = startOffset;
18+
EndOffset = endOffset;
19+
}
20+
21+
/// <summary>
22+
/// Start offset
23+
/// </summary>
24+
[JsonProperty("startOffset")]
25+
public int StartOffset { get; set; }
26+
27+
/// <summary>
28+
/// End offset
29+
/// </summary>
30+
[JsonProperty("endOffset")]
31+
public int EndOffset { get; set; }
32+
33+
/// <summary>
34+
/// Equality
35+
/// </summary>
36+
/// <param name="other">Offset to compare for equality</param>
37+
/// <returns>bool</returns>
38+
public bool Equals(MentionOffset other) {
39+
if (other == null) {
40+
return false;
41+
}
42+
return StartOffset.Equals(other.StartOffset) && EndOffset.Equals(other.EndOffset);
43+
}
44+
45+
/// <summary>
46+
/// Override for Equals
47+
/// </summary>
48+
/// <param name="obj">Object to check for equality</param>
49+
/// <returns>bool</returns>
50+
public override bool Equals(Object obj) {
51+
if (Object.ReferenceEquals(obj, null)) {
52+
return false;
53+
}
54+
55+
MentionOffset mentionOffsetObj = obj as MentionOffset;
56+
if (mentionOffsetObj == null) {
57+
return false;
58+
} else {
59+
return Equals(mentionOffsetObj);
60+
}
61+
}
62+
63+
/// <summary>
64+
/// Override for GetHashCode specific to MentionOffset
65+
/// </summary>
66+
/// <returns>int</returns>
67+
public override int GetHashCode() {
68+
return StartOffset.GetHashCode() ^ EndOffset.GetHashCode();
69+
}
70+
71+
/// <summary>
72+
/// ToString override
73+
/// </summary>
74+
/// <returns>This MentionOffset in JSON form</returns>
75+
public override string ToString() {
76+
return JsonConvert.SerializeObject(this);
77+
}
78+
}
79+
}

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.1.0")]
35-
[assembly: AssemblyVersion("1.12.1.0")]
36-
[assembly: AssemblyFileVersion("1.12.1.0")]
34+
// [assembly: AssemblyVersion("1.12.2.0")]
35+
[assembly: AssemblyVersion("1.12.2.0")]
36+
[assembly: AssemblyFileVersion("1.12.2.0")]

rosette_api/RosetteEntity.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace rosette_api
1111
/// A class for representing an identified entity and its properties
1212
/// </summary>
1313
[JsonObject(MemberSerialization.OptOut)]
14-
public class RosetteEntity
14+
public class RosetteEntity : IEquatable<RosetteEntity>
1515
{
1616
/// <summary>
1717
/// The Location entity type
@@ -119,13 +119,31 @@ public class RosetteEntity
119119
/// </summary>
120120
[JsonProperty("confidence")]
121121
public Nullable<double> Confidence { get; set; }
122-
122+
123123
/// <summary>
124124
/// Gets or sets the dbpediaType of the extracted entity
125125
/// </summary>
126126
[JsonProperty("dbpediaType", NullValueHandling = NullValueHandling.Ignore)]
127127
public String DBpediaType { get; set; }
128128

129+
/// <summary>
130+
/// Gets or sets the offsets of the extracted entity
131+
/// </summary>
132+
[JsonProperty("mentionOffsets")]
133+
public List<MentionOffset> MentionOffsets { get; set; }
134+
135+
/// <summary>
136+
/// Gets or sets the linking confidence of the extracted entity
137+
/// </summary>
138+
[JsonProperty("linkingConfidence", NullValueHandling = NullValueHandling.Ignore)]
139+
public Nullable<double> LinkingConfidence { get; set; }
140+
141+
/// <summary>
142+
/// Gets or sets the salience of the extracted entity
143+
/// </summary>
144+
[JsonProperty("salience", NullValueHandling = NullValueHandling.Ignore)]
145+
public Nullable<double> Salience { get; set; }
146+
129147
/// <summary>
130148
/// Creates an entity
131149
/// </summary>
@@ -136,8 +154,12 @@ public class RosetteEntity
136154
/// <param name="count">The number of times this entity appeared in the input to the API</param>
137155
/// <param name="confidence">The confidence of this entity appeared in the input to the API</param>
138156
/// <param name="dbpediaType">The DBpedia type of the entity</param>
157+
/// <param name="mentionOffsets">The mention offsets of the entity</param>
158+
/// <param name="linkingConfidence">The linking confidence of the entity</param>
159+
/// <param name="salience">The salience of the entity</param>
139160
public RosetteEntity(string mention, string normalizedMention, EntityID id, string entityType, int? count,
140-
double? confidence, string dbpediaType)
161+
double? confidence, string dbpediaType, List<MentionOffset> mentionOffsets, double? linkingConfidence,
162+
double? salience)
141163
{
142164
this.Mention = mention;
143165
this.NormalizedMention = normalizedMention;
@@ -146,16 +168,28 @@ public RosetteEntity(string mention, string normalizedMention, EntityID id, stri
146168
this.EntityType = entityType;
147169
this.Confidence = confidence;
148170
this.DBpediaType = dbpediaType;
171+
this.MentionOffsets = mentionOffsets;
172+
this.LinkingConfidence = linkingConfidence;
173+
this.Salience = salience;
149174
}
150175

151176
/// <summary>
152177
/// Equals for RosetteEntity
153178
/// </summary>
154179
/// <param name="other">RosetteEntity</param>
155180
/// <returns></returns>
156-
protected bool Equals(RosetteEntity other)
181+
public bool Equals(RosetteEntity other)
157182
{
158-
return string.Equals(Mention, other.Mention) && string.Equals(NormalizedMention, other.NormalizedMention) && Equals(ID, other.ID) && string.Equals(EntityType, other.EntityType) && Count == other.Count && Confidence.Equals(other.Confidence) && string.Equals(DBpediaType, other.DBpediaType);
183+
return string.Equals(Mention, other.Mention)
184+
&& string.Equals(NormalizedMention, other.NormalizedMention)
185+
&& Equals(ID, other.ID)
186+
&& string.Equals(EntityType, other.EntityType)
187+
&& Count == other.Count
188+
&& Confidence.Equals(other.Confidence)
189+
&& string.Equals(DBpediaType, other.DBpediaType)
190+
&& MentionOffsets.SequenceEqual(other.MentionOffsets)
191+
&& LinkingConfidence.Equals(other.LinkingConfidence)
192+
&& Salience.Equals(other.Salience);
159193
}
160194

161195
/// <summary>
@@ -168,7 +202,7 @@ public override bool Equals(object obj)
168202
if (ReferenceEquals(null, obj)) return false;
169203
if (ReferenceEquals(this, obj)) return true;
170204
if (obj.GetType() != this.GetType()) return false;
171-
return Equals((RosetteEntity) obj);
205+
return Equals(obj as RosetteEntity);
172206
}
173207

174208
/// <summary>
@@ -186,6 +220,9 @@ public override int GetHashCode()
186220
hashCode = (hashCode * 397) ^ Count.GetHashCode();
187221
hashCode = (hashCode * 397) ^ Confidence.GetHashCode();
188222
hashCode = (hashCode * 397) ^ (DBpediaType != null ? DBpediaType.GetHashCode() : 0);
223+
hashCode = (hashCode * 397) ^ (MentionOffsets != null ? MentionOffsets.GetHashCode() : 0);
224+
hashCode = (hashCode * 397) ^ (LinkingConfidence != null ? LinkingConfidence.GetHashCode() : 0);
225+
hashCode = (hashCode * 397) ^ (Salience != null ? Salience.GetHashCode() : 0);
189226
return hashCode;
190227
}
191228
}

0 commit comments

Comments
 (0)