public async Task <StringsModel> LoadAsync(StringsModel stringsModel) { using SqliteConnection connection = await ConnectionFactory.ConnectAsync(); SqliteCommand query = connection.CreateCommand(); query.CommandText = "select String from Strings where Identifier = @Identifier and Locale = @Locale"; query.Parameters.AddWithValue("@Identifier", stringsModel.Identifier); query.Parameters.AddWithValue("@Locale", stringsModel.Locale); SqliteDataReader reader = await query.ExecuteReaderAsync(); if (await reader.ReadAsync()) { stringsModel.String = (string)reader["String"]; } return(stringsModel); }
public IActionResult ComputeLevenshteinDistance(StringsModel stringsModel) { if (stringsModel == null) { return(BadRequest("Invalid argument(s).")); } // if (string.IsNullOrEmpty(stringsModel.FirstString) || string.IsNullOrEmpty(stringsModel.SecondString)) { return(BadRequest("Invalid argument(s).")); } // int n = stringsModel.FirstString.Length; int m = stringsModel.SecondString.Length; IActionResult response = Unauthorized(); LevenshteinDistanceMatrixAndCostResult levenshteinDistanceMatrixAndCostResult = StringDistance.GetLevenshteinDistanceMatrixAndCost(stringsModel.FirstString, stringsModel.SecondString); response = Ok(levenshteinDistanceMatrixAndCostResult); return(response); }
public async Task <IActionResult> GetLevenshteinDistanceResult(StringsViewModel stringsViewModel) { LevenshteinDistanceViewModel levenshteinDistanceViewModel = null; LevenshteinDistanceMatrixAndCostResult levenshteinDistanceMatrixAndCostResult = null; StringsModel stringsModel = null; string JWTToken = null; if (stringsViewModel != null) { stringsModel = new StringsModel { FirstString = stringsViewModel.FirstString , SecondString = stringsViewModel.SecondString }; JWTToken = HttpContext.Session.GetString(accessTokenSession).ToString(); ViewData["JWTToken"] = HttpContext.Session.GetString(accessTokenSession); using (LevenshteinDistanceApiClient levenshteinDistanceApiClient = new LevenshteinDistanceApiClient(this.configuration)) { levenshteinDistanceMatrixAndCostResult = await levenshteinDistanceApiClient.GetLevenshteinDistanceMatrixAndCostResult(stringsModel, JWTToken); } if (levenshteinDistanceMatrixAndCostResult != null) { levenshteinDistanceViewModel = new LevenshteinDistanceViewModel { StringsAsCriteria = new StringsViewModel { FirstString = levenshteinDistanceMatrixAndCostResult.StringsAsCriteria.FirstString , SecondString = levenshteinDistanceMatrixAndCostResult.StringsAsCriteria.SecondString }, ResultTable = new LevenshteinResultTableViewModel { Cost = levenshteinDistanceMatrixAndCostResult.Cost , ResultMatrix = levenshteinDistanceMatrixAndCostResult.MatrixResult } }; } } return(View("Index", levenshteinDistanceViewModel)); }
/// <summary> /// Getting the cost and array containing compute values as matrix. /// </summary> /// <param name="stringsModel">The object containing first and second strings whose distance to be calculated.</param> /// <returns></returns> public async Task <LevenshteinDistanceMatrixAndCostResult> GetLevenshteinDistanceMatrixAndCostResult(StringsModel stringsModel, string JWTToken) { LevenshteinDistanceMatrixAndCostResult levenshteinDistanceMatrixAndCostResult = null; HttpResponseMessage httpResponseMessage = null; Uri resourcePath = null; string requestUri = null; string baseAddress = null; StringBuilder stringBuilder = null; try { baseAddress = configuration.GetValue <string>("MySettings:ApiBaseAddress"); resourcePath = _levenshteinDistanceUri; stringBuilder = new StringBuilder(); stringBuilder.Append(baseAddress); stringBuilder.Append(resourcePath.ToString()); requestUri = stringBuilder.ToString(); // using (var httpclient = new HttpClient()) { httpclient.DefaultRequestHeaders.Add("Authorization", "Bearer " + JWTToken); httpResponseMessage = await httpclient.PostAsJsonAsync(requestUri, stringsModel); if (httpResponseMessage.IsSuccessStatusCode) { levenshteinDistanceMatrixAndCostResult = httpResponseMessage.Content.ReadAsAsync <LevenshteinDistanceMatrixAndCostResult>().Result; } } } catch (Exception exception) { throw (exception); } finally { httpResponseMessage = null; resourcePath = null; baseAddress = null; requestUri = null; stringBuilder = null; } return(levenshteinDistanceMatrixAndCostResult); }