-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCAPI.cs
More file actions
1655 lines (1524 loc) · 78.1 KB
/
CAPI.cs
File metadata and controls
1655 lines (1524 loc) · 78.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Text;
using Newtonsoft.Json;
namespace rosette_api
{
/// <summary>
/// Enum to provide feature options for Morphology
/// </summary>
public enum MorphologyFeature
{
/// <summary>provide complete morphology</summary>
complete,
/// <summary>provide lemmas</summary>
lemmas,
/// <summary>provide parts of speech</summary>
partsOfSpeech,
/// <summary>provide compound components</summary>
compoundComponents,
/// <summary>provide han readings</summary>
hanReadings
};
/// <summary>C# Babel Street Analytics API.
/// <para>
/// Primary class for interfacing with the Analytics API
/// @copyright 2014-2024 Basis Technology Corporation.
/// Licensed under the Apache License, Version 2.0 (the "License"); you may not use file except in compliance
/// with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
/// Unless required by applicable law or agreed to in writing, software distributed under the License is
/// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and limitations under the License.
/// </para>
/// </summary>
public class CAPI
{
private const string LEGACY_CONCURRENCY_HEADER = "X-RosetteAPI-Concurrency";
private const string CONCURRENCY_HEADER = "X-BabelStreetAPI-Concurrency";
/// <summary>
/// setupLock is used to ensure that the setup operation cannot be run
/// by multiple processes
/// </summary>
private Object setupLock = new Object();
/// <summary>
/// Internal string to hold the uri ending for each endpoint.
/// Set when an endpoint is called.
/// </summary>
private string _uri = null;
/// <summary>
/// Internal container for options
/// </summary>
private Dictionary<string, object> _options;
/// <summary>
/// Internal container for custom headers
/// </summary>
private Dictionary<string, string> _customHeaders;
/// <summary>
/// Internal container for URL parameters
/// </summary>
private NameValueCollection _urlParameters;
/// <summary>
/// Http client to be used for life of API object
/// </summary>
private HttpClient _httpClient = null;
/// <summary>
/// Reference to external http client, if provided
/// </summary>
private HttpClient _externalHttpClient = null;
/// <summary>
/// Current timeout value for the http client in milliseconds
/// </summary>
private int _timeout = 0;
/// <summary>
/// Debug setting for the http client
/// </summary>
private bool _debug = false;
/// <summary>
/// The number of current concurrent connections
/// </summary>
private int _concurrentConnections = 1;
/// <summary>C# API class
/// <para>Babel Street Analytics Client Binding API; representation of an Analytics server.
/// Instance methods of the C# API provide communication with specific Analytics server endpoints.
/// Requires user_key to start and has 3 additional parameters to be specified.
/// Will run a Version Check against the Analytics Server. If the version check fails, a
/// RosetteException will be thrown.
/// </para>
/// </summary>
/// <param name="user_key">string: API key required by the Analytics server to allow access to endpoints</param>
/// <param name="uristring">(string, optional): Base URL for the HttpClient requests. If none is given, will use the default API URI</param>
/// <param name="maxRetry">(int, optional): Maximum number of times to retry a request on HttpResponse error. Default is 3 times.</param>
/// <param name="client">(HttpClient, optional): Forces the API to use a custom HttpClient.</param>
public CAPI(string user_key, string uristring = "https://analytics.babelstreet.com/rest/v1/", int maxRetry = 5, HttpClient client = null)
{
UserKey = user_key;
URIstring = uristring ?? "https://analytics.babelstreet.com/rest/v1/";
if (!URIstring.EndsWith("/"))
{
URIstring = URIstring + "/";
}
MaxRetry = (maxRetry == 0) ? 1 : maxRetry;
MillisecondsBetweenRetries = 5000;
_externalHttpClient = client;
_options = new Dictionary<string, object>();
_customHeaders = new Dictionary<string, string>();
_urlParameters = new NameValueCollection();
SetupClient();
}
/// <summary>UserKey
/// <para>
/// Getter, Setter for the UserKey
/// UserKey: API key required by the Analytics Server
/// Allows users to change their UserKey later (e.g. if instantiated class incorrectly)
/// </para>
/// </summary>
public string UserKey { get; set; }
/// <summary>URIstring
/// <para>
/// URIString returns the current URI of the Analytics server
/// </para>
/// </summary>
public string URIstring { get; private set; }
/// <summary>Version
/// <para>
/// Getter, Setter for the Version
/// Version: Internal Server Version number.
/// </para>
/// </summary>
public static string Version
{
get { return typeof(CAPI).Assembly.GetName().Version.ToString(); }
}
/// <summary>
/// UserAgent returns the string that will be used for User-Agent
/// </summary>
/// <returns>string User-Agent</returns>
public string UserAgent
{
get
{
return string.Format("Babel-Street-Analytics-API-Csharp/{0}/{1}", Version, Environment.Version.ToString());
}
}
/// <summary>MaxRetry
/// <para>
/// Getter, Setter for the MaxRetry
/// MaxRetry: Maximum number of times to retry a request on HTTPResponse error.
/// Allows users to change their MaxRetry later (e.g. if instantiated class incorrectly)
/// </para>
/// </summary>
public int MaxRetry { get; set; }
/// <summary>MillisecondsBetweenRetries
/// <para>
/// Getter, Setter for the MillisecondsBetweenRetries
/// MillisecondsBetweenRetries: milliseconds between retry attempts
/// </para>
/// </summary>
public int MillisecondsBetweenRetries { get; set; }
/// <summary>Client
/// Returns the http client instance. For externally provided http clients, this will return the same
/// client with some added headers that are required by the Analytics API. For the default internal client
/// it will return the current instance, which is maintained at the class level.
/// </summary>
public HttpClient Client
{
get { return _externalHttpClient ?? _httpClient; }
}
/// <summary>Concurrency
/// Returns the number of concurrent connections allowed by the current Analytics API plan.
/// For externally provided http clients, it is up to the user to update the connection limit within their own software.
/// For the default internal http client, the concurrent connections will adjust to the maximum allowed.
/// </summary>
public int Concurrency
{
get { return _concurrentConnections; }
private set
{
_concurrentConnections = value;
if (_httpClient != null && _concurrentConnections != ServicePointManager.DefaultConnectionLimit)
{
ServicePointManager.DefaultConnectionLimit = _concurrentConnections;
SetupClient(true);
}
}
}
/// <summary>Debug
/// <para>
/// Debug turns debugging on/off for the http client
/// </para>
/// </summary>
public bool Debug
{
get { return _debug; }
set
{
_debug = value;
if (_debug)
{
AddRequestHeader("X-RosetteAPI-Devel", "true");
}
else
{
if (Client.DefaultRequestHeaders.Contains("X-RosetteAPI-Devel"))
{
Client.DefaultRequestHeaders.Remove("X-RosetteAPI-Devel");
}
}
}
}
/// <summary>Timeout
/// <para>
/// Timeout is the http client timespan in milliseconds
/// </para>
/// </summary>
public int Timeout
{
get { return _timeout; }
set
{
try
{
if (value != 0 && Client.Timeout != TimeSpan.FromMilliseconds(value))
{
Client.Timeout = TimeSpan.FromMilliseconds(value);
}
_timeout = value;
}
catch (Exception ex)
{
throw new RosetteException("Invalid timeout, " + ex.Message);
}
}
}
/// <summary>
/// Sets the named option to the provided value
/// </summary>
/// <param name="name">string option name</param>
/// <param name="value">object value</param>
public void SetOption(string name, object value)
{
if (_options.ContainsKey(name) && value == null)
{
_options.Remove(name);
return;
}
_options[name] = value;
}
/// <summary>
/// Gets the requested option
/// </summary>
/// <param name="name">string option name</param>
/// <returns>object value if exists</returns>
public object GetOption(string name)
{
if (_options.ContainsKey(name))
{
return _options[name];
}
else
{
return null;
}
}
/// <summary>
/// Clears all of the options
/// </summary>
public void ClearOptions()
{
_options.Clear();
}
/// <summary>
/// Sets a custom header to the named value. The header name must be prefixed with "X-RosetteAPI-"
/// </summary>
/// <param name="key">string custom header key</param>
/// <param name="value">custom header value</param>
public void SetCustomHeaders(string key, string value)
{
if (!key.StartsWith("X-RosetteAPI-") && !key.StartsWith("X-BabelStreetAPI-"))
{
throw new RosetteException("Custom header name must begin with \"X-RosetteAPI-\" or \"X-BabelStreetAPI-\"");
}
if (_customHeaders.ContainsKey(key) && value == null)
{
_customHeaders.Remove(key);
Client.DefaultRequestHeaders.Remove(key);
return;
}
_customHeaders[key] = value;
AddRequestHeader(key, value);
}
/// <summary>
/// Gets the custom headers
/// </summary>
/// <returns>dictionary of custom headers</returns>
public Dictionary<string, string> GetCustomHeaders()
{
return _customHeaders;
}
/// <summary>
/// Clears all of the custom headers
/// </summary>
public void ClearCustomHeaders()
{
_customHeaders.Clear();
}
private Dictionary<object, object> AppendOptions(Dictionary<object, object> dict)
{
if (_options.Count > 0)
{
dict["options"] = _options;
}
return dict;
}
/// <summary>
/// Adds a value to a url parameter
/// </summary>
/// <param name="key">Parameter name</param>
/// <param name="value">Parameter value</param>
public void SetUrlParameter(string key, string value)
{
_urlParameters.Add(key, value);
}
/// <summary>
/// Removes the values for a given Url parameter key
/// </summary>
/// <param name="key">Name of parameter</param>
public void RemoveUrlParameter(string key)
{
_urlParameters.Remove(key);
}
/// <summary>
/// Returns the URL Parameters
/// </summary>
/// <returns>NameValueCollection</returns>
public NameValueCollection GetUrlParameters()
{
return _urlParameters;
}
/// <summary>
/// Removes all URL parameters
/// </summary>
public void ClearUrlParameters()
{
_urlParameters.Clear();
}
/// <summary>AddressSimilarity
/// <para>
/// (POST)AddressSimilarity Endpoint: Returns the result of matching 2 addresses.
/// </para>
/// </summary>
/// <param name="a1">IAddress: First address to be matched</param>
/// <param name="a2">IAddress: Second address to be matched</param>
/// <returns>AddressSimilarityResponse containing the results of the request.
/// </returns>
public AddressSimilarityResponse AddressSimilarity(IAddress a1, IAddress a2)
{
_uri = "address-similarity";
Dictionary<object, object> dict = new Dictionary<object, object>(){
{ "address1", a1},
{ "address2", a2}
};
return GetResponse<AddressSimilarityResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>AddressSimilarity
/// <para>
/// (POST)AddressSimilarity Endpoint: Returns the result of matching 2 addresses.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>AddressSimilarityResponse containing the results of the request.
/// </returns>
public AddressSimilarityResponse AddressSimilarity(Dictionary<object, object> dict)
{
_uri = "address-similarity";
return GetResponse<AddressSimilarityResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Categories
/// <para>
/// (POST)Categories Endpoint: Returns an ordered list of categories identified in the input. The categories are Tier 1 contextual categories defined in the QAG Taxonomy.
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): not used at time</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>CategoriesResponse containing the results of the request.
/// The response is the contextual categories identified in the input.
/// </returns>
public CategoriesResponse Categories(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
{
_uri = "categories";
return Process<CategoriesResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>Categories
/// <para>
/// (POST)Categories Endpoint: Returns an ordered list of categories identified in the input. The categories are Tier 1 contextual categories defined in the QAG Taxonomy.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>CategoriesResponse containing the results of the request.
/// The response is the contextual categories identified in the input.
/// </returns>
public CategoriesResponse Categories(Dictionary<object, object> dict)
{
_uri = "categories";
return GetResponse<CategoriesResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Categories
/// <para>
/// (POST)Categories Endpoint: Returns an ordered list of categories identified in the input. The categories are Tier 1 contextual categories defined in the QAG Taxonomy.
/// </para>
/// </summary>
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
/// <returns>RosetteResponse containing the results of the request.
/// The response is the contextual categories identified in the input.
/// </returns>
public CategoriesResponse Categories(RosetteFile file)
{
_uri = "categories";
return Process<CategoriesResponse>(file);
}
/// <summary>Entity
/// <para>
/// (POST)Entity Endpoint: Returns each entity extracted from the input.
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): not used at time</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>EntitiesResponse containing the results of the request.
/// </returns>
public EntitiesResponse Entity(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
{
_uri = "entities";
return Process<EntitiesResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>Entity
/// <para>
/// (POST)Entity Endpoint: Returns each entity extracted from the input.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>EntitiesResponse containing the results of the request.
/// </returns>
public EntitiesResponse Entity(Dictionary<object, object> dict)
{
_uri = "entities";
return GetResponse<EntitiesResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Entity
/// <para>
/// (POST)Entity Endpoint: Returns each entity extracted from the input.
/// </para>
/// </summary>
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
/// <returns>EntitiesResponse containing the results of the request.
/// </returns>
public EntitiesResponse Entity(RosetteFile file)
{
_uri = "entities";
return Process<EntitiesResponse>(file);
}
/// <summary>Event
/// <para>
/// (POST)Event Endpoint: Returns each event extracted from the input.
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): not used at time</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>EventsResponse containing the results of the request.
/// </returns>
public EventsResponse Event(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
{
_uri = "events";
return Process<EventsResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>Event
/// <para>
/// (POST)Event Endpoint: Returns each event extracted from the input.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>EventsResponse containing the results of the request.
/// </returns>
public EventsResponse Event(Dictionary<object, object> dict)
{
_uri = "events";
return GetResponse<EventsResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Event
/// <para>
/// (POST)Event Endpoint: Returns each event extracted from the input.
/// </para>
/// </summary>
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
/// <returns>EntitiesResponse containing the results of the request.
/// </returns>
public EventsResponse Event(RosetteFile file)
{
_uri = "events";
return Process<EventsResponse>(file);
}
/// <summary>Info
/// <para>
/// (GET)Info Endpoint: Response is a JSON string with Analytics API information including buildNumber, name, version, and buildTime.
/// </para>
/// </summary>
/// <returns>InfoResponse containing the results of the info GET.</returns>
public InfoResponse Info()
{
_uri = "info";
return GetResponse<InfoResponse>();
}
/// <summary>Language
/// <para>
/// (POST)Language Endpoint: Returns list of candidate languages.
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): MIME type of the input (required for base64 content; if content type is unknown, set to "application/octet-stream")</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>LanguageIdentificationResponse containing the results of the request.
/// The response is an ordered list of detected languages.
/// </returns>
public LanguageIdentificationResponse Language(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
{
_uri = "language";
return Process<LanguageIdentificationResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>Language
/// <para>
/// (POST)Language Endpoint: Returns list of candidate languages.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>LanguageIdentificationResponse containing the results of the request.
/// The response is an ordered list of detected languages.
/// </returns>
public LanguageIdentificationResponse Language(Dictionary<object, object> dict)
{
_uri = "language";
return GetResponse<LanguageIdentificationResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Language
/// <para>
/// (POST)Language Endpoint: Returns list of candidate languages.
/// </para>
/// </summary>
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
/// <returns>LanguageIdentificationResponse containing the results of the request.
/// The response is an ordered list of detected languages.
/// </returns>
public LanguageIdentificationResponse Language(RosetteFile file)
{
_uri = "language";
return Process<LanguageIdentificationResponse>(file);
}
/// <summary>Morphology
/// <para>
/// (POST)Morphology Endpoint: Returns morphological analysis of input.
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): not used at time</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="feature">(string, optional): Description of what morphology feature to request from the Analytics server</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>MorphologyResponse containing the results of the request.
/// The response may include lemmas, part of speech tags, compound word components, and Han readings.
/// Support for specific return types depends on language.
/// </returns>
public MorphologyResponse Morphology(string content = null, string language = null, string contentType = null, string contentUri = null, MorphologyFeature feature = MorphologyFeature.complete, string genre = null)
{
_uri = "morphology/" + feature.MorphologyEndpoint();
return Process<MorphologyResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>Morphology
/// <para>
/// (POST)Morphology Endpoint: Returns morphological analysis of input.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <param name="feature">(string, optional): Description of what morphology feature to request from the Analytics server</param>
/// <returns>MorphologyResponse containing the results of the request.
/// The response may include lemmas, part of speech tags, compound word components, and Han readings.
/// Support for specific return types depends on language.
/// </returns>
public MorphologyResponse Morphology(Dictionary<object, object> dict, MorphologyFeature feature = MorphologyFeature.complete)
{
_uri = "morphology/" + feature.MorphologyEndpoint();
return GetResponse<MorphologyResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Morphology
/// <para>
/// (POST)Morphology Endpoint: Returns morphological analysis of input.
/// </para>
/// </summary>
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
/// <param name="feature">(string, optional): Description of what morphology feature to request from the Rosette server</param>
/// <returns>MorphologyResponse containing the results of the request.
/// The response may include lemmas, part of speech tags, compound word components, and Han readings.
/// Support for specific return types depends on language.
/// </returns>
public MorphologyResponse Morphology(RosetteFile file, MorphologyFeature feature = MorphologyFeature.complete)
{
_uri = "morphology/" + feature.MorphologyEndpoint();
return Process<MorphologyResponse>(file);
}
/// <summary>RecordSimilarity
/// <para>
/// (POST)RecordSimilarity Endpoint: Returns the result of matching 2 lists of records.
/// </para>
/// </summary>
/// <param name="request">RecordSimilarityRequest: RecordSimilarityRequest object to send</param>
/// <returns>RecordSimilarityResponse containing the results of the request.
/// </returns>
public RecordSimilarityResponse RecordSimilarity(RecordSimilarityRequest request)
{
_uri = "record-similarity";
return GetResponse<RecordSimilarityResponse>(JsonConvert.SerializeObject(request, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
}
/// <summary>NameSimilarity
/// <para>
/// (POST)NameSimilarity Endpoint: Returns the result of matching 2 names.
/// </para>
/// </summary>
/// <param name="n1">Name: First name to be matched</param>
/// <param name="n2">Name: Second name to be matched</param>
/// <returns>NameSimilarityResponse containing the results of the request.
/// </returns>
public NameSimilarityResponse NameSimilarity(Name n1, Name n2)
{
_uri = "name-similarity";
Dictionary<object, object> dict = new Dictionary<object, object>(){
{ "name1", n1},
{ "name2", n2}
};
return GetResponse<NameSimilarityResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>MatchedName
/// <para>
/// (POST)MatchedName Endpoint: Returns the result of matching 2 names.
/// </para>
/// </summary>
/// <param name="n1">Name: First name to be matched</param>
/// <param name="n2">Name: Second name to be matched</param>
/// <returns>NameSimilarityResponse containing the results of the request.
/// </returns>
[Obsolete("Use NameSimilarity")]
public NameSimilarityResponse MatchedName(Name n1, Name n2)
{
return NameSimilarity(n1, n2);
}
/// <summary>NameSimilarity
/// <para>
/// (POST)NameSimilarity Endpoint: Returns the result of matching 2 names.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>NameSimilarityResponse containing the results of the request.
/// </returns>
public NameSimilarityResponse NameSimilarity(Dictionary<object, object> dict)
{
_uri = "name-similarity";
return GetResponse<NameSimilarityResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>NameDeduplication
/// <para>
/// (POST)NameDeduplication Endpoint: Returns the result of deduplicating a list of names.
/// </para>
/// </summary>
/// <param name="names">List of Name: List of Name objects to be deduplicated</param>
/// <param name="threshold">float: Threshold to be used for cluster sizing. Can be null for default value.</param>
/// <returns>NameDeduplicationResponse containing the results of the request.
/// </returns>
public NameDeduplicationResponse NameDeduplication(List<Name> names, Nullable<float> threshold = null)
{
_uri = "name-deduplication";
Dictionary<object, object> dict = new Dictionary<object, object>(){
{ "names", names},
{ "threshold", threshold}
};
return GetResponse<NameDeduplicationResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>NameDeduplication
/// <para>
/// (POST)NameDeduplication Endpoint: Returns the result deduplicating a list of names.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>NameDeduplicationResponse containing the results of the request.
/// </returns>
public NameDeduplicationResponse NameDeduplication(Dictionary<object, object> dict)
{
_uri = "name-deduplication";
return GetResponse<NameDeduplicationResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Transliteration
/// <para>
/// (POST)Transliteration Endpoint: Returns the result of transliterating a name.
/// </para>
/// </summary>
/// <param name="content">string: content to be transliterated</param>
/// <param name="language">string: optional ISO language code</param>
/// <returns>TransliterationResponse containing the results of the request.
/// </returns>
public TransliterationResponse Transliteration(string content, string language = null)
{
_uri = "transliteration";
Dictionary<object, object> dict = new Dictionary<object, object>(){
{ "content", content },
{ "language", language }
}.Where(f => f.Value != null).ToDictionary(x => x.Key, x => x.Value);
return GetResponse<TransliterationResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Transliteration
/// <para>
/// (POST)Transliteration Endpoint: Returns the result of transliterating a name.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>TransliterationResponse containing the results of the request.
/// </returns>
public TransliterationResponse Transliteration(Dictionary<object, object> dict)
{
_uri = "transliteration";
return GetResponse<TransliterationResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Ping
/// (GET)Ping Endpoint: Pings Analytics API for a response indicting that the service is available
/// </summary>
/// <returns>PingResponse containing the results of the info GET.
/// The reponse contains a message and time.
/// </returns>
/// <summary>Ping
/// (GET)Ping Endpoint: Pings Analytics API for a response indicting that the service is available
/// </summary>
/// <returns>PingResponse containing the results of the info GET.
/// The reponse contains a message and time.
/// </returns>
public PingResponse Ping()
{
_uri = "ping";
return GetResponse<PingResponse>();
}
/// <summary>TextEmbeddings
/// <para>
/// (POST)TextEmbeddings Endpoint: Returns an averaged text vector of the input text.
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): not used at time</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>
/// A TextEmbeddingResponse:
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
/// The text embedding represents the relationships between words in your document in the semantic space.
/// The semantic space is a multilingual network that maps the input based on the words and their context.
/// Words with similar meanings have similar contexts, and Analytics maps them close to each other
/// </returns>
public TextEmbeddingResponse TextEmbedding(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
{
_uri = "text-embedding";
return Process<TextEmbeddingResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>TextEmbeddings
/// <para>
/// (POST)TextEmbeddings Endpoint: Returns an averaged text vector of the input text.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>
/// A TextEmbeddingResponse:
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
/// The text embedding represents the relationships between words in your document in the semantic space.
/// The semantic space is a multilingual network that maps the input based on the words and their context.
/// Words with similar meanings have similar contexts, and Analytics maps them close to each other
/// </returns>
public TextEmbeddingResponse TextEmbedding(Dictionary<object, object> dict)
{
_uri = "text-embedding";
return GetResponse<TextEmbeddingResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>TextEmbeddings
/// <para>
/// (POST)TextEmbeddings Endpoint: Returns an averaged text vector of the input text.
/// </para>
/// </summary>
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
/// <returns>
/// A TextEmbeddingResponse:
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
/// The text embedding represents the relationships between words in your document in the semantic space.
/// The semantic space is a multilingual network that maps the input based on the words and their context.
/// Words with similar meanings have similar contexts, and Analytics maps them close to each other
/// </returns>
public TextEmbeddingResponse TextEmbedding(RosetteFile file)
{
_uri = "text-embedding";
return Process<TextEmbeddingResponse>(file);
}
/// <summary>SemanticVectors
/// <para>
/// (POST)SemanticVectors Endpoint: Returns an averaged text vector of the input text.
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): not used at time</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>
/// A SemanticVectorsResponse:
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
/// The text embedding represents the relationships between words in your document in the semantic space.
/// The semantic space is a multilingual network that maps the input based on the words and their context.
/// Words with similar meanings have similar contexts, and Analytics maps them close to each other
/// </returns>
public SemanticVectorsResponse SemanticVectors(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
{
_uri = "semantics/vector";
return Process<SemanticVectorsResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>SemanticVectors
/// <para>
/// (POST)SemanticVectors Endpoint: Returns an averaged text vector of the input text.
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>
/// A SemanticVectorsResponse:
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
/// The text embedding represents the relationships between words in your document in the semantic space.
/// The semantic space is a multilingual network that maps the input based on the words and their context.
/// Words with similar meanings have similar contexts, and Analytics maps them close to each other
/// </returns>
public SemanticVectorsResponse SemanticVectors(Dictionary<object, object> dict)
{
_uri = "semantics/vector";
return GetResponse<SemanticVectorsResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>SemanticVectors
/// <para>
/// (POST)SemanticVectors Endpoint: Returns an averaged text vector of the input text.
/// </para>
/// </summary>
/// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
/// <returns>
/// A SemanticVectorsResponse:
/// Contains a single vector of floating point numbers for your input, known as a text embedding.
/// Among other uses, a text embedding enables you to calculate the similarity between two documents or two words.
/// The text embedding represents the relationships between words in your document in the semantic space.
/// The semantic space is a multilingual network that maps the input based on the words and their context.
/// Words with similar meanings have similar contexts, and Analytics maps them close to each other
/// </returns>
public SemanticVectorsResponse SemanticVectors(RosetteFile file)
{
_uri = "semantics/vector";
return Process<SemanticVectorsResponse>(file);
}
/// <summary>Similar terms
/// <para>
/// (POST)Similar Terms Endpoint: Returns the terms similar to an input term
/// </para>
/// </summary>
/// <param name="content">(string, optional): Input to process (JSON string or base64 encoding of non-JSON string)</param>
/// <param name="language">(string, optional): Language: ISO 639-3 code (ignored for the /language endpoint)</param>
/// <param name="contentType">(string, optional): not used at time</param>
/// <param name="contentUri">(string, optional): URI to accessible content (content and contentUri are mutually exclusive)</param>
/// <param name="genre">(string, optional): genre to categorize the input data</param>
/// <returns>SimilarTermsResponse containing the results of the request.
/// The response contains a mapping of language to similar terms.
/// </returns>
public SimilarTermsResponse SimilarTerms(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null)
{
_uri = "semantics/similar";
return Process<SimilarTermsResponse>(content, language, contentType, contentUri, genre);
}
/// <summary>Similar terms
/// <para>
/// (POST)Similar Terms Endpoint: Returns the terms similar to an input term
/// </para>
/// </summary>
/// <param name="dict">Dictionary<object, object>: Dictionary containing parameters as (key,value) pairs</param>
/// <returns>SimilarTermsResponse containing the results of the request.
/// The response contains a mapping of language to similar terms.
/// </returns>
public SimilarTermsResponse SimilarTerms(Dictionary<object, object> dict)
{
_uri = "semantics/similar";
return GetResponse<SimilarTermsResponse>(JsonConvert.SerializeObject(AppendOptions(dict)));
}
/// <summary>Similar terms