diff --git a/.nuget/packages.config b/.nuget/packages.config deleted file mode 100644 index 7b21e2f6..00000000 --- a/.nuget/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/rosette_api.sln b/rosette_api.sln deleted file mode 100644 index 5a508d5a..00000000 --- a/rosette_api.sln +++ /dev/null @@ -1,35 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rosette_api", "rosette_api\rosette_api.csproj", "{D719A8A7-C5C7-49CF-BFFC-523D605E5E37}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rosette_apiUnitTests", "rosette_apiUnitTests\rosette_apiUnitTests.csproj", "{10EAD22C-041F-4436-A391-935897309C23}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F17AACDD-48B8-43EA-BF0C-0129592B2BC9}" - ProjectSection(SolutionItems) = preProject - .nuget\packages.config = .nuget\packages.config - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F9FBE70-5FE8-4A79-96B1-E504266A3CE1}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D719A8A7-C5C7-49CF-BFFC-523D605E5E37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D719A8A7-C5C7-49CF-BFFC-523D605E5E37}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D719A8A7-C5C7-49CF-BFFC-523D605E5E37}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D719A8A7-C5C7-49CF-BFFC-523D605E5E37}.Release|Any CPU.Build.0 = Release|Any CPU - {10EAD22C-041F-4436-A391-935897309C23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {10EAD22C-041F-4436-A391-935897309C23}.Debug|Any CPU.Build.0 = Debug|Any CPU - {10EAD22C-041F-4436-A391-935897309C23}.Release|Any CPU.ActiveCfg = Release|Any CPU - {10EAD22C-041F-4436-A391-935897309C23}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/rosette_api.slnx b/rosette_api.slnx new file mode 100644 index 00000000..a9d394bd --- /dev/null +++ b/rosette_api.slnx @@ -0,0 +1,5 @@ + + + + + diff --git a/rosette_api/Address.cs b/rosette_api/Address.cs index 66720ac0..b5105450 100644 --- a/rosette_api/Address.cs +++ b/rosette_api/Address.cs @@ -1,27 +1,27 @@ namespace rosette_api { - public class Address: IAddress + public class Address : IAddress { - public Address(string house = null, string houseNumber = null, string road = null, string unit = null, string level = null, string staircase = null, string entrance = null, string suburb = null, string cityDistrict = null, string city = null, string island = null, string stateDistrict = null, string state = null, string countryRegion = null, string country = null, string worldRegion = null, string postCode = null, string poBox = null) + public Address(string? house = null, string? houseNumber = null, string? road = null, string? unit = null, string? level = null, string? staircase = null, string? entrance = null, string? suburb = null, string? cityDistrict = null, string? city = null, string? island = null, string? stateDistrict = null, string? state = null, string? countryRegion = null, string? country = null, string? worldRegion = null, string? postCode = null, string? poBox = null) { - this.house = house; - this.houseNumber = houseNumber; - this.road = road; - this.unit = unit; - this.level = level; - this.staircase = staircase; - this.entrance = entrance; - this.suburb = suburb; - this.cityDistrict = cityDistrict; - this.city = city; - this.island = island; - this.stateDistrict = stateDistrict; - this.state = state; - this.countryRegion = countryRegion; - this.country = country; - this.worldRegion = worldRegion; - this.postCode = postCode; - this.poBox = poBox; + this.House = house; + this.HouseNumber = houseNumber; + this.Road = road; + this.Unit = unit; + this.Level = level; + this.Staircase = staircase; + this.Entrance = entrance; + this.Suburb = suburb; + this.CityDistrict = cityDistrict; + this.City = city; + this.Island = island; + this.StateDistrict = stateDistrict; + this.State = state; + this.CountryRegion = countryRegion; + this.Country = country; + this.WorldRegion = worldRegion; + this.PostCode = postCode; + this.PoBox = poBox; } /// house @@ -29,130 +29,130 @@ public Address(string house = null, string houseNumber = null, string road = nul /// Getter, Setter for the house /// /// - public string house { get; set; } + public string? House { get; set; } /// houseNumber /// /// Getter, Setter for the houseNumber /// /// - public string houseNumber { get; set; } + public string? HouseNumber { get; set; } /// road /// /// Getter, Setter for the road /// /// - public string road { get; set; } + public string? Road { get; set; } /// unit /// /// Getter, Setter for the unit /// /// - public string unit { get; set; } + public string? Unit { get; set; } /// level /// /// Getter, Setter for the level /// /// - public string level { get; set; } + public string? Level { get; set; } /// staircase /// /// Getter, Setter for the staircase /// /// - public string staircase { get; set; } + public string? Staircase { get; set; } /// entrance /// /// Getter, Setter for the entrance /// /// - public string entrance { get; set; } + public string? Entrance { get; set; } /// suburb /// /// Getter, Setter for the suburb /// /// - public string suburb { get; set; } + public string? Suburb { get; set; } /// cityDistrict /// /// Getter, Setter for the cityDistrict /// /// - public string cityDistrict { get; set; } + public string? CityDistrict { get; set; } /// city /// /// Getter, Setter for the city /// /// - public string city { get; set; } + public string? City { get; set; } /// island /// /// Getter, Setter for the island /// /// - public string island { get; set; } + public string? Island { get; set; } /// stateDistrict /// /// Getter, Setter for the stateDistrict /// /// - public string stateDistrict { get; set; } + public string? StateDistrict { get; set; } /// state /// /// Getter, Setter for the state /// /// - public string state { get; set; } + public string? State { get; set; } /// countryRegion /// /// Getter, Setter for the countryRegion /// /// - public string countryRegion { get; set; } + public string? CountryRegion { get; set; } /// country /// /// Getter, Setter for the country /// /// - public string country { get; set; } + public string? Country { get; set; } /// worldRegion /// /// Getter, Setter for the worldRegion /// /// - public string worldRegion { get; set; } + public string? WorldRegion { get; set; } /// postCode /// /// Getter, Setter for the postCode /// /// - public string postCode { get; set; } + public string? PostCode { get; set; } /// poBox /// /// Getter, Setter for the poBox /// /// - public string poBox { get; set; } + public string? PoBox { get; set; } /// is this address fielded? /// - public bool fielded() + public bool Fielded() { return true; } diff --git a/rosette_api/AddressSimilarityResponse.cs b/rosette_api/AddressSimilarityResponse.cs index 610b73fc..c69bd068 100644 --- a/rosette_api/AddressSimilarityResponse.cs +++ b/rosette_api/AddressSimilarityResponse.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using System.Net.Http; +using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/CAPI.cs b/rosette_api/CAPI.cs index 51ee81ff..1e1602d7 100644 --- a/rosette_api/CAPI.cs +++ b/rosette_api/CAPI.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.IO; +using System.Collections.Specialized; using System.IO.Compression; -using System.Linq; using System.Net; -using System.Net.Http; -using System.Threading.Tasks; using System.Text; using Newtonsoft.Json; @@ -49,13 +43,13 @@ public class CAPI /// setupLock is used to ensure that the setup operation cannot be run /// by multiple processes /// - private Object setupLock = new Object(); + private readonly Lock setupLock = new(); /// /// Internal string to hold the uri ending for each endpoint. /// Set when an endpoint is called. /// - private string _uri = null; + private string? _uri = null; /// /// Internal container for options @@ -75,12 +69,12 @@ public class CAPI /// /// Http client to be used for life of API object /// - private HttpClient _httpClient = null; + private HttpClient? _httpClient = null; /// /// Reference to external http client, if provided /// - private HttpClient _externalHttpClient = null; + private HttpClient? _externalHttpClient = null; /// /// Current timeout value for the http client in milliseconds @@ -109,7 +103,7 @@ public class CAPI /// (string, optional): Base URL for the HttpClient requests. If none is given, will use the default API URI /// (int, optional): Maximum number of times to retry a request on HttpResponse error. Default is 3 times. /// (HttpClient, optional): Forces the API to use a custom HttpClient. - public CAPI(string user_key, string uristring = "https://analytics.babelstreet.com/rest/v1/", int maxRetry = 5, HttpClient client = null) + 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/"; @@ -120,9 +114,9 @@ public CAPI(string user_key, string uristring = "https://analytics.babelstreet.c MaxRetry = (maxRetry == 0) ? 1 : maxRetry; MillisecondsBetweenRetries = 5000; _externalHttpClient = client; - _options = new Dictionary(); - _customHeaders = new Dictionary(); - _urlParameters = new NameValueCollection(); + _options = []; + _customHeaders = []; + _urlParameters = []; SetupClient(); } @@ -149,21 +143,14 @@ public CAPI(string user_key, string uristring = "https://analytics.babelstreet.c /// Version: Internal Server Version number. /// /// - public static string Version - { - get { return typeof(CAPI).Assembly.GetName().Version.ToString(); } - } + public static string Version => typeof(CAPI).Assembly.GetName().Version.ToString(); + /// /// UserAgent returns the string that will be used for User-Agent /// /// string User-Agent - public string UserAgent - { - get - { - return string.Format("Babel-Street-Analytics-API-Csharp/{0}/{1}", Version, Environment.Version.ToString()); - } - } + public static string UserAgent => string.Format("Babel-Street-Analytics-API-Csharp/{0}/{1}", Version, Environment.Version.ToString()); + /// MaxRetry /// /// Getter, Setter for the MaxRetry @@ -186,10 +173,7 @@ public string UserAgent /// 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. /// - public HttpClient Client - { - get { return _externalHttpClient ?? _httpClient; } - } + public HttpClient Client => _externalHttpClient ?? _httpClient; /// Concurrency /// Returns the number of concurrent connections allowed by the current Analytics API plan. @@ -282,7 +266,7 @@ public void SetOption(string name, object value) /// /// string option name /// object value if exists - public object GetOption(string name) + public object? GetOption(string name) { if (_options.ContainsKey(name)) { @@ -398,7 +382,7 @@ public AddressSimilarityResponse AddressSimilarity(IAddress a1, IAddress a2) { _uri = "address-similarity"; - Dictionary dict = new Dictionary(){ + Dictionary dict = new(){ { "address1", a1}, { "address2", a2} }; @@ -435,7 +419,7 @@ public AddressSimilarityResponse AddressSimilarity(Dictionary di /// CategoriesResponse containing the results of the request. /// The response is the contextual categories identified in the input. /// - public CategoriesResponse Categories(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public CategoriesResponse Categories(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "categories"; return Process(content, language, contentType, contentUri, genre); @@ -483,7 +467,7 @@ public CategoriesResponse Categories(RosetteFile file) /// (string, optional): genre to categorize the input data /// EntitiesResponse containing the results of the request. /// - public EntitiesResponse Entity(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public EntitiesResponse Entity(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "entities"; return Process(content, language, contentType, contentUri, genre); @@ -529,7 +513,7 @@ public EntitiesResponse Entity(RosetteFile file) /// (string, optional): genre to categorize the input data /// EventsResponse containing the results of the request. /// - public EventsResponse Event(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public EventsResponse Event(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "events"; return Process(content, language, contentType, contentUri, genre); @@ -588,7 +572,7 @@ public InfoResponse Info() /// LanguageIdentificationResponse containing the results of the request. /// The response is an ordered list of detected languages. /// - public LanguageIdentificationResponse Language(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public LanguageIdentificationResponse Language(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "language"; return Process(content, language, contentType, contentUri, genre); @@ -639,7 +623,7 @@ public LanguageIdentificationResponse Language(RosetteFile file) /// The response may include lemmas, part of speech tags, compound word components, and Han readings. /// Support for specific return types depends on language. /// - public MorphologyResponse Morphology(string content = null, string language = null, string contentType = null, string contentUri = null, MorphologyFeature feature = MorphologyFeature.complete, string genre = null) + 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(content, language, contentType, contentUri, genre); @@ -707,7 +691,7 @@ public NameSimilarityResponse NameSimilarity(Name n1, Name n2) { _uri = "name-similarity"; - Dictionary dict = new Dictionary(){ + Dictionary dict = new(){ { "name1", n1}, { "name2", n2} }; @@ -757,7 +741,7 @@ public NameDeduplicationResponse NameDeduplication(List names, Nullable dict = new Dictionary(){ + Dictionary dict = new(){ { "names", names}, { "threshold", threshold} }; @@ -789,7 +773,7 @@ public NameDeduplicationResponse NameDeduplication(Dictionary di /// TransliterationResponse containing the results of the request. /// - public TransliterationResponse Transliteration(string content, string language = null) + public TransliterationResponse Transliteration(string content, string? language = null) { _uri = "transliteration"; @@ -853,7 +837,7 @@ public PingResponse Ping() /// 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 /// - public TextEmbeddingResponse TextEmbedding(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public TextEmbeddingResponse TextEmbedding(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "text-embedding"; return Process(content, language, contentType, contentUri, genre); @@ -917,7 +901,7 @@ public TextEmbeddingResponse TextEmbedding(RosetteFile file) /// 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 /// - public SemanticVectorsResponse SemanticVectors(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public SemanticVectorsResponse SemanticVectors(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "semantics/vector"; return Process(content, language, contentType, contentUri, genre); @@ -976,7 +960,7 @@ public SemanticVectorsResponse SemanticVectors(RosetteFile file) /// SimilarTermsResponse containing the results of the request. /// The response contains a mapping of language to similar terms. /// - public SimilarTermsResponse SimilarTerms(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public SimilarTermsResponse SimilarTerms(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "semantics/similar"; return Process(content, language, contentType, contentUri, genre); @@ -1026,7 +1010,7 @@ public SimilarTermsResponse SimilarTerms(RosetteFile file) /// A SyntaxDependenciesResponse: /// The parsed text is represented in terms of syntactic dependencies /// - public SyntaxDependenciesResponse SyntaxDependencies(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public SyntaxDependenciesResponse SyntaxDependencies(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "syntax/dependencies"; return Process(content, language, contentType, contentUri, genre); @@ -1085,7 +1069,7 @@ public SyntaxDependenciesResponse SyntaxDependencies(RosetteFile file) /// locatives [optional] - usually express the locations the action expressed by the relationship took place /// temporals [optional] - usually express the time in which the action expressed by the relationship took place /// - public RelationshipsResponse Relationships(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public RelationshipsResponse Relationships(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "relationships"; return Process(content, language, contentType, contentUri, genre); @@ -1150,7 +1134,7 @@ public RelationshipsResponse Relationships(RosetteFile file) /// SentenceTaggingResponse containing the results of the request /// The response contains a list of sentences. /// - public SentenceTaggingResponse Sentences(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public SentenceTaggingResponse Sentences(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "sentences"; return Process(content, language, contentType, contentUri, genre); @@ -1199,7 +1183,7 @@ public SentenceTaggingResponse Sentences(RosetteFile file) /// SentimentResponse containing the results of the request. /// The response contains sentiment analysis results. /// - public SentimentResponse Sentiment(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public SentimentResponse Sentiment(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "sentiment"; return Process(content, language, contentType, contentUri, genre); @@ -1248,7 +1232,7 @@ public SentimentResponse Sentiment(RosetteFile file) /// TokenizationResponse containing the results of the request. /// The response contains a list of tokens. /// - public TokenizationResponse Tokens(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public TokenizationResponse Tokens(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "tokens"; return Process(content, language, contentType, contentUri, genre); @@ -1297,7 +1281,7 @@ public TokenizationResponse Tokens(RosetteFile file) /// TopicsResponse containing the results of the request. /// The response contains a list of concepts and key phrases. /// - public TopicsResponse Topics(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) + public TopicsResponse Topics(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) { _uri = "topics"; return Process(content, language, contentType, contentUri, genre); @@ -1349,7 +1333,7 @@ public TopicsResponse Topics(RosetteFile file) /// (string, optional): genre to categorize the input data /// TranslateNamesResponse containing the results of the request. /// - public TranslateNamesResponse NameTranslation(string name, string sourceLanguageOfUse = null, string sourceScript = null, string targetLanguage = null, string targetScript = null, string targetScheme = null, string sourceLanguageOfOrigin = null, string entityType = null, string genre = null) + public TranslateNamesResponse NameTranslation(string name, string? sourceLanguageOfUse = null, string? sourceScript = null, string? targetLanguage = null, string? targetScript = null, string? targetScheme = null, string? sourceLanguageOfOrigin = null, string? entityType = null, string? genre = null) { _uri = "name-translation"; @@ -1388,7 +1372,7 @@ public TranslateNamesResponse NameTranslation(Dictionary dict) /// query string private string ToQueryString(NameValueCollection urlParameters) { - StringBuilder sb = new StringBuilder("?"); + StringBuilder sb = new("?"); bool first = true; foreach (string key in urlParameters.AllKeys) @@ -1415,9 +1399,9 @@ private string ToQueryString(NameValueCollection urlParameters) /// (string, optional): Content to use as the request to the server with POST. If none given, assume an Info endpoint and use GET /// (MultipartFormDataContent, optional): Used for file uploads /// RosetteResponse derivative - private T GetResponse(string jsonRequest = null, MultipartFormDataContent multiPart = null) where T : RosetteResponse + private T GetResponse(string? jsonRequest = null, MultipartFormDataContent? multiPart = null) where T : RosetteResponse { - HttpResponseMessage responseMsg = null; + HttpResponseMessage? responseMsg = null; string wholeURI = _uri; if (wholeURI.StartsWith("/")) { @@ -1508,7 +1492,7 @@ private T Process(RosetteFile file) where T : RosetteResponse /// (string, optional): URI to accessible content (content and contentUri are mutually exclusive) /// (string, optional): genre to categorize the input data /// RosetteResponse derivative containing the results of the response from the server from the getResponse call. - private T Process(string content = null, string language = null, string contentType = null, string contentUri = null, string genre = null) where T : RosetteResponse + private T Process(string? content = null, string? language = null, string? contentType = null, string? contentUri = null, string? genre = null) where T : RosetteResponse { if (content == null) { @@ -1627,11 +1611,11 @@ private static byte[] Decompress(byte[] gzip) { // Create a GZIP stream with decompression mode. // ... Then create a buffer and write into while reading from the GZIP stream. - using (GZipStream stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress)) + using (GZipStream stream = new(new MemoryStream(gzip), CompressionMode.Decompress)) { const int size = 4096; byte[] buffer = new byte[size]; - using (MemoryStream memory = new MemoryStream()) + using (MemoryStream memory = new()) { int count = 0; do diff --git a/rosette_api/CategoriesResponse.cs b/rosette_api/CategoriesResponse.cs index 4cdbfdc3..72d3c505 100644 --- a/rosette_api/CategoriesResponse.cs +++ b/rosette_api/CategoriesResponse.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using System.Collections; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; namespace rosette_api diff --git a/rosette_api/Concept.cs b/rosette_api/Concept.cs index 824be4fb..36dcf9fd 100644 --- a/rosette_api/Concept.cs +++ b/rosette_api/Concept.cs @@ -1,5 +1,4 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace rosette_api { /// diff --git a/rosette_api/EntitiesResponse.cs b/rosette_api/EntitiesResponse.cs index 4724e728..a0fac725 100644 --- a/rosette_api/EntitiesResponse.cs +++ b/rosette_api/EntitiesResponse.cs @@ -1,13 +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.Linq; using Newtonsoft.Json; -using System.Net.Http; -using System.Collections; -using System.Runtime.Serialization; namespace rosette_api { diff --git a/rosette_api/EntityID.cs b/rosette_api/EntityID.cs index 37d1cce2..e79f7f5a 100644 --- a/rosette_api/EntityID.cs +++ b/rosette_api/EntityID.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using System.IO; +using System.Text; using Newtonsoft.Json; namespace rosette_api diff --git a/rosette_api/EventMention.cs b/rosette_api/EventMention.cs index b81df724..b5625b9e 100644 --- a/rosette_api/EventMention.cs +++ b/rosette_api/EventMention.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using System.Linq; +using Newtonsoft.Json; namespace rosette_api { /// diff --git a/rosette_api/EventsResponse.cs b/rosette_api/EventsResponse.cs index e357191a..704121f3 100644 --- a/rosette_api/EventsResponse.cs +++ b/rosette_api/EventsResponse.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace rosette_api diff --git a/rosette_api/FieldedAddress.cs b/rosette_api/FieldedAddress.cs index 14fc8c48..b986445f 100644 --- a/rosette_api/FieldedAddress.cs +++ b/rosette_api/FieldedAddress.cs @@ -1,28 +1,28 @@ namespace rosette_api { - public class FieldedAddress: IAddress + public class FieldedAddress : IAddress { - public FieldedAddress(string house = null, string houseNumber = null, string road = null, string unit = null, string level = null, string staircase = null, string entrance = null, string suburb = null, string cityDistrict = null, string city = null, string island = null, string stateDistrict = null, string state = null, string countryRegion = null, string country = null, string worldRegion = null, string postCode = null, string poBox = null) + public FieldedAddress(string? house = null, string? houseNumber = null, string? road = null, string? unit = null, string? level = null, string? staircase = null, string? entrance = null, string? suburb = null, string? cityDistrict = null, string? city = null, string? island = null, string? stateDistrict = null, string? state = null, string? countryRegion = null, string? country = null, string? worldRegion = null, string? postCode = null, string? poBox = null) { - this.house = house; - this.houseNumber = houseNumber; - this.road = road; - this.unit = unit; - this.level = level; - this.staircase = staircase; - this.entrance = entrance; - this.suburb = suburb; - this.cityDistrict = cityDistrict; - this.city = city; - this.island = island; - this.stateDistrict = stateDistrict; - this.state = state; - this.countryRegion = countryRegion; - this.country = country; - this.worldRegion = worldRegion; - this.postCode = postCode; - this.poBox = poBox; + this.House = house; + this.HouseNumber = houseNumber; + this.Road = road; + this.Unit = unit; + this.Level = level; + this.Staircase = staircase; + this.Entrance = entrance; + this.Suburb = suburb; + this.CityDistrict = cityDistrict; + this.City = city; + this.Island = island; + this.StateDistrict = stateDistrict; + this.State = state; + this.CountryRegion = countryRegion; + this.Country = country; + this.WorldRegion = worldRegion; + this.PostCode = postCode; + this.PoBox = poBox; } /// house @@ -30,130 +30,130 @@ public FieldedAddress(string house = null, string houseNumber = null, string roa /// Getter, Setter for the house /// /// - public string house { get; set; } + public string? House { get; set; } /// houseNumber /// /// Getter, Setter for the houseNumber /// /// - public string houseNumber { get; set; } + public string? HouseNumber { get; set; } /// road /// /// Getter, Setter for the road /// /// - public string road { get; set; } + public string? Road { get; set; } /// unit /// /// Getter, Setter for the unit /// /// - public string unit { get; set; } + public string? Unit { get; set; } /// level /// /// Getter, Setter for the level /// /// - public string level { get; set; } + public string? Level { get; set; } /// staircase /// /// Getter, Setter for the staircase /// /// - public string staircase { get; set; } + public string? Staircase { get; set; } /// entrance /// /// Getter, Setter for the entrance /// /// - public string entrance { get; set; } + public string? Entrance { get; set; } /// suburb /// /// Getter, Setter for the suburb /// /// - public string suburb { get; set; } + public string? Suburb { get; set; } /// cityDistrict /// /// Getter, Setter for the cityDistrict /// /// - public string cityDistrict { get; set; } + public string? CityDistrict { get; set; } /// city /// /// Getter, Setter for the city /// /// - public string city { get; set; } + public string? City { get; set; } /// island /// /// Getter, Setter for the island /// /// - public string island { get; set; } + public string? Island { get; set; } /// stateDistrict /// /// Getter, Setter for the stateDistrict /// /// - public string stateDistrict { get; set; } + public string? StateDistrict { get; set; } /// state /// /// Getter, Setter for the state /// /// - public string state { get; set; } + public string? State { get; set; } /// countryRegion /// /// Getter, Setter for the countryRegion /// /// - public string countryRegion { get; set; } + public string? CountryRegion { get; set; } /// country /// /// Getter, Setter for the country /// /// - public string country { get; set; } + public string? Country { get; set; } /// worldRegion /// /// Getter, Setter for the worldRegion /// /// - public string worldRegion { get; set; } + public string? WorldRegion { get; set; } /// postCode /// /// Getter, Setter for the postCode /// /// - public string postCode { get; set; } + public string? PostCode { get; set; } /// poBox /// /// Getter, Setter for the poBox /// /// - public string poBox { get; set; } + public string? PoBox { get; set; } /// is this address fielded? /// - public bool fielded() + public bool Fielded() { return true; } diff --git a/rosette_api/IAddress.cs b/rosette_api/IAddress.cs index b2babef1..f7fef310 100644 --- a/rosette_api/IAddress.cs +++ b/rosette_api/IAddress.cs @@ -2,6 +2,6 @@ namespace rosette_api { public interface IAddress { - bool fielded(); + bool Fielded(); } } \ No newline at end of file diff --git a/rosette_api/IEnumerableExpanderContractResolver.cs b/rosette_api/IEnumerableExpanderContractResolver.cs deleted file mode 100644 index adc40489..00000000 --- a/rosette_api/IEnumerableExpanderContractResolver.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using Newtonsoft.Json.Linq; -using System.Reflection; - -namespace rosette_api -{ - internal class IEnumerableExpanderContractResolver : IContractResolver - { - public new static readonly ConditionalContractResolver Instance = new ConditionalContractResolver(); - - protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) - { - IList property = base.CreateProperties(typeof(T), memberSerialization); - return property; - } - - public JsonContract ResolveContract(Type type) - { - return new JsonArrayContract(type).ItemConverter.; - } - } -} diff --git a/rosette_api/InfoResponse.cs b/rosette_api/InfoResponse.cs index 7d4b4ca6..f073bee4 100644 --- a/rosette_api/InfoResponse.cs +++ b/rosette_api/InfoResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/KeyPhrase.cs b/rosette_api/KeyPhrase.cs index 4a49cbc6..0d7c40e2 100644 --- a/rosette_api/KeyPhrase.cs +++ b/rosette_api/KeyPhrase.cs @@ -1,5 +1,4 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace rosette_api { /// diff --git a/rosette_api/LanguageIdentificationResponse.cs b/rosette_api/LanguageIdentificationResponse.cs index b4c62829..42d23310 100644 --- a/rosette_api/LanguageIdentificationResponse.cs +++ b/rosette_api/LanguageIdentificationResponse.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using System.Collections; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace rosette_api diff --git a/rosette_api/MentionOffset.cs b/rosette_api/MentionOffset.cs index 3cec1d87..1a52fea8 100644 --- a/rosette_api/MentionOffset.cs +++ b/rosette_api/MentionOffset.cs @@ -1,4 +1,3 @@ -using System; using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/MorphologyResponse.cs b/rosette_api/MorphologyResponse.cs index 338a3b93..cd95ef89 100644 --- a/rosette_api/MorphologyResponse.cs +++ b/rosette_api/MorphologyResponse.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; -using System.Collections; namespace rosette_api { diff --git a/rosette_api/Name.cs b/rosette_api/Name.cs index 7515f409..f27f34a4 100644 --- a/rosette_api/Name.cs +++ b/rosette_api/Name.cs @@ -1,6 +1,4 @@ -using System; - -namespace rosette_api { +namespace rosette_api { /// Name Class /// /// Name: Custom Datatype to use in Matched Name endpoint diff --git a/rosette_api/NameDeduplicationResponse.cs b/rosette_api/NameDeduplicationResponse.cs index 334e4682..c21fbb5c 100644 --- a/rosette_api/NameDeduplicationResponse.cs +++ b/rosette_api/NameDeduplicationResponse.cs @@ -1,8 +1,5 @@ -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; namespace rosette_api { /// diff --git a/rosette_api/NameSimilarityResponse.cs b/rosette_api/NameSimilarityResponse.cs index 4728309b..0f85555d 100644 --- a/rosette_api/NameSimilarityResponse.cs +++ b/rosette_api/NameSimilarityResponse.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using System.Net.Http; +using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/PingResponse.cs b/rosette_api/PingResponse.cs index 0473f4f9..9c9c236b 100644 --- a/rosette_api/PingResponse.cs +++ b/rosette_api/PingResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/Properties/AssemblyInfo.cs b/rosette_api/Properties/AssemblyInfo.cs deleted file mode 100644 index cd21d71f..00000000 --- a/rosette_api/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Babel Street Analytics API C# Binding")] -[assembly: AssemblyDescription("Provides a C# interface to the Babel Street Analytics API web service")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Babel Street")] -[assembly: AssemblyProduct("CSharp Binding")] -[assembly: AssemblyCopyright("Copyright © Basis Technology 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("620cf3eb-35fa-4c7a-a659-676b9e4a1b51")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.36.0.0")] -[assembly: AssemblyVersion("1.36.0.0")] -[assembly: AssemblyFileVersion("1.36.0.0")] diff --git a/rosette_api/Properties/Resources.Designer.cs b/rosette_api/Properties/Resources.Designer.cs deleted file mode 100644 index c09ad37f..00000000 --- a/rosette_api/Properties/Resources.Designer.cs +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace rosette_api.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("rosette_api.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - } -} diff --git a/rosette_api/Properties/Resources.resx b/rosette_api/Properties/Resources.resx deleted file mode 100644 index af7dbebb..00000000 --- a/rosette_api/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/rosette_api/Properties/Settings.Designer.cs b/rosette_api/Properties/Settings.Designer.cs deleted file mode 100644 index 943d70e6..00000000 --- a/rosette_api/Properties/Settings.Designer.cs +++ /dev/null @@ -1,26 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace rosette_api.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } -} diff --git a/rosette_api/Properties/Settings.settings b/rosette_api/Properties/Settings.settings deleted file mode 100644 index 39645652..00000000 --- a/rosette_api/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/rosette_api/RecordSimilarityConverter.cs b/rosette_api/RecordSimilarityConverter.cs index 53d11fbf..c2e0e486 100644 --- a/rosette_api/RecordSimilarityConverter.cs +++ b/rosette_api/RecordSimilarityConverter.cs @@ -1,4 +1,3 @@ -using System; using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/RecordSimilarityField.cs b/rosette_api/RecordSimilarityField.cs index 7cd50d14..4e185a57 100644 --- a/rosette_api/RecordSimilarityField.cs +++ b/rosette_api/RecordSimilarityField.cs @@ -1,7 +1,5 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Collections.Generic; -using System.Linq; namespace rosette_api { /// diff --git a/rosette_api/RecordSimilarityFieldInfo.cs b/rosette_api/RecordSimilarityFieldInfo.cs index 1f6946f1..5631f870 100644 --- a/rosette_api/RecordSimilarityFieldInfo.cs +++ b/rosette_api/RecordSimilarityFieldInfo.cs @@ -1,7 +1,4 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using System.Collections.Generic; -using System.Linq; namespace rosette_api { /// RecordFieldType diff --git a/rosette_api/RecordSimilarityRequest.cs b/rosette_api/RecordSimilarityRequest.cs index cea087cb..1e78b9cf 100644 --- a/rosette_api/RecordSimilarityRequest.cs +++ b/rosette_api/RecordSimilarityRequest.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using Newtonsoft.Json; diff --git a/rosette_api/RecordSimilarityResponse.cs b/rosette_api/RecordSimilarityResponse.cs index 6a1d9cf9..541c088a 100644 --- a/rosette_api/RecordSimilarityResponse.cs +++ b/rosette_api/RecordSimilarityResponse.cs @@ -1,9 +1,5 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; namespace rosette_api { diff --git a/rosette_api/RelationshipsResponse.cs b/rosette_api/RelationshipsResponse.cs index d1bf09bf..9326bdab 100644 --- a/rosette_api/RelationshipsResponse.cs +++ b/rosette_api/RelationshipsResponse.cs @@ -1,14 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; -using System.Collections; using Newtonsoft.Json.Serialization; -using Newtonsoft.Json.Converters; using System.Text.RegularExpressions; namespace rosette_api diff --git a/rosette_api/ResponseHeaders.cs b/rosette_api/ResponseHeaders.cs index 2ea123f9..dc59cf11 100644 --- a/rosette_api/ResponseHeaders.cs +++ b/rosette_api/ResponseHeaders.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http.Headers; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using Newtonsoft.Json; using Newtonsoft.Json.Serialization; namespace rosette_api diff --git a/rosette_api/RosetteEntity.cs b/rosette_api/RosetteEntity.cs index b1f5701a..6d6fa863 100644 --- a/rosette_api/RosetteEntity.cs +++ b/rosette_api/RosetteEntity.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/RosetteEvent.cs b/rosette_api/RosetteEvent.cs index 2bea4509..bae1090b 100644 --- a/rosette_api/RosetteEvent.cs +++ b/rosette_api/RosetteEvent.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; -using static System.Collections.Specialized.BitVector32; +using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/RosetteException.cs b/rosette_api/RosetteException.cs index 4f57cab3..f5815608 100644 --- a/rosette_api/RosetteException.cs +++ b/rosette_api/RosetteException.cs @@ -1,6 +1,4 @@ -using System; - -namespace rosette_api { +namespace rosette_api { /// RosetteException Class /// /// RosetteException: Custom exception to describe an exception from the Analytics API. diff --git a/rosette_api/RosetteExtensions.cs b/rosette_api/RosetteExtensions.cs index 5a51749a..c5474053 100644 --- a/rosette_api/RosetteExtensions.cs +++ b/rosette_api/RosetteExtensions.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; +using System.Text.RegularExpressions; namespace rosette_api { /// diff --git a/rosette_api/RosetteFile.cs b/rosette_api/RosetteFile.cs index f8f1a799..d6e7b177 100644 --- a/rosette_api/RosetteFile.cs +++ b/rosette_api/RosetteFile.cs @@ -1,8 +1,4 @@ -using System; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Text; +using System.Text; namespace rosette_api { /// RosetteFile Class diff --git a/rosette_api/RosetteResponse.cs b/rosette_api/RosetteResponse.cs index 4e3b1fbb..35d33262 100755 --- a/rosette_api/RosetteResponse.cs +++ b/rosette_api/RosetteResponse.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net.Http; +using System.IO.Compression; using System.Text; -using System.Threading.Tasks; using Newtonsoft.Json; namespace rosette_api { diff --git a/rosette_api/RosetteResponseContractResolver.cs b/rosette_api/RosetteResponseContractResolver.cs index 5fca1eed..13ae11e5 100755 --- a/rosette_api/RosetteResponseContractResolver.cs +++ b/rosette_api/RosetteResponseContractResolver.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json.Serialization; +using Newtonsoft.Json.Serialization; using Newtonsoft.Json; -using System.Threading.Tasks; namespace rosette_api { diff --git a/rosette_api/SemanticVectorsResponse.cs b/rosette_api/SemanticVectorsResponse.cs index b0c1cd41..75c7904c 100644 --- a/rosette_api/SemanticVectorsResponse.cs +++ b/rosette_api/SemanticVectorsResponse.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using System.Collections; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.IO; namespace rosette_api { diff --git a/rosette_api/SentenceTaggingResponse.cs b/rosette_api/SentenceTaggingResponse.cs index a3f956fb..43463cb2 100644 --- a/rosette_api/SentenceTaggingResponse.cs +++ b/rosette_api/SentenceTaggingResponse.cs @@ -1,12 +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.Linq; using Newtonsoft.Json; -using System.Net.Http; -using System.Collections; namespace rosette_api { diff --git a/rosette_api/SentimentResponse.cs b/rosette_api/SentimentResponse.cs index 78379d23..8f310531 100644 --- a/rosette_api/SentimentResponse.cs +++ b/rosette_api/SentimentResponse.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; -using System.Collections; using Newtonsoft.Json.Converters; namespace rosette_api diff --git a/rosette_api/SimilarTermsResponse.cs b/rosette_api/SimilarTermsResponse.cs index 223bc350..79bc9e8d 100644 --- a/rosette_api/SimilarTermsResponse.cs +++ b/rosette_api/SimilarTermsResponse.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using System.Collections; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; namespace rosette_api diff --git a/rosette_api/StaticValueProvider.cs b/rosette_api/StaticValueProvider.cs index 0f4fbca3..7f6650a9 100644 --- a/rosette_api/StaticValueProvider.cs +++ b/rosette_api/StaticValueProvider.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json.Serialization; +using Newtonsoft.Json.Serialization; namespace rosette_api { diff --git a/rosette_api/SyntaxDependenciesResponse.cs b/rosette_api/SyntaxDependenciesResponse.cs index 03f56015..3b339c23 100644 --- a/rosette_api/SyntaxDependenciesResponse.cs +++ b/rosette_api/SyntaxDependenciesResponse.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; -using System.Collections; -using Newtonsoft.Json.Converters; namespace rosette_api { @@ -45,11 +37,11 @@ public class SyntaxDependenciesResponse : RosetteResponse public SyntaxDependenciesResponse(HttpResponseMessage apiResult) : base(apiResult) { - List sentences = new List(); + List sentences = []; JArray enumerableResults = this.ContentDictionary.ContainsKey(SENTENCES) ? this.ContentDictionary[SENTENCES] as JArray : new JArray(); foreach (JObject result in enumerableResults) { - List dependencies = new List(); + List dependencies = []; JArray depArr = result.Properties().Where((p) => p.Name == DEPENDENCIES).Any() ? result[DEPENDENCIES] as JArray : new JArray(); foreach (JObject dependency in depArr) { @@ -92,7 +84,7 @@ public override bool Equals(object obj) if (obj is SyntaxDependenciesResponse) { SyntaxDependenciesResponse other = obj as SyntaxDependenciesResponse; - List conditions = new List() { + List conditions = new() { this.Sentences != null && other.Sentences != null ? this.Sentences.SequenceEqual(other.Sentences) : this.Sentences == other.Sentences, this.Tokens != null && other.Tokens != null ? this.Tokens.SequenceEqual(other.Tokens) : this.Tokens == other.Tokens, this.ResponseHeaders != null && other.ResponseHeaders != null ? this.ResponseHeaders.Equals(other.ResponseHeaders) : this.ResponseHeaders == other.ResponseHeaders, @@ -165,7 +157,7 @@ public override bool Equals(object obj) if (obj is SentenceWithDependencies) { SentenceWithDependencies other = obj as SentenceWithDependencies; - List conditions = new List() { + List conditions = new() { this.Dependencies != null && other.Dependencies != null ? this.Dependencies.SequenceEqual(other.Dependencies) : this.Dependencies == other.Dependencies, this.StartTokenIndex.Equals(other.StartTokenIndex), this.EndTokenIndex.Equals(other.EndTokenIndex), @@ -248,7 +240,7 @@ public override bool Equals(object obj) if (obj is Dependency) { Dependency other = obj as Dependency; - List conditions = new List() { + List conditions = new() { this.DependencyType.Equals(other.DependencyType), this.GovernorTokenIndex.Equals(other.GovernorTokenIndex), this.DependentTokenIndex.Equals(other.DependentTokenIndex), diff --git a/rosette_api/TextEmbeddingResponse.cs b/rosette_api/TextEmbeddingResponse.cs index 1f1f0864..1d12852e 100644 --- a/rosette_api/TextEmbeddingResponse.cs +++ b/rosette_api/TextEmbeddingResponse.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net.Http; -using System.Collections; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.IO; namespace rosette_api { diff --git a/rosette_api/TokenizationResponse.cs b/rosette_api/TokenizationResponse.cs index 67047839..5408d771 100644 --- a/rosette_api/TokenizationResponse.cs +++ b/rosette_api/TokenizationResponse.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; namespace rosette_api { diff --git a/rosette_api/TopicsResponse.cs b/rosette_api/TopicsResponse.cs index d6900350..7d58a7a1 100644 --- a/rosette_api/TopicsResponse.cs +++ b/rosette_api/TopicsResponse.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; namespace rosette_api { /// diff --git a/rosette_api/TranslateNamesResponse.cs b/rosette_api/TranslateNamesResponse.cs index 3fc9ed6d..22beaa6e 100644 --- a/rosette_api/TranslateNamesResponse.cs +++ b/rosette_api/TranslateNamesResponse.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Net.Http; namespace rosette_api { diff --git a/rosette_api/TransliterationResponse.cs b/rosette_api/TransliterationResponse.cs index e86fb3ea..e56bc134 100644 --- a/rosette_api/TransliterationResponse.cs +++ b/rosette_api/TransliterationResponse.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using System.Net.Http; +using Newtonsoft.Json; namespace rosette_api { /// diff --git a/rosette_api/UnfieldedAddress.cs b/rosette_api/UnfieldedAddress.cs index 396ed03c..985d783d 100644 --- a/rosette_api/UnfieldedAddress.cs +++ b/rosette_api/UnfieldedAddress.cs @@ -1,11 +1,11 @@ namespace rosette_api { - public class UnfieldedAddress: IAddress + public class UnfieldedAddress : IAddress { - public UnfieldedAddress(string address = null) + public UnfieldedAddress(string? address = null) { - this.address = address; + this.Address = address; } /// address @@ -13,11 +13,11 @@ public UnfieldedAddress(string address = null) /// Getter, Setter for the address /// /// - public string address { get; set; } + public string? Address { get; set; } /// is this address fielded? /// - public bool fielded() + public bool Fielded() { return false; } diff --git a/rosette_api/Utilities.cs b/rosette_api/Utilities.cs index c8ebe815..9caebfb8 100644 --- a/rosette_api/Utilities.cs +++ b/rosette_api/Utilities.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System; - namespace rosette_api { /// /// Utilities class diff --git a/rosette_api/app.config b/rosette_api/app.config deleted file mode 100644 index 51278a45..00000000 --- a/rosette_api/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/rosette_api/packages.config b/rosette_api/packages.config deleted file mode 100755 index f91e8b48..00000000 --- a/rosette_api/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/rosette_api/rosette_api.csproj b/rosette_api/rosette_api.csproj index 38f84b34..bd5a7432 100644 --- a/rosette_api/rosette_api.csproj +++ b/rosette_api/rosette_api.csproj @@ -1,137 +1,13 @@ - - - + + - Debug - AnyCPU - {D719A8A7-C5C7-49CF-BFFC-523D605E5E37} - Library - Properties - rosette_api - rosette_api - v4.5 - 512 - - - + net10.0 + enable + enable - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - bin\Debug\rosette_api.XML - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - - - ..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - Designer - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - + - - - \ No newline at end of file + + diff --git a/rosette_api/rosette_api.nuspec b/rosette_api/rosette_api.nuspec deleted file mode 100644 index ca759654..00000000 --- a/rosette_api/rosette_api.nuspec +++ /dev/null @@ -1,28 +0,0 @@ - - - - rosette_api - 1.36.0 - .Net (C#) Binding for Babel Street Analytics API - - basistech - Rosette by Babel Street - Copyright 2014-2024 Basis Technology Corp. - - https://www.babelstreet.com/rosette - - https://github.com/rosette-api/csharp/wiki/Release-Notes - Apache-2.0 - false - address similarity analyze language babel street categories coreference entity extraction entity linking event extraction fuzzy matching language identification lemmatization match identity morphology name deduplication name similarity name translation ner nlp parts of speech record similarity relationships rosette semantic similarity semantic vectors sentiment analysis text analytics text embeddings tokenization - - - - - - - - - - - diff --git a/rosette_apiExamples/address_similarity.cs b/rosette_apiExamples/AddressSimilarity.cs similarity index 85% rename from rosette_apiExamples/address_similarity.cs rename to rosette_apiExamples/AddressSimilarity.cs index 911add43..f4f64818 100644 --- a/rosette_apiExamples/address_similarity.cs +++ b/rosette_apiExamples/AddressSimilarity.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; -using rosette_api; +using rosette_api; namespace rosette_apiExamples { - class address_similarity + class AddressSimilarity { /// /// Example code to call Analytics API to get match score (similarity) for two addresses. @@ -22,7 +16,7 @@ static void Main(string[] args) string alturl = string.Empty; //You may set the API key via command line argument: - //address_similarity yourapikeyhere + //AddressSimilarity yourapikeyhere if (args.Length != 0) { apikey = args[0]; diff --git a/rosette_apiExamples/categories.cs b/rosette_apiExamples/Categories.cs similarity index 92% rename from rosette_apiExamples/categories.cs rename to rosette_apiExamples/Categories.cs index 484a9c88..e9456a89 100644 --- a/rosette_apiExamples/categories.cs +++ b/rosette_apiExamples/Categories.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class categories + class Categories { /// /// Example code to call Analytics API to get a document's (located at given URL) categories. diff --git a/rosette_apiExamples/concurrencyTest.cs b/rosette_apiExamples/ConcurrencyTest.cs similarity index 96% rename from rosette_apiExamples/concurrencyTest.cs rename to rosette_apiExamples/ConcurrencyTest.cs index 172ae197..cbc3cf3f 100644 --- a/rosette_apiExamples/concurrencyTest.cs +++ b/rosette_apiExamples/ConcurrencyTest.cs @@ -1,7 +1,3 @@ -using System; -using System.Threading.Tasks; -using System.Collections.Generic; -using System.Linq; using rosette_api; namespace rosette_apiExamples diff --git a/rosette_apiExamples/entities.cs b/rosette_apiExamples/Entities.cs similarity index 93% rename from rosette_apiExamples/entities.cs rename to rosette_apiExamples/Entities.cs index 3d09afda..6bfd5292 100644 --- a/rosette_apiExamples/entities.cs +++ b/rosette_apiExamples/Entities.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; -using rosette_api; +using rosette_api; namespace rosette_apiExamples { - class entities + class Entities { /// /// Example code to call Analytics API to get entities from a piece of text. diff --git a/rosette_apiExamples/events.cs b/rosette_apiExamples/Events.cs similarity index 90% rename from rosette_apiExamples/events.cs rename to rosette_apiExamples/Events.cs index 2c593a9c..a5411d9c 100644 --- a/rosette_apiExamples/events.cs +++ b/rosette_apiExamples/Events.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class events + class Events { /// /// Example code to call Analytics API to get events from a piece of text. diff --git a/rosette_apiExamples/events_negation.cs b/rosette_apiExamples/EventsNegation.cs similarity index 89% rename from rosette_apiExamples/events_negation.cs rename to rosette_apiExamples/EventsNegation.cs index d51ee104..6cc7ed81 100644 --- a/rosette_apiExamples/events_negation.cs +++ b/rosette_apiExamples/EventsNegation.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class events_negation + class EventsNegation { /// /// Example code to call Analytics API to get events from a piece of text. diff --git a/rosette_apiExamples/info.cs b/rosette_apiExamples/Info.cs similarity index 89% rename from rosette_apiExamples/info.cs rename to rosette_apiExamples/Info.cs index ca589bb3..8e5b0a27 100644 --- a/rosette_apiExamples/info.cs +++ b/rosette_apiExamples/Info.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class info + class Info { /// /// Example code to call Analytics API to get information such as version and build. diff --git a/rosette_apiExamples/language.cs b/rosette_apiExamples/Language.cs similarity index 89% rename from rosette_apiExamples/language.cs rename to rosette_apiExamples/Language.cs index f07e623c..07a000b2 100644 --- a/rosette_apiExamples/language.cs +++ b/rosette_apiExamples/Language.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; -using rosette_api; +using rosette_api; namespace rosette_apiExamples { - class language + class Language { /// /// Example code to call Analytics API to detect possible languages for a piece of text. diff --git a/rosette_apiExamples/language_multilingual.cs b/rosette_apiExamples/LanguageMultilingual.cs similarity index 93% rename from rosette_apiExamples/language_multilingual.cs rename to rosette_apiExamples/LanguageMultilingual.cs index 26a7a836..dc9da750 100644 --- a/rosette_apiExamples/language_multilingual.cs +++ b/rosette_apiExamples/LanguageMultilingual.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class language + class LanguageMultilingual { /// /// Example code to call Analytics API to detect possible languages for a piece of text. diff --git a/rosette_apiExamples/name_similarity.cs b/rosette_apiExamples/MatchedName.cs similarity index 90% rename from rosette_apiExamples/name_similarity.cs rename to rosette_apiExamples/MatchedName.cs index 295a7a60..2bb163f7 100644 --- a/rosette_apiExamples/name_similarity.cs +++ b/rosette_apiExamples/MatchedName.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class matched_name + class MatchedName { /// /// Example code to call Analytics API to get match score (similarity) for two names. diff --git a/rosette_apiExamples/morphology_complete.cs b/rosette_apiExamples/MorphologyComplete.cs similarity index 89% rename from rosette_apiExamples/morphology_complete.cs rename to rosette_apiExamples/MorphologyComplete.cs index ed3f03b8..bc9c0e50 100644 --- a/rosette_apiExamples/morphology_complete.cs +++ b/rosette_apiExamples/MorphologyComplete.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class morphology_complete + class MorphologyComplete { /// /// Example code to call Analytics API to get the complete set of morphological analysis results for a piece of text. diff --git a/rosette_apiExamples/morphology_compound-components.cs b/rosette_apiExamples/MorphologyCompoundComponents.cs similarity index 89% rename from rosette_apiExamples/morphology_compound-components.cs rename to rosette_apiExamples/MorphologyCompoundComponents.cs index a42c67e2..7ed875fd 100644 --- a/rosette_apiExamples/morphology_compound-components.cs +++ b/rosette_apiExamples/MorphologyCompoundComponents.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class morphology_compound_components + class MorphologyCompoundComponents { /// /// Example code to call Analytics API to get de-compounded words from a piece of text. diff --git a/rosette_apiExamples/morphology_han-readings.cs b/rosette_apiExamples/MorphologyHanReadings.cs similarity index 89% rename from rosette_apiExamples/morphology_han-readings.cs rename to rosette_apiExamples/MorphologyHanReadings.cs index b350b1e7..28a627a6 100644 --- a/rosette_apiExamples/morphology_han-readings.cs +++ b/rosette_apiExamples/MorphologyHanReadings.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class morphology_han_readings + class MorphologyHanReadings { /// /// Example code to call Analytics API to get Chinese readings for words in a piece of text. diff --git a/rosette_apiExamples/morphology_lemmas.cs b/rosette_apiExamples/MorphologyLemmas.cs similarity index 89% rename from rosette_apiExamples/morphology_lemmas.cs rename to rosette_apiExamples/MorphologyLemmas.cs index 007e6fdf..0ec307ae 100644 --- a/rosette_apiExamples/morphology_lemmas.cs +++ b/rosette_apiExamples/MorphologyLemmas.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class morphology_lemmas + class MorphologyLemmas { /// /// Example code to call Analytics API to get lemmas for words in a piece of text. diff --git a/rosette_apiExamples/morphology_parts-of-speech.cs b/rosette_apiExamples/MorphologyPartsOfSpeech.cs similarity index 89% rename from rosette_apiExamples/morphology_parts-of-speech.cs rename to rosette_apiExamples/MorphologyPartsOfSpeech.cs index 050b5d5b..7b8c8455 100644 --- a/rosette_apiExamples/morphology_parts-of-speech.cs +++ b/rosette_apiExamples/MorphologyPartsOfSpeech.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class morphology_parts_of_speech + class MorphologyPartsOfSpeech { /// /// Example code to call Analytics API to get part-of-speech tags for words a piece of text. diff --git a/rosette_apiExamples/name_deduplication.cs b/rosette_apiExamples/NameDeduplication.cs similarity index 89% rename from rosette_apiExamples/name_deduplication.cs rename to rosette_apiExamples/NameDeduplication.cs index 6cb9f7eb..125eb641 100644 --- a/rosette_apiExamples/name_deduplication.cs +++ b/rosette_apiExamples/NameDeduplication.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; -using rosette_api; +using rosette_api; namespace rosette_apiExamples { - class name_deduplication + class NameDeduplication { /// /// Example code to call Analytics API to deduplication a list of names. diff --git a/rosette_apiExamples/ping.cs b/rosette_apiExamples/Ping.cs similarity index 88% rename from rosette_apiExamples/ping.cs rename to rosette_apiExamples/Ping.cs index 0536b690..0f4bfb62 100644 --- a/rosette_apiExamples/ping.cs +++ b/rosette_apiExamples/Ping.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class ping + class Ping { /// /// Example code to send Analytics API a ping to check its reachability. diff --git a/rosette_apiExamples/README.md b/rosette_apiExamples/README.md index d14801f3..31c22217 100644 --- a/rosette_apiExamples/README.md +++ b/rosette_apiExamples/README.md @@ -9,37 +9,71 @@ A note on prerequisites. Analytics API only supports TLS 1.2 so ensure your too Here are some methods for running the examples. -#### Latest Version on NuGet with Docker +#### Latest Source with Docker - Clone the repository. ``` git clone git@github.com:rosette-api/csharp.git cd csharp ``` -- Launch a `mono` container. +- Launch a container. ``` - docker run -it -v $(pwd):/csharp mono:6 + docker run -it -v $(pwd):/csharp debian:13 ``` -- Install the package from NuGet +- Set up the environment. + ``` + apt-get update + apt-get install -y wget libicu76 + + wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && chmod +x dotnet-install.sh + ./dotnet-install.sh --version latest + export DOTNET_ROOT=/root/.dotnet + export PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools" + ``` + +- _Optional:_ Setup environment for running unit tests with nunit console. You can run them without this. + ``` + apt-get install -y unzip + wget https://github.com/nunit/nunit-console/releases/download/3.22.0/NUnit.Console-3.22.0.zip + unzip NUnit.Console-3.22.0.zip + + ``` +- Build the package from source. ``` cd /csharp - nuget install rosette_api - ``` -- Copy the runtime binaries to the examples directory. + dotnet restore rosette_api.slnx + dotnet build /p:Configuration=Release rosette_api.slnx + dotnet build /p:Configuration=Debug rosette_api.slnx ``` - cp Newtonsoft.Json.13.0.2/lib/net45/Newtonsoft.Json.dll rosette_apiExamples/. - cp rosette_api.1.14.4/lib/net45/rosette_api.dll rosette_apiExamples/. +- _Optional:_ Run the Unit Tests. ``` -- Compile the example you'd like to execute. E.g. language.cs + dotnet test ./rosette_apiUnitTests/bin/Release/net10.0/rosette_apiUnitTests.dll + ``` + + Or with the nunit console runner... + ``` + dotnet /root/bin/net8.0/nunit3-console.dll ./rosette_apiUnitTests/bin/Release/net10.0/rosette_apiUnitTests.dll + ``` +- Prepare a project for the example you'd like to execute. E.g. language.cs ``` cd rosette_apiExamples - csc language.cs /r:rosette_api.dll /r:System.Net.Http.dll /r:System.Web.Extensions.dll + mkdir LanguageExample + cd LanguageExample + dotnet new console --framework net10.0 + cp ../Language.cs ./Program.cs + dotnet add reference ../../rosette_api/rosette_api.csproj ``` -- Run the compiled example against Analytics Cloud. In this example, your Cloud API key is stored in the environment variable `$API_KEY`. +- Run the example against Analytics Cloud. In this example, your Cloud API key is stored in the environment variable `$API_KEY`. ``` - mono language.exe $API_KEY + dotnet run $API_KEY + ``` + Or against an alternate url. The key, in this case, can be anything if you aren't using authorization + ``` + dotnet run $API_KEY http://example.com:8181/rest/v1 ``` -#### Latest Source with Docker + +#### TODO: Refresh After Publish +#### Latest Version on NuGet with Docker - Clone the repository. ``` git clone git@github.com:rosette-api/csharp.git @@ -49,27 +83,15 @@ Here are some methods for running the examples. ``` docker run -it -v $(pwd):/csharp mono:6 ``` -- Build the package from source. +- Install the package from NuGet ``` cd /csharp - nuget restore rosette_api.sln - msbuild /p:Configuration=Release rosette_api.sln + nuget install rosette_api ``` -- _Optional:_ Run the Unit Tests. - - First, fix the certificate store so we can download wikidata. - Per: https://github.com/KSP-CKAN/CKAN/wiki/SSL-certificate-errors#removing-expired-lets-encrypt-certificates - ``` - sed -i 's/^mozilla\/DST_Root_CA_X3.crt$/!mozilla\/DST_Root_CA_X3.crt/' /etc/ca-certificates.conf - update-ca-certificates - cert-sync /etc/ssl/certs/ca-certificates.crt - ``` - - Then run the tests. - ``` - mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll - ```- Copy the runtime binaries to the examples directory. - ``` - cp packages/Newtonsoft.Json.13.0.2/lib/net45/Newtonsoft.Json.dll rosette_apiExamples/. - cp rosette_api/bin/Release/rosette_api.dll rosette_apiExamples/. +- Copy the runtime binaries to the examples directory. + ``` + cp Newtonsoft.Json.13.0.2/lib/net45/Newtonsoft.Json.dll rosette_apiExamples/. + cp rosette_api.1.14.4/lib/net45/rosette_api.dll rosette_apiExamples/. ``` - Compile the example you'd like to execute. E.g. language.cs ``` @@ -81,7 +103,3 @@ Here are some methods for running the examples. mono language.exe $API_KEY ``` -### Visual Studio -- If you are using Visual Studio, you can use the Nuget Package Manager. Search for `rosette_api` in the Online Packages and install. - -You can now run your desired endpoint file to see it in action. diff --git a/rosette_apiExamples/record_similarity.cs b/rosette_apiExamples/RecordSimilarity.cs similarity index 98% rename from rosette_apiExamples/record_similarity.cs rename to rosette_apiExamples/RecordSimilarity.cs index 890e3b30..9fada087 100644 --- a/rosette_apiExamples/record_similarity.cs +++ b/rosette_apiExamples/RecordSimilarity.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; using rosette_api; namespace rosette_apiExamples { - class record_similarity + class RecordSimilarity { /// /// Example code to call Analytics API to get record similarity scores between two list of records diff --git a/rosette_apiExamples/relationships.cs b/rosette_apiExamples/Relationships.cs similarity index 92% rename from rosette_apiExamples/relationships.cs rename to rosette_apiExamples/Relationships.cs index 6dc27a57..b1977b18 100644 --- a/rosette_apiExamples/relationships.cs +++ b/rosette_apiExamples/Relationships.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class relationships + class Relationships { /// /// Example code to call Analytics API to get sentences in a piece of text. diff --git a/rosette_apiExamples/semantic_vectors.cs b/rosette_apiExamples/SemanticVectors.cs similarity index 88% rename from rosette_apiExamples/semantic_vectors.cs rename to rosette_apiExamples/SemanticVectors.cs index d4fc25b4..eef6a19b 100644 --- a/rosette_apiExamples/semantic_vectors.cs +++ b/rosette_apiExamples/SemanticVectors.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; -using rosette_api; +using rosette_api; namespace rosette_apiExamples { - class semantic_vectors + class SemanticVectors { /// /// Example code to call Analytics API to get an input's text-vector. diff --git a/rosette_apiExamples/sentences.cs b/rosette_apiExamples/Sentences.cs similarity index 91% rename from rosette_apiExamples/sentences.cs rename to rosette_apiExamples/Sentences.cs index 6f96d846..7349a9bb 100644 --- a/rosette_apiExamples/sentences.cs +++ b/rosette_apiExamples/Sentences.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class sentences + class Sentences { /// /// Example code to call Analytics API to get sentences in a piece of text. diff --git a/rosette_apiExamples/sentiment.cs b/rosette_apiExamples/Sentiment.cs similarity index 92% rename from rosette_apiExamples/sentiment.cs rename to rosette_apiExamples/Sentiment.cs index 8e3825da..36cde80d 100644 --- a/rosette_apiExamples/sentiment.cs +++ b/rosette_apiExamples/Sentiment.cs @@ -1,15 +1,8 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class sentiment + class Sentiment { /// /// Example code to call Analytics API to get a document's sentiment diff --git a/rosette_apiExamples/similar_terms.cs b/rosette_apiExamples/SimilarTerms.cs similarity index 89% rename from rosette_apiExamples/similar_terms.cs rename to rosette_apiExamples/SimilarTerms.cs index fcccae51..ff81664f 100644 --- a/rosette_apiExamples/similar_terms.cs +++ b/rosette_apiExamples/SimilarTerms.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class similar_terms + class SimilarTerms { /// /// Example code to call Analytics API to get an input's similar terms. diff --git a/rosette_apiExamples/syntax_dependencies.cs b/rosette_apiExamples/SyntaxDependencies.cs similarity index 88% rename from rosette_apiExamples/syntax_dependencies.cs rename to rosette_apiExamples/SyntaxDependencies.cs index 54fccc0f..27130184 100644 --- a/rosette_apiExamples/syntax_dependencies.cs +++ b/rosette_apiExamples/SyntaxDependencies.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; -using rosette_api; +using rosette_api; namespace rosette_apiExamples { - class entities + class SyntaxDependencies { /// /// Example code to call Analytics API to get syntax dependencies from a piece of text. diff --git a/rosette_apiExamples/tokens.cs b/rosette_apiExamples/Tokens.cs similarity index 89% rename from rosette_apiExamples/tokens.cs rename to rosette_apiExamples/Tokens.cs index 7d732366..95ab259f 100644 --- a/rosette_apiExamples/tokens.cs +++ b/rosette_apiExamples/Tokens.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class tokens + class Tokens { /// /// Example code to call Analytics API to get tokens (words) in a piece of text. diff --git a/rosette_apiExamples/topics.cs b/rosette_apiExamples/Topics.cs similarity index 91% rename from rosette_apiExamples/topics.cs rename to rosette_apiExamples/Topics.cs index 16a6d970..65cccb79 100644 --- a/rosette_apiExamples/topics.cs +++ b/rosette_apiExamples/Topics.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class topics + class Topics { /// /// Example code to call Analytics API to get concepts and key phrases in a piece of text. diff --git a/rosette_apiExamples/name_translation.cs b/rosette_apiExamples/TranslatedName.cs similarity index 89% rename from rosette_apiExamples/name_translation.cs rename to rosette_apiExamples/TranslatedName.cs index cb151e92..b8ed6cd3 100644 --- a/rosette_apiExamples/name_translation.cs +++ b/rosette_apiExamples/TranslatedName.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using rosette_api; namespace rosette_apiExamples { - class translated_name + class TranslatedName { /// /// Example code to call Analytics API to translate a name from language to another. diff --git a/rosette_apiExamples/transliteration.cs b/rosette_apiExamples/Transliteration.cs similarity index 88% rename from rosette_apiExamples/transliteration.cs rename to rosette_apiExamples/Transliteration.cs index 20f117fb..52b06d8f 100644 --- a/rosette_apiExamples/transliteration.cs +++ b/rosette_apiExamples/Transliteration.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; -using rosette_api; +using rosette_api; namespace rosette_apiExamples { - class transliteration + class Transliteration { /// /// Example code to call Analytics API to transliterate a name. diff --git a/rosette_apiExamples/rosette_apiExamples.csproj b/rosette_apiExamples/rosette_apiExamples.csproj new file mode 100644 index 00000000..f0b26ff4 --- /dev/null +++ b/rosette_apiExamples/rosette_apiExamples.csproj @@ -0,0 +1,13 @@ + + + + net10.0 + enable + enable + + + + + + + diff --git a/rosette_apiUnitTests/Properties/AssemblyInfo.cs b/rosette_apiUnitTests/Properties/AssemblyInfo.cs deleted file mode 100644 index a4eef44b..00000000 --- a/rosette_apiUnitTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Rosette API Unit Tests")] -[assembly: AssemblyDescription("Provides testing for the Rosette API C# Binding")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Basis Technology")] -[assembly: AssemblyProduct("Rosette API")] -[assembly: AssemblyCopyright("2016 Basis Technology Corp")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("02d49180-2983-4cda-84f6-dc3ce79efe00")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/rosette_apiUnitTests/app.config b/rosette_apiUnitTests/app.config deleted file mode 100755 index 7c63cadb..00000000 --- a/rosette_apiUnitTests/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/rosette_apiUnitTests/packages.config b/rosette_apiUnitTests/packages.config deleted file mode 100644 index e084854b..00000000 --- a/rosette_apiUnitTests/packages.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/rosette_apiUnitTests/rosette_apiUnitTests.cs b/rosette_apiUnitTests/rosette_apiUnitTests.cs index 9e2a611f..d0749fe2 100755 --- a/rosette_apiUnitTests/rosette_apiUnitTests.cs +++ b/rosette_apiUnitTests/rosette_apiUnitTests.cs @@ -1,18 +1,10 @@ -using NUnit.Framework; -using rosette_api; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using RichardSzalay.MockHttp; -using System; -using System.Collections.Generic; +using rosette_api; using System.Collections.Specialized; -using System.IO; using System.IO.Compression; -using System.Linq; using System.Net; -using System.Net.Http; -using System.Web.Script.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System.Threading.Tasks; namespace rosette_apiUnitTests { /// @@ -80,45 +72,47 @@ public void Init() { [Test] public void RosetteResponse_HeaderTest() { - HttpResponseMessage message = new HttpResponseMessage { + HttpResponseMessage message = new() + { StatusCode = (HttpStatusCode)200, ReasonPhrase = "OK", Content = new StringContent(_testJson) }; message.Headers.Add(_testHeaderKey, _testHeaderValue); - RosetteResponse rr = new RosetteResponse(message); - Assert.AreEqual(_testHeaderValue, rr.Headers[_testHeaderKey], "RosetteResponse: header mismatch"); + RosetteResponse rr = new(message); + Assert.That(rr.Headers[_testHeaderKey], Is.EqualTo(_testHeaderValue), "RosetteResponse: header mismatch"); } [Test] public void RosetteResponse_ContentTest() { - HttpResponseMessage message = new HttpResponseMessage { + HttpResponseMessage message = new() + { StatusCode = (HttpStatusCode)200, ReasonPhrase = "OK", Content = new StringContent(_testJson) }; message.Headers.Add(_testHeaderKey, _testHeaderValue); - RosetteResponse rr = new RosetteResponse(message); -# pragma warning disable 618 - Assert.AreEqual(_testItemCount, rr.Content.Count, "RosetteResponse: header mismatch"); -# pragma warning restore 618 + RosetteResponse rr = new(message); + Assert.That(rr.Content.Count, Is.EqualTo(_testItemCount), "RosetteResponse: header mismatch"); } [Test] public void RosetteResponse_ContentAsJsonTest() { - HttpResponseMessage message = new HttpResponseMessage { + HttpResponseMessage message = new() + { StatusCode = (HttpStatusCode)200, ReasonPhrase = "OK", Content = new StringContent(_testJson) }; message.Headers.Add(_testHeaderKey, _testHeaderValue); - RosetteResponse rr = new RosetteResponse(message); - Assert.AreEqual(_testJson, rr.ContentAsJson, "RosetteResponse: json mismatch"); + RosetteResponse rr = new(message); + Assert.That(rr.ContentAsJson, Is.EqualTo(_testJson), "RosetteResponse: json mismatch"); } [Test] public void RosetteResponse_ExceptionTest() { - HttpResponseMessage message = new HttpResponseMessage { + HttpResponseMessage message = new() + { StatusCode = (HttpStatusCode)404, ReasonPhrase = "Not Found", Content = new StringContent(_testJson) @@ -129,7 +123,7 @@ public void RosetteResponse_ExceptionTest() { Assert.Fail("Exception should have been thrown"); } catch (RosetteException ex) { - Assert.AreEqual(404, ex.Code, "RosetteResponse: Exception mismatch"); + Assert.That(ex.Code, Is.EqualTo(404), "RosetteResponse: Exception mismatch"); } } } @@ -139,7 +133,7 @@ public class RosetteExtensionsTests { [Test] public void MorphologyEndpointTest() { string expected = "han-readings"; - Assert.AreEqual(expected, RosetteExtensions.MorphologyEndpoint(MorphologyFeature.hanReadings), "Morphology endpoint mismatch"); + Assert.That(RosetteExtensions.MorphologyEndpoint(MorphologyFeature.hanReadings), Is.EqualTo(expected), "Morphology endpoint mismatch"); } } @@ -194,7 +188,7 @@ public void Error409_Test() { } catch (RosetteException ex) { Console.WriteLine("Error code: " + ex.Code); - Assert.AreEqual(ex.Code, 409); + Assert.That(ex.Code, Is.EqualTo(409)); return; } catch (Exception) { @@ -208,11 +202,11 @@ public void Error409_Test() { public class Rosette_classTests { [Test] public void NameClassTest() { - Name name = new Name("text", "language", "script", "entityType"); - Assert.AreEqual("text", name.text, "Name does not match"); - Assert.AreEqual("language", name.language, "Language does not match"); - Assert.AreEqual("script", name.script, "Script does not match"); - Assert.AreEqual("entityType", name.entityType, "EntityType does not match"); + Name name = new("text", "language", "script", "entityType"); + Assert.That(name.text, Is.EqualTo("text"), "Name does not match"); + Assert.That(name.language, Is.EqualTo("language"), "Language does not match"); + Assert.That(name.script, Is.EqualTo("script"), "Script does not match"); + Assert.That(name.entityType, Is.EqualTo("entityType"), "EntityType does not match"); } [Test] @@ -223,20 +217,20 @@ public void RosetteFileClassTest() { sw.Flush(); sw.Close(); - RosetteFile f = new RosetteFile(tmpFile, "application/octet-stream", null); - Assert.IsNotNull(f.Filename, "Filename is null"); - Assert.AreEqual(tmpFile, f.Filename, "Filename does not match"); - Assert.AreEqual("application/octet-stream", f.ContentType, "ContentType does not match"); - Assert.IsNull(f.Options, "Options does not match"); + RosetteFile f = new(tmpFile, "application/octet-stream", null); + Assert.That(f.Filename, Is.Not.Null, "Filename is null"); + Assert.That(f.Filename, Is.EqualTo(tmpFile), "Filename does not match"); + Assert.That(f.ContentType, Is.EqualTo("application/octet-stream"), "ContentType does not match"); + Assert.That(f.Options, Is.Null, "Options does not match"); byte[] b = f.getFileData(); - Assert.IsTrue(b.Count() > 0, "File is empty"); + Assert.That(b.Count() > 0, Is.True, "File is empty"); string content = f.getFileDataString(); - Assert.IsTrue(content.Length > 0, "File is empty"); + Assert.That(content.Length > 0, Is.True, "File is empty"); MultipartContent multiPart = f.AsMultipart(); - Assert.IsTrue(multiPart.Headers.Count() > 0, "Multipart not populated"); + Assert.That(multiPart.Headers.Count() > 0, Is.True, "Multipart not populated"); f.Dispose(); if (File.Exists(tmpFile)) { @@ -246,12 +240,12 @@ public void RosetteFileClassTest() { [Test] public void RosetteExceptionClassTest() { - RosetteException ex = new RosetteException("message", 1, "requestID", "file", "line"); - Assert.AreEqual("message", ex.Message, "Message does not match"); - Assert.AreEqual(1, ex.Code, "Code does not match"); - Assert.AreEqual("requestID", ex.RequestID, "RequestID does not match"); - Assert.AreEqual("file", ex.File, "File does not match"); - Assert.AreEqual("line", ex.Line, "Line does not match"); + RosetteException ex = new("message", 1, "requestID", "file", "line"); + Assert.That(ex.Message, Is.EqualTo("message"), "Message does not match"); + Assert.That(ex.Code, Is.EqualTo(1), "Code does not match"); + Assert.That(ex.RequestID, Is.EqualTo("requestID"), "RequestID does not match"); + Assert.That(ex.File, Is.EqualTo("file"), "File does not match"); + Assert.That(ex.Line, Is.EqualTo("line"), "Line does not match"); } } @@ -274,12 +268,12 @@ public void RecordFieldTypeSerializationTest() { string numberSerialized = JsonConvert.SerializeObject(number); string booleanSerialized = JsonConvert.SerializeObject(boolean); - Assert.AreEqual( "\"rni_date\"", dateSerialized, "RniDate does not deserialize to 'rni_date'"); - Assert.AreEqual("\"rni_address\"", addressSerialized, "RniAddress does not deserialize to 'rni_address'"); - Assert.AreEqual("\"rni_name\"", nameSerialized, "RniName does not deserialize to 'rni_name'"); - Assert.AreEqual("\"rni_string\"", strSerialized, "RniString does not deserialize to 'rni_string'"); - Assert.AreEqual("\"rni_number\"", numberSerialized, "RniNumber does not deserialize to 'rni_number'"); - Assert.AreEqual("\"rni_boolean\"", booleanSerialized, "RniBoolean does not deserialize to 'rni_boolean'"); + Assert.That(dateSerialized, Is.EqualTo("\"rni_date\""), "RniDate does not deserialize to 'rni_date'"); + Assert.That(addressSerialized, Is.EqualTo("\"rni_address\""), "RniAddress does not deserialize to 'rni_address'"); + Assert.That(nameSerialized, Is.EqualTo("\"rni_name\""), "RniName does not deserialize to 'rni_name'"); + Assert.That(strSerialized, Is.EqualTo("\"rni_string\""), "RniString does not deserialize to 'rni_string'"); + Assert.That(numberSerialized, Is.EqualTo("\"rni_number\""), "RniNumber does not deserialize to 'rni_number'"); + Assert.That(booleanSerialized, Is.EqualTo("\"rni_boolean\""), "RniBoolean does not deserialize to 'rni_boolean'"); } [Test] @@ -293,11 +287,11 @@ public void RecordSimilarityFieldSerializationTest() { RecordSimilarityField dateUnfielded = new UnfieldedDateRecord("1993-04-16"); string dateUnfieldedSerialized = JsonConvert.SerializeObject(dateUnfielded); - Assert.AreEqual("\"123 Roadlane Ave\"", addressUnfieldedSerialized, "Unfielded Address does not serialize correctly"); - Assert.AreEqual("\"Ethan R\"", nameUnfieldedSerialized, "Unfielded Name does not serialize correctly"); - Assert.AreEqual("\"1993-04-16\"", dateUnfieldedSerialized, "Unfielded Date does not serialize correctly"); + Assert.That(addressUnfieldedSerialized, Is.EqualTo("\"123 Roadlane Ave\""), "Unfielded Address does not serialize correctly"); + Assert.That(nameUnfieldedSerialized, Is.EqualTo("\"Ethan R\""), "Unfielded Name does not serialize correctly"); + Assert.That(dateUnfieldedSerialized, Is.EqualTo("\"1993-04-16\""), "Unfielded Date does not serialize correctly"); - FieldedAddressRecord addressFielded = new FieldedAddressRecord(); + FieldedAddressRecord addressFielded = new(); addressFielded.HouseNumber = "123"; addressFielded.Road = "Roadlane Ave"; string addressFieldedSerialized = JsonConvert.SerializeObject(addressFielded, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); @@ -309,76 +303,77 @@ public void RecordSimilarityFieldSerializationTest() { RecordSimilarityField dateFielded = new FieldedDateRecord("04161993", "MMddyyyy"); string dateFieldedSerialized = JsonConvert.SerializeObject(dateFielded); - Assert.AreEqual("{\"houseNumber\":\"123\",\"road\":\"Roadlane Ave\"}", addressFieldedSerialized, "Fielded Address does not serialize correctly"); - Assert.AreEqual("{\"text\":\"Ethan R\"}", nameFieldedSerialized, "Fielded Name does not serialize correctly"); - Assert.AreEqual("{\"format\":\"MMddyyyy\",\"date\":\"04161993\"}", dateFieldedSerialized, "Fielded Date does not serialize correctly"); + Assert.That(addressFieldedSerialized, Is.EqualTo("{\"houseNumber\":\"123\",\"road\":\"Roadlane Ave\"}"), "Fielded Address does not serialize correctly"); + Assert.That(nameFieldedSerialized, Is.EqualTo("{\"text\":\"Ethan R\"}"), "Fielded Name does not serialize correctly"); + Assert.That(dateFieldedSerialized, Is.EqualTo("{\"format\":\"MMddyyyy\",\"date\":\"04161993\"}"), "Fielded Date does not serialize correctly"); string jsonString = "{\"key\":\"value\",\"key2\":[\"value2\",\"value3\"]}"; RecordSimilarityField unknownField = new UnknownFieldRecord(JToken.Parse(jsonString)); string unknownFieldSerialized = JsonConvert.SerializeObject(unknownField); - Assert.AreEqual(jsonString, unknownFieldSerialized, "Unknown Field does not serialize correctly"); + Assert.That(unknownFieldSerialized, Is.EqualTo(jsonString), "Unknown Field does not serialize correctly"); RecordSimilarityField stringField = new StringRecord("software engineer"); string stringFieldSerialized = JsonConvert.SerializeObject(stringField); - Assert.AreEqual("\"software engineer\"", stringFieldSerialized, "String Field does not serialize correctly"); + Assert.That(stringFieldSerialized, Is.EqualTo("\"software engineer\""), "String Field does not serialize correctly"); RecordSimilarityField numberField = new NumberRecord(47); string numberFieldSerialized = JsonConvert.SerializeObject(numberField); - Assert.AreEqual("47.0", numberFieldSerialized, "Number Field does not serialize correctly"); + Assert.That(numberFieldSerialized, Is.EqualTo("47.0"), "Number Field does not serialize correctly"); RecordSimilarityField booleanField = new BooleanRecord(false); string booleanFieldSerialized = JsonConvert.SerializeObject(booleanField); - Assert.AreEqual("false", booleanFieldSerialized, "Boolean Field does not serialize correctly"); + Assert.That(booleanFieldSerialized, Is.EqualTo("false"), "Boolean Field does not serialize correctly"); } [Test] public void RecodSimilarityFullResponseDeserializationTest() { string jsonResponse = "{\"info\":[\"Threshold not specified, defaulting to 0.0\",\"IncludeExplainInfo not specified, defaulting to false\"],\"results\":[{\"score\":0.904213806305046,\"left\":{\"dob\":{\"date\":\"1993-04-16\"},\"primaryName\":{\"text\":\"Evan R\"}},\"right\":{\"dob\":{\"date\":\"1993-04-16\"},\"primaryName\":\"Ivan R\"},\"explainInfo\":{\"scoredFields\":{\"dob\":{\"weight\":0.2,\"calculatedWeight\":0.28571428571428575,\"rawScore\":1,\"finalScore\":0.28571428571428575,\"details\":{\"leftInput\":{\"originalString\":\"1993-04-16\",\"day\":16,\"month\":4,\"yearWithoutCentury\":93,\"century\":19,\"modifiedJulianDay\":49093,\"canonicalForm\":\"1993-04-16\",\"empty\":false},\"rightInput\":{\"originalString\":\"1993-04-16\",\"day\":16,\"month\":4,\"yearWithoutCentury\":93,\"century\":19,\"modifiedJulianDay\":49093,\"canonicalForm\":\"1993-04-16\",\"empty\":false},\"scoreTuples\":[{\"scoreInIsolation\":1,\"scoreInContext\":1,\"left\":\"1993-04-16\",\"right\":\"1993-04-16\",\"marked\":true,\"weight\":1,\"component\":\"EXACT_MATCH\"}],\"scoreAdjustments\":[{\"unbiasedScore\":1,\"score\":1,\"parameter\":\"dateFinalBias\"}],\"finalScore\":1,\"scores\":[{\"scoreInIsolation\":1,\"scoreInContext\":1,\"left\":\"1993-04-16\",\"right\":\"1993-04-16\",\"marked\":true,\"weight\":1,\"component\":\"EXACT_MATCH\"}],\"defaultInput\":{\"empty\":true},\"empty\":false}},\"primaryName\":{\"weight\":0.5,\"calculatedWeight\":0.7142857142857143,\"rawScore\":0.8658993288270642,\"finalScore\":0.6184995205907602,\"details\":{\"leftInput\":{\"data\":\"Evan R\",\"normalizedData\":\"evan r\",\"latnData\":\"evan r\",\"script\":\"Latn\",\"languageOfUse\":\"ENGLISH\",\"languageOfOrigin\":\"ENGLISH\",\"tokens\":[{\"token\":\"evan\",\"latnToken\":\"evan\",\"tokenWeight\":0.7213975215425366,\"bin\":3,\"biasedBin\":2.902736521062578,\"tokenType\":\"GIVEN\"},{\"token\":\"r\",\"latnToken\":\"r\",\"tokenWeight\":0.27860247845746355,\"bin\":8,\"biasedBin\":7.5161819937120935,\"tokenType\":\"UNKNOWN\"}],\"entityType\":\"PERSON\",\"empty\":false},\"rightInput\":{\"data\":\"Ivan R\",\"normalizedData\":\"ivan r\",\"latnData\":\"ivan r\",\"script\":\"Latn\",\"languageOfUse\":\"ENGLISH\",\"languageOfOrigin\":\"SPANISH\",\"tokens\":[{\"token\":\"ivan\",\"latnToken\":\"ivan\",\"tokenWeight\":0.7213975215425366,\"bin\":3,\"biasedBin\":2.902736521062578,\"tokenType\":\"UNKNOWN\"},{\"token\":\"r\",\"latnToken\":\"r\",\"tokenWeight\":0.27860247845746355,\"bin\":8,\"biasedBin\":7.5161819937120935,\"tokenType\":\"UNKNOWN\"}],\"entityType\":\"PERSON\",\"empty\":false},\"scoreTuples\":[{\"scoreInIsolation\":0.6599663295739067,\"scoreInContext\":0.6599663295739067,\"left\":\"evan\",\"right\":\"ivan\",\"marked\":true,\"reason\":\"HMM_MATCH\",\"leftMinTokenIndex\":0,\"leftMaxTokenIndex\":0,\"rightMinTokenIndex\":0,\"rightMaxTokenIndex\":0},{\"scoreInIsolation\":1,\"scoreInContext\":1,\"left\":\"r\",\"right\":\"r\",\"marked\":true,\"reason\":\"MATCH\",\"leftMinTokenIndex\":1,\"leftMaxTokenIndex\":1,\"rightMinTokenIndex\":1,\"rightMaxTokenIndex\":1}],\"scoreAdjustments\":[{\"unbiasedScore\":0.7290304644108475,\"score\":0.8658993288270642,\"parameter\":\"finalBias\"}],\"finalScore\":0.8658993288270642,\"defaultInput\":{\"empty\":true},\"empty\":false}}},\"leftOnlyFields\":[],\"rightOnlyFields\":[]}}],\"errorMessage\":\"dummy\"}"; // create a HttpResponseMessage from this JSON - HttpResponseMessage message = new HttpResponseMessage { + HttpResponseMessage message = new() + { StatusCode = (HttpStatusCode)200, ReasonPhrase = "OK", Content = new StringContent(jsonResponse) }; - RecordSimilarityResponse response = new RecordSimilarityResponse(message); + RecordSimilarityResponse response = new(message); // Assert info messages - Assert.IsNotNull(response.Info, "Info is null"); - Assert.AreEqual(2, response.Info.Count, "Info count does not match"); - Assert.AreEqual("Threshold not specified, defaulting to 0.0", response.Info[0], "Info message 0 does not match"); - Assert.AreEqual("IncludeExplainInfo not specified, defaulting to false", response.Info[1], "Info message 1 does not match"); + Assert.That(response.Info, Is.Not.Null, "Info is null"); + Assert.That(response.Info.Count, Is.EqualTo(2), "Info count does not match"); + Assert.That(response.Info[0], Is.EqualTo("Threshold not specified, defaulting to 0.0"), "Info message 0 does not match"); + Assert.That(response.Info[1], Is.EqualTo("IncludeExplainInfo not specified, defaulting to false"), "Info message 1 does not match"); // Assert error message - Assert.AreEqual("dummy", response.ErrorMessage, "Error message does not match"); + Assert.That(response.ErrorMessage, Is.EqualTo("dummy"), "Error message does not match"); // Assert result - Assert.IsNotNull(response.Results, "Results is null"); - Assert.AreEqual(1, response.Results.Count, "Results count does not match"); + Assert.That(response.Results, Is.Not.Null, "Results is null"); + Assert.That(response.Results.Count, Is.EqualTo(1), "Results count does not match"); RecordSimilarityResult result = response.Results[0]; - Assert.AreEqual(0.904213806305046, result.Score, "Score does not match"); - Assert.IsNotNull(result.Left, "Left is null"); - Assert.AreEqual(2, result.Left.Count, "Left count does not match"); - Assert.IsNotNull(result.Right, "Right is null"); - Assert.AreEqual(2, result.Right.Count, "Right count does not match"); + Assert.That(result.Score, Is.EqualTo(0.904213806305046), "Score does not match"); + Assert.That(result.Left, Is.Not.Null, "Left is null"); + Assert.That(result.Left.Count, Is.EqualTo(2), "Left count does not match"); + Assert.That(result.Right, Is.Not.Null, "Right is null"); + Assert.That(result.Right.Count, Is.EqualTo(2), "Right count does not match"); // Assert explainInfo RecordSimilarityExplainInfo explainInfo = result.ExplainInfo; - Assert.IsNotNull(result.ExplainInfo, "ExplainInfo is null"); - Assert.IsNotNull(explainInfo.RightOnlyFields, "RightOnlyFields is null"); - Assert.AreEqual(0, explainInfo.RightOnlyFields.Count, "RightOnlyFields count does not match"); - Assert.IsNotNull(explainInfo.LeftOnlyFields, "LeftOnlyFields is null"); - Assert.AreEqual(0, explainInfo.LeftOnlyFields.Count, "LeftOnlyFields count does not match"); + Assert.That(result.ExplainInfo, Is.Not.Null, "ExplainInfo is null"); + Assert.That(explainInfo.RightOnlyFields, Is.Not.Null, "RightOnlyFields is null"); + Assert.That(explainInfo.RightOnlyFields.Count, Is.Zero, "RightOnlyFields count does not match"); + Assert.That(explainInfo.LeftOnlyFields, Is.Not.Null, "LeftOnlyFields is null"); + Assert.That(explainInfo.LeftOnlyFields.Count, Is.Zero, "LeftOnlyFields count does not match"); // Assert scoredFields is not null and has both keys - Assert.IsNotNull(explainInfo.ScoredFields, "ScoredFields is null"); - Assert.IsTrue(explainInfo.ScoredFields.ContainsKey("dob"), "ScoredFields does not contain key 'dob'"); - Assert.IsTrue(explainInfo.ScoredFields.ContainsKey("primaryName"), "ScoredFields does not contain key 'primaryName'"); + Assert.That(explainInfo.ScoredFields, Is.Not.Null, "ScoredFields is null"); + Assert.That(explainInfo.ScoredFields.ContainsKey("dob"), Is.True, "ScoredFields does not contain key 'dob'"); + Assert.That(explainInfo.ScoredFields.ContainsKey("primaryName"), Is.True, "ScoredFields does not contain key 'primaryName'"); // Assert dob RecordSimilarityFieldExplainInfo dob = explainInfo.ScoredFields["dob"]; - Assert.IsNotNull(dob, "dob is null"); - Assert.AreEqual(0.2, dob.Weight, "dob weight does not match"); - Assert.AreEqual(0.28571428571428575, dob.CalculatedWeight, "dob calculated weight does not match"); - Assert.AreEqual(1, dob.RawScore, "dob raw score does not match"); - Assert.AreEqual(0.28571428571428575, dob.FinalScore, "dob final score does not match"); - Assert.IsNotNull(dob.Details, "dob details is null"); + Assert.That(dob, Is.Not.Null, "dob is null"); + Assert.That(dob.Weight, Is.EqualTo(0.2), "dob weight does not match"); + Assert.That(dob.CalculatedWeight, Is.EqualTo(0.28571428571428575), "dob calculated weight does not match"); + Assert.That(dob.RawScore, Is.EqualTo(1), "dob raw score does not match"); + Assert.That(dob.FinalScore, Is.EqualTo(0.28571428571428575), "dob final score does not match"); + Assert.That(dob.Details, Is.Not.Null, "dob details is null"); } } @@ -410,9 +405,9 @@ protected virtual void Dispose(bool disposing) { /// /// (byte[]): Raw data to be compressed /// (byte[]): Compressed data - public static byte[] Compress(byte[] raw) { - MemoryStream memory = new MemoryStream(); - using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress, true)) { + private static byte[] Compress(byte[] raw) { + MemoryStream memory = new(); + using (GZipStream gzip = new(memory, CompressionMode.Compress, true)) { gzip.Write(raw, 0, raw.Length); } return memory.ToArray(); @@ -428,10 +423,10 @@ public static byte[] Compress(byte[] raw) { private static byte[] Decompress(byte[] gzip) { // Create a GZIP stream with decompression mode. // ... Then create a buffer and write into while reading from the GZIP stream. - using (GZipStream stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress)) { + using (GZipStream stream = new(new MemoryStream(gzip), CompressionMode.Decompress)) { const int size = 4096; byte[] buffer = new byte[size]; - using (MemoryStream memory = new MemoryStream()) { + using (MemoryStream memory = new()) { int count = 0; do { count = stream.Read(buffer, 0, size); @@ -482,7 +477,7 @@ public void Cleanup() { [Test] public void UserAgentTest() { string uaString = string.Format("Babel-Street-Analytics-API-Csharp/{0}/{1}", CAPI.Version, Environment.Version.ToString()); - Assert.AreEqual(uaString, _rosetteApi.UserAgent); + Assert.That(CAPI.UserAgent, Is.EqualTo(uaString)); } @@ -492,11 +487,11 @@ public void UserAgentTest() { [Test] public void OptionsTest() { - KeyValuePair expected = new KeyValuePair("test", "testValue"); + KeyValuePair expected = new("test", "testValue"); _rosetteApi.SetOption(expected.Key, expected.Value); - Assert.AreEqual(expected.Value, _rosetteApi.GetOption(expected.Key)); + Assert.That(_rosetteApi.GetOption(expected.Key), Is.EqualTo(expected.Value)); } [Test] @@ -506,7 +501,7 @@ public void ClearOptionsTest() { _rosetteApi.ClearOptions(); - Assert.IsNull(_rosetteApi.GetOption("option1")); + Assert.That(_rosetteApi.GetOption("option1"), Is.Null); } //------------------------- Simple Custom Header Tests ---------------------------------------- @@ -514,20 +509,20 @@ public void ClearOptionsTest() { [Test] public void CustomHeadersTestRosette() { - KeyValuePair expected = new KeyValuePair("X-RosetteAPI-Test", "testValue"); + KeyValuePair expected = new("X-RosetteAPI-Test", "testValue"); _rosetteApi.SetCustomHeaders(expected.Key, expected.Value); - Assert.AreEqual(expected.Value, _rosetteApi.GetCustomHeaders()[expected.Key]); + Assert.That(_rosetteApi.GetCustomHeaders()[expected.Key], Is.EqualTo(expected.Value)); } [Test] public void CustomHeadersTestBabelStreet() { - KeyValuePair expected = new KeyValuePair("X-BabelStreetAPI-Test", "testValue"); + KeyValuePair expected = new("X-BabelStreetAPI-Test", "testValue"); _rosetteApi.SetCustomHeaders(expected.Key, expected.Value); - Assert.AreEqual(expected.Value, _rosetteApi.GetCustomHeaders()[expected.Key]); + Assert.That(_rosetteApi.GetCustomHeaders()[expected.Key], Is.EqualTo(expected.Value)); } [Test] @@ -536,18 +531,18 @@ public void ClearHeadersTest() { _rosetteApi.ClearCustomHeaders(); - Assert.IsEmpty(_rosetteApi.GetCustomHeaders()); + Assert.That(_rosetteApi.GetCustomHeaders(), Is.Empty); } [Test] public void CheckInvalidCustomHeader() { - KeyValuePair expected = new KeyValuePair("Test", "testValue"); + KeyValuePair expected = new("Test", "testValue"); try { _rosetteApi.SetCustomHeaders(expected.Key, expected.Value); } catch (RosetteException ex) { - Assert.AreEqual(ex.Message, "Custom header name must begin with \"X-RosetteAPI-\" or \"X-BabelStreetAPI-\""); + Assert.That(ex.Message, Is.EqualTo("Custom header name must begin with \"X-RosetteAPI-\" or \"X-BabelStreetAPI-\"")); return; } } @@ -558,34 +553,37 @@ public void CheckInvalidCustomHeader() { [Test] public void CustomUrlParametersTest() { - NameValueCollection expected = new NameValueCollection { + NameValueCollection expected = new() + { { "output", "rosette" } }; _rosetteApi.SetUrlParameter("output", "rosette"); - Assert.AreEqual(expected["output"], _rosetteApi.GetUrlParameters()["output"]); + Assert.That(_rosetteApi.GetUrlParameters()["output"], Is.EqualTo(expected["output"])); } [Test] public void ClearUrlParametersTest() { - NameValueCollection expected = new NameValueCollection { + NameValueCollection expected = new() + { { "output", "rosette" } }; _rosetteApi.SetUrlParameter("output", "rosette"); _rosetteApi.ClearUrlParameters(); - Assert.IsEmpty(_rosetteApi.GetUrlParameters()); + Assert.That(_rosetteApi.GetUrlParameters(), Is.Empty); } [Test] public void RemoveURLParametersTest() { - NameValueCollection expected = new NameValueCollection { + NameValueCollection expected = new() + { { "output", "rosette" } }; _rosetteApi.RemoveUrlParameter("output"); - Assert.IsEmpty(_rosetteApi.GetUrlParameters()); + Assert.That(_rosetteApi.GetUrlParameters(), Is.Empty); } @@ -597,9 +595,7 @@ public void InfoTest() { .Respond("application/json", "{'response': 'OK'}"); var response = _rosetteApi.Info(); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -611,23 +607,24 @@ public void InfoTestFull() string buildNumber = null; string buildTime = null; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary content = new Dictionary { + Dictionary content = new() + { { "name", name }, { "version", version }, { "buildNumber", buildNumber }, { "buildTime", buildTime } }; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, new JavaScriptSerializer().Serialize(content)); + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, JsonConvert.SerializeObject(content)); _mockHttp.When(_testUrl + "info").Respond(req => mockedMessage); - InfoResponse expected = new InfoResponse(name, version, buildNumber, buildTime, responseHeaders, content); + InfoResponse expected = new(name, version, buildNumber, buildTime, responseHeaders, content); InfoResponse response = _rosetteApi.Info(); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } private HttpResponseMessage MakeMockedMessage(Dictionary responseHeaders, HttpStatusCode statusCode, String content) { - HttpResponseMessage mockedMessage = new HttpResponseMessage(statusCode) { + HttpResponseMessage mockedMessage = new(statusCode) { Content = new StringContent(content) }; foreach (KeyValuePair header in responseHeaders) @@ -664,16 +661,17 @@ public void PingTestFull() { string message = "Rosette API at your service."; long time = 1470930452887; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary content = new Dictionary { + Dictionary content = new() + { { "message", message }, { "time", time } }; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, new JavaScriptSerializer().Serialize(content)); + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, JsonConvert.SerializeObject(content)); _mockHttp.When(_testUrl + "ping").Respond(req => mockedMessage); - PingResponse expected = new PingResponse(message, time, responseHeaders, content); + PingResponse expected = new(message, time, responseHeaders, content); PingResponse response = _rosetteApi.Ping(); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -683,9 +681,7 @@ public void PingTest() .Respond("application/json", "{'response': 'OK'}"); var response = _rosetteApi.Ping(); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Exceptions ---------------------------------------- @@ -704,7 +700,7 @@ public void NoParams_Test() { _rosetteApi.Categories(); } catch (RosetteException ex) { - Assert.AreEqual(ex.Message, "Must supply one of Content or ContentUri"); + Assert.That(ex.Message, Is.EqualTo("Must supply one of Content or ContentUri")); return; } Assert.Fail("Exception not thrown"); @@ -719,7 +715,7 @@ public void ConflictingParams_Test() { _rosetteApi.Categories("content", null, null, "contentUri"); } catch (RosetteException ex) { - Assert.AreEqual(ex.Message, "Cannot supply both Content and ContentUri"); + Assert.That(ex.Message, Is.EqualTo("Cannot supply both Content and ContentUri")); return; } Assert.Fail("Exception not thrown"); @@ -732,27 +728,26 @@ public void AddressSimilarityTestFull() Init(); double score = (double)0.9486632809417912; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "score", score } }; - AddressSimilarityResponse expected = new AddressSimilarityResponse(score, responseHeaders, content, null); + AddressSimilarityResponse expected = new(score, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "address-similarity").Respond(req => mockedMessage); AddressSimilarityResponse response = _rosetteApi.AddressSimilarity(new Address(city:"Cambridge"), new Address(city:"cambridge")); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] public void AddressSimilarity_Content_Test() { _mockHttp.When(_testUrl + "address-similarity").Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); - Address name1 = new Address("Address One"); - Address name2 = new Address("Address Two"); + Address name1 = new("Address One"); + Address name2 = new("Address Two"); var response = _rosetteApi.AddressSimilarity(name1, name2); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -761,9 +756,7 @@ public void AddressSimilarity_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.AddressSimilarity(new Dictionary() { { "address1", "Address One" }, { "address2", "Address Two" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Categories ---------------------------------------- @@ -773,30 +766,29 @@ public void Categories_Content_Test() { _mockHttp.When(_testUrl + "categories") .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Categories("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] public void CategoriesContentTestFull() { Init(); - JsonSerializer serializer = new JsonSerializer(); - List categories = new List(); - RosetteCategory cat0 = new RosetteCategory("ARTS_AND_ENTERTAINMENT", (decimal)0.23572849069656435, (decimal)0.12312312312312312); + JsonSerializer serializer = new(); + List categories = []; + RosetteCategory cat0 = new("ARTS_AND_ENTERTAINMENT", (decimal)0.23572849069656435, (decimal)0.12312312312312312); categories.Add(cat0); string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary content = new Dictionary { + Dictionary content = new() + { { "categories", categories } }; Dictionary responseHeaders = serializer.Deserialize>(new JsonTextReader(new StringReader(headersAsString))); String mockedContent = "{\"categories\": [ { \"label\": \"" + cat0.Label + "\", \"confidence\": " + cat0.Confidence + ", \"score\": " + cat0.Score + "} ] }"; HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "categories").Respond(req => mockedMessage); - CategoriesResponse expected = new CategoriesResponse(categories, responseHeaders, null, mockedContent); + CategoriesResponse expected = new(categories, responseHeaders, null, mockedContent); CategoriesResponse response = _rosetteApi.Categories("Sony Pictures is planning to shoot a good portion of the new \"\"Ghostbusters\"\" in Boston as well."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -805,9 +797,7 @@ public void Categories_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Categories(new Dictionary(){ {"contentUri", "contentUrl"} }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -815,11 +805,9 @@ public void Categories_File_Test() { _mockHttp.When(_testUrl + "categories") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Categories(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } @@ -828,21 +816,22 @@ public void Categories_File_Test() { public void EntityTestFull() { Init(); - RosetteEntity e0 = new RosetteEntity("Dan Akroyd", "Dan Akroyd", new EntityID("Q105221"), "PERSON", 2, 0.99, "X1", null, new List() { new MentionOffset(0, 10), new MentionOffset(20,32) }, .99, 1, null); - RosetteEntity e1 = new RosetteEntity("The Hollywood Reporter", "The Hollywood Reporter", new EntityID("Q61503"), "ORGANIZATION", 1, null, "X1", null, new List() { new MentionOffset(15, 18) }, null, null, null); - RosetteEntity e2 = new RosetteEntity("Dan Akroyd", "Dan Akroyd", new EntityID("Q105221"), "PERSON", 2, 0.99, "X1", null, new List() { new MentionOffset(0, 10), new MentionOffset(20, 32) }, .99, 0.0, null); - List entities = new List() { e0, e1, e2 }; + RosetteEntity e0 = new("Dan Akroyd", "Dan Akroyd", new EntityID("Q105221"), "PERSON", 2, 0.99, "X1", null, [new(0, 10), new(20,32)], .99, 1, null); + RosetteEntity e1 = new("The Hollywood Reporter", "The Hollywood Reporter", new EntityID("Q61503"), "ORGANIZATION", 1, null, "X1", null, [new(15, 18)], null, null, null); + RosetteEntity e2 = new("Dan Akroyd", "Dan Akroyd", new EntityID("Q105221"), "PERSON", 2, 0.99, "X1", null, [new(0, 10), new(20, 32)], .99, 0.0, null); + List entities = [e0, e1, e2]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "entities", entities } }; - EntitiesResponse expected = new EntitiesResponse(entities, responseHeaders, content, null); + EntitiesResponse expected = new(entities, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "entities").Respond(req => mockedMessage); EntitiesResponse response = _rosetteApi.Entity("Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”"); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -857,32 +846,32 @@ public void EntityTestExtendedProperties() { String e_normalized = "Toyota"; Nullable e_count = 1; Nullable e_confidence = null; - List e_mentionOffsets = new List() { new MentionOffset(0, 6) }; - EntityID e_entityID = new EntityID("Q53268"); + List e_mentionOffsets = [new MentionOffset(0, 6)]; + EntityID e_entityID = new("Q53268"); Nullable e_linkingConfidence = 0.14286868; Nullable e_salience = null; String e_dbpediaType = "Agent/Organisation"; - List e_dbpediaTypes = new List() {"Agent/Organisation"}; + List e_dbpediaTypes = ["Agent/Organisation"]; String e_permId = "4295876746"; - RosetteEntity e = new RosetteEntity(e_mention, e_normalized, e_entityID, e_type, e_count, e_confidence, + RosetteEntity e = new(e_mention, e_normalized, e_entityID, e_type, e_count, e_confidence, e_dbpediaType, e_dbpediaTypes, e_mentionOffsets, e_linkingConfidence, e_salience, e_permId); - List entities = new List() { e }; - Dictionary content = new Dictionary { { "entities", entities } }; + List entities = [e]; + Dictionary content = new() { { "entities", entities } }; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); - EntitiesResponse expected = new EntitiesResponse(entities, responseHeaders, content, null); + EntitiesResponse expected = new(entities, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "entities").Respond(req => mockedMessage); EntitiesResponse response = _rosetteApi.Entity("Toyota"); - Assert.AreEqual(expected, response); - Assert.AreEqual(expected.Entities[0].PermID, response.Entities[0].PermID); - Assert.AreEqual(expected.Entities[0].DBpediaType, response.Entities[0].DBpediaType); - Assert.AreEqual(expected.Entities[0].DBpediaTypes, response.Entities[0].DBpediaTypes); + Assert.That(response, Is.EqualTo(expected)); + Assert.That(response.Entities[0].PermID, Is.EqualTo(expected.Entities[0].PermID)); + Assert.That(response.Entities[0].DBpediaType, Is.EqualTo(expected.Entities[0].DBpediaType)); + Assert.That(response.Entities[0].DBpediaTypes, Is.EqualTo(expected.Entities[0].DBpediaTypes)); } [Test] @@ -891,9 +880,7 @@ public void Entity_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Entity("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -902,9 +889,7 @@ public void Entity_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Entity(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -912,18 +897,16 @@ public void Entity_File_Test() { _mockHttp.When(_testUrl + "entities") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Entity(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] public void EntityIDLinkNullOnSetToNull() { - EntityID eid = new EntityID(null); - Assert.AreEqual(null, eid.GetWikipedaURL()); + EntityID eid = new(null); + Assert.That(eid.GetWikipedaURL(), Is.Null); } //------------------------- Event ---------------------------------------- @@ -931,23 +914,24 @@ public void EntityIDLinkNullOnSetToNull() public void EventTestFull() { Init(); - RosetteEvent e0 = new RosetteEvent("DATA-1275-Meet-Travel.TRAVEL", new List() { - new EventMention(new List { new EventRole("key", "E1", "travel", null, null, null, 15, 21) }, - "Negative", null, new List { new NegationCue("not", 11, 14) }, 15, 21) }, 0.3333333333333333, "test"); + RosetteEvent e0 = new("DATA-1275-Meet-Travel.TRAVEL", [ + new([new("key", "E1", "travel", null, null, null, 15, 21)], + "Negative", null, [new("not", 11, 14)], 15, 21) ], 0.3333333333333333, "test"); - List events = new List() { e0 }; + List events = [e0]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "events", events } }; - EventsResponse expected = new EventsResponse(events, responseHeaders, content, null); + EventsResponse expected = new(events, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "events").Respond(req => mockedMessage); _rosetteApi.SetOption("negation", "BOTH"); EventsResponse response = _rosetteApi.Event("Vivian went to Moscow."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -957,9 +941,7 @@ public void Event_Content_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Event("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -969,9 +951,7 @@ public void Event_Dict_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Event(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -980,11 +960,9 @@ public void Event_File_Test() _mockHttp.When(_testUrl + "events") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Event(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Language ---------------------------------------- @@ -993,27 +971,28 @@ public void Event_File_Test() public void LanguageTestFull() { Init(); - LanguageDetection lang0 = new LanguageDetection("spa", (decimal)0.38719602327387076); - LanguageDetection lang1 = new LanguageDetection("eng", (decimal)0.32699986625091865); - LanguageDetection lang2 = new LanguageDetection("por", (decimal)0.05569054210624943); - LanguageDetection lang3 = new LanguageDetection("deu", (decimal)0.030069489878380328); - LanguageDetection lang4 = new LanguageDetection("zho", (decimal)0.23572849069656435); - LanguageDetection lang5 = new LanguageDetection("swe", (decimal)0.027734757034048835); - LanguageDetection lang6 = new LanguageDetection("ces", (decimal)0.02583105013400886); - LanguageDetection lang7 = new LanguageDetection("fin", (decimal)0.23572849069656435); - LanguageDetection lang8 = new LanguageDetection("fra", (decimal)0.023298946617300347); - List languageDetections = new List() { lang0, lang1, lang2, lang3, lang4, lang5, lang6, lang7, lang8 }; + LanguageDetection lang0 = new("spa", (decimal)0.38719602327387076); + LanguageDetection lang1 = new("eng", (decimal)0.32699986625091865); + LanguageDetection lang2 = new("por", (decimal)0.05569054210624943); + LanguageDetection lang3 = new("deu", (decimal)0.030069489878380328); + LanguageDetection lang4 = new("zho", (decimal)0.23572849069656435); + LanguageDetection lang5 = new("swe", (decimal)0.027734757034048835); + LanguageDetection lang6 = new("ces", (decimal)0.02583105013400886); + LanguageDetection lang7 = new("fin", (decimal)0.23572849069656435); + LanguageDetection lang8 = new("fra", (decimal)0.023298946617300347); + List languageDetections = [lang0, lang1, lang2, lang3, lang4, lang5, lang6, lang7, lang8]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "languageDetections", languageDetections } }; - LanguageIdentificationResponse expected = new LanguageIdentificationResponse(languageDetections, responseHeaders, content, null); + LanguageIdentificationResponse expected = new(languageDetections, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "language").Respond(req => mockedMessage); LanguageIdentificationResponse response = _rosetteApi.Language("Por favor Señorita, says the man."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1022,9 +1001,7 @@ public void Language_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Language("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1033,9 +1010,7 @@ public void Language_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Language(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1043,11 +1018,9 @@ public void Language_File_Test() { _mockHttp.When(_testUrl + "language") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Language(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Morphology ---------------------------------------- @@ -1055,103 +1028,107 @@ public void Language_File_Test() { public void MorphologyTestFullComplete() { Init(); - MorphologyItem m0 = new MorphologyItem("The", "DET", "the", new List(), new List()); - MorphologyItem m1 = new MorphologyItem("quick", "ADJ", "quick", new List(), new List()); - MorphologyItem m2 = new MorphologyItem("brown", "ADJ", "brown", new List(), new List()); - MorphologyItem m3 = new MorphologyItem("fox", "NOUN", "fox", new List(), new List()); - MorphologyItem m4 = new MorphologyItem("jumped", "VERB", "jump", new List(), new List()); - MorphologyItem m5 = new MorphologyItem(".", "PUNCT", ".", new List(), new List()); - List morphology = new List() { m0, m1, m2, m3, m4, m5 }; + MorphologyItem m0 = new("The", "DET", "the", [], []); + MorphologyItem m1 = new("quick", "ADJ", "quick", [], []); + MorphologyItem m2 = new("brown", "ADJ", "brown", [], []); + MorphologyItem m3 = new("fox", "NOUN", "fox", [], []); + MorphologyItem m4 = new("jumped", "VERB", "jump", [], []); + MorphologyItem m5 = new(".", "PUNCT", ".", [], []); + List morphology = [m0, m1, m2, m3, m4, m5]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "tokens", new List(morphology.Select((item) => item.Token)) }, { "posTags", new List(morphology.Select((item) => item.PosTag)) }, { "lemmas", new List(morphology.Select((item) => item.Lemma)) }, { "compoundComponents", new List>(morphology.Select>((item) => item.CompoundComponents)) }, { "hanReadings", new List>(morphology.Select>((item) => item.HanReadings)) } }; - MorphologyResponse expected = new MorphologyResponse(morphology, responseHeaders, content, null); + MorphologyResponse expected = new(morphology, responseHeaders, content, null); String mockedContent = expected.ContentAsJson; HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "morphology/complete").Respond(req => mockedMessage); MorphologyResponse response = _rosetteApi.Morphology("The quick brown fox jumped."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] public void MorphologyTestFullLemmas() { Init(); - MorphologyItem m0 = new MorphologyItem("The", null, "the", null, null); - MorphologyItem m1 = new MorphologyItem("quick", null, "quick", null, null); - MorphologyItem m2 = new MorphologyItem("brown", null, "brown", null, null); - MorphologyItem m3 = new MorphologyItem("fox", null, "fox", null, null); - MorphologyItem m4 = new MorphologyItem("jumped", null, "jump", null, null); - MorphologyItem m5 = new MorphologyItem(".", null, ".", null, null); - List morphology = new List() { m0, m1, m2, m3, m4, m5 }; + MorphologyItem m0 = new("The", null, "the", null, null); + MorphologyItem m1 = new("quick", null, "quick", null, null); + MorphologyItem m2 = new("brown", null, "brown", null, null); + MorphologyItem m3 = new("fox", null, "fox", null, null); + MorphologyItem m4 = new("jumped", null, "jump", null, null); + MorphologyItem m5 = new(".", null, ".", null, null); + List morphology = [m0, m1, m2, m3, m4, m5]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "tokens", new List(morphology.Select((item) => item.Token)) } }; ; content.Add("lemmas", new List(morphology.Select((item) => item.Lemma))); - MorphologyResponse expected = new MorphologyResponse(morphology, responseHeaders, content, null); + MorphologyResponse expected = new(morphology, responseHeaders, content, null); String mockedContent = expected.ContentAsJson; HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "morphology/lemmas").Respond(req => mockedMessage); MorphologyResponse response = _rosetteApi.Morphology("The quick brown fox jumped.", feature: MorphologyFeature.lemmas); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] public void MorphologyTestFullCompoundComponents() { Init(); - MorphologyItem m0 = new MorphologyItem("Er", null, null, new List(), null); - List compoundComponents = new List() { "Rechts", "Schutz", "Versicherungs", "Gesellschaft" }; - MorphologyItem m1 = new MorphologyItem("Rechtsschutzversicherungsgesellschaft", null, null, compoundComponents, null); - List morphology = new List() { m0, m1 }; + MorphologyItem m0 = new("Er", null, null, [], null); + List compoundComponents = ["Rechts", "Schutz", "Versicherungs", "Gesellschaft"]; + MorphologyItem m1 = new("Rechtsschutzversicherungsgesellschaft", null, null, compoundComponents, null); + List morphology = [m0, m1]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "tokens", new List(morphology.Select((item) => item.Token)) } }; ; content.Add("compoundComponents", new List>(morphology.Select>((item) => item.CompoundComponents))); - MorphologyResponse expected = new MorphologyResponse(morphology, responseHeaders, content, null); + MorphologyResponse expected = new(morphology, responseHeaders, content, null); String mockedContent = expected.ContentAsJson; HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "morphology/compound-components").Respond(req => mockedMessage); MorphologyResponse response = _rosetteApi.Morphology("Er Rechtsschutzversicherungsgesellschaft.", feature: MorphologyFeature.compoundComponents); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] public void MorphologyTestFullHanReadings() { Init(); - List h0 = new List() { "Bei3-jing1-Da4-xue2" }; + List h0 = ["Bei3-jing1-Da4-xue2"]; List h1 = null; - List h2 = new List() { "zhu3-ren4" }; - MorphologyItem m0 = new MorphologyItem("北京大学", null, null, null, h0); - MorphologyItem m1 = new MorphologyItem("生物系", null, null, null, h1); - MorphologyItem m2 = new MorphologyItem("主任", null, null, null, h2); - List morphology = new List() { m0, m1, m2 }; + List h2 = ["zhu3-ren4"]; + MorphologyItem m0 = new("北京大学", null, null, null, h0); + MorphologyItem m1 = new("生物系", null, null, null, h1); + MorphologyItem m2 = new("主任", null, null, null, h2); + List morphology = [m0, m1, m2]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "tokens", new List(morphology.Select((item) => item.Token)) } }; ; content.Add("hanReadings", new List>(morphology.Select>((item) => item.HanReadings))); - MorphologyResponse expected = new MorphologyResponse(morphology, responseHeaders, content, null); + MorphologyResponse expected = new(morphology, responseHeaders, content, null); String mockedContent = expected.ContentAsJson; HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "morphology/han-readings").Respond(req => mockedMessage); MorphologyResponse response = _rosetteApi.Morphology("北京大学生物系主任.", feature: MorphologyFeature.hanReadings); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1160,9 +1137,7 @@ public void Morphology_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Morphology("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1171,9 +1146,7 @@ public void Morphology_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Morphology(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1181,11 +1154,9 @@ public void Morphology_File_Test() { _mockHttp.When(_testUrl + "morphology/complete") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Morphology(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Name Similarity ---------------------------------------- @@ -1195,27 +1166,26 @@ public void NameSimilarityTestFull() Init(); double score = (double)0.9486632809417912; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "score", score } }; - NameSimilarityResponse expected = new NameSimilarityResponse(score, responseHeaders, content, null); + NameSimilarityResponse expected = new(score, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "name-similarity").Respond(req => mockedMessage); NameSimilarityResponse response = _rosetteApi.NameSimilarity(new Name("Влади́мир Влади́мирович Пу́тин", "rus", null, "PERSON", Gender.Male), new Name("Vladmir Putin", "eng", null, "PERSON")); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] public void NameSimilarity_Content_Test() { _mockHttp.When(_testUrl + "name-similarity").Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); - Name name1 = new Name("Name One"); - Name name2 = new Name("Name Two"); + Name name1 = new("Name One"); + Name name2 = new("Name Two"); var response = _rosetteApi.NameSimilarity(name1, name2); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1224,35 +1194,29 @@ public void NameSimilarity_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.NameSimilarity(new Dictionary() { { "name1", "Name One" }, { "name2", "Name Two" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Name Deduplication ---------------------------------------- [Test] public void NameDeduplication_Content_Test() { _mockHttp.When(_testUrl + "name-deduplication").Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); - List dedup_names = new List {"John Smith", "Johnathon Smith", "Fred Jones"}; - List names = dedup_names.Select(name => new Name(name, "eng", "Latn")).ToList(); + List dedup_names = ["John Smith", "Johnathon Smith", "Fred Jones"]; + List names = [.. dedup_names.Select(name => new Name(name, "eng", "Latn"))]; float threshold = 0.75f; var response = _rosetteApi.NameDeduplication(names, threshold); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] public void NameDeduplication_Content_NoThreshold_Test() { _mockHttp.When(_testUrl + "name-deduplication").Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); - List dedup_names = new List {"John Smith", "Johnathon Smith", "Fred Jones"}; - List names = dedup_names.Select(name => new Name(name, "eng", "Latn")).ToList(); + List dedup_names = ["John Smith", "Johnathon Smith", "Fred Jones"]; + List names = [.. dedup_names.Select(name => new Name(name, "eng", "Latn"))]; var response = _rosetteApi.NameDeduplication(names); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1260,21 +1224,19 @@ public void NameDeduplication_Dict_Test() { _mockHttp.When(_testUrl + "name-deduplication") .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); - List dedup_names = new List {"John Smith", "Johnathon Smith", "Fred Jones"}; - Dictionary dict = new Dictionary() { + List dedup_names = ["John Smith", "Johnathon Smith", "Fred Jones"]; + Dictionary dict = new() { { "names", dedup_names.Select(name => new Name(name, "eng", "Latn"))}, { "threshold", 0.75f }}; var response = _rosetteApi.NameDeduplication(dict); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Record-Similarity ---------------------------------------- private RecordSimilarityRequest CreateTestRecordSimilarityRequest(string name, string dob, string address, string job, string age, string retired) { // Creating the request object - Dictionary fields = new Dictionary + Dictionary fields = new() { { name, new RecordSimilarityFieldInfo { Type = RecordFieldType.RniName, Weight = 0.5 } }, { dob, new RecordSimilarityFieldInfo { Type = RecordFieldType.RniDate, Weight = 0.2 } }, @@ -1284,13 +1246,13 @@ private RecordSimilarityRequest CreateTestRecordSimilarityRequest(string name, s { retired, new RecordSimilarityFieldInfo { Type = RecordFieldType.RniBoolean, Weight = 0.05 } } }; - RecordSimilarityProperties properties = new RecordSimilarityProperties { Threshold = 0.7, IncludeExplainInfo = false }; + RecordSimilarityProperties properties = new() { Threshold = 0.7, IncludeExplainInfo = false }; - RecordSimilarityRecords records = new RecordSimilarityRecords { - Left = new List> - { - new Dictionary - { + RecordSimilarityRecords records = new() + { + Left = + [ + new() { { name, new FieldedNameRecord { Text = "Ethan R", Language = "eng", LanguageOfOrigin = "eng", Script = "Latn", EntityType = "PERSON"} }, { dob, new UnfieldedDateRecord { Date = "1993-04-16"} }, { address, new UnfieldedAddressRecord { Address = "123 Roadlane Ave"}}, @@ -1298,21 +1260,20 @@ private RecordSimilarityRequest CreateTestRecordSimilarityRequest(string name, s { age, new NumberRecord { Number = 77 } }, { retired, new BooleanRecord { Boolean = true } } } - }, - Right = new List> - { - new Dictionary - { + ], + Right = + [ + new() { { name, new UnfieldedNameRecord { Text = "Ivan R"} }, { dob, new FieldedDateRecord { Date = "1993/04/16"} }, { address, new FieldedAddressRecord { HouseNumber = "234", Road = "Roadlane Ave"} }, { age, new NumberRecord { Number = 47 } }, { retired, new BooleanRecord { Boolean = false } } } - } + ] }; - RecordSimilarityRequest request = new RecordSimilarityRequest + RecordSimilarityRequest request = new() { Fields = fields, Properties = properties, @@ -1341,10 +1302,10 @@ public void RecordSimilarity_Request_Test() { RecordSimilarityRequest request = CreateTestRecordSimilarityRequest(name, dob, address, job, age, retired); var response = _rosetteApi.RecordSimilarity(request); - Assert.AreEqual(response.Content["response"], "OK"); + Assert.That(response.Content["response"], Is.EqualTo("OK")); } - private JToken getJTokenFromField(RecordSimilarityField field) { + private JToken GetJTokenFromField(RecordSimilarityField field) { return JToken.FromObject(field); } @@ -1364,42 +1325,45 @@ public void RecordSimilarity_WithoutExplainInfo_Test() { RecordSimilarityRequest request = CreateTestRecordSimilarityRequest(name, dob, address, job, age, retired); //creating response headers string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - - UnfieldedAddressRecord addressUnfielded = new UnfieldedAddressRecord { Address = "123 Roadlane Ave" }; - UnfieldedDateRecord dobUnfielded = new UnfieldedDateRecord { Date = "1993-04-16" }; - FieldedNameRecord nameFielded = new FieldedNameRecord { Text = "Ethan R", Language = "eng", LanguageOfOrigin = "eng", Script = "Latn", EntityType = "PERSON" }; - Dictionary left = new Dictionary { - {address, new UnknownFieldRecord(getJTokenFromField(addressUnfielded)) }, - {dob, new UnknownFieldRecord(getJTokenFromField(dobUnfielded)) }, - {name, new UnknownFieldRecord(getJTokenFromField(nameFielded)) }, + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + + UnfieldedAddressRecord addressUnfielded = new() { Address = "123 Roadlane Ave" }; + UnfieldedDateRecord dobUnfielded = new() { Date = "1993-04-16" }; + FieldedNameRecord nameFielded = new() { Text = "Ethan R", Language = "eng", LanguageOfOrigin = "eng", Script = "Latn", EntityType = "PERSON" }; + Dictionary left = new() + { + {address, new UnknownFieldRecord(GetJTokenFromField(addressUnfielded)) }, + {dob, new UnknownFieldRecord(GetJTokenFromField(dobUnfielded)) }, + {name, new UnknownFieldRecord(GetJTokenFromField(nameFielded)) }, }; - FieldedAddressRecord addressFielded = new FieldedAddressRecord { HouseNumber = "234", Road = "Roadlane Ave" }; - FieldedDateRecord dobFielded = new FieldedDateRecord { Date = "1993/04/16" }; - UnfieldedNameRecord nameUnfielded = new UnfieldedNameRecord { Text = "Ivan R" }; - Dictionary right = new Dictionary { - {address, new UnknownFieldRecord(getJTokenFromField(addressFielded)) }, - {dob, new UnknownFieldRecord(getJTokenFromField(dobFielded)) }, - {name, new UnknownFieldRecord(getJTokenFromField(nameUnfielded)) }, + FieldedAddressRecord addressFielded = new() { HouseNumber = "234", Road = "Roadlane Ave" }; + FieldedDateRecord dobFielded = new() { Date = "1993/04/16" }; + UnfieldedNameRecord nameUnfielded = new() { Text = "Ivan R" }; + Dictionary right = new() + { + {address, new UnknownFieldRecord(GetJTokenFromField(addressFielded)) }, + {dob, new UnknownFieldRecord(GetJTokenFromField(dobFielded)) }, + {name, new UnknownFieldRecord(GetJTokenFromField(nameUnfielded)) }, }; - RecordSimilarityResult result = new RecordSimilarityResult(0.72, left, right, null, null, null); - List results = new List { result }; + RecordSimilarityResult result = new(0.72, left, right, null, null, null); + List results = [result]; - Dictionary content = new Dictionary { + Dictionary content = new() + { { "results", results } }; RecordSimilarityResponse expected = - new RecordSimilarityResponse(results, null, null, responseHeaders, content, null); + new(results, null, null, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "record-similarity").Respond(req => mockedMessage); RecordSimilarityResponse response = _rosetteApi.RecordSimilarity(request); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } @@ -1414,9 +1378,7 @@ public void Transliteration_Content_Test() { var response = _rosetteApi.Transliteration(transliteration_data, language); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1424,15 +1386,13 @@ public void Transliteration_Dict_Test() { _mockHttp.When(_testUrl + "transliteration") .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); - Dictionary dict = new Dictionary() { + Dictionary dict = new() { { "content", "haza ya7taj fakat ila an takoun ba3dh el-nousous allati na7n ymkn an tata7awal ila al-3arabizi."}, { "language", "ara" } }; var response = _rosetteApi.Transliteration(dict); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } @@ -1446,22 +1406,23 @@ public void RelationshipsTestFull() string arg1 = "The Ghostbusters movie"; string arg1ID = "Q20120108"; string loc1 = "in Boston"; - List locatives = new List() {loc1}; - HashSet modalities = new HashSet() {"assertion", "someOtherModality"}; + List locatives = [loc1]; + HashSet modalities = ["assertion", "someOtherModality"]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - List relationships = new List() { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + List relationships = [ new RosetteRelationship(predicate, new Dictionary() {{1, arg1}}, new Dictionary() {{1, arg1ID}}, null, locatives, null, confidence, modalities) - }; - Dictionary content = new Dictionary { + ]; + Dictionary content = new() + { { "relationships", relationships } }; - RelationshipsResponse expected = new RelationshipsResponse(relationships, responseHeaders, content, null); + RelationshipsResponse expected = new(relationships, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "relationships").Respond(req => mockedMessage); RelationshipsResponse response = _rosetteApi.Relationships("The Ghostbusters movie was filmed in Boston."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1472,22 +1433,23 @@ public void RelationshipsTestFullNoArgID() string predicate = "be filmed"; string arg1 = "The Ghostbusters movie"; string loc1 = "in Boston"; - List locatives = new List() { loc1 }; - HashSet modalities = new HashSet() { "assertion", "someOtherModality" }; + List locatives = [loc1]; + HashSet modalities = ["assertion", "someOtherModality"]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - List relationships = new List() { - new RosetteRelationship(predicate, new Dictionary() {{1, arg1}}, new Dictionary(), null, locatives, null, confidence, modalities) - }; - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + List relationships = [ + new RosetteRelationship(predicate, new Dictionary() {{1, arg1}}, [], null, locatives, null, confidence, modalities) + ]; + Dictionary content = new() + { { "relationships", relationships } }; - RelationshipsResponse expected = new RelationshipsResponse(relationships, responseHeaders, content, null); + RelationshipsResponse expected = new(relationships, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "relationships").Respond(req => mockedMessage); RelationshipsResponse response = _rosetteApi.Relationships("The Ghostbusters movie was filmed in Boston."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1498,11 +1460,11 @@ public void Relationships_All_Constructors_Equal_Test() string predicate = "be filmed"; string arg1 = "The Ghostbusters movie"; string loc1 = "in Boston"; - List locatives = new List() {loc1}; - RosetteRelationship relationshipFromOriginalConstructor = new RosetteRelationship(predicate, new List() {arg1}, null, locatives, null, confidence); - RosetteRelationship relationshipFromDoubleDictConstructor = new RosetteRelationship(predicate, new Dictionary() {{1, arg1}}, new Dictionary(), null, locatives, null, confidence, null); - RosetteRelationship relationshipFromFullArgumentsConstructor = new RosetteRelationship(predicate, new List() {new Argument(1, arg1, null)}, null, locatives, null, confidence, null); - Assert.True(relationshipFromOriginalConstructor.Equals(relationshipFromDoubleDictConstructor) && relationshipFromDoubleDictConstructor.Equals(relationshipFromFullArgumentsConstructor) && + List locatives = [loc1]; + RosetteRelationship relationshipFromOriginalConstructor = new(predicate, [arg1], null, locatives, null, confidence); + RosetteRelationship relationshipFromDoubleDictConstructor = new(predicate, new Dictionary() {{1, arg1}}, [], null, locatives, null, confidence, null); + RosetteRelationship relationshipFromFullArgumentsConstructor = new(predicate, [new(1, arg1, null)], null, locatives, null, confidence, null); + Assert.That(relationshipFromOriginalConstructor.Equals(relationshipFromDoubleDictConstructor) && relationshipFromDoubleDictConstructor.Equals(relationshipFromFullArgumentsConstructor) && relationshipFromOriginalConstructor.ToString().Equals(relationshipFromDoubleDictConstructor.ToString()) && relationshipFromDoubleDictConstructor.ToString().Equals(relationshipFromFullArgumentsConstructor.ToString())); } @@ -1512,9 +1474,7 @@ public void Relationships_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Relationships("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1523,9 +1483,7 @@ public void Relationships_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Relationships(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1533,11 +1491,9 @@ public void Relationships_File_Test() { _mockHttp.When(_testUrl + "relationships") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Relationships(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Semantic Vectors ---------------------------------------- @@ -1545,20 +1501,21 @@ public void Relationships_File_Test() { public void SemanticVectorsTestFull() { Init(); - List vector = new List() {0.02164695, 0.0032850206, 0.0038508752, -0.009704393, -0.0016203842}; + List vector = [0.02164695, 0.0032850206, 0.0038508752, -0.009704393, -0.0016203842]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "documentEmbedding", vector }, { "tokens", null }, { "tokenEmbeddings", null } }; - SemanticVectorsResponse expected = new SemanticVectorsResponse(vector, null, null, responseHeaders, content, null); + SemanticVectorsResponse expected = new(vector, null, null, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "semantics/vector").Respond(req => mockedMessage); SemanticVectorsResponse response = _rosetteApi.SemanticVectors("The Ghostbusters movie was filmed in Boston."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1568,9 +1525,7 @@ public void SemanticVectors_Content_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.SemanticVectors("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1580,9 +1535,7 @@ public void SemanticVectors_Dict_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.SemanticVectors(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1591,11 +1544,9 @@ public void SemanticVectors_File_Test() _mockHttp.When(_testUrl + "semantics/vector") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.SemanticVectors(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Similar Terms ---------------------------------------- @@ -1604,19 +1555,19 @@ public void SimilarTermsTestFull() { Init(); IDictionary> terms = new Dictionary>() { - {"eng", new List() {new SimilarTerm("spy", 1.0m)}} + {"eng", new List() {new("spy", 1.0m)}} }; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary() { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() { {"similarTerms", terms} }; - SimilarTermsResponse expected = new SimilarTermsResponse(terms, responseHeaders, content, null); + SimilarTermsResponse expected = new(terms, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "semantics/similar").Respond(req => mockedMessage); SimilarTermsResponse response = _rosetteApi.SimilarTerms("spy"); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1626,9 +1577,7 @@ public void SimilarTerms_Content_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.SimilarTerms("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1638,9 +1587,7 @@ public void SimilarTerms_Dict_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.SimilarTerms(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1649,11 +1596,9 @@ public void SimilarTerms_File_Test() _mockHttp.When(_testUrl + "semantics/similar") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.SimilarTerms(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Sentences ---------------------------------------- @@ -1665,18 +1610,19 @@ public void SentencesTestFull() string s0 = "This land is your land. "; string s1 = "This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\n"; string s2 = "As I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me."; - List sentences = new List() { s0, s1, s2 }; + List sentences = [s0, s1, s2]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "sentences", sentences } }; - SentenceTaggingResponse expected = new SentenceTaggingResponse(sentences, responseHeaders, content, null); + SentenceTaggingResponse expected = new(sentences, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "sentences").Respond(req => mockedMessage); SentenceTaggingResponse response = _rosetteApi.Sentences("This land is your land. This land is my land\\nFrom California to the New York island;\\nFrom the red wood forest to the Gulf Stream waters\\n\\nThis land was made for you and Me.\\n\\nAs I was walking that ribbon of highway,\\nI saw above me that endless skyway:\\nI saw below me that golden valley:\\nThis land was made for you and me."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1685,9 +1631,7 @@ public void Sentences_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Sentences("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1696,9 +1640,7 @@ public void Sentences_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Sentences(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1706,11 +1648,9 @@ public void Sentences_File_Test() { _mockHttp.When(_testUrl + "sentences") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Sentences(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Sentiment ---------------------------------------- @@ -1718,22 +1658,23 @@ public void Sentences_File_Test() { public void SentimentTestFull() { Init(); - SentimentResponse.RosetteSentiment docSentiment = new SentimentResponse.RosetteSentiment("pos", (double)0.7962072011038756); - RosetteSentimentEntity e0 = new RosetteSentimentEntity("Dan Akroyd", "Dan Akroyd", new EntityID("Q105221"), "PERSON", 2, docSentiment, (double)0.5005508052749595, null, null, new List() { new MentionOffset(0, 10), new MentionOffset(20, 32) }, .99, 1, null); - RosetteSentimentEntity e1 = new RosetteSentimentEntity("The Hollywood Reporter", "The Hollywood Reporter", new EntityID("Q61503"), "ORGANIZATION", 1, docSentiment, (double)0.5338094035254866, null, null, new List() { new MentionOffset(15, 18) }, null, null, null); - List entities = new List() { e0, e1 }; + SentimentResponse.RosetteSentiment docSentiment = new("pos", (double)0.7962072011038756); + RosetteSentimentEntity e0 = new("Dan Akroyd", "Dan Akroyd", new EntityID("Q105221"), "PERSON", 2, docSentiment, (double)0.5005508052749595, null, null, [new(0, 10), new(20, 32)], .99, 1, null); + RosetteSentimentEntity e1 = new("The Hollywood Reporter", "The Hollywood Reporter", new EntityID("Q61503"), "ORGANIZATION", 1, docSentiment, (double)0.5338094035254866, null, null, [new(15, 18)], null, null, null); + List entities = [e0, e1]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "document", docSentiment }, { "entities", entities } }; - SentimentResponse expected = new SentimentResponse(docSentiment, entities, responseHeaders, content, null); + SentimentResponse expected = new(docSentiment, entities, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "sentiment").Respond(req => mockedMessage); SentimentResponse response = _rosetteApi.Sentiment("Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”"); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1742,9 +1683,7 @@ public void Sentiment_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Sentiment("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1753,9 +1692,7 @@ public void Sentiment_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Sentiment(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1763,38 +1700,37 @@ public void Sentiment_File_Test() { _mockHttp.When(_testUrl + "sentiment") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Sentiment(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Syntax Dependencies ------------------------------------ - public void SyntaxDependenciesTestFull() + private void SyntaxDependenciesTestFull() { Init(); - SyntaxDependenciesResponse.Dependency e0 = new SyntaxDependenciesResponse.Dependency("compound", 1, 0); - SyntaxDependenciesResponse.Dependency e1 = new SyntaxDependenciesResponse.Dependency("nsubj", 3, 1); - SyntaxDependenciesResponse.Dependency e2 = new SyntaxDependenciesResponse.Dependency("aux", 3, 2); - SyntaxDependenciesResponse.Dependency e3 = new SyntaxDependenciesResponse.Dependency("root", -1, 3); - SyntaxDependenciesResponse.Dependency e4 = new SyntaxDependenciesResponse.Dependency("punc", 3, 4); - List dependencies = new List() { e0, e1, e2, e3, e4 }; - SyntaxDependenciesResponse.SentenceWithDependencies sentence = new SyntaxDependenciesResponse.SentenceWithDependencies(0, 4, dependencies); - List sentences = new List() { sentence }; - List tokens = new List() { "Sony", "Pictures", "is", "planning", "."}; + SyntaxDependenciesResponse.Dependency e0 = new("compound", 1, 0); + SyntaxDependenciesResponse.Dependency e1 = new("nsubj", 3, 1); + SyntaxDependenciesResponse.Dependency e2 = new("aux", 3, 2); + SyntaxDependenciesResponse.Dependency e3 = new("root", -1, 3); + SyntaxDependenciesResponse.Dependency e4 = new("punc", 3, 4); + List dependencies = [e0, e1, e2, e3, e4]; + SyntaxDependenciesResponse.SentenceWithDependencies sentence = new(0, 4, dependencies); + List sentences = [sentence]; + List tokens = ["Sony", "Pictures", "is", "planning", "."]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "sentences", sentences }, { "tokens", tokens } }; - SyntaxDependenciesResponse expected = new SyntaxDependenciesResponse(sentences, tokens, responseHeaders, content, null); + SyntaxDependenciesResponse expected = new(sentences, tokens, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "syntax/dependencies").Respond(req => mockedMessage); SyntaxDependenciesResponse response = _rosetteApi.SyntaxDependencies("Sony Pictures is planning."); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1804,9 +1740,7 @@ public void SyntaxDependencies_Content_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); SyntaxDependenciesResponse response = _rosetteApi.SyntaxDependencies("content"); -#pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -#pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1816,9 +1750,7 @@ public void SyntaxDependencies_Dict_Test() .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); SyntaxDependenciesResponse response = _rosetteApi.SyntaxDependencies(new Dictionary() { { "contentUri", "contentUrl" } }); -#pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -#pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1827,11 +1759,9 @@ public void SyntaxDependencies_File_Test() _mockHttp.When(_testUrl + "syntax/dependencies") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); SyntaxDependenciesResponse response = _rosetteApi.SyntaxDependencies(f); -#pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -#pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Tokens ---------------------------------------- @@ -1839,25 +1769,26 @@ public void SyntaxDependencies_File_Test() public void TokensTestFull() { Init(); - List tokens = new List() { + List tokens = [ "北京大学", "生物系", "主任", "办公室", "内部", "会议" - }; + ]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "tokens", tokens } }; - TokenizationResponse expected = new TokenizationResponse(tokens, responseHeaders, content, null); + TokenizationResponse expected = new(tokens, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "tokens").Respond(req => mockedMessage); TokenizationResponse response = _rosetteApi.Tokens("北京大学生物系主任办公室内部会议"); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1866,9 +1797,7 @@ public void Tokens_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Tokens("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1877,9 +1806,7 @@ public void Tokens_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Tokens(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1887,11 +1814,9 @@ public void Tokens_File_Test() { _mockHttp.When(_testUrl + "tokens") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Tokens(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Name Translation ---------------------------------------- @@ -1905,25 +1830,26 @@ public void NameTranslationTestFull() string targetScheme = "IC"; double confidence = (double)0.06856099342585828; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "translation", translation }, { "targetLanguage", targetLanguage }, { "targetScript", targetScript }, { "targetScheme", targetScheme }, { "confidence", confidence } }; - TranslateNamesResponse expected = new TranslateNamesResponse(translation, targetLanguage: targetLanguage, targetScript:targetScript, targetScheme:targetScheme, confidence: confidence, responseHeaders:responseHeaders, content: content); + TranslateNamesResponse expected = new(translation, targetLanguage: targetLanguage, targetScript:targetScript, targetScheme:targetScheme, confidence: confidence, responseHeaders:responseHeaders, content: content); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "name-translation").Respond(req => mockedMessage); - Dictionary input = new Dictionary() { + Dictionary input = new() { {"name", "معمر محمد أبو منيار القذاف"}, {"targetLanguage", "eng"}, {"targetScript", "Latn"} }; TranslateNamesResponse response = _rosetteApi.NameTranslation(input); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1932,9 +1858,7 @@ public void NameTranslation_Content_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.NameTranslation("content"); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -1942,7 +1866,7 @@ public void NameTranslation_Dict_Test() { _mockHttp.When(_testUrl + "name-translation") .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); - Dictionary sampleDict = new Dictionary(){ + Dictionary sampleDict = new(){ { "name", "name"}, { "sourceLanguageOfUse", "sourceLanguageOfUse"}, { "sourceScript", "sourceScript"}, @@ -1953,36 +1877,35 @@ public void NameTranslation_Dict_Test() { { "entityType", "entityType"} }; var response = _rosetteApi.NameTranslation(sampleDict); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } //------------------------- Topics ---------------------------------------- [Test] public void TopicsTestFull() { Init(); - List concepts = new List() { + List concepts = [ new Concept("Unfinished Tales", null, "Q309019"), new Concept("Nicholas Hoult", null, "Q298347") - }; - List keyPhrases = new List() { + ]; + List keyPhrases = [ new KeyPhrase("Scorpius Malfoy", null), new KeyPhrase("Nicholas Hoult", null) - }; + ]; string headersAsString = " { \"Content-Type\": \"application/json\", \"Date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"Server\": \"openresty\", \"Strict-Transport-Security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"Content-Length\": \"72\", \"Connection\": \"Close\" }"; - Dictionary responseHeaders = new JavaScriptSerializer().Deserialize>(headersAsString); - Dictionary content = new Dictionary { + Dictionary responseHeaders = JsonConvert.DeserializeObject>(headersAsString); + Dictionary content = new() + { { "concepts", concepts }, { "keyphrases", keyPhrases } }; - TopicsResponse expected = new TopicsResponse(concepts, keyPhrases, responseHeaders, content, null); + TopicsResponse expected = new(concepts, keyPhrases, responseHeaders, content, null); String mockedContent = expected.ContentToString(); HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent); _mockHttp.When(_testUrl + "topics").Respond(req => mockedMessage); string testContent = @"Lily Collins is in talks to join Nicholas Hoult in Chernin Entertainment and Fox Searchlights J.R.R. Tolkien biopic Tolkien. Anthony Boyle, known for playing Scorpius Malfoy in the British play Harry Potter and the Cursed Child, also has signed on for the film centered on the famed author. In Tolkien, Hoult will play the author of the Hobbit and Lord of the Rings book series that were later adapted into two Hollywood trilogies from Peter Jackson. Dome Karukoski is directing the project."; TopicsResponse response = _rosetteApi.Topics(content: testContent); - Assert.AreEqual(expected, response); + Assert.That(response, Is.EqualTo(expected)); } [Test] @@ -1991,9 +1914,7 @@ public void Topics_Dict_Test() { .Respond(HttpStatusCode.OK, "application/json", "{'response': 'OK'}"); var response = _rosetteApi.Topics(new Dictionary() { { "contentUri", "contentUrl" } }); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } [Test] @@ -2001,11 +1922,9 @@ public void Topics_File_Test() { _mockHttp.When(_testUrl + "topics") .Respond("application/json", "{'response': 'OK'}"); - RosetteFile f = new RosetteFile(_tmpFile); + RosetteFile f = new(_tmpFile); var response = _rosetteApi.Topics(f); -# pragma warning disable 618 - Assert.AreEqual(response.Content["response"], "OK"); -# pragma warning restore 618 + Assert.That(response.Content["response"], Is.EqualTo("OK")); } } @@ -2017,78 +1936,78 @@ public class Rosette_UtilitiesTests { public void DictionaryEquals_with_null() { Dictionary dict1 = null; Dictionary dict2 = null; - Assert.True(Utilities.DictionaryEquals(dict1, dict2)); + Assert.That(Utilities.DictionaryEquals(dict1, dict2)); } [Test] public void DictionaryEquals_with_one_null() { Dictionary dict1 = null; - Dictionary dict2 = new Dictionary() { + Dictionary dict2 = new() { {"key1", "value1"} }; - Assert.False(Utilities.DictionaryEquals(dict1, dict2)); + Assert.That(Utilities.DictionaryEquals(dict1, dict2), Is.False); } [Test] public void DictionaryEquals_with_different_count() { - Dictionary dict1 = new Dictionary(); - Dictionary dict2 = new Dictionary() { + Dictionary dict1 = []; + Dictionary dict2 = new() { {"key1", "value1"} }; - Assert.False(Utilities.DictionaryEquals(dict1, dict2)); + Assert.That(Utilities.DictionaryEquals(dict1, dict2), Is.False); } [Test] public void DictionaryEquals_with_different_keys() { - Dictionary dict1 = new Dictionary() { + Dictionary dict1 = new() { {"key1", "value1"} }; - Dictionary dict2 = new Dictionary() { + Dictionary dict2 = new() { {"key2", "value1"} }; - Assert.False(Utilities.DictionaryEquals(dict1, dict2)); + Assert.That(Utilities.DictionaryEquals(dict1, dict2), Is.False); } [Test] public void DictionaryEquals_with_different_values() { - Dictionary dict1 = new Dictionary() { + Dictionary dict1 = new() { {"key1", "value1"} }; - Dictionary dict2 = new Dictionary() { + Dictionary dict2 = new() { {"key1", "value2"} }; - Assert.False(Utilities.DictionaryEquals(dict1, dict2)); + Assert.That(Utilities.DictionaryEquals(dict1, dict2), Is.False); } [Test] public void DictionaryEquals_with_same_order() { - Dictionary dict1 = new Dictionary() { + Dictionary dict1 = new() { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; - Dictionary dict2 = new Dictionary() { + Dictionary dict2 = new() { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; - Assert.True(Utilities.DictionaryEquals(dict1, dict2)); + Assert.That(Utilities.DictionaryEquals(dict1, dict2)); } [Test] public void DictionaryEquals_with_different_order() { - Dictionary dict1 = new Dictionary() { + Dictionary dict1 = new() { {"key3", "value3"}, {"key2", "value2"}, {"key1", "value1"} }; - Dictionary dict2 = new Dictionary() { + Dictionary dict2 = new() { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; - Assert.True(Utilities.DictionaryEquals(dict1, dict2)); + Assert.That(Utilities.DictionaryEquals(dict1, dict2)); } } } diff --git a/rosette_apiUnitTests/rosette_apiUnitTests.csproj b/rosette_apiUnitTests/rosette_apiUnitTests.csproj index fe8d3cc8..6cfbaab7 100644 --- a/rosette_apiUnitTests/rosette_apiUnitTests.csproj +++ b/rosette_apiUnitTests/rosette_apiUnitTests.csproj @@ -1,150 +1,32 @@ - - - + + - Debug - AnyCPU - {10EAD22C-041F-4436-A391-935897309C23} - Library - Properties - rosette_apiUnitTests - rosette_apiUnitTests - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - + net10.0 + latest + enable + enable + false + - - ..\packages\LinqToExcel.1.11.0\lib\LinqToExcel.dll - - - ..\packages\log4net.2.0.15\lib\net45\log4net.dll - - - ..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll - - - ..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll - - - ..\packages\LinqToExcel.1.11.0\lib\Remotion.dll - - - ..\packages\LinqToExcel.1.11.0\lib\Remotion.Data.Linq.dll - - - ..\packages\LinqToExcel.1.11.0\lib\Remotion.Interfaces.dll - - - ..\packages\RichardSzalay.MockHttp.3.2.1\lib\net45\RichardSzalay.MockHttp.dll - - - - 3.5 - - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - - - - - - + - - + + - - {d719a8a7-c5c7-49cf-bffc-523d605e5e37} - rosette_api - + - - - Designer - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file + +