From c2a4c352593202554c0975c6d2aeb3c840aed9d4 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:14:51 -0400 Subject: [PATCH 01/16] chore(assistantv1): Generate assistantv1 --- ibm_watson/assistant_v1.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ibm_watson/assistant_v1.py b/ibm_watson/assistant_v1.py index bee3e9232..f232c23a3 100644 --- a/ibm_watson/assistant_v1.py +++ b/ibm_watson/assistant_v1.py @@ -145,6 +145,10 @@ def message(self, Get response to user input. Send user input to a workspace and receive a response. + **Note:** For most applications, there are significant advantages to using the v2 + runtime API instead. These advantages include ease of deployment, automatic state + management, versioning, and search capabilities. For more information, see the + [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-api-overview). There is no rate limit for this operation. :param str workspace_id: Unique identifier of the workspace. @@ -6773,9 +6777,9 @@ class RuntimeEntity(object): :attr str entity: An entity detected in the input. :attr list[int] location: An array of zero-based character offsets that indicate where the detected entity values begin and end in the input text. - :attr str value: The term in the input text that was recognized as an entity value. + :attr str value: The entity value that was recognized in the user input. :attr float confidence: (optional) A decimal percentage that represents Watson's - confidence in the entity. + confidence in the recognized entity. :attr dict metadata: (optional) Any metadata for the entity. :attr list[CaptureGroup] groups: (optional) The recognized capture groups for the entity, as defined by the entity pattern. @@ -6795,10 +6799,9 @@ def __init__(self, :param str entity: An entity detected in the input. :param list[int] location: An array of zero-based character offsets that indicate where the detected entity values begin and end in the input text. - :param str value: The term in the input text that was recognized as an entity - value. + :param str value: The entity value that was recognized in the user input. :param float confidence: (optional) A decimal percentage that represents Watson's - confidence in the entity. + confidence in the recognized entity. :param dict metadata: (optional) Any metadata for the entity. :param list[CaptureGroup] groups: (optional) The recognized capture groups for the entity, as defined by the entity pattern. From 9d9a85a70c926ed2238403748e36829eefdf0c41 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:22:25 -0400 Subject: [PATCH 02/16] feat(assistantv2): DialogRuntimeResponseGeneric model has new params header and results --- ibm_watson/assistant_v2.py | 311 ++++++++++++++++++++++++++++++++++++- 1 file changed, 306 insertions(+), 5 deletions(-) diff --git a/ibm_watson/assistant_v2.py b/ibm_watson/assistant_v2.py index cc51f6251..78bfd0f4e 100644 --- a/ibm_watson/assistant_v2.py +++ b/ibm_watson/assistant_v2.py @@ -722,6 +722,10 @@ class DialogRuntimeResponseGeneric(object): the possible matching dialog nodes from which the user can choose. **Note:** The **suggestions** property is part of the disambiguation feature, which is only available for Premium users. + :attr str header: (optional) The title or introductory text to show before the + response. This text is defined in the search skill configuration. + :attr list[SearchResult] results: (optional) An array of objects containing search + results. """ def __init__(self, @@ -736,7 +740,9 @@ def __init__(self, options=None, message_to_human_agent=None, topic=None, - suggestions=None): + suggestions=None, + header=None, + results=None): """ Initialize a DialogRuntimeResponseGeneric object. @@ -763,6 +769,10 @@ def __init__(self, describing the possible matching dialog nodes from which the user can choose. **Note:** The **suggestions** property is part of the disambiguation feature, which is only available for Premium users. + :param str header: (optional) The title or introductory text to show before the + response. This text is defined in the search skill configuration. + :param list[SearchResult] results: (optional) An array of objects containing + search results. """ self.response_type = response_type self.text = text @@ -776,6 +786,8 @@ def __init__(self, self.message_to_human_agent = message_to_human_agent self.topic = topic self.suggestions = suggestions + self.header = header + self.results = results @classmethod def _from_dict(cls, _dict): @@ -784,7 +796,7 @@ def _from_dict(cls, _dict): validKeys = [ 'response_type', 'text', 'time', 'typing', 'source', 'title', 'description', 'preference', 'options', 'message_to_human_agent', - 'topic', 'suggestions' + 'topic', 'suggestions', 'header', 'results' ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: @@ -825,6 +837,12 @@ def _from_dict(cls, _dict): DialogSuggestion._from_dict(x) for x in (_dict.get('suggestions')) ] + if 'header' in _dict: + args['header'] = _dict.get('header') + if 'results' in _dict: + args['results'] = [ + SearchResult._from_dict(x) for x in (_dict.get('results')) + ] return cls(**args) def _to_dict(self): @@ -855,6 +873,10 @@ def _to_dict(self): _dict['topic'] = self.topic if hasattr(self, 'suggestions') and self.suggestions is not None: _dict['suggestions'] = [x._to_dict() for x in self.suggestions] + if hasattr(self, 'header') and self.header is not None: + _dict['header'] = self.header + if hasattr(self, 'results') and self.results is not None: + _dict['results'] = [x._to_dict() for x in self.results] return _dict def __str__(self): @@ -1811,14 +1833,14 @@ def __ne__(self, other): class RuntimeEntity(object): """ - A term from the request that was identified as an entity. + The entity value that was recognized in the user input. :attr str entity: An entity detected in the input. :attr list[int] location: An array of zero-based character offsets that indicate where the detected entity values begin and end in the input text. :attr str value: The term in the input text that was recognized as an entity value. :attr float confidence: (optional) A decimal percentage that represents Watson's - confidence in the entity. + confidence in the recognized entity. :attr dict metadata: (optional) Any metadata for the entity. :attr list[CaptureGroup] groups: (optional) The recognized capture groups for the entity, as defined by the entity pattern. @@ -1840,7 +1862,7 @@ def __init__(self, :param str value: The term in the input text that was recognized as an entity value. :param float confidence: (optional) A decimal percentage that represents Watson's - confidence in the entity. + confidence in the recognized entity. :param dict metadata: (optional) Any metadata for the entity. :param list[CaptureGroup] groups: (optional) The recognized capture groups for the entity, as defined by the entity pattern. @@ -1991,6 +2013,285 @@ def __ne__(self, other): return not self == other +class SearchResult(object): + """ + SearchResult. + + :attr str id: The unique identifier of the document in the Discovery service + collection. + This property is included in responses from search skills, which are a beta feature + available only to Plus or Premium plan users. + :attr SearchResultMetadata result_metadata: An object containing search result + metadata from the Discovery service. + :attr str body: (optional) A description of the search result. This is taken from an + abstract, summary, or highlight field in the Discovery service response, as specified + in the search skill configuration. + :attr str title: (optional) The title of the search result. This is taken from a title + or name field in the Discovery service response, as specified in the search skill + configuration. + :attr str url: (optional) The URL of the original data object in its native data + source. + :attr SearchResultHighlight highlight: (optional) An object containing segments of + text from search results with query-matching text highlighted using HTML tags. + """ + + def __init__(self, + id, + result_metadata, + body=None, + title=None, + url=None, + highlight=None): + """ + Initialize a SearchResult object. + + :param str id: The unique identifier of the document in the Discovery service + collection. + This property is included in responses from search skills, which are a beta + feature available only to Plus or Premium plan users. + :param SearchResultMetadata result_metadata: An object containing search result + metadata from the Discovery service. + :param str body: (optional) A description of the search result. This is taken from + an abstract, summary, or highlight field in the Discovery service response, as + specified in the search skill configuration. + :param str title: (optional) The title of the search result. This is taken from a + title or name field in the Discovery service response, as specified in the search + skill configuration. + :param str url: (optional) The URL of the original data object in its native data + source. + :param SearchResultHighlight highlight: (optional) An object containing segments + of text from search results with query-matching text highlighted using HTML + tags. + """ + self.id = id + self.result_metadata = result_metadata + self.body = body + self.title = title + self.url = url + self.highlight = highlight + + @classmethod + def _from_dict(cls, _dict): + """Initialize a SearchResult object from a json dictionary.""" + args = {} + validKeys = [ + 'id', 'result_metadata', 'body', 'title', 'url', 'highlight' + ] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class SearchResult: ' + + ', '.join(badKeys)) + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError( + 'Required property \'id\' not present in SearchResult JSON') + if 'result_metadata' in _dict: + args['result_metadata'] = SearchResultMetadata._from_dict( + _dict.get('result_metadata')) + else: + raise ValueError( + 'Required property \'result_metadata\' not present in SearchResult JSON' + ) + if 'body' in _dict: + args['body'] = _dict.get('body') + if 'title' in _dict: + args['title'] = _dict.get('title') + if 'url' in _dict: + args['url'] = _dict.get('url') + if 'highlight' in _dict: + args['highlight'] = SearchResultHighlight._from_dict( + _dict.get('highlight')) + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, + 'result_metadata') and self.result_metadata is not None: + _dict['result_metadata'] = self.result_metadata._to_dict() + if hasattr(self, 'body') and self.body is not None: + _dict['body'] = self.body + if hasattr(self, 'title') and self.title is not None: + _dict['title'] = self.title + if hasattr(self, 'url') and self.url is not None: + _dict['url'] = self.url + if hasattr(self, 'highlight') and self.highlight is not None: + _dict['highlight'] = self.highlight._to_dict() + return _dict + + def __str__(self): + """Return a `str` version of this SearchResult object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class SearchResultHighlight(object): + """ + An object containing segments of text from search results with query-matching text + highlighted using HTML tags. + + :attr list[str] body: (optional) An array of strings containing segments taken from + body text in the search results, with query-matching substrings highlighted. + :attr list[str] title: (optional) An array of strings containing segments taken from + title text in the search results, with query-matching substrings highlighted. + :attr list[str] url: (optional) An array of strings containing segments taken from + URLs in the search results, with query-matching substrings highlighted. + """ + + def __init__(self, body=None, title=None, url=None, **kwargs): + """ + Initialize a SearchResultHighlight object. + + :param list[str] body: (optional) An array of strings containing segments taken + from body text in the search results, with query-matching substrings highlighted. + :param list[str] title: (optional) An array of strings containing segments taken + from title text in the search results, with query-matching substrings highlighted. + :param list[str] url: (optional) An array of strings containing segments taken + from URLs in the search results, with query-matching substrings highlighted. + :param **kwargs: (optional) Any additional properties. + """ + self.body = body + self.title = title + self.url = url + for _key, _value in kwargs.items(): + setattr(self, _key, _value) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a SearchResultHighlight object from a json dictionary.""" + args = {} + xtra = _dict.copy() + if 'body' in _dict: + args['body'] = _dict.get('body') + del xtra['body'] + if 'title' in _dict: + args['title'] = _dict.get('title') + del xtra['title'] + if 'url' in _dict: + args['url'] = _dict.get('url') + del xtra['url'] + args.update(xtra) + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'body') and self.body is not None: + _dict['body'] = self.body + if hasattr(self, 'title') and self.title is not None: + _dict['title'] = self.title + if hasattr(self, 'url') and self.url is not None: + _dict['url'] = self.url + if hasattr(self, '_additionalProperties'): + for _key in self._additionalProperties: + _value = getattr(self, _key, None) + if _value is not None: + _dict[_key] = _value + return _dict + + def __setattr__(self, name, value): + properties = {'body', 'title', 'url'} + if not hasattr(self, '_additionalProperties'): + super(SearchResultHighlight, self).__setattr__( + '_additionalProperties', set()) + if name not in properties: + self._additionalProperties.add(name) + super(SearchResultHighlight, self).__setattr__(name, value) + + def __str__(self): + """Return a `str` version of this SearchResultHighlight object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class SearchResultMetadata(object): + """ + An object containing search result metadata from the Discovery service. + + :attr float confidence: (optional) The confidence score for the given result. For more + information about how the confidence is calculated, see the Discovery service + [documentation](../discovery#query-your-collection). + :attr float score: (optional) An unbounded measure of the relevance of a particular + result, dependent on the query and matching document. A higher score indicates a + greater match to the query parameters. + """ + + def __init__(self, confidence=None, score=None): + """ + Initialize a SearchResultMetadata object. + + :param float confidence: (optional) The confidence score for the given result. For + more information about how the confidence is calculated, see the Discovery service + [documentation](../discovery#query-your-collection). + :param float score: (optional) An unbounded measure of the relevance of a + particular result, dependent on the query and matching document. A higher score + indicates a greater match to the query parameters. + """ + self.confidence = confidence + self.score = score + + @classmethod + def _from_dict(cls, _dict): + """Initialize a SearchResultMetadata object from a json dictionary.""" + args = {} + validKeys = ['confidence', 'score'] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class SearchResultMetadata: ' + + ', '.join(badKeys)) + if 'confidence' in _dict: + args['confidence'] = _dict.get('confidence') + if 'score' in _dict: + args['score'] = _dict.get('score') + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'confidence') and self.confidence is not None: + _dict['confidence'] = self.confidence + if hasattr(self, 'score') and self.score is not None: + _dict['score'] = self.score + return _dict + + def __str__(self): + """Return a `str` version of this SearchResultMetadata object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class SessionResponse(object): """ SessionResponse. From ad624bb479e07b4539c93ba0943255e8b6f25078 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:26:41 -0400 Subject: [PATCH 03/16] feat(compare comply): Basic auth support for compare and comply --- ibm_watson/compare_comply_v1.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ibm_watson/compare_comply_v1.py b/ibm_watson/compare_comply_v1.py index d210fe3b8..c8ca50053 100644 --- a/ibm_watson/compare_comply_v1.py +++ b/ibm_watson/compare_comply_v1.py @@ -48,6 +48,8 @@ def __init__( icp4d_access_token=None, icp4d_url=None, authentication_type=None, + username=None, + password=None, ): """ Construct a new client for the Compare Comply service. @@ -67,6 +69,18 @@ def __init__( "https://gateway.watsonplatform.net/compare-comply/api/compare-comply/api"). The base url may differ between IBM Cloud regions. + :param str username: The username used to authenticate with the service. + Username and password credentials are only required to run your + application locally or outside of IBM Cloud. When running on + IBM Cloud, the credentials will be automatically loaded from the + `VCAP_SERVICES` environment variable. + + :param str password: The password used to authenticate with the service. + Username and password credentials are only required to run your + application locally or outside of IBM Cloud. When running on + IBM Cloud, the credentials will be automatically loaded from the + `VCAP_SERVICES` environment variable. + :param str iam_apikey: An API key that can be used to request IAM tokens. If this API key is provided, the SDK will manage the token and handle the refreshing. @@ -99,6 +113,8 @@ def __init__( self, vcap_services_name='compare-comply', url=url, + username=username, + password=password, iam_apikey=iam_apikey, iam_access_token=iam_access_token, iam_url=iam_url, From a20c81e2345f39b6c7d39eb1d666fdbfc69fb9ad Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:28:14 -0400 Subject: [PATCH 04/16] feat(compare comply): ClassifyReturn model changes --- ibm_watson/compare_comply_v1.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ibm_watson/compare_comply_v1.py b/ibm_watson/compare_comply_v1.py index c8ca50053..93d761f81 100644 --- a/ibm_watson/compare_comply_v1.py +++ b/ibm_watson/compare_comply_v1.py @@ -1556,11 +1556,6 @@ class ClassifyReturn(object): :attr str model_version: (optional) The version of the analysis model identified by the value of the `model_id` key. :attr list[Element] elements: (optional) Document elements identified by the service. - :attr list[Tables] tables: (optional) Definition of tables identified in the input - document. - :attr DocStructure document_structure: (optional) The structure of the input document. - :attr list[Parties] parties: (optional) Definitions of the parties identified in the - input document. :attr list[EffectiveDates] effective_dates: (optional) The date or dates on which the document becomes effective. :attr list[ContractAmts] contract_amounts: (optional) The monetary amounts that @@ -1568,8 +1563,17 @@ class ClassifyReturn(object): another. :attr list[TerminationDates] termination_dates: (optional) The date or dates on which the document is to be terminated. - :attr list[ContractType] contract_type: (optional) The document's contract type or + :attr list[ContractTypes] contract_types: (optional) The document's contract type or types as declared in the document. + :attr list[ContractTerms] contract_terms: (optional) The duration or durations of the + contract. + :attr list[PaymentTerms] payment_terms: (optional) The document's payment duration or + durations. + :attr list[Tables] tables: (optional) Definition of tables identified in the input + document. + :attr DocStructure document_structure: (optional) The structure of the input document. + :attr list[Parties] parties: (optional) Definitions of the parties identified in the + input document. """ def __init__(self, @@ -1577,13 +1581,15 @@ def __init__(self, model_id=None, model_version=None, elements=None, - tables=None, - document_structure=None, - parties=None, effective_dates=None, contract_amounts=None, termination_dates=None, - contract_type=None): + contract_types=None, + contract_terms=None, + payment_terms=None, + tables=None, + document_structure=None, + parties=None): """ Initialize a ClassifyReturn object. From 612b8ba0ac66397d2c50ea0b70f14c1b107dbabb Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:41:10 -0400 Subject: [PATCH 05/16] feat(compare comply): ClassifyReturn model updates --- ibm_watson/compare_comply_v1.py | 101 ++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/ibm_watson/compare_comply_v1.py b/ibm_watson/compare_comply_v1.py index 93d761f81..8e5345e7c 100644 --- a/ibm_watson/compare_comply_v1.py +++ b/ibm_watson/compare_comply_v1.py @@ -1601,12 +1601,6 @@ def __init__(self, by the value of the `model_id` key. :param list[Element] elements: (optional) Document elements identified by the service. - :param list[Tables] tables: (optional) Definition of tables identified in the - input document. - :param DocStructure document_structure: (optional) The structure of the input - document. - :param list[Parties] parties: (optional) Definitions of the parties identified in - the input document. :param list[EffectiveDates] effective_dates: (optional) The date or dates on which the document becomes effective. :param list[ContractAmts] contract_amounts: (optional) The monetary amounts that @@ -1614,29 +1608,42 @@ def __init__(self, another. :param list[TerminationDates] termination_dates: (optional) The date or dates on which the document is to be terminated. - :param list[ContractType] contract_type: (optional) The document's contract type + :param list[ContractTypes] contract_types: (optional) The document's contract type or types as declared in the document. + :param list[ContractTerms] contract_terms: (optional) The duration or durations of + the contract. + :param list[PaymentTerms] payment_terms: (optional) The document's payment + duration or durations. + :param list[Tables] tables: (optional) Definition of tables identified in the + input document. + :param DocStructure document_structure: (optional) The structure of the input + document. + :param list[Parties] parties: (optional) Definitions of the parties identified in + the input document. """ self.document = document self.model_id = model_id self.model_version = model_version self.elements = elements - self.tables = tables - self.document_structure = document_structure - self.parties = parties self.effective_dates = effective_dates self.contract_amounts = contract_amounts self.termination_dates = termination_dates - self.contract_type = contract_type + self.contract_types = contract_types + self.contract_terms = contract_terms + self.payment_terms = payment_terms + self.tables = tables + self.document_structure = document_structure + self.parties = parties @classmethod def _from_dict(cls, _dict): """Initialize a ClassifyReturn object from a json dictionary.""" args = {} validKeys = [ - 'document', 'model_id', 'model_version', 'elements', 'tables', - 'document_structure', 'parties', 'effective_dates', - 'contract_amounts', 'termination_dates', 'contract_type' + 'document', 'model_id', 'model_version', 'elements', + 'effective_dates', 'contract_amounts', 'termination_dates', + 'contract_types', 'contract_terms', 'payment_terms', 'tables', + 'document_structure', 'parties' ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: @@ -1653,17 +1660,6 @@ def _from_dict(cls, _dict): args['elements'] = [ Element._from_dict(x) for x in (_dict.get('elements')) ] - if 'tables' in _dict: - args['tables'] = [ - Tables._from_dict(x) for x in (_dict.get('tables')) - ] - if 'document_structure' in _dict: - args['document_structure'] = DocStructure._from_dict( - _dict.get('document_structure')) - if 'parties' in _dict: - args['parties'] = [ - Parties._from_dict(x) for x in (_dict.get('parties')) - ] if 'effective_dates' in _dict: args['effective_dates'] = [ EffectiveDates._from_dict(x) @@ -1679,9 +1675,30 @@ def _from_dict(cls, _dict): TerminationDates._from_dict(x) for x in (_dict.get('termination_dates')) ] - if 'contract_type' in _dict: - args['contract_type'] = [ - ContractType._from_dict(x) for x in (_dict.get('contract_type')) + if 'contract_types' in _dict: + args['contract_types'] = [ + ContractTypes._from_dict(x) + for x in (_dict.get('contract_types')) + ] + if 'contract_terms' in _dict: + args['contract_terms'] = [ + ContractTerms._from_dict(x) + for x in (_dict.get('contract_terms')) + ] + if 'payment_terms' in _dict: + args['payment_terms'] = [ + PaymentTerms._from_dict(x) for x in (_dict.get('payment_terms')) + ] + if 'tables' in _dict: + args['tables'] = [ + Tables._from_dict(x) for x in (_dict.get('tables')) + ] + if 'document_structure' in _dict: + args['document_structure'] = DocStructure._from_dict( + _dict.get('document_structure')) + if 'parties' in _dict: + args['parties'] = [ + Parties._from_dict(x) for x in (_dict.get('parties')) ] return cls(**args) @@ -1696,14 +1713,6 @@ def _to_dict(self): _dict['model_version'] = self.model_version if hasattr(self, 'elements') and self.elements is not None: _dict['elements'] = [x._to_dict() for x in self.elements] - if hasattr(self, 'tables') and self.tables is not None: - _dict['tables'] = [x._to_dict() for x in self.tables] - if hasattr( - self, - 'document_structure') and self.document_structure is not None: - _dict['document_structure'] = self.document_structure._to_dict() - if hasattr(self, 'parties') and self.parties is not None: - _dict['parties'] = [x._to_dict() for x in self.parties] if hasattr(self, 'effective_dates') and self.effective_dates is not None: _dict['effective_dates'] = [ @@ -1719,8 +1728,24 @@ def _to_dict(self): _dict['termination_dates'] = [ x._to_dict() for x in self.termination_dates ] - if hasattr(self, 'contract_type') and self.contract_type is not None: - _dict['contract_type'] = [x._to_dict() for x in self.contract_type] + if hasattr(self, 'contract_types') and self.contract_types is not None: + _dict['contract_types'] = [ + x._to_dict() for x in self.contract_types + ] + if hasattr(self, 'contract_terms') and self.contract_terms is not None: + _dict['contract_terms'] = [ + x._to_dict() for x in self.contract_terms + ] + if hasattr(self, 'payment_terms') and self.payment_terms is not None: + _dict['payment_terms'] = [x._to_dict() for x in self.payment_terms] + if hasattr(self, 'tables') and self.tables is not None: + _dict['tables'] = [x._to_dict() for x in self.tables] + if hasattr( + self, + 'document_structure') and self.document_structure is not None: + _dict['document_structure'] = self.document_structure._to_dict() + if hasattr(self, 'parties') and self.parties is not None: + _dict['parties'] = [x._to_dict() for x in self.parties] return _dict def __str__(self): From e14b93da193aa0237bda2652913d60a5432021ce Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:50:06 -0400 Subject: [PATCH 06/16] feat(compare comply): model changes --- ibm_watson/compare_comply_v1.py | 908 ++++++++++++++++++++++++++++---- 1 file changed, 807 insertions(+), 101 deletions(-) diff --git a/ibm_watson/compare_comply_v1.py b/ibm_watson/compare_comply_v1.py index 8e5345e7c..7afa828dd 100644 --- a/ibm_watson/compare_comply_v1.py +++ b/ibm_watson/compare_comply_v1.py @@ -2227,45 +2227,141 @@ def __ne__(self, other): return not self == other +class Contexts(object): + """ + Text that is related to the contents of the table and that precedes or follows the + current table. + + :attr str text: (optional) The related text. + :attr Location location: (optional) The numeric location of the identified element in + the document, represented with two integers labeled `begin` and `end`. + """ + + def __init__(self, text=None, location=None): + """ + Initialize a Contexts object. + + :param str text: (optional) The related text. + :param Location location: (optional) The numeric location of the identified + element in the document, represented with two integers labeled `begin` and `end`. + """ + self.text = text + self.location = location + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Contexts object from a json dictionary.""" + args = {} + validKeys = ['text', 'location'] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class Contexts: ' + + ', '.join(badKeys)) + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'location' in _dict: + args['location'] = Location._from_dict(_dict.get('location')) + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, 'location') and self.location is not None: + _dict['location'] = self.location._to_dict() + return _dict + + def __str__(self): + """Return a `str` version of this Contexts object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ContractAmts(object): """ A monetary amount identified in the input document. - :attr str text: (optional) The monetary amount. :attr str confidence_level: (optional) The confidence level in the identification of the contract amount. + :attr str text: (optional) The monetary amount. + :attr str text_normalized: (optional) The normalized form of the amount, which is + listed as a string. This element is optional; that is, the service output lists it + only if normalized text exists. + :attr Interpretation interpretation: (optional) The details of the normalized text, if + applicable. This element is optional; that is, the service output lists it only if + normalized text exists. + :attr list[str] provenance_ids: (optional) One or more hash values that you can send + to IBM to provide feedback or receive support. :attr Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - def __init__(self, text=None, confidence_level=None, location=None): + def __init__(self, + confidence_level=None, + text=None, + text_normalized=None, + interpretation=None, + provenance_ids=None, + location=None): """ Initialize a ContractAmts object. - :param str text: (optional) The monetary amount. :param str confidence_level: (optional) The confidence level in the identification of the contract amount. + :param str text: (optional) The monetary amount. + :param str text_normalized: (optional) The normalized form of the amount, which is + listed as a string. This element is optional; that is, the service output lists it + only if normalized text exists. + :param Interpretation interpretation: (optional) The details of the normalized + text, if applicable. This element is optional; that is, the service output lists + it only if normalized text exists. + :param list[str] provenance_ids: (optional) One or more hash values that you can + send to IBM to provide feedback or receive support. :param Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - self.text = text self.confidence_level = confidence_level + self.text = text + self.text_normalized = text_normalized + self.interpretation = interpretation + self.provenance_ids = provenance_ids self.location = location @classmethod def _from_dict(cls, _dict): """Initialize a ContractAmts object from a json dictionary.""" args = {} - validKeys = ['text', 'confidence_level', 'location'] + validKeys = [ + 'confidence_level', 'text', 'text_normalized', 'interpretation', + 'provenance_ids', 'location' + ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( 'Unrecognized keys detected in dictionary for class ContractAmts: ' + ', '.join(badKeys)) - if 'text' in _dict: - args['text'] = _dict.get('text') if 'confidence_level' in _dict: args['confidence_level'] = _dict.get('confidence_level') + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'text_normalized' in _dict: + args['text_normalized'] = _dict.get('text_normalized') + if 'interpretation' in _dict: + args['interpretation'] = Interpretation._from_dict( + _dict.get('interpretation')) + if 'provenance_ids' in _dict: + args['provenance_ids'] = _dict.get('provenance_ids') if 'location' in _dict: args['location'] = Location._from_dict(_dict.get('location')) return cls(**args) @@ -2273,11 +2369,18 @@ def _from_dict(cls, _dict): def _to_dict(self): """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'text') and self.text is not None: - _dict['text'] = self.text if hasattr(self, 'confidence_level') and self.confidence_level is not None: _dict['confidence_level'] = self.confidence_level + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, + 'text_normalized') and self.text_normalized is not None: + _dict['text_normalized'] = self.text_normalized + if hasattr(self, 'interpretation') and self.interpretation is not None: + _dict['interpretation'] = self.interpretation._to_dict() + if hasattr(self, 'provenance_ids') and self.provenance_ids is not None: + _dict['provenance_ids'] = self.provenance_ids if hasattr(self, 'location') and self.location is not None: _dict['location'] = self.location._to_dict() return _dict @@ -2297,45 +2400,80 @@ def __ne__(self, other): return not self == other -class ContractType(object): +class ContractTerms(object): """ - The contract type identified in the input document. + The duration or durations of the contract. - :attr str text: (optional) The contract type. :attr str confidence_level: (optional) The confidence level in the identification of - the termination date. + the contract term. + :attr str text: (optional) The contract term (duration). + :attr str text_normalized: (optional) The normalized form of the contract term, which + is listed as a string. This element is optional; that is, the service output lists it + only if normalized text exists. + :attr Interpretation interpretation: (optional) The details of the normalized text, if + applicable. This element is optional; that is, the service output lists it only if + normalized text exists. + :attr list[str] provenance_ids: (optional) One or more hash values that you can send + to IBM to provide feedback or receive support. :attr Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - def __init__(self, text=None, confidence_level=None, location=None): + def __init__(self, + confidence_level=None, + text=None, + text_normalized=None, + interpretation=None, + provenance_ids=None, + location=None): """ - Initialize a ContractType object. + Initialize a ContractTerms object. - :param str text: (optional) The contract type. :param str confidence_level: (optional) The confidence level in the identification - of the termination date. + of the contract term. + :param str text: (optional) The contract term (duration). + :param str text_normalized: (optional) The normalized form of the contract term, + which is listed as a string. This element is optional; that is, the service output + lists it only if normalized text exists. + :param Interpretation interpretation: (optional) The details of the normalized + text, if applicable. This element is optional; that is, the service output lists + it only if normalized text exists. + :param list[str] provenance_ids: (optional) One or more hash values that you can + send to IBM to provide feedback or receive support. :param Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - self.text = text self.confidence_level = confidence_level + self.text = text + self.text_normalized = text_normalized + self.interpretation = interpretation + self.provenance_ids = provenance_ids self.location = location @classmethod def _from_dict(cls, _dict): - """Initialize a ContractType object from a json dictionary.""" + """Initialize a ContractTerms object from a json dictionary.""" args = {} - validKeys = ['text', 'confidence_level', 'location'] + validKeys = [ + 'confidence_level', 'text', 'text_normalized', 'interpretation', + 'provenance_ids', 'location' + ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( - 'Unrecognized keys detected in dictionary for class ContractType: ' + 'Unrecognized keys detected in dictionary for class ContractTerms: ' + ', '.join(badKeys)) - if 'text' in _dict: - args['text'] = _dict.get('text') if 'confidence_level' in _dict: args['confidence_level'] = _dict.get('confidence_level') + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'text_normalized' in _dict: + args['text_normalized'] = _dict.get('text_normalized') + if 'interpretation' in _dict: + args['interpretation'] = Interpretation._from_dict( + _dict.get('interpretation')) + if 'provenance_ids' in _dict: + args['provenance_ids'] = _dict.get('provenance_ids') if 'location' in _dict: args['location'] = Location._from_dict(_dict.get('location')) return cls(**args) @@ -2343,17 +2481,107 @@ def _from_dict(cls, _dict): def _to_dict(self): """Return a json dictionary representing this model.""" _dict = {} + if hasattr(self, + 'confidence_level') and self.confidence_level is not None: + _dict['confidence_level'] = self.confidence_level if hasattr(self, 'text') and self.text is not None: _dict['text'] = self.text + if hasattr(self, + 'text_normalized') and self.text_normalized is not None: + _dict['text_normalized'] = self.text_normalized + if hasattr(self, 'interpretation') and self.interpretation is not None: + _dict['interpretation'] = self.interpretation._to_dict() + if hasattr(self, 'provenance_ids') and self.provenance_ids is not None: + _dict['provenance_ids'] = self.provenance_ids + if hasattr(self, 'location') and self.location is not None: + _dict['location'] = self.location._to_dict() + return _dict + + def __str__(self): + """Return a `str` version of this ContractTerms object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ContractTypes(object): + """ + The contract type identified in the input document. + + :attr str confidence_level: (optional) The confidence level in the identification of + the contract type. + :attr str text: (optional) The contract type. + :attr list[str] provenance_ids: (optional) One or more hash values that you can send + to IBM to provide feedback or receive support. + :attr Location location: (optional) The numeric location of the identified element in + the document, represented with two integers labeled `begin` and `end`. + """ + + def __init__(self, + confidence_level=None, + text=None, + provenance_ids=None, + location=None): + """ + Initialize a ContractTypes object. + + :param str confidence_level: (optional) The confidence level in the identification + of the contract type. + :param str text: (optional) The contract type. + :param list[str] provenance_ids: (optional) One or more hash values that you can + send to IBM to provide feedback or receive support. + :param Location location: (optional) The numeric location of the identified + element in the document, represented with two integers labeled `begin` and `end`. + """ + self.confidence_level = confidence_level + self.text = text + self.provenance_ids = provenance_ids + self.location = location + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ContractTypes object from a json dictionary.""" + args = {} + validKeys = ['confidence_level', 'text', 'provenance_ids', 'location'] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class ContractTypes: ' + + ', '.join(badKeys)) + if 'confidence_level' in _dict: + args['confidence_level'] = _dict.get('confidence_level') + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'provenance_ids' in _dict: + args['provenance_ids'] = _dict.get('provenance_ids') + if 'location' in _dict: + args['location'] = Location._from_dict(_dict.get('location')) + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} if hasattr(self, 'confidence_level') and self.confidence_level is not None: _dict['confidence_level'] = self.confidence_level + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, 'provenance_ids') and self.provenance_ids is not None: + _dict['provenance_ids'] = self.provenance_ids if hasattr(self, 'location') and self.location is not None: _dict['location'] = self.location._to_dict() return _dict def __str__(self): - """Return a `str` version of this ContractType object.""" + """Return a `str` version of this ContractTypes object.""" return json.dumps(self._to_dict(), indent=2) def __eq__(self, other): @@ -2515,9 +2743,14 @@ class DocStructure(object): :attr list[LeadingSentence] leading_sentences: (optional) An array containing one object per section or subsection, in parallel with the `section_titles` array, that details the leading sentences in the corresponding section or subsection. + :attr list[Paragraphs] paragraphs: (optional) An array containing one object per + paragraph, in parallel with the `section_titles` and `leading_sentences` arrays. """ - def __init__(self, section_titles=None, leading_sentences=None): + def __init__(self, + section_titles=None, + leading_sentences=None, + paragraphs=None): """ Initialize a DocStructure object. @@ -2526,15 +2759,18 @@ def __init__(self, section_titles=None, leading_sentences=None): :param list[LeadingSentence] leading_sentences: (optional) An array containing one object per section or subsection, in parallel with the `section_titles` array, that details the leading sentences in the corresponding section or subsection. + :param list[Paragraphs] paragraphs: (optional) An array containing one object per + paragraph, in parallel with the `section_titles` and `leading_sentences` arrays. """ self.section_titles = section_titles self.leading_sentences = leading_sentences + self.paragraphs = paragraphs @classmethod def _from_dict(cls, _dict): """Initialize a DocStructure object from a json dictionary.""" args = {} - validKeys = ['section_titles', 'leading_sentences'] + validKeys = ['section_titles', 'leading_sentences', 'paragraphs'] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( @@ -2550,6 +2786,10 @@ def _from_dict(cls, _dict): LeadingSentence._from_dict(x) for x in (_dict.get('leading_sentences')) ] + if 'paragraphs' in _dict: + args['paragraphs'] = [ + Paragraphs._from_dict(x) for x in (_dict.get('paragraphs')) + ] return cls(**args) def _to_dict(self): @@ -2564,6 +2804,8 @@ def _to_dict(self): _dict['leading_sentences'] = [ x._to_dict() for x in self.leading_sentences ] + if hasattr(self, 'paragraphs') and self.paragraphs is not None: + _dict['paragraphs'] = [x._to_dict() for x in self.paragraphs] return _dict def __str__(self): @@ -2661,41 +2903,65 @@ class EffectiveDates(object): """ An effective date. - :attr str text: (optional) The effective date, listed as a string. :attr str confidence_level: (optional) The confidence level in the identification of the effective date. + :attr str text: (optional) The effective date, listed as a string. + :attr str text_normalized: (optional) The normalized form of the effective date, which + is listed as a string. This element is optional; that is, the service output lists it + only if normalized text exists. + :attr list[str] provenance_ids: (optional) One or more hash values that you can send + to IBM to provide feedback or receive support. :attr Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - def __init__(self, text=None, confidence_level=None, location=None): + def __init__(self, + confidence_level=None, + text=None, + text_normalized=None, + provenance_ids=None, + location=None): """ Initialize a EffectiveDates object. - :param str text: (optional) The effective date, listed as a string. :param str confidence_level: (optional) The confidence level in the identification of the effective date. + :param str text: (optional) The effective date, listed as a string. + :param str text_normalized: (optional) The normalized form of the effective date, + which is listed as a string. This element is optional; that is, the service output + lists it only if normalized text exists. + :param list[str] provenance_ids: (optional) One or more hash values that you can + send to IBM to provide feedback or receive support. :param Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - self.text = text self.confidence_level = confidence_level + self.text = text + self.text_normalized = text_normalized + self.provenance_ids = provenance_ids self.location = location @classmethod def _from_dict(cls, _dict): """Initialize a EffectiveDates object from a json dictionary.""" args = {} - validKeys = ['text', 'confidence_level', 'location'] + validKeys = [ + 'confidence_level', 'text', 'text_normalized', 'provenance_ids', + 'location' + ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( 'Unrecognized keys detected in dictionary for class EffectiveDates: ' + ', '.join(badKeys)) - if 'text' in _dict: - args['text'] = _dict.get('text') if 'confidence_level' in _dict: args['confidence_level'] = _dict.get('confidence_level') + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'text_normalized' in _dict: + args['text_normalized'] = _dict.get('text_normalized') + if 'provenance_ids' in _dict: + args['provenance_ids'] = _dict.get('provenance_ids') if 'location' in _dict: args['location'] = Location._from_dict(_dict.get('location')) return cls(**args) @@ -2703,11 +2969,16 @@ def _from_dict(cls, _dict): def _to_dict(self): """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'text') and self.text is not None: - _dict['text'] = self.text if hasattr(self, 'confidence_level') and self.confidence_level is not None: _dict['confidence_level'] = self.confidence_level + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, + 'text_normalized') and self.text_normalized is not None: + _dict['text_normalized'] = self.text_normalized + if hasattr(self, 'provenance_ids') and self.provenance_ids is not None: + _dict['provenance_ids'] = self.provenance_ids if hasattr(self, 'location') and self.location is not None: _dict['location'] = self.location._to_dict() return _dict @@ -3659,44 +3930,124 @@ def __ne__(self, other): return not self == other -class Key(object): +class Interpretation(object): """ - A key in a key-value pair. - - :attr str cell_id: (optional) The unique ID of the key in the table. - :attr Location location: (optional) The numeric location of the identified element in - the document, represented with two integers labeled `begin` and `end`. - :attr str text: (optional) The text content of the table cell without HTML markup. + The details of the normalized text, if applicable. This element is optional; that is, + the service output lists it only if normalized text exists. + + :attr str value: (optional) The value that was located in the normalized text. + :attr float numeric_value: (optional) An integer or float expressing the numeric value + of the `value` key. + :attr str unit: (optional) A string listing the unit of the value that was found in + the normalized text. + **Note:** The value of `unit` is the [ISO-4217 currency + code](https://www.iso.org/iso-4217-currency-codes.html) identified for the currency + amount (for example, `USD` or `EUR`). If the service cannot disambiguate a currency + symbol (for example, `$` or `£`), the value of `unit` contains the ambiguous symbol + as-is. """ - def __init__(self, cell_id=None, location=None, text=None): + def __init__(self, value=None, numeric_value=None, unit=None): """ - Initialize a Key object. + Initialize a Interpretation object. - :param str cell_id: (optional) The unique ID of the key in the table. - :param Location location: (optional) The numeric location of the identified - element in the document, represented with two integers labeled `begin` and `end`. - :param str text: (optional) The text content of the table cell without HTML - markup. + :param str value: (optional) The value that was located in the normalized text. + :param float numeric_value: (optional) An integer or float expressing the numeric + value of the `value` key. + :param str unit: (optional) A string listing the unit of the value that was found + in the normalized text. + **Note:** The value of `unit` is the [ISO-4217 currency + code](https://www.iso.org/iso-4217-currency-codes.html) identified for the + currency amount (for example, `USD` or `EUR`). If the service cannot disambiguate + a currency symbol (for example, `$` or `£`), the value of `unit` contains the + ambiguous symbol as-is. """ - self.cell_id = cell_id - self.location = location - self.text = text + self.value = value + self.numeric_value = numeric_value + self.unit = unit @classmethod def _from_dict(cls, _dict): - """Initialize a Key object from a json dictionary.""" + """Initialize a Interpretation object from a json dictionary.""" args = {} - validKeys = ['cell_id', 'location', 'text'] + validKeys = ['value', 'numeric_value', 'unit'] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( - 'Unrecognized keys detected in dictionary for class Key: ' + - ', '.join(badKeys)) - if 'cell_id' in _dict: - args['cell_id'] = _dict.get('cell_id') - if 'location' in _dict: - args['location'] = Location._from_dict(_dict.get('location')) + 'Unrecognized keys detected in dictionary for class Interpretation: ' + + ', '.join(badKeys)) + if 'value' in _dict: + args['value'] = _dict.get('value') + if 'numeric_value' in _dict: + args['numeric_value'] = _dict.get('numeric_value') + if 'unit' in _dict: + args['unit'] = _dict.get('unit') + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value + if hasattr(self, 'numeric_value') and self.numeric_value is not None: + _dict['numeric_value'] = self.numeric_value + if hasattr(self, 'unit') and self.unit is not None: + _dict['unit'] = self.unit + return _dict + + def __str__(self): + """Return a `str` version of this Interpretation object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class Key(object): + """ + A key in a key-value pair. + + :attr str cell_id: (optional) The unique ID of the key in the table. + :attr Location location: (optional) The numeric location of the identified element in + the document, represented with two integers labeled `begin` and `end`. + :attr str text: (optional) The text content of the table cell without HTML markup. + """ + + def __init__(self, cell_id=None, location=None, text=None): + """ + Initialize a Key object. + + :param str cell_id: (optional) The unique ID of the key in the table. + :param Location location: (optional) The numeric location of the identified + element in the document, represented with two integers labeled `begin` and `end`. + :param str text: (optional) The text content of the table cell without HTML + markup. + """ + self.cell_id = cell_id + self.location = location + self.text = text + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Key object from a json dictionary.""" + args = {} + validKeys = ['cell_id', 'location', 'text'] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class Key: ' + + ', '.join(badKeys)) + if 'cell_id' in _dict: + args['cell_id'] = _dict.get('cell_id') + if 'location' in _dict: + args['location'] = Location._from_dict(_dict.get('location')) if 'text' in _dict: args['text'] = _dict.get('text') return cls(**args) @@ -3991,6 +4342,66 @@ def __ne__(self, other): return not self == other +class Mention(object): + """ + A mention of a party. + + :attr str text: (optional) The name of the party. + :attr Location location: (optional) The numeric location of the identified element in + the document, represented with two integers labeled `begin` and `end`. + """ + + def __init__(self, text=None, location=None): + """ + Initialize a Mention object. + + :param str text: (optional) The name of the party. + :param Location location: (optional) The numeric location of the identified + element in the document, represented with two integers labeled `begin` and `end`. + """ + self.text = text + self.location = location + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Mention object from a json dictionary.""" + args = {} + validKeys = ['text', 'location'] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class Mention: ' + + ', '.join(badKeys)) + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'location' in _dict: + args['location'] = Location._from_dict(_dict.get('location')) + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, 'location') and self.location is not None: + _dict['location'] = self.location._to_dict() + return _dict + + def __str__(self): + """Return a `str` version of this Mention object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class OriginalLabelsIn(object): """ The original labeling from the input document, without the submitted feedback. @@ -4230,48 +4641,109 @@ def __ne__(self, other): return not self == other +class Paragraphs(object): + """ + The locations of each paragraph in the input document. + + :attr Location location: (optional) The numeric location of the identified element in + the document, represented with two integers labeled `begin` and `end`. + """ + + def __init__(self, location=None): + """ + Initialize a Paragraphs object. + + :param Location location: (optional) The numeric location of the identified + element in the document, represented with two integers labeled `begin` and `end`. + """ + self.location = location + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Paragraphs object from a json dictionary.""" + args = {} + validKeys = ['location'] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class Paragraphs: ' + + ', '.join(badKeys)) + if 'location' in _dict: + args['location'] = Location._from_dict(_dict.get('location')) + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'location') and self.location is not None: + _dict['location'] = self.location._to_dict() + return _dict + + def __str__(self): + """Return a `str` version of this Paragraphs object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class Parties(object): """ A party and its corresponding role, including address and contact information if identified. - :attr str party: (optional) A string identifying the party. - :attr str importance: (optional) A string that identifies the importance of the party. + :attr str party: (optional) The normalized form of the party's name. :attr str role: (optional) A string identifying the party's role. - :attr list[Address] addresses: (optional) List of the party's address or addresses. - :attr list[Contact] contacts: (optional) List of the names and roles of contacts + :attr str importance: (optional) A string that identifies the importance of the party. + :attr list[Address] addresses: (optional) A list of the party's address or addresses. + :attr list[Contact] contacts: (optional) A list of the names and roles of contacts identified in the input document. + :attr list[Mention] mentions: (optional) A list of the party's mentions in the input + document. """ def __init__(self, party=None, - importance=None, role=None, + importance=None, addresses=None, - contacts=None): + contacts=None, + mentions=None): """ Initialize a Parties object. - :param str party: (optional) A string identifying the party. + :param str party: (optional) The normalized form of the party's name. + :param str role: (optional) A string identifying the party's role. :param str importance: (optional) A string that identifies the importance of the party. - :param str role: (optional) A string identifying the party's role. - :param list[Address] addresses: (optional) List of the party's address or + :param list[Address] addresses: (optional) A list of the party's address or addresses. - :param list[Contact] contacts: (optional) List of the names and roles of contacts - identified in the input document. + :param list[Contact] contacts: (optional) A list of the names and roles of + contacts identified in the input document. + :param list[Mention] mentions: (optional) A list of the party's mentions in the + input document. """ self.party = party - self.importance = importance self.role = role + self.importance = importance self.addresses = addresses self.contacts = contacts + self.mentions = mentions @classmethod def _from_dict(cls, _dict): """Initialize a Parties object from a json dictionary.""" args = {} - validKeys = ['party', 'importance', 'role', 'addresses', 'contacts'] + validKeys = [ + 'party', 'role', 'importance', 'addresses', 'contacts', 'mentions' + ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( @@ -4279,10 +4751,10 @@ def _from_dict(cls, _dict): ', '.join(badKeys)) if 'party' in _dict: args['party'] = _dict.get('party') - if 'importance' in _dict: - args['importance'] = _dict.get('importance') if 'role' in _dict: args['role'] = _dict.get('role') + if 'importance' in _dict: + args['importance'] = _dict.get('importance') if 'addresses' in _dict: args['addresses'] = [ Address._from_dict(x) for x in (_dict.get('addresses')) @@ -4291,6 +4763,10 @@ def _from_dict(cls, _dict): args['contacts'] = [ Contact._from_dict(x) for x in (_dict.get('contacts')) ] + if 'mentions' in _dict: + args['mentions'] = [ + Mention._from_dict(x) for x in (_dict.get('mentions')) + ] return cls(**args) def _to_dict(self): @@ -4298,14 +4774,16 @@ def _to_dict(self): _dict = {} if hasattr(self, 'party') and self.party is not None: _dict['party'] = self.party - if hasattr(self, 'importance') and self.importance is not None: - _dict['importance'] = self.importance if hasattr(self, 'role') and self.role is not None: _dict['role'] = self.role + if hasattr(self, 'importance') and self.importance is not None: + _dict['importance'] = self.importance if hasattr(self, 'addresses') and self.addresses is not None: _dict['addresses'] = [x._to_dict() for x in self.addresses] if hasattr(self, 'contacts') and self.contacts is not None: _dict['contacts'] = [x._to_dict() for x in self.contacts] + if hasattr(self, 'mentions') and self.mentions is not None: + _dict['mentions'] = [x._to_dict() for x in self.mentions] return _dict def __str__(self): @@ -4323,6 +4801,118 @@ def __ne__(self, other): return not self == other +class PaymentTerms(object): + """ + The document's payment duration or durations. + + :attr str confidence_level: (optional) The confidence level in the identification of + the payment term. + :attr str text: (optional) The payment term (duration). + :attr str text_normalized: (optional) The normalized form of the payment term, which + is listed as a string. This element is optional; that is, the service output lists it + only if normalized text exists. + :attr Interpretation interpretation: (optional) The details of the normalized text, if + applicable. This element is optional; that is, the service output lists it only if + normalized text exists. + :attr list[str] provenance_ids: (optional) One or more hash values that you can send + to IBM to provide feedback or receive support. + :attr Location location: (optional) The numeric location of the identified element in + the document, represented with two integers labeled `begin` and `end`. + """ + + def __init__(self, + confidence_level=None, + text=None, + text_normalized=None, + interpretation=None, + provenance_ids=None, + location=None): + """ + Initialize a PaymentTerms object. + + :param str confidence_level: (optional) The confidence level in the identification + of the payment term. + :param str text: (optional) The payment term (duration). + :param str text_normalized: (optional) The normalized form of the payment term, + which is listed as a string. This element is optional; that is, the service output + lists it only if normalized text exists. + :param Interpretation interpretation: (optional) The details of the normalized + text, if applicable. This element is optional; that is, the service output lists + it only if normalized text exists. + :param list[str] provenance_ids: (optional) One or more hash values that you can + send to IBM to provide feedback or receive support. + :param Location location: (optional) The numeric location of the identified + element in the document, represented with two integers labeled `begin` and `end`. + """ + self.confidence_level = confidence_level + self.text = text + self.text_normalized = text_normalized + self.interpretation = interpretation + self.provenance_ids = provenance_ids + self.location = location + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PaymentTerms object from a json dictionary.""" + args = {} + validKeys = [ + 'confidence_level', 'text', 'text_normalized', 'interpretation', + 'provenance_ids', 'location' + ] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class PaymentTerms: ' + + ', '.join(badKeys)) + if 'confidence_level' in _dict: + args['confidence_level'] = _dict.get('confidence_level') + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'text_normalized' in _dict: + args['text_normalized'] = _dict.get('text_normalized') + if 'interpretation' in _dict: + args['interpretation'] = Interpretation._from_dict( + _dict.get('interpretation')) + if 'provenance_ids' in _dict: + args['provenance_ids'] = _dict.get('provenance_ids') + if 'location' in _dict: + args['location'] = Location._from_dict(_dict.get('location')) + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, + 'confidence_level') and self.confidence_level is not None: + _dict['confidence_level'] = self.confidence_level + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, + 'text_normalized') and self.text_normalized is not None: + _dict['text_normalized'] = self.text_normalized + if hasattr(self, 'interpretation') and self.interpretation is not None: + _dict['interpretation'] = self.interpretation._to_dict() + if hasattr(self, 'provenance_ids') and self.provenance_ids is not None: + _dict['provenance_ids'] = self.provenance_ids + if hasattr(self, 'location') and self.location is not None: + _dict['location'] = self.location._to_dict() + return _dict + + def __str__(self): + """Return a `str` version of this PaymentTerms object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class RowHeaderIds(object): """ An array of values, each being the `id` value of a row header that is applicable to @@ -5028,6 +5618,68 @@ def __ne__(self, other): return not self == other +class TableTitle(object): + """ + If identified, the title or caption of the current table of the form `Table x.: ...`. + Empty when no title is identified. When exposed, the `title` is also excluded from the + `contexts` array of the same table. + + :attr Location location: (optional) The numeric location of the identified element in + the document, represented with two integers labeled `begin` and `end`. + :attr str text: (optional) The text of the identified table title or caption. + """ + + def __init__(self, location=None, text=None): + """ + Initialize a TableTitle object. + + :param Location location: (optional) The numeric location of the identified + element in the document, represented with two integers labeled `begin` and `end`. + :param str text: (optional) The text of the identified table title or caption. + """ + self.location = location + self.text = text + + @classmethod + def _from_dict(cls, _dict): + """Initialize a TableTitle object from a json dictionary.""" + args = {} + validKeys = ['location', 'text'] + badKeys = set(_dict.keys()) - set(validKeys) + if badKeys: + raise ValueError( + 'Unrecognized keys detected in dictionary for class TableTitle: ' + + ', '.join(badKeys)) + if 'location' in _dict: + args['location'] = Location._from_dict(_dict.get('location')) + if 'text' in _dict: + args['text'] = _dict.get('text') + return cls(**args) + + def _to_dict(self): + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'location') and self.location is not None: + _dict['location'] = self.location._to_dict() + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + return _dict + + def __str__(self): + """Return a `str` version of this TableTitle object.""" + return json.dumps(self._to_dict(), indent=2) + + def __eq__(self, other): + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class Tables(object): """ The contents of the tables extracted from a document. @@ -5037,6 +5689,9 @@ class Tables(object): :attr str text: (optional) The textual contents of the current table from the input document without associated markup content. :attr SectionTitle section_title: (optional) The table's section title, if identified. + :attr TableTitle title: (optional) If identified, the title or caption of the current + table of the form `Table x.: ...`. Empty when no title is identified. When exposed, + the `title` is also excluded from the `contexts` array of the same table. :attr list[TableHeaders] table_headers: (optional) An array of table-level cells that apply as headers to all the other cells in the current table. :attr list[RowHeaders] row_headers: (optional) An array of row-level cells, each @@ -5044,22 +5699,26 @@ class Tables(object): :attr list[ColumnHeaders] column_headers: (optional) An array of column-level cells, each applicable as a header to other cells in the same column as itself, of the current table. - :attr list[KeyValuePair] key_value_pairs: (optional) An array of key-value pairs - identified in the current table. :attr list[BodyCells] body_cells: (optional) An array of cells that are neither table header nor column header nor row header cells, of the current table with corresponding row and column header associations. + :attr list[Contexts] contexts: (optional) An array of objects that list text that is + related to the table contents and that precedes or follows the current table. + :attr list[KeyValuePair] key_value_pairs: (optional) An array of key-value pairs + identified in the current table. """ def __init__(self, location=None, text=None, section_title=None, + title=None, table_headers=None, row_headers=None, column_headers=None, - key_value_pairs=None, - body_cells=None): + body_cells=None, + contexts=None, + key_value_pairs=None): """ Initialize a Tables object. @@ -5069,6 +5728,9 @@ def __init__(self, input document without associated markup content. :param SectionTitle section_title: (optional) The table's section title, if identified. + :param TableTitle title: (optional) If identified, the title or caption of the + current table of the form `Table x.: ...`. Empty when no title is identified. When + exposed, the `title` is also excluded from the `contexts` array of the same table. :param list[TableHeaders] table_headers: (optional) An array of table-level cells that apply as headers to all the other cells in the current table. :param list[RowHeaders] row_headers: (optional) An array of row-level cells, each @@ -5077,28 +5739,33 @@ def __init__(self, :param list[ColumnHeaders] column_headers: (optional) An array of column-level cells, each applicable as a header to other cells in the same column as itself, of the current table. - :param list[KeyValuePair] key_value_pairs: (optional) An array of key-value pairs - identified in the current table. :param list[BodyCells] body_cells: (optional) An array of cells that are neither table header nor column header nor row header cells, of the current table with corresponding row and column header associations. + :param list[Contexts] contexts: (optional) An array of objects that list text that + is related to the table contents and that precedes or follows the current table. + :param list[KeyValuePair] key_value_pairs: (optional) An array of key-value pairs + identified in the current table. """ self.location = location self.text = text self.section_title = section_title + self.title = title self.table_headers = table_headers self.row_headers = row_headers self.column_headers = column_headers - self.key_value_pairs = key_value_pairs self.body_cells = body_cells + self.contexts = contexts + self.key_value_pairs = key_value_pairs @classmethod def _from_dict(cls, _dict): """Initialize a Tables object from a json dictionary.""" args = {} validKeys = [ - 'location', 'text', 'section_title', 'table_headers', 'row_headers', - 'column_headers', 'key_value_pairs', 'body_cells' + 'location', 'text', 'section_title', 'title', 'table_headers', + 'row_headers', 'column_headers', 'body_cells', 'contexts', + 'key_value_pairs' ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: @@ -5112,6 +5779,8 @@ def _from_dict(cls, _dict): if 'section_title' in _dict: args['section_title'] = SectionTitle._from_dict( _dict.get('section_title')) + if 'title' in _dict: + args['title'] = TableTitle._from_dict(_dict.get('title')) if 'table_headers' in _dict: args['table_headers'] = [ TableHeaders._from_dict(x) for x in (_dict.get('table_headers')) @@ -5125,15 +5794,19 @@ def _from_dict(cls, _dict): ColumnHeaders._from_dict(x) for x in (_dict.get('column_headers')) ] + if 'body_cells' in _dict: + args['body_cells'] = [ + BodyCells._from_dict(x) for x in (_dict.get('body_cells')) + ] + if 'contexts' in _dict: + args['contexts'] = [ + Contexts._from_dict(x) for x in (_dict.get('contexts')) + ] if 'key_value_pairs' in _dict: args['key_value_pairs'] = [ KeyValuePair._from_dict(x) for x in (_dict.get('key_value_pairs')) ] - if 'body_cells' in _dict: - args['body_cells'] = [ - BodyCells._from_dict(x) for x in (_dict.get('body_cells')) - ] return cls(**args) def _to_dict(self): @@ -5145,6 +5818,8 @@ def _to_dict(self): _dict['text'] = self.text if hasattr(self, 'section_title') and self.section_title is not None: _dict['section_title'] = self.section_title._to_dict() + if hasattr(self, 'title') and self.title is not None: + _dict['title'] = self.title._to_dict() if hasattr(self, 'table_headers') and self.table_headers is not None: _dict['table_headers'] = [x._to_dict() for x in self.table_headers] if hasattr(self, 'row_headers') and self.row_headers is not None: @@ -5153,13 +5828,15 @@ def _to_dict(self): _dict['column_headers'] = [ x._to_dict() for x in self.column_headers ] + if hasattr(self, 'body_cells') and self.body_cells is not None: + _dict['body_cells'] = [x._to_dict() for x in self.body_cells] + if hasattr(self, 'contexts') and self.contexts is not None: + _dict['contexts'] = [x._to_dict() for x in self.contexts] if hasattr(self, 'key_value_pairs') and self.key_value_pairs is not None: _dict['key_value_pairs'] = [ x._to_dict() for x in self.key_value_pairs ] - if hasattr(self, 'body_cells') and self.body_cells is not None: - _dict['body_cells'] = [x._to_dict() for x in self.body_cells] return _dict def __str__(self): @@ -5181,41 +5858,65 @@ class TerminationDates(object): """ Termination dates identified in the input document. - :attr str text: (optional) The termination date. :attr str confidence_level: (optional) The confidence level in the identification of the termination date. + :attr str text: (optional) The termination date. + :attr str text_normalized: (optional) The normalized form of the termination date, + which is listed as a string. This element is optional; that is, the service output + lists it only if normalized text exists. + :attr list[str] provenance_ids: (optional) One or more hash values that you can send + to IBM to provide feedback or receive support. :attr Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - def __init__(self, text=None, confidence_level=None, location=None): + def __init__(self, + confidence_level=None, + text=None, + text_normalized=None, + provenance_ids=None, + location=None): """ Initialize a TerminationDates object. - :param str text: (optional) The termination date. :param str confidence_level: (optional) The confidence level in the identification of the termination date. + :param str text: (optional) The termination date. + :param str text_normalized: (optional) The normalized form of the termination + date, which is listed as a string. This element is optional; that is, the service + output lists it only if normalized text exists. + :param list[str] provenance_ids: (optional) One or more hash values that you can + send to IBM to provide feedback or receive support. :param Location location: (optional) The numeric location of the identified element in the document, represented with two integers labeled `begin` and `end`. """ - self.text = text self.confidence_level = confidence_level + self.text = text + self.text_normalized = text_normalized + self.provenance_ids = provenance_ids self.location = location @classmethod def _from_dict(cls, _dict): """Initialize a TerminationDates object from a json dictionary.""" args = {} - validKeys = ['text', 'confidence_level', 'location'] + validKeys = [ + 'confidence_level', 'text', 'text_normalized', 'provenance_ids', + 'location' + ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( 'Unrecognized keys detected in dictionary for class TerminationDates: ' + ', '.join(badKeys)) - if 'text' in _dict: - args['text'] = _dict.get('text') if 'confidence_level' in _dict: args['confidence_level'] = _dict.get('confidence_level') + if 'text' in _dict: + args['text'] = _dict.get('text') + if 'text_normalized' in _dict: + args['text_normalized'] = _dict.get('text_normalized') + if 'provenance_ids' in _dict: + args['provenance_ids'] = _dict.get('provenance_ids') if 'location' in _dict: args['location'] = Location._from_dict(_dict.get('location')) return cls(**args) @@ -5223,11 +5924,16 @@ def _from_dict(cls, _dict): def _to_dict(self): """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'text') and self.text is not None: - _dict['text'] = self.text if hasattr(self, 'confidence_level') and self.confidence_level is not None: _dict['confidence_level'] = self.confidence_level + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, + 'text_normalized') and self.text_normalized is not None: + _dict['text_normalized'] = self.text_normalized + if hasattr(self, 'provenance_ids') and self.provenance_ids is not None: + _dict['provenance_ids'] = self.provenance_ids if hasattr(self, 'location') and self.location is not None: _dict['location'] = self.location._to_dict() return _dict From a3cf2ade6530939fa31db60eba0b8a491c0ca689 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:50:27 -0400 Subject: [PATCH 07/16] chore(lt): regenerate LTV3 --- ibm_watson/language_translator_v3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm_watson/language_translator_v3.py b/ibm_watson/language_translator_v3.py index d49d90f43..6b9fd8fce 100644 --- a/ibm_watson/language_translator_v3.py +++ b/ibm_watson/language_translator_v3.py @@ -320,7 +320,7 @@ def create_model(self, cumulative file size of all uploaded files is limited to 250 MB. To successfully train with a parallel corpus you must have at least 5,000 parallel sentences in your corpus. - You can have a maxium of 10 custom models per language pair. + You can have a maximum of 10 custom models per language pair. :param str base_model_id: The model ID of the model to use as the base for customization. To see available models, use the `List models` method. Usually all From 7a915f5845e17641477a4a4c036c6689d6f2b8e8 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:52:22 -0400 Subject: [PATCH 08/16] feat(NLU): NLU Confidence field in EntitesResult and EntityMention --- .../natural_language_understanding_v1.py | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/ibm_watson/natural_language_understanding_v1.py b/ibm_watson/natural_language_understanding_v1.py index 2b81cd44f..71a91616c 100644 --- a/ibm_watson/natural_language_understanding_v1.py +++ b/ibm_watson/natural_language_understanding_v1.py @@ -1657,6 +1657,10 @@ class EntitiesResult(object): :attr str text: (optional) The name of the entity. :attr float relevance: (optional) Relevance score from 0 to 1. Higher values indicate greater relevance. + :attr float confidence: (optional) Confidence in the entity identification from 0 to + 1. Higher values indicate higher confidence. In standard entities requests, confidence + is returned only for English text. All entities requests that use custom models return + the confidence score. :attr list[EntityMention] mentions: (optional) Entity mentions and locations. :attr int count: (optional) How many times the entity was mentioned in the text. :attr EmotionScores emotion: (optional) Emotion analysis results for the entity, @@ -1671,6 +1675,7 @@ def __init__(self, type=None, text=None, relevance=None, + confidence=None, mentions=None, count=None, emotion=None, @@ -1683,6 +1688,10 @@ def __init__(self, :param str text: (optional) The name of the entity. :param float relevance: (optional) Relevance score from 0 to 1. Higher values indicate greater relevance. + :param float confidence: (optional) Confidence in the entity identification from 0 + to 1. Higher values indicate higher confidence. In standard entities requests, + confidence is returned only for English text. All entities requests that use + custom models return the confidence score. :param list[EntityMention] mentions: (optional) Entity mentions and locations. :param int count: (optional) How many times the entity was mentioned in the text. :param EmotionScores emotion: (optional) Emotion analysis results for the entity, @@ -1695,6 +1704,7 @@ def __init__(self, self.type = type self.text = text self.relevance = relevance + self.confidence = confidence self.mentions = mentions self.count = count self.emotion = emotion @@ -1706,8 +1716,8 @@ def _from_dict(cls, _dict): """Initialize a EntitiesResult object from a json dictionary.""" args = {} validKeys = [ - 'type', 'text', 'relevance', 'mentions', 'count', 'emotion', - 'sentiment', 'disambiguation' + 'type', 'text', 'relevance', 'confidence', 'mentions', 'count', + 'emotion', 'sentiment', 'disambiguation' ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: @@ -1720,6 +1730,8 @@ def _from_dict(cls, _dict): args['text'] = _dict.get('text') if 'relevance' in _dict: args['relevance'] = _dict.get('relevance') + if 'confidence' in _dict: + args['confidence'] = _dict.get('confidence') if 'mentions' in _dict: args['mentions'] = [ EntityMention._from_dict(x) for x in (_dict.get('mentions')) @@ -1745,6 +1757,8 @@ def _to_dict(self): _dict['text'] = self.text if hasattr(self, 'relevance') and self.relevance is not None: _dict['relevance'] = self.relevance + if hasattr(self, 'confidence') and self.confidence is not None: + _dict['confidence'] = self.confidence if hasattr(self, 'mentions') and self.mentions is not None: _dict['mentions'] = [x._to_dict() for x in self.mentions] if hasattr(self, 'count') and self.count is not None: @@ -1779,24 +1793,33 @@ class EntityMention(object): :attr str text: (optional) Entity mention text. :attr list[int] location: (optional) Character offsets indicating the beginning and end of the mention in the analyzed text. + :attr float confidence: (optional) Confidence in the entity identification from 0 to + 1. Higher values indicate higher confidence. In standard entities requests, confidence + is returned only for English text. All entities requests that use custom models return + the confidence score. """ - def __init__(self, text=None, location=None): + def __init__(self, text=None, location=None, confidence=None): """ Initialize a EntityMention object. :param str text: (optional) Entity mention text. :param list[int] location: (optional) Character offsets indicating the beginning and end of the mention in the analyzed text. + :param float confidence: (optional) Confidence in the entity identification from 0 + to 1. Higher values indicate higher confidence. In standard entities requests, + confidence is returned only for English text. All entities requests that use + custom models return the confidence score. """ self.text = text self.location = location + self.confidence = confidence @classmethod def _from_dict(cls, _dict): """Initialize a EntityMention object from a json dictionary.""" args = {} - validKeys = ['text', 'location'] + validKeys = ['text', 'location', 'confidence'] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( @@ -1806,6 +1829,8 @@ def _from_dict(cls, _dict): args['text'] = _dict.get('text') if 'location' in _dict: args['location'] = _dict.get('location') + if 'confidence' in _dict: + args['confidence'] = _dict.get('confidence') return cls(**args) def _to_dict(self): @@ -1815,6 +1840,8 @@ def _to_dict(self): _dict['text'] = self.text if hasattr(self, 'location') and self.location is not None: _dict['location'] = self.location + if hasattr(self, 'confidence') and self.confidence is not None: + _dict['confidence'] = self.confidence return _dict def __str__(self): From 2cd15d2400eb89772fa66e68a3f919481c02b0e3 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:52:59 -0400 Subject: [PATCH 09/16] chore(PI): reegenerate PI --- ibm_watson/personality_insights_v3.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ibm_watson/personality_insights_v3.py b/ibm_watson/personality_insights_v3.py index ac3dbf790..fba01291e 100644 --- a/ibm_watson/personality_insights_v3.py +++ b/ibm_watson/personality_insights_v3.py @@ -221,7 +221,6 @@ def profile(self, returned with the results. By default, no consumption preferences are returned. :param str content_type: The type of the input. For more information, see **Content types** in the method description. - Default: `text/plain`. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse From ebdff64cb5cae19ea8b1db82642a97843b0b2041 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 14:56:16 -0400 Subject: [PATCH 10/16] chore(tts): regenerate text to speech --- ibm_watson/text_to_speech_v1.py | 89 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/ibm_watson/text_to_speech_v1.py b/ibm_watson/text_to_speech_v1.py index 94fcdde80..3eae5a650 100644 --- a/ibm_watson/text_to_speech_v1.py +++ b/ibm_watson/text_to_speech_v1.py @@ -161,17 +161,17 @@ def get_voice(self, voice, customization_id=None, **kwargs): Gets information about the specified voice. The information includes the name, language, gender, and other details about the voice. Specify a customization ID to - obtain information for that custom voice model of the specified voice. To list - information about all available voices, use the **List voices** method. + obtain information for a custom voice model that is defined for the language of + the specified voice. To list information about all available voices, use the + **List voices** method. **See also:** [Listing a specific voice](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-voices#listVoice). :param str voice: The voice for which information is to be returned. :param str customization_id: The customization ID (GUID) of a custom voice model - for which information is to be returned. You must make the request with service - credentials created for the instance of the service that owns the custom model. - Omit the parameter to see information about the specified voice with no - customization. + for which information is to be returned. You must make the request with + credentials for the instance of the service that owns the custom model. Omit the + parameter to see information about the specified voice with no customization. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse @@ -282,14 +282,12 @@ def synthesize(self, :param str customization_id: The customization ID (GUID) of a custom voice model to use for the synthesis. If a custom voice model is specified, it is guaranteed to work only if it matches the language of the indicated voice. You must make the - request with service credentials created for the instance of the service that owns - the custom model. Omit the parameter to use the specified voice with no - customization. + request with credentials for the instance of the service that owns the custom + model. Omit the parameter to use the specified voice with no customization. :param str accept: The requested format (MIME type) of the audio. You can use the `Accept` header or the `accept` parameter to specify the audio format. For more information about specifying an audio format, see **Audio formats (accept types)** in the method description. - Default: `audio/ogg;codecs=opus`. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse @@ -349,9 +347,9 @@ def get_pronunciation(self, for which the pronunciation is to be returned. The language of a specified custom model must match the language of the specified voice. If the word is not defined in the specified custom model, the service returns the default translation for the - custom model's language. You must make the request with service credentials - created for the instance of the service that owns the custom model. Omit the - parameter to see the translation for the specified voice with no customization. + custom model's language. You must make the request with credentials for the + instance of the service that owns the custom model. Omit the parameter to see the + translation for the specified voice with no customization. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse @@ -449,8 +447,8 @@ def list_voice_models(self, language=None, **kwargs): models](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customModels#cuModelsQueryAll). :param str language: The language for which custom voice models that are owned by - the requesting service credentials are to be returned. Omit the parameter to see - all custom voice models that are owned by the requester. + the requesting credentials are to be returned. Omit the parameter to see all + custom voice models that are owned by the requester. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse @@ -509,8 +507,8 @@ def update_voice_model(self, customization](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customIntro#customIntro). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param str name: A new name for the custom voice model. :param str description: A new description for the custom voice model. :param list[Word] words: An array of `Word` objects that provides the words and @@ -558,8 +556,8 @@ def get_voice_model(self, customization_id, **kwargs): model](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customModels#cuModelsQuery). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse @@ -591,8 +589,8 @@ def delete_voice_model(self, customization_id, **kwargs): model](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customModels#cuModelsDelete). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse @@ -647,8 +645,8 @@ def add_words(self, customization_id, words, **kwargs): customization](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customIntro#customIntro). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param list[Word] words: The **Add custom words** method accepts an array of `Word` objects. Each object provides a word that is to be added or updated for the custom voice model and the word's translation. @@ -698,8 +696,8 @@ def list_words(self, customization_id, **kwargs): model](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customWords#cuWordsQueryModel). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse @@ -754,8 +752,8 @@ def add_word(self, customization](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customIntro#customIntro). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param str word: The word that is to be added or updated for the custom voice model. :param str translation: The phonetic or sounds-like translation for the word. A @@ -810,8 +808,8 @@ def get_word(self, customization_id, word, **kwargs): model](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customWords#cuWordQueryModel). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param str word: The word that is to be queried from the custom voice model. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. @@ -846,8 +844,8 @@ def delete_word(self, customization_id, word, **kwargs): model](https://cloud.ibm.com/docs/services/text-to-speech?topic=text-to-speech-customWords#cuWordDelete). :param str customization_id: The customization ID (GUID) of the custom voice - model. You must make the request with service credentials created for the instance - of the service that owns the custom model. + model. You must make the request with credentials for the instance of the service + that owns the custom model. :param str word: The word that is to be deleted from the custom voice model. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. @@ -1292,15 +1290,15 @@ class VoiceModel(object): :attr str name: (optional) The name of the custom voice model. :attr str language: (optional) The language identifier of the custom voice model (for example, `en-US`). - :attr str owner: (optional) The GUID of the service credentials for the instance of - the service that owns the custom voice model. + :attr str owner: (optional) The GUID of the credentials for the instance of the + service that owns the custom voice model. :attr str created: (optional) The date and time in Coordinated Universal Time (UTC) at which the custom voice model was created. The value is provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). :attr str last_modified: (optional) The date and time in Coordinated Universal Time - (UTC) at which the custom voice model was last modified. Equals `created` when a new - voice model is first added but has yet to be updated. The value is provided in full - ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). + (UTC) at which the custom voice model was last modified. The `created` and `updated` + fields are equal when a voice model is first added but has yet to be updated. The + value is provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). :attr str description: (optional) The description of the custom voice model. :attr list[Word] words: (optional) An array of `Word` objects that lists the words and their translations from the custom voice model. The words are listed in alphabetical @@ -1327,15 +1325,16 @@ def __init__(self, :param str name: (optional) The name of the custom voice model. :param str language: (optional) The language identifier of the custom voice model (for example, `en-US`). - :param str owner: (optional) The GUID of the service credentials for the instance - of the service that owns the custom voice model. + :param str owner: (optional) The GUID of the credentials for the instance of the + service that owns the custom voice model. :param str created: (optional) The date and time in Coordinated Universal Time (UTC) at which the custom voice model was created. The value is provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). :param str last_modified: (optional) The date and time in Coordinated Universal - Time (UTC) at which the custom voice model was last modified. Equals `created` - when a new voice model is first added but has yet to be updated. The value is - provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). + Time (UTC) at which the custom voice model was last modified. The `created` and + `updated` fields are equal when a voice model is first added but has yet to be + updated. The value is provided in full ISO 8601 format + (`YYYY-MM-DDThh:mm:ss.sTZD`). :param str description: (optional) The description of the custom voice model. :param list[Word] words: (optional) An array of `Word` objects that lists the words and their translations from the custom voice model. The words are listed in @@ -1431,8 +1430,8 @@ class VoiceModels(object): :attr list[VoiceModel] customizations: An array of `VoiceModel` objects that provides information about each available custom voice model. The array is empty if the - requesting service credentials own no custom voice models (if no language is - specified) or own no custom voice models for the specified language. + requesting credentials own no custom voice models (if no language is specified) or own + no custom voice models for the specified language. """ def __init__(self, customizations): @@ -1441,8 +1440,8 @@ def __init__(self, customizations): :param list[VoiceModel] customizations: An array of `VoiceModel` objects that provides information about each available custom voice model. The array is empty - if the requesting service credentials own no custom voice models (if no language - is specified) or own no custom voice models for the specified language. + if the requesting credentials own no custom voice models (if no language is + specified) or own no custom voice models for the specified language. """ self.customizations = customizations From 6b2f7dae747f4c9b6b503c81a96b508cd8a570b1 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 15:02:21 -0400 Subject: [PATCH 11/16] chore(stt): regenerate speech to text --- ibm_watson/speech_to_text_v1.py | 98 ++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 37 deletions(-) diff --git a/ibm_watson/speech_to_text_v1.py b/ibm_watson/speech_to_text_v1.py index 457c989df..961699cae 100644 --- a/ibm_watson/speech_to_text_v1.py +++ b/ibm_watson/speech_to_text_v1.py @@ -1249,8 +1249,9 @@ def train_language_model(self, * No training data have been added to the custom model. * The custom model contains one or more invalid corpora, grammars, or words (for example, a custom word has an invalid sounds-like pronunciation). You can correct - the invalid resources. The model must contain at least one valid resource for training - to succeed. + the invalid resources or set the `strict` parameter to `false` to exclude the + invalid resources from the training. The model must contain at least one valid + resource for training to succeed. :param str customization_id: The customization ID (GUID) of the custom language model that is to be used for the request. You must make the request with @@ -1481,11 +1482,17 @@ def add_corpus(self, Use a localized name that matches the language of the custom model and reflects the contents of the corpus. * Include a maximum of 128 characters in the name. - * Do not include spaces, slashes, or backslashes in the name. + * Do not use characters that need to be URL-encoded. For example, do not use + spaces, slashes, backslashes, colons, ampersands, double quotes, plus signs, + equals signs, questions marks, and so on in the name. (The service does not + prevent the use of these characters. But because they must be URL-encoded wherever + used, their use is strongly discouraged.) * Do not use the name of an existing corpus or grammar that is already defined for the custom model. * Do not use the name `user`, which is reserved by the service to denote custom words that are added or modified by the user. + * Do not use the name `base_lm` or `default_lm`. Both names are reserved for + future use by the service. :param file corpus_file: A plain text file that contains the training data for the corpus. Encode the file in UTF-8 if it contains non-ASCII characters; the service assumes UTF-8 encoding if it encounters non-ASCII characters. @@ -1644,7 +1651,7 @@ def list_words(self, customization_id, word_type=None, sort=None, **kwargs): descending order. By default, words are sorted in ascending alphabetical order. For alphabetical ordering, the lexicographical precedence is numeric values, uppercase letters, and lowercase letters. For count ordering, values with the same - count are ordered alphabetically. With the `curl` command, URL encode the `+` + count are ordered alphabetically. With the `curl` command, URL-encode the `+` symbol as `%2B`. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. @@ -2032,11 +2039,17 @@ def add_grammar(self, model. Use a localized name that matches the language of the custom model and reflects the contents of the grammar. * Include a maximum of 128 characters in the name. - * Do not include spaces, slashes, or backslashes in the name. + * Do not use characters that need to be URL-encoded. For example, do not use + spaces, slashes, backslashes, colons, ampersands, double quotes, plus signs, + equals signs, questions marks, and so on in the name. (The service does not + prevent the use of these characters. But because they must be URL-encoded wherever + used, their use is strongly discouraged.) * Do not use the name of an existing grammar or corpus that is already defined for the custom model. * Do not use the name `user`, which is reserved by the service to denote custom words that are added or modified by the user. + * Do not use the name `base_lm` or `default_lm`. Both names are reserved for + future use by the service. :param str grammar_file: A plain text file that contains the grammar in the format specified by the `Content-Type` header. Encode the file in UTF-8 (ASCII is a subset of UTF-8). Using any other encoding can lead to issues when compiling the @@ -2360,8 +2373,10 @@ def train_acoustic_model(self, model** method to poll the model's status. Use a loop to check the status once a minute. The method returns an `AcousticModel` object that includes `status` and `progress` fields. A status of `available` indicates that the custom model is - trained and ready to use. The service cannot accept subsequent training requests, - or requests to add new audio resources, until the existing request completes. + trained and ready to use. The service cannot train a model while it is handling + another request for the model. The service cannot accept subsequent training + requests, or requests to add new audio resources, until the existing training + request completes. You can use the optional `custom_language_model_id` parameter to specify the GUID of a separately created custom language model that is to be used during training. Train with a custom language model if you have verbatim transcriptions of the @@ -2384,7 +2399,8 @@ def train_acoustic_model(self, `custom_language_model_id` query parameter. Both custom models must be based on the same version of the same base model. * The custom model contains one or more invalid audio resources. You can correct - the invalid audio resources. The model must contain at least one valid + the invalid audio resources or set the `strict` parameter to `false` to exclude + the invalid resources from the training. The model must contain at least one valid resource for training to succeed. :param str customization_id: The customization ID (GUID) of the custom acoustic @@ -2412,9 +2428,7 @@ def train_acoustic_model(self, 'train_acoustic_model') headers.update(sdk_headers) - params = { - 'custom_language_model_id': custom_language_model_id - } + params = {'custom_language_model_id': custom_language_model_id} url = '/v1/acoustic_customizations/{0}/train'.format( *self._encode_path_vars(customization_id)) @@ -2433,8 +2447,11 @@ def reset_acoustic_model(self, customization_id, **kwargs): Resets a custom acoustic model by removing all audio resources from the model. Resetting a custom acoustic model initializes the model to its state when it was first created. Metadata such as the name and language of the model are preserved, - but the model's audio resources are removed and must be re-created. You must use - credentials for the instance of the service that owns a model to reset it. + but the model's audio resources are removed and must be re-created. The service + cannot reset a model while it is handling another request for the model. The + service cannot accept subsequent requests for the model until the existing reset + request completes. You must use credentials for the instance of the service that + owns a model to reset it. **See also:** [Resetting a custom acoustic model](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-manageAcousticModels#resetModel-acoustic). @@ -2483,8 +2500,10 @@ def upgrade_acoustic_model(self, returns an `AcousticModel` object that includes `status` and `progress` fields. Use a loop to check the status once a minute. While it is being upgraded, the custom model has the status `upgrading`. When the upgrade is complete, the model - resumes the status that it had prior to upgrade. The service cannot accept - subsequent requests for the model until the upgrade completes. + resumes the status that it had prior to upgrade. The service cannot upgrade a + model while it is handling another request for the model. The service cannot + accept subsequent requests for the model until the existing upgrade request + completes. If the custom acoustic model was trained with a separately created custom language model, you must use the `custom_language_model_id` parameter to specify the GUID of that custom language model. The custom language model must be upgraded before @@ -2600,21 +2619,21 @@ def add_audio(self, efficient than adding each file individually. You can add audio resources in any format that the service supports for speech recognition. You can use this method to add any number of audio resources to a custom model by - calling the method once for each audio or archive file. But the addition of one - audio resource must be fully complete before you can add another. You must add a - minimum of 10 minutes and a maximum of 200 hours of audio that includes speech, - not just silence, to a custom acoustic model before you can train it. No audio - resource, audio- or archive-type, can be larger than 100 MB. To add an audio - resource that has the same name as an existing audio resource, set the - `allow_overwrite` parameter to `true`; otherwise, the request fails. + calling the method once for each audio or archive file. You can add multiple + different audio resources at the same time. You must add a minimum of 10 minutes + and a maximum of 200 hours of audio that includes speech, not just silence, to a + custom acoustic model before you can train it. No audio resource, audio- or + archive-type, can be larger than 100 MB. To add an audio resource that has the + same name as an existing audio resource, set the `allow_overwrite` parameter to + `true`; otherwise, the request fails. The method is asynchronous. It can take several seconds to complete depending on the duration of the audio and, in the case of an archive file, the total number of audio files being processed. The service returns a 201 response code if the audio is valid. It then asynchronously analyzes the contents of the audio file or files and automatically extracts information about the audio such as its length, - sampling rate, and encoding. You cannot submit requests to add additional audio - resources to a custom acoustic model, or to train the model, until the service's - analysis of all audio files for the current request completes. + sampling rate, and encoding. You cannot submit requests to train or upgrade the + model until the service's analysis of all audio resources for current requests + completes. To determine the status of the service's analysis of the audio, use the **Get an audio resource** method to poll the status of the audio. The method accepts the customization ID of the custom model and the name of the audio resource, and it @@ -2671,13 +2690,9 @@ def add_audio(self, have the same format. Do not use the `Contained-Content-Type` header when adding an audio-type resource. ### Naming restrictions for embedded audio files - The name of an audio file that is embedded within an archive-type resource must - meet the following restrictions: - * Include a maximum of 128 characters in the file name; this includes the file - extension. - * Do not include spaces, slashes, or backslashes in the file name. - * Do not use the name of an audio file that has already been added to the custom - model as part of an archive-type resource. + The name of an audio file that is contained in an archive-type resource can + include a maximum of 128 characters. This includes the file extension and all + elements of the name (for example, slashes). :param str customization_id: The customization ID (GUID) of the custom acoustic model that is to be used for the request. You must make the request with @@ -2686,7 +2701,11 @@ def add_audio(self, model. Use a localized name that matches the language of the custom model and reflects the contents of the resource. * Include a maximum of 128 characters in the name. - * Do not include spaces, slashes, or backslashes in the name. + * Do not use characters that need to be URL-encoded. For example, do not use + spaces, slashes, backslashes, colons, ampersands, double quotes, plus signs, + equals signs, questions marks, and so on in the name. (The service does not + prevent the use of these characters. But because they must be URL-encoded wherever + used, their use is strongly discouraged.) * Do not use the name of an audio resource that has already been added to the custom model. :param file audio_resource: The audio resource that is to be added to the custom @@ -2808,12 +2827,13 @@ def delete_audio(self, customization_id, audio_name, **kwargs): Delete an audio resource. Deletes an existing audio resource from a custom acoustic model. Deleting an - archive-type audio resource removes the entire archive of files; the current - interface does not allow deletion of individual files from an archive resource. + archive-type audio resource removes the entire archive of files. The service does + not allow deletion of individual files from an archive resource. Removing an audio resource does not affect the custom model until you train the model on its updated data by using the **Train a custom acoustic model** method. - You must use credentials for the instance of the service that owns a model to - delete its audio resources. + You can delete an existing audio resource from a model while a different resource + is being added to the model. You must use credentials for the instance of the + service that owns a model to delete its audio resources. **See also:** [Deleting an audio resource from a custom acoustic model](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-manageAudio#deleteAudio). @@ -2905,6 +2925,10 @@ class AcousticModel(object): :attr str created: (optional) The date and time in Coordinated Universal Time (UTC) at which the custom acoustic model was created. The value is provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). + :attr str updated: (optional) The date and time in Coordinated Universal Time (UTC) at + which the custom acoustic model was last modified. The `created` and `updated` fields + are equal when an acoustic model is first added but has yet to be updated. The value + is provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD). :attr str language: (optional) The language identifier of the custom acoustic model (for example, `en-US`). :attr list[str] versions: (optional) A list of the available versions of the custom From 306e42a57de5c5fdc0d8e495644a1fa50db1fcce Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 15:04:39 -0400 Subject: [PATCH 12/16] feat(speech to text): AcousticModel & LanguageModel have updated field --- ibm_watson/speech_to_text_v1.py | 49 ++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/ibm_watson/speech_to_text_v1.py b/ibm_watson/speech_to_text_v1.py index 961699cae..6e16b8746 100644 --- a/ibm_watson/speech_to_text_v1.py +++ b/ibm_watson/speech_to_text_v1.py @@ -2944,7 +2944,8 @@ class AcousticModel(object): :attr str status: (optional) The current status of the custom acoustic model: * `pending`: The model was created but is waiting either for valid training data to be added or for the service to finish analyzing added data. - * `ready`: The model contains valid data and is ready to be trained. + * `ready`: The model contains valid data and is ready to be trained. If the model + contains a mix of valid and invalid resources, you need to set the `strict` parameter to `false` for the training to proceed. * `training`: The model is currently being trained. * `available`: The model is trained and ready to use. @@ -2962,6 +2963,7 @@ class AcousticModel(object): def __init__(self, customization_id, created=None, + updated=None, language=None, versions=None, owner=None, @@ -2980,6 +2982,10 @@ def __init__(self, :param str created: (optional) The date and time in Coordinated Universal Time (UTC) at which the custom acoustic model was created. The value is provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). + :param str updated: (optional) The date and time in Coordinated Universal Time + (UTC) at which the custom acoustic model was last modified. The `created` and + `updated` fields are equal when an acoustic model is first added but has yet to be + updated. The value is provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD). :param str language: (optional) The language identifier of the custom acoustic model (for example, `en-US`). :param list[str] versions: (optional) A list of the available versions of the @@ -2995,7 +3001,8 @@ def __init__(self, :param str status: (optional) The current status of the custom acoustic model: * `pending`: The model was created but is waiting either for valid training data to be added or for the service to finish analyzing added data. - * `ready`: The model contains valid data and is ready to be trained. + * `ready`: The model contains valid data and is ready to be trained. If the model + contains a mix of valid and invalid resources, you need to set the `strict` parameter to `false` for the training to proceed. * `training`: The model is currently being trained. * `available`: The model is trained and ready to use. @@ -3012,6 +3019,7 @@ def __init__(self, """ self.customization_id = customization_id self.created = created + self.updated = updated self.language = language self.versions = versions self.owner = owner @@ -3027,9 +3035,9 @@ def _from_dict(cls, _dict): """Initialize a AcousticModel object from a json dictionary.""" args = {} validKeys = [ - 'customization_id', 'created', 'language', 'versions', 'owner', - 'name', 'description', 'base_model_name', 'status', 'progress', - 'warnings' + 'customization_id', 'created', 'updated', 'language', 'versions', + 'owner', 'name', 'description', 'base_model_name', 'status', + 'progress', 'warnings' ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: @@ -3044,6 +3052,8 @@ def _from_dict(cls, _dict): ) if 'created' in _dict: args['created'] = _dict.get('created') + if 'updated' in _dict: + args['updated'] = _dict.get('updated') if 'language' in _dict: args['language'] = _dict.get('language') if 'versions' in _dict: @@ -3072,6 +3082,8 @@ def _to_dict(self): _dict['customization_id'] = self.customization_id if hasattr(self, 'created') and self.created is not None: _dict['created'] = self.created + if hasattr(self, 'updated') and self.updated is not None: + _dict['updated'] = self.updated if hasattr(self, 'language') and self.language is not None: _dict['language'] = self.language if hasattr(self, 'versions') and self.versions is not None: @@ -4536,6 +4548,10 @@ class LanguageModel(object): :attr str created: (optional) The date and time in Coordinated Universal Time (UTC) at which the custom language model was created. The value is provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). + :attr str updated: (optional) The date and time in Coordinated Universal Time (UTC) at + which the custom language model was last modified. The `created` and `updated` fields + are equal when a language model is first added but has yet to be updated. The value is + provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD). :attr str language: (optional) The language identifier of the custom language model (for example, `en-US`). :attr str dialect: (optional) The dialect of the language for the custom language @@ -4558,7 +4574,9 @@ class LanguageModel(object): :attr str status: (optional) The current status of the custom language model: * `pending`: The model was created but is waiting either for valid training data to be added or for the service to finish analyzing added data. - * `ready`: The model contains valid data and is ready to be trained. + * `ready`: The model contains valid data and is ready to be trained. If the model + contains a mix of valid and invalid resources, you need to set the `strict` parameter + to `false` for the training to proceed. * `training`: The model is currently being trained. * `available`: The model is trained and ready to use. * `upgrading`: The model is currently being upgraded. @@ -4579,6 +4597,7 @@ class LanguageModel(object): def __init__(self, customization_id, created=None, + updated=None, language=None, dialect=None, versions=None, @@ -4599,6 +4618,10 @@ def __init__(self, :param str created: (optional) The date and time in Coordinated Universal Time (UTC) at which the custom language model was created. The value is provided in full ISO 8601 format (`YYYY-MM-DDThh:mm:ss.sTZD`). + :param str updated: (optional) The date and time in Coordinated Universal Time + (UTC) at which the custom language model was last modified. The `created` and + `updated` fields are equal when a language model is first added but has yet to be + updated. The value is provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD). :param str language: (optional) The language identifier of the custom language model (for example, `en-US`). :param str dialect: (optional) The dialect of the language for the custom language @@ -4621,7 +4644,8 @@ def __init__(self, :param str status: (optional) The current status of the custom language model: * `pending`: The model was created but is waiting either for valid training data to be added or for the service to finish analyzing added data. - * `ready`: The model contains valid data and is ready to be trained. + * `ready`: The model contains valid data and is ready to be trained. If the model + contains a mix of valid and invalid resources, you need to set the `strict` parameter to `false` for the training to proceed. * `training`: The model is currently being trained. * `available`: The model is trained and ready to use. @@ -4642,6 +4666,7 @@ def __init__(self, """ self.customization_id = customization_id self.created = created + self.updated = updated self.language = language self.dialect = dialect self.versions = versions @@ -4659,9 +4684,9 @@ def _from_dict(cls, _dict): """Initialize a LanguageModel object from a json dictionary.""" args = {} validKeys = [ - 'customization_id', 'created', 'language', 'dialect', 'versions', - 'owner', 'name', 'description', 'base_model_name', 'status', - 'progress', 'error', 'warnings' + 'customization_id', 'created', 'updated', 'language', 'dialect', + 'versions', 'owner', 'name', 'description', 'base_model_name', + 'status', 'progress', 'error', 'warnings' ] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: @@ -4676,6 +4701,8 @@ def _from_dict(cls, _dict): ) if 'created' in _dict: args['created'] = _dict.get('created') + if 'updated' in _dict: + args['updated'] = _dict.get('updated') if 'language' in _dict: args['language'] = _dict.get('language') if 'dialect' in _dict: @@ -4708,6 +4735,8 @@ def _to_dict(self): _dict['customization_id'] = self.customization_id if hasattr(self, 'created') and self.created is not None: _dict['created'] = self.created + if hasattr(self, 'updated') and self.updated is not None: + _dict['updated'] = self.updated if hasattr(self, 'language') and self.language is not None: _dict['language'] = self.language if hasattr(self, 'dialect') and self.dialect is not None: From 482ccd6caca4c50fc933a3d048d6163d0a1f42c8 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 15:05:55 -0400 Subject: [PATCH 13/16] feat(speech to text): ProcessingMetrics has processing_metrics field --- ibm_watson/speech_to_text_v1.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ibm_watson/speech_to_text_v1.py b/ibm_watson/speech_to_text_v1.py index 6e16b8746..4972d3bc9 100644 --- a/ibm_watson/speech_to_text_v1.py +++ b/ibm_watson/speech_to_text_v1.py @@ -4968,7 +4968,8 @@ def __ne__(self, other): class ProcessingMetrics(object): """ If processing metrics are requested, information about the service's processing of the - input audio. + input audio. Processing metrics are not available with the synchronous **Recognize + audio** method. :attr ProcessedAudio processed_audio: Detailed timing information about the service's processing of the input audio. @@ -5945,7 +5946,8 @@ class SpeechRecognitionResults(object): methods that support them, it is possible for a `SpeechRecognitionResults` object to include only the `speaker_labels` field. :attr ProcessingMetrics processing_metrics: (optional) If processing metrics are - requested, information about the service's processing of the input audio. + requested, information about the service's processing of the input audio. Processing + metrics are not available with the synchronous **Recognize audio** method. :attr AudioMetrics audio_metrics: (optional) If audio metrics are requested, information about the signal characteristics of the input audio. :attr list[str] warnings: (optional) An array of warning messages associated with the @@ -5967,6 +5969,7 @@ def __init__(self, results=None, result_index=None, speaker_labels=None, + processing_metrics=None, audio_metrics=None, warnings=None): """ @@ -5990,6 +5993,8 @@ def __init__(self, to include only the `speaker_labels` field. :param ProcessingMetrics processing_metrics: (optional) If processing metrics are requested, information about the service's processing of the input audio. + Processing metrics are not available with the synchronous **Recognize audio** + method. :param AudioMetrics audio_metrics: (optional) If audio metrics are requested, information about the signal characteristics of the input audio. :param list[str] warnings: (optional) An array of warning messages associated with @@ -6010,6 +6015,7 @@ def __init__(self, self.results = results self.result_index = result_index self.speaker_labels = speaker_labels + self.processing_metrics = processing_metrics self.audio_metrics = audio_metrics self.warnings = warnings @@ -6038,6 +6044,9 @@ def _from_dict(cls, _dict): SpeakerLabelsResult._from_dict(x) for x in (_dict.get('speaker_labels')) ] + if 'processing_metrics' in _dict: + args['processing_metrics'] = ProcessingMetrics._from_dict( + _dict.get('processing_metrics')) if 'audio_metrics' in _dict: args['audio_metrics'] = AudioMetrics._from_dict( _dict.get('audio_metrics')) @@ -6056,6 +6065,10 @@ def _to_dict(self): _dict['speaker_labels'] = [ x._to_dict() for x in self.speaker_labels ] + if hasattr( + self, + 'processing_metrics') and self.processing_metrics is not None: + _dict['processing_metrics'] = self.processing_metrics._to_dict() if hasattr(self, 'audio_metrics') and self.audio_metrics is not None: _dict['audio_metrics'] = self.audio_metrics._to_dict() if hasattr(self, 'warnings') and self.warnings is not None: @@ -6154,7 +6167,8 @@ class TrainingResponse(object): :attr list[TrainingWarning] warnings: (optional) An array of `TrainingWarning` objects that lists any invalid resources contained in the custom model. For custom language - models, invalid resources are grouped and identified by type of resource. + models, invalid resources are grouped and identified by type of resource. The method + can return warnings only if the `strict` parameter is set to `false`. """ def __init__(self, warnings=None): @@ -6164,6 +6178,7 @@ def __init__(self, warnings=None): :param list[TrainingWarning] warnings: (optional) An array of `TrainingWarning` objects that lists any invalid resources contained in the custom model. For custom language models, invalid resources are grouped and identified by type of resource. + The method can return warnings only if the `strict` parameter is set to `false`. """ self.warnings = warnings From 780f3c18bb7aada1dd58156899286be1c77d4354 Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 15:06:25 -0400 Subject: [PATCH 14/16] chore(speech to text) generate speech to text --- ibm_watson/speech_to_text_v1.py | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ibm_watson/speech_to_text_v1.py b/ibm_watson/speech_to_text_v1.py index 4972d3bc9..70aaf4cde 100644 --- a/ibm_watson/speech_to_text_v1.py +++ b/ibm_watson/speech_to_text_v1.py @@ -6224,60 +6224,60 @@ class TrainingWarning(object): """ A warning from training of a custom language or custom acoustic model. - :attr str description: A warning message that lists the invalid resources that are + :attr str code: An identifier for the type of invalid resources listed in the + `description` field. + :attr str message: A warning message that lists the invalid resources that are excluded from the custom model's training. The message has the following format: `Analysis of the following {resource_type} has not completed successfully: [{resource_names}]. They will be excluded from custom {model_type} model training.`. - :attr str warning_id: An identifier for the type of invalid resources listed in the - `description` field. """ - def __init__(self, description, warning_id): + def __init__(self, code, message): """ Initialize a TrainingWarning object. - :param str description: A warning message that lists the invalid resources that - are excluded from the custom model's training. The message has the following - format: `Analysis of the following {resource_type} has not completed successfully: + :param str code: An identifier for the type of invalid resources listed in the + `description` field. + :param str message: A warning message that lists the invalid resources that are + excluded from the custom model's training. The message has the following format: + `Analysis of the following {resource_type} has not completed successfully: [{resource_names}]. They will be excluded from custom {model_type} model training.`. - :param str warning_id: An identifier for the type of invalid resources listed in - the `description` field. """ - self.description = description - self.warning_id = warning_id + self.code = code + self.message = message @classmethod def _from_dict(cls, _dict): """Initialize a TrainingWarning object from a json dictionary.""" args = {} - validKeys = ['description', 'warning_id'] + validKeys = ['code', 'message'] badKeys = set(_dict.keys()) - set(validKeys) if badKeys: raise ValueError( 'Unrecognized keys detected in dictionary for class TrainingWarning: ' + ', '.join(badKeys)) - if 'description' in _dict: - args['description'] = _dict.get('description') + if 'code' in _dict: + args['code'] = _dict.get('code') else: raise ValueError( - 'Required property \'description\' not present in TrainingWarning JSON' + 'Required property \'code\' not present in TrainingWarning JSON' ) - if 'warning_id' in _dict: - args['warning_id'] = _dict.get('warning_id') + if 'message' in _dict: + args['message'] = _dict.get('message') else: raise ValueError( - 'Required property \'warning_id\' not present in TrainingWarning JSON' + 'Required property \'message\' not present in TrainingWarning JSON' ) return cls(**args) def _to_dict(self): """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'description') and self.description is not None: - _dict['description'] = self.description - if hasattr(self, 'warning_id') and self.warning_id is not None: - _dict['warning_id'] = self.warning_id + if hasattr(self, 'code') and self.code is not None: + _dict['code'] = self.code + if hasattr(self, 'message') and self.message is not None: + _dict['message'] = self.message return _dict def __str__(self): From ec377bec86426b87b3deb1b3d20d1ea518ff7bca Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 15:57:57 -0400 Subject: [PATCH 15/16] chore(examples): Added examples for compare comply --- examples/compare_comply_v1.py | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/compare_comply_v1.py diff --git a/examples/compare_comply_v1.py b/examples/compare_comply_v1.py new file mode 100644 index 000000000..e69770b2a --- /dev/null +++ b/examples/compare_comply_v1.py @@ -0,0 +1,37 @@ +# coding: utf-8 +from __future__ import print_function +import json +import os +from ibm_watson import CompareComplyV1 + +# If service instance provides API key authentication +compare_comply = CompareComplyV1( + version='2018-03-23', + ## url is optional, and defaults to the URL below. Use the correct URL for your region. + url='https://gateway.watsonplatform.net/compare-comply/api', + iam_apikey='YOUR APIKEY') + +# compare_comply = CompareComplyV1( +# version='2018-03-23', +# ## url is optional, and defaults to the URL below. Use the correct URL for your region. +# # url='https://gateway.watsonplatform.net/compare-comply/api', +# username='YOUR SERVICE USERNAME', +# password='YOUR SERVICE PASSWORD') + +print('Convert to HTML') +contract = os.path.abspath('resources/contract_A.pdf') +with open(contract, 'rb') as file: + result = compare_comply.convert_to_html(file).get_result() + print(json.dumps(result, indent=2)) + +print('Classify elements') +contract = os.path.abspath('resources/contract_A.pdf') +with open(contract, 'rb') as file: + result = compare_comply.classify_elements(file, 'application/pdf').get_result() + print(json.dumps(result, indent=2)) + +print('Extract tables') +table = os.path.abspath('resources/contract_A.pdf') +with open(table, 'rb') as file: + result = compare_comply.extract_tables(file).get_result() + print(json.dumps(result, indent=2)) From c74248e31c0e6fe00853bb6171cb062e38b9686b Mon Sep 17 00:00:00 2001 From: ehdsouza Date: Tue, 23 Jul 2019 17:01:16 -0400 Subject: [PATCH 16/16] chore(manual changes): Hand edits for model changes --- ibm_watson/compare_comply_v1.py | 20 ++++++++++---------- ibm_watson/speech_to_text_v1.py | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ibm_watson/compare_comply_v1.py b/ibm_watson/compare_comply_v1.py index 7afa828dd..01c2bdb63 100644 --- a/ibm_watson/compare_comply_v1.py +++ b/ibm_watson/compare_comply_v1.py @@ -1581,15 +1581,15 @@ def __init__(self, model_id=None, model_version=None, elements=None, + tables=None, + document_structure=None, + parties=None, effective_dates=None, contract_amounts=None, termination_dates=None, contract_types=None, contract_terms=None, - payment_terms=None, - tables=None, - document_structure=None, - parties=None): + payment_terms=None): """ Initialize a ClassifyReturn object. @@ -2308,12 +2308,12 @@ class ContractAmts(object): """ def __init__(self, - confidence_level=None, text=None, + confidence_level=None, + location=None, text_normalized=None, interpretation=None, - provenance_ids=None, - location=None): + provenance_ids=None): """ Initialize a ContractAmts object. @@ -4711,8 +4711,8 @@ class Parties(object): def __init__(self, party=None, - role=None, importance=None, + role=None, addresses=None, contacts=None, mentions=None): @@ -5712,13 +5712,13 @@ def __init__(self, location=None, text=None, section_title=None, - title=None, table_headers=None, row_headers=None, column_headers=None, + key_value_pairs=None, body_cells=None, contexts=None, - key_value_pairs=None): + title=None): """ Initialize a Tables object. diff --git a/ibm_watson/speech_to_text_v1.py b/ibm_watson/speech_to_text_v1.py index 70aaf4cde..48cf45db9 100644 --- a/ibm_watson/speech_to_text_v1.py +++ b/ibm_watson/speech_to_text_v1.py @@ -2963,7 +2963,6 @@ class AcousticModel(object): def __init__(self, customization_id, created=None, - updated=None, language=None, versions=None, owner=None, @@ -2972,7 +2971,8 @@ def __init__(self, base_model_name=None, status=None, progress=None, - warnings=None): + warnings=None, + updated=None): """ Initialize a AcousticModel object. @@ -4597,7 +4597,6 @@ class LanguageModel(object): def __init__(self, customization_id, created=None, - updated=None, language=None, dialect=None, versions=None, @@ -4608,7 +4607,8 @@ def __init__(self, status=None, progress=None, error=None, - warnings=None): + warnings=None, + updated=None): """ Initialize a LanguageModel object. @@ -5969,9 +5969,9 @@ def __init__(self, results=None, result_index=None, speaker_labels=None, - processing_metrics=None, audio_metrics=None, - warnings=None): + warnings=None, + processing_metrics=None): """ Initialize a SpeechRecognitionResults object.