private void OnCompareDocuments(CompareReturn response, Dictionary <string, object> customData) { Log.Debug("TestCompareComplyV1.OnCompareDocuments()", "CompareDocuments Response: {0}", customData["json"].ToString()); Test(response != null); Test(response.Documents[0].Html.Contains("HairPopMetal4Evah")); compareDocumentsTested = true; }
public IEnumerator TestCompareDocuments() { Log.Debug("CompareComplyServiceV1IntegrationTests", "Attempting to CompareDocuments..."); CompareReturn compareDocumentsResponse = null; using (FileStream fs0 = File.OpenRead(contractAFilepath)) { using (FileStream fs1 = File.OpenRead(contractBFilepath)) { using (MemoryStream ms0 = new MemoryStream()) { using (MemoryStream ms1 = new MemoryStream()) { fs0.CopyTo(ms0); fs1.CopyTo(ms1); service.CompareDocuments( callback: (DetailedResponse <CompareReturn> response, IBMError error) => { Log.Debug("CompareComplyServiceV1IntegrationTests", "CompareDocuments result: {0}", response.Response); compareDocumentsResponse = response.Result; Assert.IsNotNull(compareDocumentsResponse); Assert.IsNotNull(compareDocumentsResponse.Documents); Assert.IsNull(error); }, file1: ms0, file2: ms1, file1Label: "Contract A", file2Label: "Contract B", model: "contracts", file1ContentType: Utility.GetMimeType(Path.GetExtension(contractAFilepath)), file2ContentType: Utility.GetMimeType(Path.GetExtension(contractBFilepath)) ); while (compareDocumentsResponse == null) { yield return(null); } } } } } }
private CompareReturn CompareWordWithSentiment(string word) { CompareReturn compareReturn = new CompareReturn(); if (PosSentiment.Contains(word)) { compareReturn.Polarity = "pos"; compareReturn.Weight = 1; return compareReturn; } if (NegSentiment.Contains(word)) { compareReturn.Polarity = "neg"; compareReturn.Weight = 1; return compareReturn; } double possim = 0; double negsim = 0; double Weight; foreach (string posword in PosSentiment) { possim = YiXiang.simWord(word, posword) > possim ? YiXiang.simWord(word, posword) : possim; if (possim == 1) break; } foreach (string negword in NegSentiment) { negsim = YiXiang.simWord(word, negword) > negsim ? YiXiang.simWord(word, negword) : negsim; if (negsim == 1) break; } Weight = possim - negsim; if (Math.Abs(Weight) > Confredence) { if (Weight > 0) { compareReturn.Polarity = "neg"; } else if (Weight < 0) { compareReturn.Polarity = "pos"; } else { compareReturn.Polarity = ""; } } else { compareReturn.Polarity = ""; } compareReturn.Weight = Math.Abs(Weight); return compareReturn; }
/// <summary> /// Compare two documents. /// /// Uploads two input files. The response includes JSON comparing the two documents. Uploaded files must be in /// the same file format. /// </summary> /// <param name="file1">The first file to compare.</param> /// <param name="file2">The second file to compare.</param> /// <param name="file1Label">A text label for the first file. (optional, default to file_1)</param> /// <param name="file2Label">A text label for the second file. (optional, default to file_2)</param> /// <param name="modelId">The analysis model to be used by the service. For the `/v1/element_classification` and /// `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables` method, the default is `tables`. /// These defaults apply to the standalone methods as well as to the methods' use in batch-processing requests. /// (optional)</param> /// <param name="file1ContentType">The content type of file1. (optional)</param> /// <param name="file2ContentType">The content type of file2. (optional)</param> /// <param name="customData">Custom data object to pass data including custom request headers.</param> /// <returns><see cref="CompareReturn" />CompareReturn</returns> public CompareReturn CompareDocuments(System.IO.FileStream file1, System.IO.FileStream file2, string file1Label = null, string file2Label = null, string modelId = null, string file1ContentType = null, string file2ContentType = null, Dictionary <string, object> customData = null) { if (file1 == null) { throw new ArgumentNullException(nameof(file1)); } if (file2 == null) { throw new ArgumentNullException(nameof(file2)); } if (string.IsNullOrEmpty(VersionDate)) { throw new ArgumentNullException("versionDate cannot be null."); } CompareReturn result = null; try { var formData = new MultipartFormDataContent(); if (file1 != null) { var file1Content = new ByteArrayContent((file1 as Stream).ReadAllBytes()); System.Net.Http.Headers.MediaTypeHeaderValue contentType; System.Net.Http.Headers.MediaTypeHeaderValue.TryParse(file1ContentType, out contentType); file1Content.Headers.ContentType = contentType; formData.Add(file1Content, "file_1", file1.Name); } if (file2 != null) { var file2Content = new ByteArrayContent((file2 as Stream).ReadAllBytes()); System.Net.Http.Headers.MediaTypeHeaderValue contentType; System.Net.Http.Headers.MediaTypeHeaderValue.TryParse(file2ContentType, out contentType); file2Content.Headers.ContentType = contentType; formData.Add(file2Content, "file_2", file2.Name); } IClient client = this.Client.WithAuthentication(_tokenManager.GetToken()); var restRequest = client.PostAsync($"{this.Endpoint}/v1/comparison"); restRequest.WithArgument("version", VersionDate); if (!string.IsNullOrEmpty(file1Label)) { restRequest.WithArgument("file_1_label", file1Label); } if (!string.IsNullOrEmpty(file2Label)) { restRequest.WithArgument("file_2_label", file2Label); } if (!string.IsNullOrEmpty(modelId)) { restRequest.WithArgument("model_id", modelId); } restRequest.WithBodyContent(formData); if (customData != null) { restRequest.WithCustomData(customData); } restRequest.WithHeader("X-IBMCloud-SDK-Analytics", "service_name=compare-comply;service_version=v1;operation_id=CompareDocuments"); result = restRequest.As <CompareReturn>().Result; if (result == null) { result = new CompareReturn(); } result.CustomData = restRequest.CustomData; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
private void OnCompareDocuments(CompareReturn response, Dictionary <string, object> customData) { Log.Debug("ExampleCompareComplyV1.OnCompareDocuments()", "CompareDocuments Response: {0}", customData["json"].ToString()); compareDocumentsTested = true; }