From a940bdc4bb10b9468211afd43e9cc749f3f08847 Mon Sep 17 00:00:00 2001 From: seth-mg Date: Fri, 23 Jun 2023 12:44:10 -0500 Subject: [PATCH 01/19] Post to Teams instead of Slack --- Jenkinsfile.examples | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples index 652bea6..887147a 100644 --- a/Jenkinsfile.examples +++ b/Jenkinsfile.examples @@ -21,17 +21,18 @@ node { sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source ${TEST_CONTAINER}" } } - slack(true) + postToTeams(true) } catch (e) { currentBuild.result = "FAILED" - slack(false) + postToTeams(false) throw e } } -def slack(boolean success) { +def postToTeams(boolean success) { + def webhookUrl = "${env.TEAMS_PNC_JENKINS_WEBHOOK_URL}" def color = success ? "#00FF00" : "#FF0000" def status = success ? "SUCCESSFUL" : "FAILED" - def message = status + ": Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})" - slackSend(color: color, channel: "#rapid", message: message) -} \ No newline at end of file + def message = "*" + status + ":* '${env.JOB_NAME}' - [${env.BUILD_NUMBER}] - ${env.BUILD_URL}" + office365ConnectorSend(webhookUrl: webhookUrl, color: color, message: message, status: status) +} From b87fa075b08dc750b96d3ab6b3a8eac43efa4691 Mon Sep 17 00:00:00 2001 From: Ervin Papp Date: Tue, 27 Jun 2023 12:00:36 +0200 Subject: [PATCH 02/19] RCB-601 new: events endpoint --- rosette/api.py | 11 ++++++++++- tests/test_rosette_api.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index cfe5633..ead6e04 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -589,7 +589,8 @@ def __init__( 'TEXT_EMBEDDING': 'semantics/vector', 'TOKENS': 'tokens', 'TOPICS': 'topics', - 'TRANSLITERATION': 'transliteration' + 'TRANSLITERATION': 'transliteration', + 'EVENTS': 'events' } def __del__(self): @@ -1010,3 +1011,11 @@ def similar_terms(self, parameters): :return: A python dictionary containing the similar terms and their similarity """ return EndpointCaller(self, self.endpoints['SIMILAR_TERMS']).call(parameters) + + def events(self, parameters): + """ + Topics returns events related to the provided content + :param parameters: DocumentParameters + :return: A python dictionary containing the results + """ + return EndpointCaller(self, self.endpoints['EVENTS']).call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 456a1af..1f9a169 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -882,3 +882,19 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): httpretty.disable() httpretty.reset() + +# Test the events endpoint + + +def test_the_events_endpoint(api, json_response, doc_params): + """Test the events endpoint""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + body=json_response, status=200, content_type="application/json") + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/events", + body=json_response, status=200, content_type="application/json") + + result = api.events(doc_params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() \ No newline at end of file From 8a510bbda347790d180937d953c7ae096b5c4fc0 Mon Sep 17 00:00:00 2001 From: Ervin Papp Date: Tue, 27 Jun 2023 12:13:48 +0200 Subject: [PATCH 03/19] RCB-601 new: events example --- examples/events.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/events.py diff --git a/examples/events.py b/examples/events.py new file mode 100644 index 0000000..c900977 --- /dev/null +++ b/examples/events.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +""" +Example code to call Rosette API to get entities from a piece of text. +""" + +import argparse +import json +import os + +from rosette.api import API, DocumentParameters, RosetteException + + +def run(key, alt_url='https://api.rosette.com/rest/v1/'): + """ Run the example """ + # Create an API instance + api = API(user_key=key, service_url=alt_url) + + # Set selected API options. + # For more information on the functionality of these + # and other available options, see Rosette Features & Functions + # https://developer.rosette.com/features-and-functions#entity-extraction-and-linking + + # api.set_option('calculateSalience','true') + # api.set_option('linkEntities','false') + + events_text_data = "James wanted to test this awesome document." + params = DocumentParameters() + params["content"] = events_text_data + + try: + return api.events(params) + except RosetteException as exception: + print(exception) + +PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, + description='Calls the ' + + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') +PARSER.add_argument('-k', '--key', help='Rosette API Key', required=True) +PARSER.add_argument('-u', '--url', help="Alternative API URL", + default='https://api.rosette.com/rest/v1/') + +if __name__ == '__main__': + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(RESULT) From fbf0c657308d3b0f2fe33db1d2163bb844471e7d Mon Sep 17 00:00:00 2001 From: Ervin Papp Date: Wed, 26 Jul 2023 10:43:37 +0200 Subject: [PATCH 04/19] RCB-601 fixed: events API description --- rosette/api.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index ead6e04..41004e4 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -1014,8 +1014,10 @@ def similar_terms(self, parameters): def events(self, parameters): """ - Topics returns events related to the provided content - :param parameters: DocumentParameters - :return: A python dictionary containing the results + Create an L{EndpointCaller} to identify events found in the texts. + @param parameters: An object specifying the data, + and possible metadata, to be processed by the 'events' identifier. + @type parameters: L{DocumentParameters} or L{str} + @return: A python dictionary containing the results of event extraction. """ return EndpointCaller(self, self.endpoints['EVENTS']).call(parameters) From 4a35e54b3dcfabe392d6cce9c00a7a44e313e490 Mon Sep 17 00:00:00 2001 From: seth-mg Date: Mon, 21 Aug 2023 10:24:19 -0500 Subject: [PATCH 05/19] RCB-601: Test data update. --- examples/events.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/examples/events.py b/examples/events.py index c900977..7e5147a 100644 --- a/examples/events.py +++ b/examples/events.py @@ -15,15 +15,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=alt_url) - # Set selected API options. - # For more information on the functionality of these - # and other available options, see Rosette Features & Functions - # https://developer.rosette.com/features-and-functions#entity-extraction-and-linking - - # api.set_option('calculateSalience','true') - # api.set_option('linkEntities','false') - - events_text_data = "James wanted to test this awesome document." + events_text_data = "I am looking for flights to Super Bowl 2022 in Inglewood, LA." params = DocumentParameters() params["content"] = events_text_data From d4f0770b82db0e768878c457c20bf6faab9292ff Mon Sep 17 00:00:00 2001 From: Jonathan Ju Date: Tue, 22 Aug 2023 16:25:07 -0400 Subject: [PATCH 06/19] TEJ-2055: added test file for event negation --- examples/events_negation.py | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/events_negation.py diff --git a/examples/events_negation.py b/examples/events_negation.py new file mode 100644 index 0000000..880420f --- /dev/null +++ b/examples/events_negation.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +""" +Example code to call Rosette API to get events, based on a set negation option, from a piece of text. +""" + +import argparse +import json +import os + +from rosette.api import API, DocumentParameters, RosetteException + + +def run(key, alt_url='https://api.rosette.com/rest/v1/'): + """ Run the example """ + # Create an API instance + api = API(user_key=key, service_url=alt_url) + + # Double negative, meaning that the event should be skipped with "IGNORE" or "ONLY_NEGATIVE" + # and recognized under "BOTH" or "ONLY_POSITIVE" + events_text_data = "Sam didn't not take a flight to Boston." + params = DocumentParameters() + params["content"] = events_text_data + api.set_option('negation', 'ONLY_POSITIVE') + + + try: + return api.events(params) + except RosetteException as exception: + print(exception) + +PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, + description='Calls the ' + + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') +PARSER.add_argument('-k', '--key', help='Rosette API Key', required=True) +PARSER.add_argument('-u', '--url', help="Alternative API URL", + default='https://api.rosette.com/rest/v1/') + +if __name__ == '__main__': + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(RESULT) From 87557f6ea2724dca4d57fa826e5ff27b937b9799 Mon Sep 17 00:00:00 2001 From: machine-user-rosette Date: Tue, 10 Oct 2023 12:20:06 -0500 Subject: [PATCH 07/19] Update CI.Jenkinsfile Switch from Sonar hosted binaries to Github hosted. --- CI.Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 457d077..6c7d5f9 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -16,10 +16,10 @@ def runSonnarForPythonVersion(sourceDir, ver){ // Only run Sonar once. if(ver == 3.11) { sonarExec="cd /root/ && \ - wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ - unzip -q sonar-scanner-cli-4.8.0.2856-linux.zip && \ + wget -q https://github.com/SonarSource/sonar-scanner-cli/archive/refs/tags/4.8.1.3023.zip && \ + unzip -q 4.8.1.3023.zip && \ cd /source && \ - /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner ${mySonarOpts}" + /root/sonar-scanner-4.8.1.3023/bin/sonar-scanner ${mySonarOpts}" } else { sonarExec="echo Skipping Sonar for this version." } @@ -57,4 +57,4 @@ node ("docker-light") { currentBuild.result = "FAILED" throw e } -} \ No newline at end of file +} From 7bb55cebbe0d37e2aaa09b739afc6ca6290a5dd6 Mon Sep 17 00:00:00 2001 From: machine-user-rosette Date: Tue, 10 Oct 2023 12:27:34 -0500 Subject: [PATCH 08/19] Update CI.Jenkinsfile Switch back to sonarsource binaries --- CI.Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 6c7d5f9..e4c7eb1 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -14,12 +14,13 @@ def runSonnarForPythonVersion(sourceDir, ver){ } // Only run Sonar once. + // Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/ if(ver == 3.11) { sonarExec="cd /root/ && \ - wget -q https://github.com/SonarSource/sonar-scanner-cli/archive/refs/tags/4.8.1.3023.zip && \ - unzip -q 4.8.1.3023.zip && \ + wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.1.3023-linux.zip && \ + unzip -q sonar-scanner-cli-4.8.1.3023-linux.zip && \ cd /source && \ - /root/sonar-scanner-4.8.1.3023/bin/sonar-scanner ${mySonarOpts}" + /root/sonar-scanner-cli-4.8.1.3023-linux/bin/sonar-scanner ${mySonarOpts}" } else { sonarExec="echo Skipping Sonar for this version." } From c05749270b3cd59495ef80b3b49c8e7ae585cd92 Mon Sep 17 00:00:00 2001 From: machine-user-rosette Date: Tue, 10 Oct 2023 12:37:09 -0500 Subject: [PATCH 09/19] Update CI.Jenkinsfile More sonar scanner tweaks --- CI.Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index e4c7eb1..9b10517 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -17,10 +17,11 @@ def runSonnarForPythonVersion(sourceDir, ver){ // Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/ if(ver == 3.11) { sonarExec="cd /root/ && \ - wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.1.3023-linux.zip && \ - unzip -q sonar-scanner-cli-4.8.1.3023-linux.zip && \ + sonar_version=4.8.1.3023 && \ + wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${sonar_version}-linux.zip && \ + unzip -q sonar-scanner-cli-${sonar_version}-linux.zip && \ cd /source && \ - /root/sonar-scanner-cli-4.8.1.3023-linux/bin/sonar-scanner ${mySonarOpts}" + /root/sonar-scanner-${sonar_version}-linux/bin/sonar-scanner ${mySonarOpts}" } else { sonarExec="echo Skipping Sonar for this version." } From c06b6ec3ef4c86210e25ef6886d5735343b93297 Mon Sep 17 00:00:00 2001 From: machine-user-rosette Date: Tue, 10 Oct 2023 12:45:03 -0500 Subject: [PATCH 10/19] Update CI.Jenkinsfile --- CI.Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 9b10517..04a50d6 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -18,10 +18,10 @@ def runSonnarForPythonVersion(sourceDir, ver){ if(ver == 3.11) { sonarExec="cd /root/ && \ sonar_version=4.8.1.3023 && \ - wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${sonar_version}-linux.zip && \ - unzip -q sonar-scanner-cli-${sonar_version}-linux.zip && \ + wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${sonar_version}-linux.zip && \ + unzip -q sonar-scanner-cli-\${sonar_version}-linux.zip && \ cd /source && \ - /root/sonar-scanner-${sonar_version}-linux/bin/sonar-scanner ${mySonarOpts}" + /root/sonar-scanner-\${sonar_version}-linux/bin/sonar-scanner ${mySonarOpts}" } else { sonarExec="echo Skipping Sonar for this version." } From 2580cf12dcd53b2dd6f6f184b0ac3630527009b6 Mon Sep 17 00:00:00 2001 From: machine-user-rosette Date: Tue, 10 Oct 2023 12:51:01 -0500 Subject: [PATCH 11/19] Update CI.Jenkinsfile --- CI.Jenkinsfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 04a50d6..25cf41a 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -17,11 +17,10 @@ def runSonnarForPythonVersion(sourceDir, ver){ // Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/ if(ver == 3.11) { sonarExec="cd /root/ && \ - sonar_version=4.8.1.3023 && \ - wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${sonar_version}-linux.zip && \ - unzip -q sonar-scanner-cli-\${sonar_version}-linux.zip && \ + wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.1.3023-linux.zip && \ + unzip -q sonar-scanner-cli-4.8.1.3023-linux.zip && \ cd /source && \ - /root/sonar-scanner-\${sonar_version}-linux/bin/sonar-scanner ${mySonarOpts}" + /root/sonar-scanner-4.8.1.3023-linux/bin/sonar-scanner ${mySonarOpts}" } else { sonarExec="echo Skipping Sonar for this version." } From b774ec5e5b89857d0693932137d3d48c08571bce Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 4 Dec 2023 14:56:51 +0100 Subject: [PATCH 12/19] WS_3053: replace rosette.com --- examples/categories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index 88fbb37..4f8a7d7 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -14,7 +14,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ - categories_url_data = "https://rosette.com/about" + categories_url_data = "https://www.babelstreet.com/rosette/" url = categories_url_data # Create an API instance api = API(user_key=key, service_url=alt_url) From 29603863cd3b4c8d99bacbd4f721dcd6f75793dd Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Tue, 5 Dec 2023 09:05:00 +0100 Subject: [PATCH 13/19] WS_3053: update readme and change categories example to text --- README.md | 3 +-- examples/categories.py | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bf603fa..fc7daf3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + --- @@ -13,7 +13,6 @@ comparing the similarity of names, categorizing and adding linguistic tags to te ## Rosette API Access - Rosette Cloud [Sign Up](https://developer.rosette.com/signup) -- Rosette Enterprise [Evaluation](https://www.rosette.com/product-eval/) ## Quick Start diff --git a/examples/categories.py b/examples/categories.py index 4f8a7d7..e4041aa 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -12,10 +12,9 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='http://localhost:8181/rest/v1/'): """ Run the example """ - categories_url_data = "https://www.babelstreet.com/rosette/" - url = categories_url_data + categories_text_data = "If you are a fan of the British television series Downton Abbey and you are planning to be in New York anytime before April 2nd, there is a perfect stop for you while in town." # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -29,8 +28,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): params = DocumentParameters() - # Use a URL to input data instead of a string - params["contentUri"] = url + params["content"] = categories_text_data try: return api.categories(params) except RosetteException as exception: From 97bf901906e13402292972f5a9ee1163e31a2597 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Tue, 5 Dec 2023 11:33:50 +0100 Subject: [PATCH 14/19] WS_3053: revert url --- examples/categories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index e4041aa..1c3e122 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -12,7 +12,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='http://localhost:8181/rest/v1/'): +def run(key, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ categories_text_data = "If you are a fan of the British television series Downton Abbey and you are planning to be in New York anytime before April 2nd, there is a perfect stop for you while in town." # Create an API instance From e589766abafed7029d88a463581ef0f542f86063 Mon Sep 17 00:00:00 2001 From: Katsuya Tomioka Date: Tue, 12 Dec 2023 15:33:53 +0000 Subject: [PATCH 15/19] RCB-622: add type check for non-doc requests; add tests --- rosette/api.py | 64 ++++++++++++++++---------------- tests/test_rosette_api.py | 77 +++++++++++++++++++++++++++++++++++---- 2 files changed, 102 insertions(+), 39 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 41004e4..747f257 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -86,7 +86,7 @@ def __str__(self): return sst + ": " + self.message + ":\n " + self.response_message -class _DocumentParamSetBase(object): +class _RequestParametersBase(object): def __init__(self, repertoire): self.__params = {} @@ -135,7 +135,7 @@ def _byteify(value): # py 3 only return byte_array -class DocumentParameters(_DocumentParamSetBase): +class DocumentParameters(_RequestParametersBase): """Parameter object for all operations requiring input other than translated_name. Two fields, C{content} and C{inputUri}, are set via @@ -152,7 +152,7 @@ class DocumentParameters(_DocumentParamSetBase): def __init__(self): """Create a L{DocumentParameters} object.""" - _DocumentParamSetBase.__init__( + _RequestParametersBase.__init__( self, ("content", "contentUri", "language", "profileId")) self.file_name = "" self.use_multipart = False @@ -199,7 +199,7 @@ def load_document_string(self, content_as_string): self["content"] = content_as_string -class NameTranslationParameters(_DocumentParamSetBase): +class NameTranslationParameters(_RequestParametersBase): """Parameter object for C{name-translation} endpoint. The following values may be set by the indexing (i.e.,C{ parms["name"]}) operator. The values are all strings (when not C{None}). @@ -227,7 +227,7 @@ class NameTranslationParameters(_DocumentParamSetBase): def __init__(self): self.use_multipart = False - _DocumentParamSetBase.__init__( + _RequestParametersBase.__init__( self, ("name", "targetLanguage", @@ -248,7 +248,7 @@ def validate(self): repr(option)) -class AddressSimilarityParameters(_DocumentParamSetBase): +class AddressSimilarityParameters(_RequestParametersBase): """Parameter object for C{address-similarity} endpoint. C{address1} and C{address2} are required. @@ -271,7 +271,7 @@ class AddressSimilarityParameters(_DocumentParamSetBase): def __init__(self): self.use_multipart = False - _DocumentParamSetBase.__init__(self, ("address1", "address2", "parameters")) + _RequestParametersBase.__init__(self, ("address1", "address2", "parameters")) def validate(self): """Internal. Do not use.""" @@ -283,7 +283,7 @@ def validate(self): repr(option)) -class NameSimilarityParameters(_DocumentParamSetBase): +class NameSimilarityParameters(_RequestParametersBase): """Parameter object for C{name-similarity} endpoint. C{name1} and C{name2} are required. @@ -313,7 +313,7 @@ class NameSimilarityParameters(_DocumentParamSetBase): def __init__(self): self.use_multipart = False - _DocumentParamSetBase.__init__(self, ("name1", "name2", "parameters")) + _RequestParametersBase.__init__(self, ("name1", "name2", "parameters")) def validate(self): """Internal. Do not use.""" @@ -325,7 +325,7 @@ def validate(self): repr(option)) -class NameDeduplicationParameters(_DocumentParamSetBase): +class NameDeduplicationParameters(_RequestParametersBase): """Parameter object for C{name-deduplication} endpoint. Required: C{names} A list of C{name} objects @@ -334,7 +334,7 @@ class NameDeduplicationParameters(_DocumentParamSetBase): def __init__(self): self.use_multipart = False - _DocumentParamSetBase.__init__(self, ("names", "threshold")) + _RequestParametersBase.__init__(self, ("names", "threshold")) def validate(self): """Internal. Do not use.""" @@ -438,7 +438,7 @@ def ping(self): response = self.api.get_http(url, headers=headers) return self.__finish_result(response, "ping") - def call(self, parameters): + def call(self, parameters, paramtype=None): """Invokes the endpoint to which this L{EndpointCaller} is bound. Passes data and metadata specified by C{parameters} to the server endpoint to which this L{EndpointCaller} object is bound. For all @@ -455,24 +455,26 @@ def call(self, parameters): @param parameters: An object specifying the data, and possible metadata, to be processed by the endpoint. See the details for those object types. - @type parameters: For C{name-translation}, L{NameTranslationParameters}, - otherwise L{DocumentParameters} or L{str} + @type parameters: Parameters types or L{str} for document request. + @param paramtype: Required parameters type. @return: A python dictionary expressing the result of the invocation. """ + if paramtype and not isinstance(parameters, paramtype): + raise RosetteException( + "incompatible", + "The parameters must be " + str(paramtype), + self) - if not isinstance(parameters, _DocumentParamSetBase): - if self.suburl != self.api.endpoints['NAME_SIMILARITY'] \ - and self.suburl != self.api.self.api.endpoints['NAME_TRANSLATION'] \ - and self.suburl != self.api.self.api.endpoints['NAME_DEDUPLICATION'] \ - and self.suburl != self.api.self.api.endpoints['ADDRESS_SIMILARITY']: - text = parameters - parameters = DocumentParameters() - parameters['content'] = text - else: - raise RosetteException( - "incompatible", - "Text-only input only works for DocumentParameter endpoints", - self.suburl) + if type(parameters) == str: + text = parameters + parameters = DocumentParameters() + parameters['content'] = text + + if not isinstance(parameters, _RequestParametersBase): + raise RosetteException( + "incompatible", + "The parameters must be string or DocumentParameters", + self.suburl) self.use_multipart = parameters.use_multipart url = self.service_url + self.suburl @@ -915,7 +917,7 @@ def address_similarity(self, parameters): and possible metadata, to be processed by the name matcher. @type parameters: L{AddressSimilarityParameters} @return: A python dictionary containing the results of name matching.""" - return EndpointCaller(self, self.endpoints['ADDRESS_SIMILARITY']).call(parameters) + return EndpointCaller(self, self.endpoints['ADDRESS_SIMILARITY']).call(parameters, AddressSimilarityParameters) def name_translation(self, parameters): """ @@ -925,7 +927,7 @@ def name_translation(self, parameters): and possible metadata, to be processed by the name translator. @type parameters: L{NameTranslationParameters} @return: A python dictionary containing the results of name translation.""" - return EndpointCaller(self, self.endpoints['NAME_TRANSLATION']).call(parameters) + return EndpointCaller(self, self.endpoints['NAME_TRANSLATION']).call(parameters, NameTranslationParameters) def translated_name(self, parameters): """ deprecated @@ -944,7 +946,7 @@ def name_similarity(self, parameters): and possible metadata, to be processed by the name matcher. @type parameters: L{NameSimilarityParameters} @return: A python dictionary containing the results of name matching.""" - return EndpointCaller(self, self.endpoints['NAME_SIMILARITY']).call(parameters) + return EndpointCaller(self, self.endpoints['NAME_SIMILARITY']).call(parameters, NameSimilarityParameters) def matched_name(self, parameters): """ deprecated @@ -962,7 +964,7 @@ def name_deduplication(self, parameters): as a threshold @type parameters: L{NameDeduplicationParameters} @return: A python dictionary containing the results of de-duplication""" - return EndpointCaller(self, self.endpoints['NAME_DEDUPLICATION']).call(parameters) + return EndpointCaller(self, self.endpoints['NAME_DEDUPLICATION']).call(parameters, NameDeduplicationParameters) def text_embedding(self, parameters): """ deprecated diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 1f9a169..7d316f6 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -65,6 +65,12 @@ def doc_params(): params['content'] = 'Sample test string' return params +@pytest.fixture +def doc_map(): + """ fixture for a simple map of doc request """ + return {'content': 'Simple test string'} + + # Of Note: httpretty provides a short hand decorator, @httpretty.activate, that wraps the decorated # function with httpretty.enable() and ends it with httpretty.disable(). However, when combined # with pytest fixtures, the passed in fixture arguments are ignored, resulting in a TypeError. @@ -211,32 +217,40 @@ def test_the_max_pool_size(json_response, doc_params): # Test the language endpoint -def test_the_language_endpoint(api, json_response, doc_params): +def test_the_language_endpoint(api, json_response, doc_params, doc_map): """Test language endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/language", body=json_response, status=200, content_type="application/json") result = api.language(doc_params) assert result["name"] == "Rosette" + + with pytest.raises(RosetteException) as e_rosette: + result = api.language(doc_map) + assert e_rosette.value.status == 'incompatible' + httpretty.disable() httpretty.reset() # Test the sentences endpoint -def test_the_sentences_endpoint(api, json_response, doc_params): +def test_the_sentences_endpoint(api, json_response, doc_params, doc_map): """Test the sentences endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/sentences", body=json_response, status=200, content_type="application/json") result = api.sentences(doc_params) assert result["name"] == "Rosette" + + with pytest.raises(RosetteException) as e_rosette: + result = api.sentences(doc_map) + + assert e_rosette.value.status == 'incompatible' + + httpretty.disable() httpretty.reset() @@ -246,8 +260,6 @@ def test_the_sentences_endpoint(api, json_response, doc_params): def test_the_tokens_endpoint(api, json_response, doc_params): """Test the tokens endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/tokens", body=json_response, status=200, content_type="application/json") @@ -426,6 +438,55 @@ def test_the_name_translation_endpoint(api, json_response): # Test the name similarity endpoint +def test_the_name_requests_with_text(api, json_response): + """Test the name similarity with text""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + body=json_response, status=200, content_type="application/json") + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity", + body=json_response, status=200, content_type="application/json") + with pytest.raises(RosetteException) as e_rosette: + result = api.name_similarity("should fail") + assert e_rosette.value.status == 'incompatible' + + with pytest.raises(RosetteException) as e_rosette: + result = api.name_translation("should fail") + assert e_rosette.value.status == 'incompatible' + + with pytest.raises(RosetteException) as e_rosette: + result = api.name_deduplication("should fail") + assert e_rosette.value.status == 'incompatible' + + with pytest.raises(RosetteException) as e_rosette: + result = api.address_similarity("should fail") + assert e_rosette.value.status == 'incompatible' + + httpretty.disable() + httpretty.reset() + + + +def test_the_name_similarity_single_parameters(api, json_response): + """Test the name similarity parameters""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + body=json_response, status=200, content_type="application/json") + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity", + body=json_response, status=200, content_type="application/json") + + matched_name_data1 = "John Mike Smith" + matched_name_data2 = "John Joe Smith" + params = NameSimilarityParameters() + params["name1"] = {"text": matched_name_data1} + params["name2"] = {"text": matched_name_data2} + params["parameters"] = {"conflictScore": "0.9"} + + result = api.name_similarity(params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() + + def test_the_name_similarity_single_parameters(api, json_response): """Test the name similarity parameters""" From 2df306d2c06057aa9ab1548bbe91010d549e4cdb Mon Sep 17 00:00:00 2001 From: Katsuya Tomioka Date: Wed, 13 Dec 2023 16:35:12 +0000 Subject: [PATCH 16/19] RCB-622: fix typecheck and tests --- rosette/api.py | 4 ++-- tests/test_rosette_api.py | 46 +++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 747f257..03fd991 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -463,14 +463,14 @@ def call(self, parameters, paramtype=None): raise RosetteException( "incompatible", "The parameters must be " + str(paramtype), - self) + self.suburl) if type(parameters) == str: text = parameters parameters = DocumentParameters() parameters['content'] = text - if not isinstance(parameters, _RequestParametersBase): + if not paramtype and not isinstance(parameters, DocumentParameters): raise RosetteException( "incompatible", "The parameters must be string or DocumentParameters", diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 7d316f6..c05ea05 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -415,6 +415,29 @@ def test_the_multipart_operation(api, json_response, doc_params, tmpdir): httpretty.disable() httpretty.reset() + +def test_incompatible_type(api, json_response): + """Test the name translation endpoint""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + body=json_response, status=200, content_type="application/json") + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/sentences", + body=json_response, status=200, content_type="application/json") + + params = NameTranslationParameters() + params["name"] = "some data to translate" + params["entityType"] = "PERSON" + params["targetLanguage"] = "eng" + params["targetScript"] = "Latn" + + # oops, called sentences + with pytest.raises(RosetteException) as e_rosette: + api.sentences(params) + + httpretty.disable() + httpretty.reset() + + # Test the name translation endpoint @@ -465,29 +488,6 @@ def test_the_name_requests_with_text(api, json_response): httpretty.reset() - -def test_the_name_similarity_single_parameters(api, json_response): - """Test the name similarity parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity", - body=json_response, status=200, content_type="application/json") - - matched_name_data1 = "John Mike Smith" - matched_name_data2 = "John Joe Smith" - params = NameSimilarityParameters() - params["name1"] = {"text": matched_name_data1} - params["name2"] = {"text": matched_name_data2} - params["parameters"] = {"conflictScore": "0.9"} - - result = api.name_similarity(params) - assert result["name"] == "Rosette" - httpretty.disable() - httpretty.reset() - - - def test_the_name_similarity_single_parameters(api, json_response): """Test the name similarity parameters""" httpretty.enable() From 9643b8accf3d0669c0dd8834b20afbd98139fddf Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 11 Jan 2024 11:51:51 -0600 Subject: [PATCH 17/19] DEVOPS-306: Add 3.12 and 3.13. Remove 3.7. --- CI.Jenkinsfile | 4 ++-- setup.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 25cf41a..fc44d1c 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -1,6 +1,6 @@ -def versions = [3.7, 3.8, 3.9, 3.10, 3.11] +def versions = [3.8, 3.9, 3.10, 3.11, 3.12, 3.13] def runSonnarForPythonVersion(sourceDir, ver){ mySonarOpts="-Dsonar.sources=/source -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}" @@ -15,7 +15,7 @@ def runSonnarForPythonVersion(sourceDir, ver){ // Only run Sonar once. // Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/ - if(ver == 3.11) { + if(ver == 3.13) { sonarExec="cd /root/ && \ wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.1.3023-linux.zip && \ unzip -q sonar-scanner-cli-4.8.1.3023-linux.zip && \ diff --git a/setup.py b/setup.py index b266ac2..fe2ad46 100755 --- a/setup.py +++ b/setup.py @@ -49,11 +49,12 @@ def read(*filenames, **kwargs): 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) From 84b6cf101fd3f2650d7537d627a5a0a11e66842c Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 11 Jan 2024 12:06:35 -0600 Subject: [PATCH 18/19] DEVOPS-306: 3.13 is still in pre-release. --- CI.Jenkinsfile | 4 ++-- setup.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index fc44d1c..f6aaf1e 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -1,6 +1,6 @@ -def versions = [3.8, 3.9, 3.10, 3.11, 3.12, 3.13] +def versions = [3.8, 3.9, 3.10, 3.11, 3.12] def runSonnarForPythonVersion(sourceDir, ver){ mySonarOpts="-Dsonar.sources=/source -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}" @@ -15,7 +15,7 @@ def runSonnarForPythonVersion(sourceDir, ver){ // Only run Sonar once. // Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/ - if(ver == 3.13) { + if(ver == 3.12) { sonarExec="cd /root/ && \ wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.1.3023-linux.zip && \ unzip -q sonar-scanner-cli-4.8.1.3023-linux.zip && \ diff --git a/setup.py b/setup.py index fe2ad46..551de4f 100755 --- a/setup.py +++ b/setup.py @@ -54,7 +54,6 @@ def read(*filenames, **kwargs): 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', - 'Programming Language :: Python :: 3.13', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) From 3ce3a6e731a292c674b9b324c82e76923b78965a Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 11 Jan 2024 18:21:18 +0000 Subject: [PATCH 19/19] Version 1.28.0 --- docs/source/conf.py | 4 ++-- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 06117be..c95582f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.25.1' +version = '1.28.0' # The full version, including alpha/beta/rc tags. -release = '1.25.1' +release = '1.28.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rosette/__init__.py b/rosette/__init__.py index c583524..72eac6f 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.25.1' +__version__ = '1.28.0' diff --git a/rosette/api.py b/rosette/api.py index 03fd991..f3fec57 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -30,7 +30,7 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' -_BINDING_VERSION = '1.25.1' +_BINDING_VERSION = '1.28.0' _CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' _CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' _CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX)