|
| 1 | +# Compare Comply |
| 2 | +IBM Watson™ [Compare and Comply]() analyzes governing documents to provide details about critical aspects of the documents. |
| 3 | + |
| 4 | +## Usage |
| 5 | +About |
| 6 | +IBM Watson™ Compare and Comply is a collection of advanced APIs that enable better and faster document understanding. The APIs are pre-trained to handle document conversion, table understanding, Natural Language Processing, and comparison for contracts. JSON output adds real power to end-user applications, for a wide variety of use cases. The machine learning feedback interface is available to collect your feedback which is then incorporated into regular improvements to the core NLP model; the more you use it, the better the system performs. |
| 7 | + |
| 8 | +Compare and Comply is designed to provide: |
| 9 | + |
| 10 | +- Natural language understanding of contracts and invoices |
| 11 | +- The ability to convert programmatic or scanned PDF documents, Microsoft Word files, image files, and text files to annotated JSON or to HTML |
| 12 | +- Identification of legal entities and categories that align with subject matter expertise |
| 13 | +- The ability to extract table information from an input document |
| 14 | +- The ability to compare two contracts |
| 15 | +- Compare and Comply brings together a functionally rich set of integrated, automated Watson APIs to input a file to identify sections, lists (numbered and bulleted), footnotes, and tables, converting these items into a structured HTML format. Furthermore, classification of this structured format is annotated and output as JSON with labeled elements, types, categories, and other information. |
| 16 | + |
| 17 | +### HTML Conversion |
| 18 | +Uploads a file. The response includes an HTML version of the document. |
| 19 | +```cs |
| 20 | +private void ConvertHtml() |
| 21 | +{ |
| 22 | + compareComply.ConvertToHtml(OnConvertToHtml, OnFail, <file-data>, fileContentType: "application/pdf"); |
| 23 | +} |
| 24 | + |
| 25 | +private void OnConvertToHtml(HTMLReturn response, Dictionary<string, object> customData) |
| 26 | +{ |
| 27 | + Log.Debug("ExampleCompareComplyV1.OnConvertToHtml()", "ConvertToHtml Response: {0}", customData["json"].ToString()); |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +### Classify Elements |
| 37 | +Uploads a file. The response includes an analysis of the document’s structural and semantic elements. |
| 38 | +```cs |
| 39 | +private void ClassifyElements() |
| 40 | +{ |
| 41 | + compareComply.ClassifyElements(OnClassifyElements, OnFail, <file-data>); |
| 42 | +} |
| 43 | + |
| 44 | +private void OnClassifyElements(ClassifyReturn response, Dictionary<string, object> customData) |
| 45 | +{ |
| 46 | + Log.Debug("ExampleCompareComplyV1.OnClassifyElements()", "ClassifyElements Response: {0}", customData["json"].ToString()); |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +### Extract Tables |
| 56 | +Uploads a file. The response includes an analysis of the document’s tables. |
| 57 | +```cs |
| 58 | +private void ExtractTables() |
| 59 | +{ |
| 60 | + compareComply.ExtractTables(OnExtractTables, OnFail, <file-data>); |
| 61 | +} |
| 62 | + |
| 63 | +private void OnExtractTables(TableReturn response, Dictionary<string, object> customData) |
| 64 | +{ |
| 65 | + Log.Debug("ExampleCompareComplyV1.OnExtractTables()", "ExtractTables Response: {0}", customData["json"].ToString()); |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +### Compare Documents |
| 76 | +Uploads two PDF or JSON files. The response includes JSON comparing the two documents. Uploaded files must be in the same file format. |
| 77 | +```cs |
| 78 | +private void CompareDocuments() |
| 79 | +{ |
| 80 | + compareComply.CompareDocuments(OnCompareDocuments, OnFail, <file-1-data>, <file-2-data>, file1ContentType: <file-1-content-type>, file2ContentType: <file-2-content-type>); |
| 81 | + |
| 82 | +} |
| 83 | + |
| 84 | +private void OnCompareDocuments(CompareReturn response, Dictionary<string, object> customData) |
| 85 | +{ |
| 86 | + Log.Debug("ExampleCompareComplyV1.OnCompareDocuments()", "CompareDocuments Response: {0}", customData["json"].ToString()); |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +### List Feedback |
| 96 | +Gets the list of batch-processing jobs submitted by users. |
| 97 | +```cs |
| 98 | +private void ListFeedback() |
| 99 | +{ |
| 100 | + DateTime before = new DateTime(2018, 11, 15); |
| 101 | + DateTime after = new DateTime(2018, 11, 14); |
| 102 | + compareComply.ListFeedback( |
| 103 | + successCallback: OnListFeedback, |
| 104 | + failCallback: OnFail, |
| 105 | + feedbackType: "element_classification", |
| 106 | + before: before, |
| 107 | + after: after, |
| 108 | + documentTitle: "unity-test-feedback-doc", |
| 109 | + modelId: "contracts", |
| 110 | + modelVersion: "2.0.0", |
| 111 | + categoryRemoved: "Responsibilities", |
| 112 | + categoryAdded: "Amendments", |
| 113 | + categoryNotChanged: "Audits", |
| 114 | + typeRemoved: "End User:Exclusion", |
| 115 | + typeAdded: "Disclaimer:Buyer", |
| 116 | + typeNotChanged: "Obligation:IBM", |
| 117 | + pageLimit: 1 |
| 118 | + ); |
| 119 | +} |
| 120 | + |
| 121 | +private void OnListFeedback(FeedbackList response, Dictionary<string, object> customData) |
| 122 | +{ |
| 123 | + Log.Debug("ExampleCompareComplyV1.OnListFeedback()", "ListFeedback Response: {0}", customData["json"].ToString()); |
| 124 | + listFeedbackTested = true; |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +### Add Feedback |
| 134 | +Adds feedback in the form of labels from a subject-matter expert (SME) to a governing document. |
| 135 | +Important: Feedback is not immediately incorporated into the training model, nor is it guaranteed to be incorporated at a later date. Instead, submitted feedback is used to suggest future updates to the training model. |
| 136 | +```cs |
| 137 | +private void AddFeedback() |
| 138 | +{ |
| 139 | + compareComply.AddFeedback( |
| 140 | + successCallback: OnAddFeedback, |
| 141 | + failCallback: OnFail, |
| 142 | + feedbackData: <feedback-data> |
| 143 | + ); |
| 144 | +} |
| 145 | + |
| 146 | +private void OnAddFeedback(FeedbackReturn response, Dictionary<string, object> customData) |
| 147 | +{ |
| 148 | + Log.Debug("ExampleCompareComplyV1.OnAddFeedback()", "AddFeedback Response: {0}", customData["json"].ToString()); |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | +### Get Feedback |
| 158 | +List a specified feedback entry |
| 159 | +```cs |
| 160 | +private void GetFeedback() |
| 161 | +{ |
| 162 | + // temporary fix for a bug requiring `x-watson-metadata` header |
| 163 | + Dictionary<string, object> customData = new Dictionary<string, object>(); |
| 164 | + Dictionary<string, string> customHeaders = new Dictionary<string, string>(); |
| 165 | + customHeaders.Add("x-watson-metadata", "customer_id=sdk-test-customer-id"); |
| 166 | + customData.Add(Constants.String.CUSTOM_REQUEST_HEADERS, customHeaders); |
| 167 | + |
| 168 | + compareComply.GetFeedback( |
| 169 | + successCallback: OnGetFeedback, |
| 170 | + failCallback: OnFail, |
| 171 | + feedbackId: <feedback-id> |
| 172 | + customData: customData |
| 173 | + ); |
| 174 | +} |
| 175 | + |
| 176 | +private void OnGetFeedback(GetFeedback response, Dictionary<string, object> customData) |
| 177 | +{ |
| 178 | + Log.Debug("ExampleCompareComplyV1.OnGetFeedback()", "GetFeedback Response: {0}", customData["json"].ToString()); |
| 179 | +} |
| 180 | +``` |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | +### Delete Feedback |
| 188 | +Deletes a specified feedback entry |
| 189 | +```cs |
| 190 | +private void DeleteFeedback() |
| 191 | +{ |
| 192 | + compareComply.DeleteFeedback( |
| 193 | + successCallback: OnDeleteFeedback, |
| 194 | + failCallback: OnFail, |
| 195 | + feedbackId: <feedback-id> |
| 196 | + ); |
| 197 | +} |
| 198 | + |
| 199 | +private void OnDeleteFeedback(FeedbackDeleted response, Dictionary<string, object> customData) |
| 200 | +{ |
| 201 | + Log.Debug("ExampleCompareComplyV1.OnGetFeedback()", "GetFeedback Response: {0}", customData["json"].ToString()); |
| 202 | +} |
| 203 | +``` |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | +### List Batches |
| 211 | +Gets the list of submitted batch-processing jobs |
| 212 | +```cs |
| 213 | +private void ListBatches() |
| 214 | +{ |
| 215 | + compareComply.ListBatches( |
| 216 | + successCallback: OnListBatches, |
| 217 | + failCallback: OnFail |
| 218 | + ); |
| 219 | +} |
| 220 | + |
| 221 | +private void OnListBatches(Batches response, Dictionary<string, object> customData) |
| 222 | +{ |
| 223 | + Log.Debug("ExampleCompareComplyV1.OnListBatches()", "ListBatches Response: {0}", customData["json"].ToString()); |
| 224 | +} |
| 225 | +``` |
| 226 | + |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + |
| 232 | +### Create Batch Request |
| 233 | +Run Compare and Comply methods over a collection of input documents. |
| 234 | +Important: Batch processing requires the use of the IBM Cloud Object Storage service. The use of IBM Cloud Object Storage with Compare and Comply is discussed at Using batch processing. |
| 235 | +```cs |
| 236 | +private void CreateBatch() |
| 237 | +{ |
| 238 | + compareComply.CreateBatch( |
| 239 | + successCallback: OnCreateBatch, |
| 240 | + failCallback: OnFail, |
| 241 | + function: <function>, |
| 242 | + inputCredentialsFile: <credential-file-data>, |
| 243 | + inputBucketLocation: <bucket-location>, |
| 244 | + inputBucketName: <bucket-name>, |
| 245 | + outputCredentialsFile: <credential-file-data>, |
| 246 | + outputBucketLocation: <bucket-location>, |
| 247 | + outputBucketName: <bucket-name> |
| 248 | + ); |
| 249 | +} |
| 250 | + |
| 251 | +private void OnCreateBatch(BatchStatus response, Dictionary<string, object> customData) |
| 252 | +{ |
| 253 | + Log.Debug("ExampleCompareComplyV1.OnCreateBatch()", "OnCreateBatch Response: {0}", customData["json"].ToString()); |
| 254 | +} |
| 255 | +``` |
| 256 | + |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | +### Get Batch |
| 263 | +Gets information about a specific batch-processing request |
| 264 | +```cs |
| 265 | +private void GetBatch() |
| 266 | +{ |
| 267 | + compareComply.GetBatch( |
| 268 | + successCallback: OnGetBatch, |
| 269 | + failCallback: OnFail, |
| 270 | + batchId: <batch-id> |
| 271 | + ); |
| 272 | +} |
| 273 | + |
| 274 | +private void OnGetBatch(BatchStatus response, Dictionary<string, object> customData) |
| 275 | +{ |
| 276 | + Log.Debug("ExampleCompareComplyV1.OnGetBatch()", "OnGetBatch Response: {0}", customData["json"].ToString()); |
| 277 | +} |
| 278 | +``` |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | +### Update Batch |
| 286 | +Updates a pending or active batch-processing request. You can rescan the input bucket to check for new documents or cancel a request. |
| 287 | +```cs |
| 288 | +private void UpdateBatch() |
| 289 | +{ |
| 290 | + compareComply.UpdateBatch( |
| 291 | + successCallback: OnUpdateBatch, |
| 292 | + failCallback: OnFail, |
| 293 | + batchId: <batch-id>, |
| 294 | + action: <action> |
| 295 | + ); |
| 296 | +} |
| 297 | + |
| 298 | +private void OnUpdateBatch(BatchStatus response, Dictionary<string, object> customData) |
| 299 | +{ |
| 300 | + Log.Debug("ExampleCompareComplyV1.OnUpdateBatch()", "OnUpdateBatch Response: {0}", customData["json"].ToString()); |
| 301 | +} |
| 302 | +``` |
| 303 | + |
| 304 | +[compare-comply]: https://cloud.ibm.com/docs/services/compare-comply/index.html |
0 commit comments