From f1b5d56ca6d5b6218f6132cafb63cfefbc138623 Mon Sep 17 00:00:00 2001 From: lauren12292 Date: Tue, 29 Mar 2016 15:11:51 -0400 Subject: [PATCH 001/247] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 24b92c9..075fbf1 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,14 @@ api = API("[your_api-key]") params = DocumentParameters() # 5. Set parameters. -params["content"] = u"Was ist so böse an der Europäischen Zentralbank?" +params["content"] = "The quick brown fox jumped over the lazy dog. Yes he did." # 6. Make a call. result = api.morphology(params) # result is a Python dictionary that contains -{u'lemmas': [{u'text': u'Was', u'lemma': u'was'}, {u'text': u'ist', u'lemma': u'sein'}, {u'text': u'so', u'lemma': u'so'}, {u'text': u'böse', u'lemma': u'böse'}, {u'text': u'an', u'lemma': u'an'}, {u'text': u'der', u'lemma': u'der'}, {u'text': u'Europäischen', u'lemma': u'europäisch'}, {u'text': u'Zentralbank', u'lemma': u'Zentralbank'}, {u'text': u'?', u'lemma': u'?'}]} +{u'tokens': [u'The', u'quick', u'brown', u'fox', u'jumped', u'over', u'the', u'lazy', u'dog', u'.', u'Yes', u'he', u'did', u'.'], u'posTags': [u'DET', u'ADJ', u'ADJ', u'NOUN', u'VERB', u'ADP', u'DET', u'ADJ', u'NOUN', u'PUNCT', u'VERB', u'PRON', u'VERB', u'PUNCT'], u'compoundComponents': [None, None, None, None, None, None, None, None, None, None, None, None, None, None], u'lemmas': [u'the', u'quick', u'brown', u'fox', u'jump', u'over', u'the', u'lazy', u'dog', u'.', u'yes', u'he', u'do', u'.'], u'hanReadings': [None, None, None, None, None, None, None, None, None, None, None, None, None, None]} ``` The samples use the following procedure: From 811fe5a008f1ded94ed5883fc465110e0fa31f8b Mon Sep 17 00:00:00 2001 From: lauren12292 Date: Tue, 29 Mar 2016 15:13:45 -0400 Subject: [PATCH 002/247] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 075fbf1..4c3ed91 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=master)](https://travis-ci.org/rosette-api/python) # This is the Python client binding for Rosette API. +See the wiki for more information. Installation ------------ From 6ba488947c3312d7686c45aa64a47acaf4950cfa Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 19 Aug 2016 11:39:28 -0400 Subject: [PATCH 003/247] Updated make_request to use Requests --- rosette/api.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 7149f4b..c85fc0e 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -569,24 +569,24 @@ def _make_request(self, op, url, data, headers): code = "unknownError" rdata = None response_headers = {} + + request = requests.Request(op, url, data=data, headers=headers) + prepared_request = request.prepare() + session = requests.Session() + for i in range(self.num_retries + 1): try: - self.http_connection.request(op, url, data, headers) - response = self.http_connection.getresponse() - status = response.status - rdata = response.read() - response_headers["responseHeaders"] = ( - dict(response.getheaders())) + response = session.send(prepared_request) + status = response.status_code + rdata = response.content + response_headers = {"responseHeaders": dict(response.headers)} + if status == 200: - if not self.reuse_connection: - self.http_connection.close() return rdata, status, response_headers if status == 429: code = status message = "{0} ({1})".format(rdata, i) time.sleep(self.connection_refresh_duration) - self.http_connection.close() - self._connect(parsedUrl) continue if rdata is not None: try: @@ -600,9 +600,9 @@ def _make_request(self, op, url, data, headers): raise RosetteException(code, message, url) except: raise - except (httplib.BadStatusLine, gaierror): + except requests.exceptions.RequestException as e: raise RosetteException( - "ConnectionError", + e.message, "Unable to establish connection to the Rosette API server", url) From bead60631723dfd7a9ac77ef634400b03b69aa18 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 19 Aug 2016 15:09:12 -0400 Subject: [PATCH 004/247] Added connection pooling and test - Added the responsive max pool setting - Unit test added and passed --- rosette/api.py | 48 +++++++++++++++++++++------------------ tests/test_rosette_api.py | 18 +++++++++++++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index c85fc0e..05b78c1 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -482,8 +482,8 @@ def call(self, parameters): 'application/json')} request = requests.Request( 'POST', url, files=files, headers=headers) - prepared_request = request.prepare() session = requests.Session() + prepared_request = session.prepare_request(request) resp = session.send(prepared_request) rdata = resp.content response_headers = {"responseHeaders": dict(resp.headers)} @@ -512,7 +512,6 @@ def __init__( user_key=None, service_url='https://api.rosette.com/rest/v1/', retries=5, - reuse_connection=True, refresh_duration=0.5, debug=False): """ Create an L{API} object. @@ -534,22 +533,20 @@ def __init__( refresh_duration = 0 self.num_retries = retries - self.reuse_connection = reuse_connection self.connection_refresh_duration = refresh_duration - self.http_connection = None self.options = {} self.customHeaders = {} + self.maxPoolSize = 1 + self.session = requests.Session() + + def _set_pool_size(self): + adapter = requests.adapters.HTTPAdapter(pool_maxsize=self.maxPoolSize) + if 'https:' in self.service_url: + self.session.mount('https://', adapter) + else: + self.session.mount('http://', adapter) + - def _connect(self, parsedUrl): - """ Simple connection method - @param parsedUrl: The URL on which to process - """ - if not self.reuse_connection or self.http_connection is None: - loc = parsedUrl.netloc - if parsedUrl.scheme == "https": - self.http_connection = httplib.HTTPSConnection(loc) - else: - self.http_connection = httplib.HTTPConnection(loc) def _make_request(self, op, url, data, headers): """ @@ -561,9 +558,6 @@ def _make_request(self, op, url, data, headers): @param headers: request headers """ headers['User-Agent'] = "RosetteAPIPython/" + _BINDING_VERSION - parsedUrl = urlparse.urlparse(url) - - self._connect(parsedUrl) message = None code = "unknownError" @@ -571,15 +565,21 @@ def _make_request(self, op, url, data, headers): response_headers = {} request = requests.Request(op, url, data=data, headers=headers) - prepared_request = request.prepare() session = requests.Session() + prepared_request = session.prepare_request(request) for i in range(self.num_retries + 1): try: response = session.send(prepared_request) status = response.status_code rdata = response.content - response_headers = {"responseHeaders": dict(response.headers)} + dict_headers = dict(response.headers) + response_headers = {"responseHeaders": dict_headers} + if 'x-rosetteapi-concurrency' in dict_headers: + if dict_headers['x-rosetteapi-concurrency'] != self.maxPoolSize: + self.maxPoolSize = dict_headers['x-rosetteapi-concurrency'] + self._set_pool_size() + if status == 200: return rdata, status, response_headers @@ -598,6 +598,7 @@ def _make_request(self, op, url, data, headers): else: code = status raise RosetteException(code, message, url) + except: raise except requests.exceptions.RequestException as e: @@ -606,9 +607,6 @@ def _make_request(self, op, url, data, headers): "Unable to establish connection to the Rosette API server", url) - if not self.reuse_connection: - self.http_connection.close() - raise RosetteException(code, message, url) def _get_http(self, url, headers): @@ -644,6 +642,12 @@ def _post_http(self, url, data, headers): return _ReturnObject(_my_loads(rdata, response_headers), status) + def getPoolSize(self): + """ + Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value + """ + return int(self.maxPoolSize) + def setOption(self, name, value): """ Sets an option diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index f17209c..0290d7d 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -170,6 +170,24 @@ def test_for_409(api, json_409): httpretty.disable() httpretty.reset() +# Test the maxPoolSize + + +def test_the_max_pool_size(json_response, doc_params): + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/language", + body=json_response, status=200, content_type="application/json", + adding_headers={ + 'x-rosetteapi-concurrency': 5 + }) + api = API('bogus_key') + assert api.getPoolSize() == 1 + result = api.language(doc_params) + assert result["name"] == "Rosette API" + assert api.getPoolSize() == 5 + httpretty.disable() + httpretty.reset() + # Test the language endpoint From a2696f9703593de5c7e674af513afdd45f79b5e0 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 19 Aug 2016 15:15:49 -0400 Subject: [PATCH 005/247] Formatting fix per Travis --- rosette/api.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 05b78c1..c0aa904 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -546,8 +546,6 @@ def _set_pool_size(self): else: self.session.mount('http://', adapter) - - def _make_request(self, op, url, data, headers): """ Handles the actual request, retrying if a 429 is encountered @@ -580,7 +578,6 @@ def _make_request(self, op, url, data, headers): self.maxPoolSize = dict_headers['x-rosetteapi-concurrency'] self._set_pool_size() - if status == 200: return rdata, status, response_headers if status == 429: From b92b2a8d3c90dbaea1c91888157c26bd5c0e5c51 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 26 Aug 2016 11:05:09 -0400 Subject: [PATCH 006/247] text-embedding added - Added api.text_embedding - Added unit test - Added text_embedding.py example (still requires data update) --- examples/text_embedding.py | 30 ++++++++++++++++++++++++++++++ rosette/api.py | 8 ++++++++ tests/test_rosette_api.py | 11 +++++++++++ 3 files changed, 49 insertions(+) create mode 100644 examples/text_embedding.py diff --git a/examples/text_embedding.py b/examples/text_embedding.py new file mode 100644 index 0000000..47a41e5 --- /dev/null +++ b/examples/text_embedding.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +""" +Example code to call Rosette API to get text vectors from a piece of text. +""" + +import argparse +import json +import os + +from rosette.api import API, DocumentParameters + + +def run(key, altUrl='https://api.rosette.com/rest/v1/'): + # Create an API instance + api = API(user_key=key, service_url=altUrl) + entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS" + params = DocumentParameters() + params["content"] = entities_text_data + params["genre"] = "social-media" + return api.text_embedding(params) + +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index c0aa904..62b5334 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -843,3 +843,11 @@ def matched_name(self, parameters): @type parameters: L{NameSimilarityParameters} @return: A python dictionary containing the results of name matching.""" return self.name_similarity(parameters) + + def text_embedding(self, parameters): + """ + Create an L{EndpointCaller} to identify text vectors found in the texts + to which it is applied and call it. + @type parameters: L{DocumentParameters} or L{str} + @return: A python dictionary containing the results of text embedding.""" + return EndpointCaller(self, "text-embedding").call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 0290d7d..186abda 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -579,3 +579,14 @@ def test_for_name_translation_required_parameters(api, json_response): httpretty.disable() httpretty.reset() + + +def test_the_text_embedded_endpoint(api, json_response, doc_params): + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/text-embedding", + body=json_response, status=200, content_type="application/json") + + result = api.text_embedding(doc_params) + assert result["name"] == "Rosette API" + httpretty.disable() + httpretty.reset() From 9a22db007931e220058b60667368fcf81d668852 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 29 Aug 2016 14:46:31 -0400 Subject: [PATCH 007/247] Clean up - Removed unused references --- rosette/api.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 62b5334..ed2ddd0 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -24,7 +24,6 @@ import sys import time import os -from socket import gaierror import requests import re import warnings @@ -35,15 +34,6 @@ _IsPy3 = sys.version_info[0] == 3 -try: - import urlparse -except ImportError: - import urllib.parse as urlparse -try: - import httplib -except ImportError: - import http.client as httplib - if _IsPy3: _GZIP_SIGNATURE = _GZIP_BYTEARRAY else: From 6ddba4d11796440c84531a931dd5026d4840f455 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 31 Aug 2016 10:02:23 -0400 Subject: [PATCH 008/247] Updated with embeddings_data --- examples/text_embedding.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/text_embedding.py b/examples/text_embedding.py index 47a41e5..bd23cf3 100644 --- a/examples/text_embedding.py +++ b/examples/text_embedding.py @@ -14,9 +14,9 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) - entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS" + embeddings_data = "Cambridge, Massachusetts" params = DocumentParameters() - params["content"] = entities_text_data + params["content"] = embeddings_data params["genre"] = "social-media" return api.text_embedding(params) From f9e7586ddc1209cf447b938b593a87c31f7f154f Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 31 Aug 2016 11:10:28 -0400 Subject: [PATCH 009/247] Removed errant social media from text_embedding --- examples/text_embedding.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/text_embedding.py b/examples/text_embedding.py index bd23cf3..c91ae82 100644 --- a/examples/text_embedding.py +++ b/examples/text_embedding.py @@ -17,7 +17,6 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): embeddings_data = "Cambridge, Massachusetts" params = DocumentParameters() params["content"] = embeddings_data - params["genre"] = "social-media" return api.text_embedding(params) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') From 4e654ed1892812d997e6b55c519e910382816c35 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 8 Sep 2016 16:55:33 +0000 Subject: [PATCH 010/247] Version 1.3.0 --- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index e6efe5e..84ab615 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -16,4 +16,4 @@ limitations under the License. """ -__version__ = '1.2.0' +__version__ = '1.3.0' diff --git a/rosette/api.py b/rosette/api.py index ed2ddd0..41d1c8f 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import re import warnings -_BINDING_VERSION = '1.2.0' +_BINDING_VERSION = '1.3.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _IsPy3 = sys.version_info[0] == 3 From cd295828e2483e5165e794c2e73cfdd102aa260a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 19 Sep 2016 09:36:25 -0400 Subject: [PATCH 011/247] Update to reference rosetteapi/docker-python - Removed docker directory - Updated README --- README.md | 9 ++++ docker/Dockerfile | 54 -------------------- docker/README.md | 12 ----- docker/run_python.sh | 115 ------------------------------------------- docker/tox.ini | 18 ------- 5 files changed, 9 insertions(+), 199 deletions(-) delete mode 100644 docker/Dockerfile delete mode 100644 docker/README.md delete mode 100644 docker/run_python.sh delete mode 100644 docker/tox.ini diff --git a/README.md b/README.md index 075fbf1..8e4184d 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,15 @@ The samples use the following procedure: See [examples](examples) for more request samples. +## Docker ## +A Docker image for running the examples against the compiled source library is available on Docker Hub. + +Command: `docker run -e API_KEY=api-key -v ":/source" rosetteapi/docker-python` + +Additional environment settings: +`-e ALT_URL=` +`-e FILENAME=` + API Documentation ----------------- diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index f8b6975..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,54 +0,0 @@ -FROM ubuntu:14.04 -MAINTAINER Fiona Hasanaj - -ENV DEBIAN_FRONTEND noninteractive -RUN locale-gen en_US.UTF-8 && /usr/sbin/update-locale LANG=en_US.UTF-8 -ENV LANG en_US.UTF-8 - -# proper init to handle signal propagation and zombie reaping -ADD https://github.com/krallin/tini/releases/download/v0.8.4/tini /tini -RUN chmod +x /tini -ENTRYPOINT ["/tini", "--"] - -RUN apt-get update && \ - apt-get -y install \ - wget \ - curl \ - libssl-dev \ - libffi-dev \ - python-pip \ - python-software-properties \ - software-properties-common && \ - add-apt-repository -y ppa:fkrull/deadsnakes && \ - apt-get update && \ - apt-get -y install \ - python2.6 \ - python2.7 \ - python3.3 \ - python3.4 \ - python3.5 \ - git\ - pypy && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -RUN mkdir /install && \ - wget -O /install/pypy3-2.4-linux_x86_64-portable.tar.bz2 \ - "https://bitbucket.org/squeaky/portable-pypy/downloads/pypy3-2.4-linux_x86_64-portable.tar.bz2" && \ - tar jxf /install/pypy3-*.tar.bz2 -C /install && \ - rm /install/pypy3-*.tar.bz2 && \ - ln -s /install/pypy3-*/bin/pypy3 /usr/local/bin/pypy3 - -RUN pip install -U pip && pip install tox -RUN pip install --upgrade autopep8 - -# copy over the necessary files -COPY run_python.sh /python-dev/run_python.sh -RUN chmod 755 /python-dev/run_python.sh -COPY tox.ini /python-dev/tox.ini -WORKDIR /python-dev - -# allow interactive bash inside docker container -CMD ./run_python.sh - -VOLUME ["/source"] diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index 3838653..0000000 --- a/docker/README.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -# Docker Image for Python Examples ---- -### Summary -To simplify the running of the Python examples, the Dockerfile will build an image where the examples can be tested against the development source. - -### Basic Usage -Build the docker image, e.g. `docker build -t basistech/python:1.1 .` - -Run an example as `docker run -e API_KEY=api-key -v "path-to-local-python-dir:/source" basistech/python:1.1` - -To test against a specific source file, add `-e FILENAME=filename` before the `-v`, to test against an alternate url, add `-e ALT_URL=alternate_url`. \ No newline at end of file diff --git a/docker/run_python.sh b/docker/run_python.sh deleted file mode 100644 index 04e8c50..0000000 --- a/docker/run_python.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/bash - -retcode=0 -ping_url="https://api.rosette.com/rest/v1" -errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" ) - -#------------------ Functions ---------------------------------------------------- -#Gets called when the user doesn't provide any args -function HELP { - echo -e "\nusage: --key API_KEY [--FILENAME filename] [--url ALT_URL]" - echo " API_KEY - Rosette API key (required)" - echo " FILENAME - Python source file (optional)" - echo " ALT_URL - Alternate service URL (optional)" - echo "Compiles and runs the source file(s) using the local development source." - exit 1 -} - -if [ ! -z ${ALT_URL} ]; then - ping_url=${ALT_URL} -fi - -#Checks if Rosette API key is valid -function checkAPI { - match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden") - if [ ! -z $match ]; then - echo -e "\nInvalid Rosette API Key" - exit 1 - fi -} - -function cleanURL() { - # strip the trailing slash off of the alt_url if necessary - if [ ! -z "${ALT_URL}" ]; then - case ${ALT_URL} in - */) ALT_URL=${ALT_URL::-1} - echo "Slash detected" - ;; - esac - ping_url=${ALT_URL} - fi -} - -function validateURL() { - match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API") - if [ "${match}" = "" ]; then - echo -e "\n${ping_url} server not responding\n" - exit 1 - fi -} - -function runExample() { - echo -e "\n---------- ${1} start -------------" - result="" - if [ -z ${ALT_URL} ]; then - result="$(python ${1} --key ${API_KEY} 2>&1 )" - else - result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )" - fi - echo "${result}" - echo -e "\n---------- ${1} end -------------" - for err in "${errors[@]}"; do - if [[ ${result} == *"${err}"* ]]; then - retcode=1 - fi - done -} -#------------------ Functions End ------------------------------------------------ - -#Gets API_KEY, FILENAME and ALT_URL if present -while getopts ":API_KEY:FILENAME:ALT_URL" arg; do - case "${arg}" in - API_KEY) - API_KEY=${OPTARG} - ;; - ALT_URL) - ALT_URL=${OPTARG} - ;; - FILENAME) - FILENAME=${OPTARG} - ;; - esac -done - -cleanURL - -validateURL - - -#Copy the mounted content in /source to current WORKDIR -cp -r -n /source/* . - -#Run the examples -if [ ! -z ${API_KEY} ]; then - checkAPI - #Prerequisite - python /python-dev/setup.py install - cd /python-dev/examples - if [ ! -z ${FILENAME} ]; then - echo -e "\nRunning example against: ${ping_url}\n" - runExample ${FILENAME} - else - echo -e "\nRunning examples against: ${ping_url}\n" - for file in *.py; do - runExample ${file} - done - fi -else - HELP -fi - -#Run unit tests -cd /python-dev -tox - -exit ${retcode} diff --git a/docker/tox.ini b/docker/tox.ini deleted file mode 100644 index 5955b11..0000000 --- a/docker/tox.ini +++ /dev/null @@ -1,18 +0,0 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -skipsdist = True -envlist = py26, py27, py33, py34 - -[testenv] -commands = - py.test {toxinidir}/tests -s --pep8 -deps = - pytest - pytest-pep8 - httpretty - epydoc - requests From 752e8ecbbb1a29acdff10dfc476fe64a2442e007 Mon Sep 17 00:00:00 2001 From: kbailey-basistech Date: Fri, 23 Sep 2016 10:55:33 -0400 Subject: [PATCH 012/247] syntax/dependencies added --- examples/syntax_dependencies.py | 31 +++++++++++++++++++++++++++++++ rosette/api.py | 8 ++++++++ tests/test_rosette_api.py | 10 ++++++++++ 3 files changed, 49 insertions(+) create mode 100644 examples/syntax_dependencies.py diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py new file mode 100644 index 0000000..ad8df10 --- /dev/null +++ b/examples/syntax_dependencies.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +""" +Example code to call Rosette API to get the syntactic dependencies of a document (at a given URL). +""" + +import argparse +import json +import os + +from rosette.api import API, DocumentParameters + + +def run(key, altUrl='https://api.rosette.com/rest/v1/'): + syntax_dependencies_data = "Sony Pictures is planning to shoot a good portion of the new /"Ghostbusters/" in Boston as well." + params = DocumentParameters() + params["content"] = syntax_dependencies_dataa + params["genre"] = "social-media" + # Create an API instance + api = API(user_key=key, service_url=altUrl) + return api.syntax_dependencies(params) + + +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index 41d1c8f..b769f01 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -841,3 +841,11 @@ def text_embedding(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of text embedding.""" return EndpointCaller(self, "text-embedding").call(parameters) + + def syntax_dependencies(self, parameters): + """ + Create an L{EndpointCaller} to identify the syntactic dependencies in the texts + to which it is applied and call it. + @type parameters: L{DocumentParameters} or L{str} + @return: A python dictionary containing the results of syntactic dependencies identification + return EndpointCaller(self, "syntax/dependencies").call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 186abda..05b8fd3 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -590,3 +590,13 @@ def test_the_text_embedded_endpoint(api, json_response, doc_params): assert result["name"] == "Rosette API" httpretty.disable() httpretty.reset() + +def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): + httprettry.enable() + httpretty.register_url(httpretty.POST, "https://api.rosette.com/rest/v1/syntax/dependencies", + body=json_response, status=200, content_type="application/json") + + result = api.syntax_dependencies(doc_params) + assert result["name"] == "Rosette API" + httpretty.disable() + httprettty.reset() From 9df12abdfcebaae96dcffb9889590b3ccf9620eb Mon Sep 17 00:00:00 2001 From: kbailey-basistech Date: Fri, 23 Sep 2016 13:19:31 -0400 Subject: [PATCH 013/247] syntax/dependencies with passing tests --- examples/syntax_dependencies.py | 2 +- rosette/api.py | 2 +- tests/test_rosette_api.py | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index ad8df10..58ceb7f 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -12,7 +12,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): - syntax_dependencies_data = "Sony Pictures is planning to shoot a good portion of the new /"Ghostbusters/" in Boston as well." + syntax_dependencies_data = "Sony Pictures is planning to shoot a good portion of the new \"Ghostbusters\" in Boston as well." params = DocumentParameters() params["content"] = syntax_dependencies_dataa params["genre"] = "social-media" diff --git a/rosette/api.py b/rosette/api.py index b769f01..cd6ed09 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -847,5 +847,5 @@ def syntax_dependencies(self, parameters): Create an L{EndpointCaller} to identify the syntactic dependencies in the texts to which it is applied and call it. @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of syntactic dependencies identification + @return: A python dictionary containing the results of syntactic dependencies identification""" return EndpointCaller(self, "syntax/dependencies").call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 05b8fd3..e4aa820 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -591,12 +591,13 @@ def test_the_text_embedded_endpoint(api, json_response, doc_params): httpretty.disable() httpretty.reset() + def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): - httprettry.enable() - httpretty.register_url(httpretty.POST, "https://api.rosette.com/rest/v1/syntax/dependencies", + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/syntax/dependencies", body=json_response, status=200, content_type="application/json") result = api.syntax_dependencies(doc_params) assert result["name"] == "Rosette API" httpretty.disable() - httprettty.reset() + httpretty.reset() From 16362f8f3800a0e6aa9c20e689f1e5ca4653f9f3 Mon Sep 17 00:00:00 2001 From: kbailey-basistech Date: Mon, 26 Sep 2016 16:24:58 -0400 Subject: [PATCH 014/247] examples fix for syntax dependencies --- examples/syntax_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index 58ceb7f..f76c423 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -14,7 +14,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): syntax_dependencies_data = "Sony Pictures is planning to shoot a good portion of the new \"Ghostbusters\" in Boston as well." params = DocumentParameters() - params["content"] = syntax_dependencies_dataa + params["content"] = syntax_dependencies_data params["genre"] = "social-media" # Create an API instance api = API(user_key=key, service_url=altUrl) From bdf484d1fe262daec584525a41b3dd7e5d3567f3 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 4 Oct 2016 08:48:58 -0400 Subject: [PATCH 015/247] Removed 429 loop - Removed test and loop for 429 error code - Removed retries variable - Removed 429 unit tests --- rosette/api.py | 73 ++++++++++++++++++--------------------- tests/test_rosette_api.py | 22 +----------- 2 files changed, 34 insertions(+), 61 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index cd6ed09..a087217 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -522,7 +522,6 @@ def __init__( if (refresh_duration < 0): refresh_duration = 0 - self.num_retries = retries self.connection_refresh_duration = refresh_duration self.options = {} self.customHeaders = {} @@ -538,8 +537,6 @@ def _set_pool_size(self): def _make_request(self, op, url, data, headers): """ - Handles the actual request, retrying if a 429 is encountered - @param op: POST or GET @param url: endpoing URL @param data: request data @@ -556,43 +553,39 @@ def _make_request(self, op, url, data, headers): session = requests.Session() prepared_request = session.prepare_request(request) - for i in range(self.num_retries + 1): - try: - response = session.send(prepared_request) - status = response.status_code - rdata = response.content - dict_headers = dict(response.headers) - response_headers = {"responseHeaders": dict_headers} - if 'x-rosetteapi-concurrency' in dict_headers: - if dict_headers['x-rosetteapi-concurrency'] != self.maxPoolSize: - self.maxPoolSize = dict_headers['x-rosetteapi-concurrency'] - self._set_pool_size() - - if status == 200: - return rdata, status, response_headers - if status == 429: - code = status - message = "{0} ({1})".format(rdata, i) - time.sleep(self.connection_refresh_duration) - continue - if rdata is not None: - try: - the_json = _my_loads(rdata, response_headers) - if 'message' in the_json: - message = the_json['message'] - if "code" in the_json: - code = the_json['code'] - else: - code = status - raise RosetteException(code, message, url) - - except: - raise - except requests.exceptions.RequestException as e: - raise RosetteException( - e.message, - "Unable to establish connection to the Rosette API server", - url) + try: + response = session.send(prepared_request) + status = response.status_code + rdata = response.content + dict_headers = dict(response.headers) + response_headers = {"responseHeaders": dict_headers} + if 'x-rosetteapi-concurrency' in dict_headers: + if dict_headers['x-rosetteapi-concurrency'] != self.maxPoolSize: + self.maxPoolSize = dict_headers['x-rosetteapi-concurrency'] + self._set_pool_size() + + if status == 200: + return rdata, status, response_headers + if rdata is not None: + try: + the_json = _my_loads(rdata, response_headers) + if 'message' in the_json: + message = the_json['message'] + if "code" in the_json: + code = the_json['code'] + else: + code = status + if not message: + message = rdata + raise RosetteException(code, message, url) + + except: + raise + except requests.exceptions.RequestException as e: + raise RosetteException( + e.message, + "Unable to establish connection to the Rosette API server", + url) raise RosetteException(code, message, url) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index e4aa820..4a4f058 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -47,12 +47,6 @@ def api(): return api -@pytest.fixture -def json_429(scope="module"): - body = json.dumps({'message': 'too many requests', 'versionChecked': True}) - return body - - @pytest.fixture def json_409(scope="module"): body = json.dumps({'code': 'incompatibleClientVersion', 'message': 'the version of client library used is not compatible with this server', 'versionChecked': True}) @@ -140,22 +134,8 @@ def test_info(api, json_response): httpretty.disable() httpretty.reset() -# Test for 429 - - -def test_for_429(api, json_429): - httpretty.enable() - httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info", - body=json_429, status=429, content_type="application/json") - - with pytest.raises(RosetteException) as e_rosette: - result = api.info() - - assert e_rosette.value.status == 429 - httpretty.disable() - httpretty.reset() -# Test for 429 +# Test for 409 def test_for_409(api, json_409): From affb3e51ff034e768cc15cad7d4409fac9ae2d73 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 5 Oct 2016 14:41:48 -0400 Subject: [PATCH 016/247] Updated examples --- examples/relationships.py | 2 +- examples/syntax_dependencies.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/relationships.py b/examples/relationships.py index e117ac9..86aefec 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -14,7 +14,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) - relationships_text_data = "The Ghostbusters movie was filmed in Boston." + relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." params = DocumentParameters() params["content"] = relationships_text_data api.setOption('accuracyMode', 'PRECISION') diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index f76c423..1f5f511 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -12,7 +12,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): - syntax_dependencies_data = "Sony Pictures is planning to shoot a good portion of the new \"Ghostbusters\" in Boston as well." + syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday." params = DocumentParameters() params["content"] = syntax_dependencies_data params["genre"] = "social-media" From a4a26444731c6e02247810b0c5dc181dc562cbb3 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 6 Oct 2016 13:12:48 +0000 Subject: [PATCH 017/247] Version 1.4.0 --- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index 84ab615..340a3ad 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -16,4 +16,4 @@ limitations under the License. """ -__version__ = '1.3.0' +__version__ = '1.4.0' diff --git a/rosette/api.py b/rosette/api.py index a087217..344955e 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import re import warnings -_BINDING_VERSION = '1.3.0' +_BINDING_VERSION = '1.4.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _IsPy3 = sys.version_info[0] == 3 From f371fa5ab83ab42509c727c6442ef8a483abc201 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 17 Nov 2016 07:50:36 -0500 Subject: [PATCH 018/247] RCB-492 setUrlParameters - Added api.[set|get]urlParameters to python binding - Added unit tests for get/set/clear to python binding --- rosette/api.py | 38 +++++++++++++++++++++++++++++++++++++- tests/test_rosette_api.py | 18 ++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 344955e..9079b37 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -525,6 +525,7 @@ def __init__( self.connection_refresh_duration = refresh_duration self.options = {} self.customHeaders = {} + self.urlParameters = {} self.maxPoolSize = 1 self.session = requests.Session() @@ -549,7 +550,11 @@ def _make_request(self, op, url, data, headers): rdata = None response_headers = {} - request = requests.Request(op, url, data=data, headers=headers) + payload = None + if (self.urlParameters): + payload = self.urlParameters + + request = requests.Request(op, url, data=data, headers=headers, params=payload) session = requests.Session() prepared_request = session.prepare_request(request) @@ -659,6 +664,37 @@ def clearOptions(self): """ self.options.clear() + def setUrlParameter(self, name, value): + """ + Sets a URL parameter + + @param name: name of parameter + @param value: value of parameter + """ + if value is None: + self.urlParameters.pop(name, None) + else: + self.urlParameters[name] = value + + def getUrlParameter(self, name): + """ + Gets a URL parameter + + @param name: name of parameter + + @return: value of parameter + """ + if name in self.urlParameters.keys(): + return self.urlParameters[name] + else: + return None + + def clearUrlParameters(self): + """ + Clears all options + """ + self.urlParameters.clear() + def setCustomHeaders(self, name, value): """ Sets custom headers diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 4a4f058..cb0e793 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -82,6 +82,24 @@ def test_option_clear_single_option(api): api.setOption('test', None) assert api.getOption('test') is None +# Test the URL parameter set/get/clear + + +def test_UrlParameter_get_set_clear(api): + api.setUrlParameter('test', 'foo') + assert 'foo' == api.getUrlParameter('test') + + api.clearUrlParameters() + assert api.getUrlParameter('test') is None + + +def test_UrlParameter_clear_single_option(api): + api.setUrlParameter('test', 'foo') + assert 'foo' == api.getUrlParameter('test') + + api.setUrlParameter('test', None) + assert api.getUrlParameter('test') is None + # Test the custom header set/get/clear From ddc4cf18ab83c2f51904b2408bc6e9761ab3643a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 17 Nov 2016 13:07:03 +0000 Subject: [PATCH 019/247] Version 1.4.1 --- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index 340a3ad..9884ca7 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -16,4 +16,4 @@ limitations under the License. """ -__version__ = '1.4.0' +__version__ = '1.4.1' diff --git a/rosette/api.py b/rosette/api.py index 9079b37..ea6c08f 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import re import warnings -_BINDING_VERSION = '1.4.0' +_BINDING_VERSION = '1.4.1' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _IsPy3 = sys.version_info[0] == 3 From 8200ddf20084ac35b3bcebfa4d57f4d1a6a7346c Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 18 Nov 2016 13:09:10 +0000 Subject: [PATCH 020/247] Version 1.4.2 --- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index 9884ca7..c25e2c3 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -16,4 +16,4 @@ limitations under the License. """ -__version__ = '1.4.1' +__version__ = '1.4.2' diff --git a/rosette/api.py b/rosette/api.py index ea6c08f..1b98d2c 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import re import warnings -_BINDING_VERSION = '1.4.1' +_BINDING_VERSION = '1.4.2' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _IsPy3 = sys.version_info[0] == 3 From 22d4eb2c0a027f204447340b1066b5de9b21ee87 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 18 Nov 2016 13:09:22 +0000 Subject: [PATCH 021/247] publish python apidocs 1.4.2 --- doc/api.html | 576 +++++++++++++++++++++++++++++ rosette/__init__.py | 19 - rosette/api.py | 880 -------------------------------------------- 3 files changed, 576 insertions(+), 899 deletions(-) create mode 100644 doc/api.html delete mode 100644 rosette/__init__.py delete mode 100644 rosette/api.py diff --git a/doc/api.html b/doc/api.html new file mode 100644 index 0000000..a6ab71f --- /dev/null +++ b/doc/api.html @@ -0,0 +1,576 @@ + +Python: module api + + + + + +
 
+ 
api
index
/python/rosette/api.py
+

Python client for the Rosette API.

+Copyright (c) 2014-2015 Basis Technology Corporation.

+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+http://www.apache.org/licenses/LICENSE-2.0

+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.

+

+ + + + + +
 
+Modules
       
gzip
+json
+logging
+
os
+re
+requests
+
sys
+time
+warnings
+

+ + + + + +
 
+Classes
       
+
_DocumentParamSetBase(builtins.object) +
+
+
DocumentParameters +
NameSimilarityParameters +
NameTranslationParameters +
+
+
_PseudoEnum(builtins.object) +
+
+
MorphologyOutput +
+
+
builtins.Exception(builtins.BaseException) +
+
+
RosetteException +
+
+
builtins.object +
+
+
API +
EndpointCaller +
+
+
+

+ + + + + + + +
 
+class API(builtins.object)
   Rosette Python Client Binding API; representation of a Rosette server.
+Call instance methods upon this object to obtain L{EndpointCaller} objects
+which can communicate with particular Rosette server endpoints.
 
 Methods defined here:
+
__init__(self, user_key=None, service_url='https://api.rosette.com/rest/v1/', retries=5, refresh_duration=0.5, debug=False)
Create an L{APIobject.
+@param user_key: (Optional; required for servers requiring authentication.) An authentication string to be sent
+ as user_key with all requests.  The default Rosette server requires authentication.
+ to the server.
+ +
categories(self, parameters)
Create an L{EndpointCaller} to identify the category of the text to which
+it is applied and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the category identifier.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of categorization.
+ +
clearCustomHeaders(self)
Clears custom headers
+ +
clearOptions(self)
Clears all options
+ +
clearUrlParameters(self)
Clears all options
+ +
entities(self, parameters, resolve_entities=False)
Create an L{EndpointCaller}  to identify named entities found in the texts
+to which it is applied and call it. Linked entity information is optional, and
+its need must be specified at the time the operator is created.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the entity identifier.
+@type parameters: L{DocumentParameters} or L{str}
+@param resolve_entities: Specifies whether or not linked entity information will
+be wanted.
+@type resolve_entities: Boolean
+@return: A python dictionary containing the results of entity extraction.
+ +
getCustomHeaders(self)
Get custom headers
+ +
getOption(self, name)
Gets an option

+@param name: name of option

+@return: value of option
+ +
getPoolSize(self)
Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value
+ +
getUrlParameter(self, name)
Gets a URL parameter

+@param name: name of parameter

+@return: value of parameter
+ +
info(self)
Create a ping L{EndpointCaller} for the server and ping it.
+@return: A python dictionary including the ping message of the L{API}
+ +
language(self, parameters)
Create an L{EndpointCaller} for language identification and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the language identifier.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of language
+identification.
+ +
matched_name(self, parameters)
deprecated
+Call name_similarity to perform name matching.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the name matcher.
+@type parameters: L{NameSimilarityParameters}
+@return: A python dictionary containing the results of name matching.
+ +
morphology(self, parameters, facet='complete')
Create an L{EndpointCaller} to returns a specific facet
+of the morphological analyses of texts to which it is applied and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the morphology analyzer.
+@type parameters: L{DocumentParameters} or L{str}
+@param facet: The facet desired, to be returned by the created L{EndpointCaller}.
+@type facet: An element of L{MorphologyOutput}.
+@return: A python dictionary containing the results of morphological analysis.
+ +
name_similarity(self, parameters)
Create an L{EndpointCaller} to perform name similarity scoring and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the name matcher.
+@type parameters: L{NameSimilarityParameters}
+@return: A python dictionary containing the results of name matching.
+ +
name_translation(self, parameters)
Create an L{EndpointCaller} to perform name analysis and translation
+upon the name to which it is applied and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the name translator.
+@type parameters: L{NameTranslationParameters}
+@return: A python dictionary containing the results of name translation.
+ +
ping(self)
Create a ping L{EndpointCaller} for the server and ping it.
+@return: A python dictionary including the ping message of the L{API}
+ +
relationships(self, parameters)
Create an L{EndpointCaller} to identify the relationships between entities in the text to
+which it is applied and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the relationships identifier.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of relationship extraction.
+ +
sentences(self, parameters)
Create an L{EndpointCaller} to break a text into sentences and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the sentence identifier.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of sentence identification.
+ +
sentiment(self, parameters)
Create an L{EndpointCaller} to identify the sentiment of the text to
+which it is applied and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the sentiment identifier.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of sentiment identification.
+ +
setCustomHeaders(self, name, value)
Sets custom headers

+@param headers: array of custom headers to be set
+ +
setOption(self, name, value)
Sets an option

+@param name: name of option
+@param value: value of option
+ +
setUrlParameter(self, name, value)
Sets a URL parameter

+@param name: name of parameter
+@param value: value of parameter
+ +
syntax_dependencies(self, parameters)
Create an L{EndpointCaller} to identify the syntactic dependencies in the texts
+to which it is applied and call it.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of syntactic dependencies identification
+ +
text_embedding(self, parameters)
Create an L{EndpointCaller}  to identify text vectors found in the texts
+to which it is applied and call it.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of text embedding.
+ +
tokens(self, parameters)
Create an L{EndpointCaller} to break a text into tokens and call it.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the tokens identifier.
+@type parameters: L{DocumentParameters} or L{str}
+@return: A python dictionary containing the results of tokenization.
+ +
translated_name(self, parameters)
deprecated
+Call name_translation to perform name analysis and translation
+upon the name to which it is applied.
+@param parameters: An object specifying the data,
+and possible metadata, to be processed by the name translator.
+@type parameters: L{NameTranslationParameters}
+@return: A python dictionary containing the results of name translation.
+ +
+Data descriptors defined here:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + + + +
 
+class DocumentParameters(_DocumentParamSetBase)
   Parameter object for all operations requiring input other than
+translated_name.
+Two fields, C{content} and C{inputUri}, are set via
+the subscript operator, e.g., C{params["content"]}, or the
+convenience instance methods L{DocumentParameters.load_document_file}
+and L{DocumentParameters.load_document_string}.

+Using subscripts instead of instance variables facilitates diagnosis.

+If the field C{contentUri} is set to the URL of a web page (only
+protocols C{http, https, ftp, ftps} are accepted), the server will
+fetch the content from that web page.  In this case, C{content} may not be set.
 
 
Method resolution order:
+
DocumentParameters
+
_DocumentParamSetBase
+
builtins.object
+
+
+Methods defined here:
+
__init__(self)
Create a L{DocumentParametersobject.
+ +
load_document_file(self, path)
Loads a file into the object.
+The file will be read as bytes; the appropriate conversion will
+be determined by the server.
+@parameter path: Pathname of a file acceptable to the C{open} function.
+ +
load_document_string(self, s)
Loads a string into the object.
+The string will be taken as bytes or as Unicode dependent upon
+its native python type.
+@parameter s: A string, possibly a unicode-string, to be loaded
+for subsequent analysis.
+ +
serialize(self, options)
Internal. Do not use.
+ +
validate(self)
Internal. Do not use.
+ +
+Methods inherited from _DocumentParamSetBase:
+
__getitem__(self, key)
+ +
__setitem__(self, key, val)
+ +
+Data descriptors inherited from _DocumentParamSetBase:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + + + +
 
+class EndpointCaller(builtins.object)
   L{EndpointCaller} objects are invoked via their instance methods to obtain results
+from the Rosette server described by the L{APIobject from which they
+are created.  Each L{EndpointCallerobject communicates with a specific endpoint
+of the Rosette server, specified at its creation.  Use the specific
+instance methods of the L{APIobject to create L{EndpointCaller} objects bound to
+corresponding endpoints.

+Use L{EndpointCaller.ping} to ping, and L{EndpointCaller.info} to retrieve server info.
+For all other types of requests, use L{EndpointCaller.call}, which accepts
+an argument specifying the data to be processed and certain metadata.

+The results of all operations are returned as python dictionaries, whose
+keys and values correspond exactly to those of the corresponding
+JSON return value described in the Rosette web service documentation.
 
 Methods defined here:
+
__init__(self, api, suburl)
This method should not be invoked by the user.  Creation is reserved
+for internal use by API objects.
+ +
call(self, parameters)
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{EndpointCallerobject is bound.  For all
+endpoints except C{name-translation} and C{name-similarity}, it must be a L{DocumentParameters}
+object or a string; for C{name-translation}, it must be an L{NameTranslationParametersobject;
+for C{name-similarity}, it must be an L{NameSimilarityParametersobject. For relationships,
+it may be an L(DocumentParameters).

+In all cases, the result is returned as a python dictionary
+conforming to the JSON object described in the endpoint's entry
+in the Rosette web service documentation.

+@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}
+@return: A python dictionary expressing the result of the invocation.
+ +
info(self)
Issues an "info" request to the L{EndpointCaller}'s specific endpoint.
+@return: A dictionary telling server version and other
+identifying data.
+ +
ping(self)
Issues a "ping" request to the L{EndpointCaller}'s (server-wide) endpoint.
+@return: A dictionary if OK.  If the server cannot be reached,
+or is not the right server or some other error occurs, it will be
+signalled.
+ +
+Data descriptors defined here:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + +
 
+class MorphologyOutput(_PseudoEnum)
    
Method resolution order:
+
MorphologyOutput
+
_PseudoEnum
+
builtins.object
+
+
+Data and other attributes defined here:
+
COMPLETE = 'complete'
+ +
COMPOUND_COMPONENTS = 'compound-components'
+ +
HAN_READINGS = 'han-readings'
+ +
LEMMAS = 'lemmas'
+ +
PARTS_OF_SPEECH = 'parts-of-speech'
+ +
+Methods inherited from _PseudoEnum:
+
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
+ +
+Class methods inherited from _PseudoEnum:
+
validate(value, name) from builtins.type
+ +
+Data descriptors inherited from _PseudoEnum:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + + + +
 
+class NameSimilarityParameters(_DocumentParamSetBase)
   Parameter object for C{name-similarity} endpoint.
+All are required.

+C{name1} The name to be matched, a C{name} object.

+C{name2} The name to be matched, a C{name} object.

+The C{name} object contains these fields:

+C{text} Text of the name, required.

+C{language} Language of the name in ISO639 three-letter code, optional.

+C{script} The ISO15924 code of the name, optional.

+C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional.
 
 
Method resolution order:
+
NameSimilarityParameters
+
_DocumentParamSetBase
+
builtins.object
+
+
+Methods defined here:
+
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
+ +
validate(self)
Internal. Do not use.
+ +
+Methods inherited from _DocumentParamSetBase:
+
__getitem__(self, key)
+ +
__setitem__(self, key, val)
+ +
serialize(self, options)
+ +
+Data descriptors inherited from _DocumentParamSetBase:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + + + +
 
+class NameTranslationParameters(_DocumentParamSetBase)
   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}).
+All are optional except C{name} and C{targetLanguage}.  Scripts are in
+ISO15924 codes, and languages in ISO639 (two- or three-letter) codes.  See the Name Translation documentation for
+more description of these terms, as well as the content of the return result.

+C{name} The name to be translated.

+C{targetLangauge} The language into which the name is to be translated.

+C{entityType} The entity type (TBD) of the name.

+C{sourceLanguageOfOrigin} The language of origin of the name.

+C{sourceLanguageOfUse} The language of use of the name.

+C{sourceScript} The script in which the name is supplied.

+C{targetScript} The script into which the name should be translated.

+C{targetScheme} The transliteration scheme by which the translated name should be rendered.
 
 
Method resolution order:
+
NameTranslationParameters
+
_DocumentParamSetBase
+
builtins.object
+
+
+Methods defined here:
+
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
+ +
validate(self)
Internal. Do not use.
+ +
+Methods inherited from _DocumentParamSetBase:
+
__getitem__(self, key)
+ +
__setitem__(self, key, val)
+ +
serialize(self, options)
+ +
+Data descriptors inherited from _DocumentParamSetBase:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + + + +
 
+class RosetteException(builtins.Exception)
   Exception thrown by all Rosette API operations for errors local and remote.

+TBD. Right now, the only valid operation is conversion to __str__.
 
 
Method resolution order:
+
RosetteException
+
builtins.Exception
+
builtins.BaseException
+
builtins.object
+
+
+Methods defined here:
+
__init__(self, status, message, response_message)
Initialize self.  See help(type(self)) for accurate signature.
+ +
__str__(self)
Return str(self).
+ +
+Data descriptors defined here:
+
__weakref__
+
list of weak references to the object (if defined)
+
+
+Methods inherited from builtins.Exception:
+
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
+ +
+Methods inherited from builtins.BaseException:
+
__delattr__(self, name, /)
Implement delattr(self, name).
+ +
__getattribute__(self, name, /)
Return getattr(self, name).
+ +
__reduce__(...)
helper for pickle
+ +
__repr__(self, /)
Return repr(self).
+ +
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
+ +
__setstate__(...)
+ +
with_traceback(...)
Exception.with_traceback(tb) --
+set self.__traceback__ to tb and return self.
+ +
+Data descriptors inherited from builtins.BaseException:
+
__cause__
+
exception cause
+
+
__context__
+
exception context
+
+
__dict__
+
+
__suppress_context__
+
+
__traceback__
+
+
args
+
+

+ \ No newline at end of file diff --git a/rosette/__init__.py b/rosette/__init__.py deleted file mode 100644 index c25e2c3..0000000 --- a/rosette/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -Python client for the Rosette API. - -Copyright (c) 2014-2015 Basis Technology Corporation. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -__version__ = '1.4.2' diff --git a/rosette/api.py b/rosette/api.py deleted file mode 100644 index 1b98d2c..0000000 --- a/rosette/api.py +++ /dev/null @@ -1,880 +0,0 @@ -#!/usr/bin/env python - -""" -Python client for the Rosette API. - -Copyright (c) 2014-2015 Basis Technology Corporation. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -from io import BytesIO -import gzip -import json -import logging -import sys -import time -import os -import requests -import re -import warnings - -_BINDING_VERSION = '1.4.2' -_GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) - -_IsPy3 = sys.version_info[0] == 3 - - -if _IsPy3: - _GZIP_SIGNATURE = _GZIP_BYTEARRAY -else: - _GZIP_SIGNATURE = str(_GZIP_BYTEARRAY) - - -class _ReturnObject: - - def __init__(self, js, code): - self._json = js - self.status_code = code - - def json(self): - return self._json - - -def _my_loads(obj, response_headers): - if _IsPy3: - d1 = json.loads(obj.decode("utf-8")).copy() - d1.update(response_headers) - return d1 # if py3, need chars. - else: - d2 = json.loads(obj).copy() - d2.update(response_headers) - return d2 - - -class RosetteException(Exception): - """Exception thrown by all Rosette API operations for errors local and remote. - - TBD. Right now, the only valid operation is conversion to __str__. - """ - - def __init__(self, status, message, response_message): - self.status = status - self.message = message - self.response_message = response_message - - def __str__(self): - sst = self.status - if not (isinstance(sst, str)): - sst = repr(sst) - return sst + ": " + self.message + ":\n " + self.response_message - - -class _PseudoEnum: - - def __init__(self): - pass - - @classmethod - def validate(cls, value, name): - values = [] - for (k, v) in vars(cls).items(): - if not k.startswith("__"): - values += [v] - - # this is still needed to make sure that the parameter NAMES are known. - # If python didn't allow setting unknown values, this would be a - # language error. - if value not in values: - raise RosetteException( - "unknownVariable", - "The value supplied for " + - name + - " is not one of " + - ", ".join(values) + - ".", - repr(value)) - - -class MorphologyOutput(_PseudoEnum): - LEMMAS = "lemmas" - PARTS_OF_SPEECH = "parts-of-speech" - COMPOUND_COMPONENTS = "compound-components" - HAN_READINGS = "han-readings" - COMPLETE = "complete" - - -class _DocumentParamSetBase(object): - - def __init__(self, repertoire): - self.__params = {} - for k in repertoire: - self.__params[k] = None - - def __setitem__(self, key, val): - if key not in self.__params: - raise RosetteException( - "badKey", "Unknown Rosette parameter key", repr(key)) - self.__params[key] = val - - def __getitem__(self, key): - if key not in self.__params: - raise RosetteException( - "badKey", "Unknown Rosette parameter key", repr(key)) - return self.__params[key] - - def validate(self): - pass - - def serialize(self, options): - self.validate() - v = {} - for (key, val) in self.__params.items(): - if val is None: - pass - else: - v[key] = val - - if options is not None and len(options) > 0: - v['options'] = options - - return v - - -def _byteify(s): # py 3 only - l = len(s) - b = bytearray(l) - for ix in range(l): - oc = ord(s[ix]) - assert (oc < 256) - b[ix] = oc - return b - - -class DocumentParameters(_DocumentParamSetBase): - """Parameter object for all operations requiring input other than - translated_name. - Two fields, C{content} and C{inputUri}, are set via - the subscript operator, e.g., C{params["content"]}, or the - convenience instance methods L{DocumentParameters.load_document_file} - and L{DocumentParameters.load_document_string}. - - Using subscripts instead of instance variables facilitates diagnosis. - - If the field C{contentUri} is set to the URL of a web page (only - protocols C{http, https, ftp, ftps} are accepted), the server will - fetch the content from that web page. In this case, C{content} may not be set. - """ - - def __init__(self): - """Create a L{DocumentParameters} object.""" - _DocumentParamSetBase.__init__( - self, ("content", "contentUri", "language", "genre")) - self.file_name = "" - self.useMultipart = False - - def validate(self): - """Internal. Do not use.""" - if self["content"] is None: - if self["contentUri"] is None: - raise RosetteException( - "badArgument", - "Must supply one of Content or ContentUri", - "bad arguments") - else: # self["content"] not None - if self["contentUri"] is not None: - raise RosetteException( - "badArgument", - "Cannot supply both Content and ContentUri", - "bad arguments") - - def serialize(self, options): - """Internal. Do not use.""" - self.validate() - slz = super(DocumentParameters, self).serialize(options) - return slz - - def load_document_file(self, path): - """Loads a file into the object. - The file will be read as bytes; the appropriate conversion will - be determined by the server. - @parameter path: Pathname of a file acceptable to the C{open} function. - """ - self.useMultipart = True - self.file_name = path - self.load_document_string(open(path, "rb").read()) - - def load_document_string(self, s): - """Loads a string into the object. - The string will be taken as bytes or as Unicode dependent upon - its native python type. - @parameter s: A string, possibly a unicode-string, to be loaded - for subsequent analysis. - """ - self["content"] = s - - -class NameTranslationParameters(_DocumentParamSetBase): - """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}). - All are optional except C{name} and C{targetLanguage}. Scripts are in - ISO15924 codes, and languages in ISO639 (two- or three-letter) codes. See the Name Translation documentation for - more description of these terms, as well as the content of the return result. - - C{name} The name to be translated. - - C{targetLangauge} The language into which the name is to be translated. - - C{entityType} The entity type (TBD) of the name. - - C{sourceLanguageOfOrigin} The language of origin of the name. - - C{sourceLanguageOfUse} The language of use of the name. - - C{sourceScript} The script in which the name is supplied. - - C{targetScript} The script into which the name should be translated. - - C{targetScheme} The transliteration scheme by which the translated name should be rendered. - """ - - def __init__(self): - self.useMultipart = False - _DocumentParamSetBase.__init__( - self, - ("name", - "targetLanguage", - "entityType", - "sourceLanguageOfOrigin", - "sourceLanguageOfUse", - "sourceScript", - "targetScript", - "targetScheme", - "genre")) - - def validate(self): - """Internal. Do not use.""" - for n in ("name", "targetLanguage"): # required - if self[n] is None: - raise RosetteException( - "missingParameter", - "Required Name Translation parameter not supplied", - repr(n)) - - -class NameSimilarityParameters(_DocumentParamSetBase): - """Parameter object for C{name-similarity} endpoint. - All are required. - - C{name1} The name to be matched, a C{name} object. - - C{name2} The name to be matched, a C{name} object. - - The C{name} object contains these fields: - - C{text} Text of the name, required. - - C{language} Language of the name in ISO639 three-letter code, optional. - - C{script} The ISO15924 code of the name, optional. - - C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional. - """ - - def __init__(self): - self.useMultipart = False - _DocumentParamSetBase.__init__(self, ("name1", "name2")) - - def validate(self): - """Internal. Do not use.""" - for n in ("name1", "name2"): # required - if self[n] is None: - raise RosetteException( - "missingParameter", - "Required Name Similarity parameter not supplied", - repr(n)) - - -class EndpointCaller: - """L{EndpointCaller} objects are invoked via their instance methods to obtain results - from the Rosette server described by the L{API} object from which they - are created. Each L{EndpointCaller} object communicates with a specific endpoint - of the Rosette server, specified at its creation. Use the specific - instance methods of the L{API} object to create L{EndpointCaller} objects bound to - corresponding endpoints. - - Use L{EndpointCaller.ping} to ping, and L{EndpointCaller.info} to retrieve server info. - For all other types of requests, use L{EndpointCaller.call}, which accepts - an argument specifying the data to be processed and certain metadata. - - The results of all operations are returned as python dictionaries, whose - keys and values correspond exactly to those of the corresponding - JSON return value described in the Rosette web service documentation. - """ - - def __init__(self, api, suburl): - """This method should not be invoked by the user. Creation is reserved - for internal use by API objects.""" - - self.service_url = api.service_url - self.user_key = api.user_key - self.logger = api.logger - self.useMultipart = False - self.suburl = suburl - self.debug = api.debug - self.api = api - - def __finish_result(self, r, ename): - code = r.status_code - the_json = r.json() - if code == 200: - return the_json - else: - if 'message' in the_json: - msg = the_json['message'] - else: - msg = the_json['code'] # punt if can't get real message - if self.suburl is None: - complaint_url = "Top level info" - else: - complaint_url = ename + " " + self.suburl - - raise RosetteException(code, complaint_url + - " : failed to communicate with Rosette", msg) - - def info(self): - """Issues an "info" request to the L{EndpointCaller}'s specific endpoint. - @return: A dictionary telling server version and other - identifying data.""" - url = self.service_url + "info" - headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} - - customHeaders = self.api.getCustomHeaders() - pattern = re.compile('^X-RosetteAPI-') - if customHeaders is not None: - for key in customHeaders.keys(): - if pattern.match(key) is not None: - headers[key] = customHeaders[key] - else: - raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearCustomHeaders() - - if self.debug: - headers['X-RosetteAPI-Devel'] = 'true' - self.logger.info('info: ' + url) - if self.user_key is not None: - headers["X-RosetteAPI-Key"] = self.user_key - r = self.api._get_http(url, headers=headers) - return self.__finish_result(r, "info") - - def ping(self): - """Issues a "ping" request to the L{EndpointCaller}'s (server-wide) endpoint. - @return: A dictionary if OK. If the server cannot be reached, - or is not the right server or some other error occurs, it will be - signalled.""" - - url = self.service_url + 'ping' - headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} - - customHeaders = self.api.getCustomHeaders() - pattern = re.compile('^X-RosetteAPI-') - if customHeaders is not None: - for key in customHeaders.keys(): - if pattern.match(key) is not None: - headers[key] = customHeaders[key] - else: - raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearCustomHeaders() - - if self.debug: - headers['X-RosetteAPI-Devel'] = 'true' - self.logger.info('Ping: ' + url) - if self.user_key is not None: - headers["X-RosetteAPI-Key"] = self.user_key - r = self.api._get_http(url, headers=headers) - return self.__finish_result(r, "ping") - - def call(self, parameters): - """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 - endpoints except C{name-translation} and C{name-similarity}, it must be a L{DocumentParameters} - object or a string; for C{name-translation}, it must be an L{NameTranslationParameters} object; - for C{name-similarity}, it must be an L{NameSimilarityParameters} object. For relationships, - it may be an L(DocumentParameters). - - In all cases, the result is returned as a python dictionary - conforming to the JSON object described in the endpoint's entry - in the Rosette web service documentation. - - @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} - @return: A python dictionary expressing the result of the invocation. - """ - - if not isinstance(parameters, _DocumentParamSetBase): - if self.suburl != "name-similarity" and self.suburl != "name-translation": - text = parameters - parameters = DocumentParameters() - parameters['content'] = text - else: - raise RosetteException( - "incompatible", - "Text-only input only works for DocumentParameter endpoints", - self.suburl) - - self.useMultipart = parameters.useMultipart - url = self.service_url + self.suburl - params_to_serialize = parameters.serialize(self.api.options) - headers = {} - if self.user_key is not None: - - customHeaders = self.api.getCustomHeaders() - pattern = re.compile('^X-RosetteAPI-') - if customHeaders is not None: - for key in customHeaders.keys(): - if pattern.match(key) is not None: - headers[key] = customHeaders[key] - else: - raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearCustomHeaders() - - headers["X-RosetteAPI-Key"] = self.user_key - headers["X-RosetteAPI-Binding"] = "python" - headers["X-RosetteAPI-Binding-Version"] = _BINDING_VERSION - - if self.useMultipart: - params = dict( - (key, - value) for key, - value in params_to_serialize.iteritems() if key == 'language') - files = { - 'content': ( - os.path.basename( - parameters.file_name), - params_to_serialize["content"], - 'text/plain'), - 'request': ( - 'request_options', - json.dumps(params), - 'application/json')} - request = requests.Request( - 'POST', url, files=files, headers=headers) - session = requests.Session() - prepared_request = session.prepare_request(request) - resp = session.send(prepared_request) - rdata = resp.content - response_headers = {"responseHeaders": dict(resp.headers)} - status = resp.status_code - r = _ReturnObject(_my_loads(rdata, response_headers), status) - else: - if self.debug: - headers['X-RosetteAPI-Devel'] = True - self.logger.info('operate: ' + url) - headers['Accept'] = "application/json" - headers['Accept-Encoding'] = "gzip" - headers['Content-Type'] = "application/json" - r = self.api._post_http(url, params_to_serialize, headers) - return self.__finish_result(r, "operate") - - -class API: - """ - Rosette Python Client Binding API; representation of a Rosette server. - Call instance methods upon this object to obtain L{EndpointCaller} objects - which can communicate with particular Rosette server endpoints. - """ - - def __init__( - self, - user_key=None, - service_url='https://api.rosette.com/rest/v1/', - retries=5, - refresh_duration=0.5, - debug=False): - """ Create an L{API} object. - @param user_key: (Optional; required for servers requiring authentication.) An authentication string to be sent - as user_key with all requests. The default Rosette server requires authentication. - to the server. - """ - # logging.basicConfig(filename="binding.log", filemode="w", level=logging.DEBUG) - self.user_key = user_key - self.service_url = service_url if service_url.endswith( - '/') else service_url + '/' - self.logger = logging.getLogger('rosette.api') - self.logger.info('Initialized on ' + self.service_url) - self.debug = debug - - if (retries < 1): - retries = 1 - if (refresh_duration < 0): - refresh_duration = 0 - - self.connection_refresh_duration = refresh_duration - self.options = {} - self.customHeaders = {} - self.urlParameters = {} - self.maxPoolSize = 1 - self.session = requests.Session() - - def _set_pool_size(self): - adapter = requests.adapters.HTTPAdapter(pool_maxsize=self.maxPoolSize) - if 'https:' in self.service_url: - self.session.mount('https://', adapter) - else: - self.session.mount('http://', adapter) - - def _make_request(self, op, url, data, headers): - """ - @param op: POST or GET - @param url: endpoing URL - @param data: request data - @param headers: request headers - """ - headers['User-Agent'] = "RosetteAPIPython/" + _BINDING_VERSION - - message = None - code = "unknownError" - rdata = None - response_headers = {} - - payload = None - if (self.urlParameters): - payload = self.urlParameters - - request = requests.Request(op, url, data=data, headers=headers, params=payload) - session = requests.Session() - prepared_request = session.prepare_request(request) - - try: - response = session.send(prepared_request) - status = response.status_code - rdata = response.content - dict_headers = dict(response.headers) - response_headers = {"responseHeaders": dict_headers} - if 'x-rosetteapi-concurrency' in dict_headers: - if dict_headers['x-rosetteapi-concurrency'] != self.maxPoolSize: - self.maxPoolSize = dict_headers['x-rosetteapi-concurrency'] - self._set_pool_size() - - if status == 200: - return rdata, status, response_headers - if rdata is not None: - try: - the_json = _my_loads(rdata, response_headers) - if 'message' in the_json: - message = the_json['message'] - if "code" in the_json: - code = the_json['code'] - else: - code = status - if not message: - message = rdata - raise RosetteException(code, message, url) - - except: - raise - except requests.exceptions.RequestException as e: - raise RosetteException( - e.message, - "Unable to establish connection to the Rosette API server", - url) - - raise RosetteException(code, message, url) - - def _get_http(self, url, headers): - """ - Simple wrapper for the GET request - - @param url: endpoint URL - @param headers: request headers - """ - (rdata, status, response_headers) = self._make_request( - "GET", url, None, headers) - return _ReturnObject(_my_loads(rdata, response_headers), status) - - def _post_http(self, url, data, headers): - """ - Simple wrapper for the POST request - - @param url: endpoint URL - @param data: request data - @param headers: request headers - """ - if data is None: - json_data = "" - else: - json_data = json.dumps(data) - - (rdata, status, response_headers) = self._make_request( - "POST", url, json_data, headers) - - if len(rdata) > 3 and rdata[0:3] == _GZIP_SIGNATURE: - buf = BytesIO(rdata) - rdata = gzip.GzipFile(fileobj=buf).read() - - return _ReturnObject(_my_loads(rdata, response_headers), status) - - def getPoolSize(self): - """ - Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value - """ - return int(self.maxPoolSize) - - def setOption(self, name, value): - """ - Sets an option - - @param name: name of option - @param value: value of option - """ - if value is None: - self.options.pop(name, None) - else: - self.options[name] = value - - def getOption(self, name): - """ - Gets an option - - @param name: name of option - - @return: value of option - """ - if name in self.options.keys(): - return self.options[name] - else: - return None - - def clearOptions(self): - """ - Clears all options - """ - self.options.clear() - - def setUrlParameter(self, name, value): - """ - Sets a URL parameter - - @param name: name of parameter - @param value: value of parameter - """ - if value is None: - self.urlParameters.pop(name, None) - else: - self.urlParameters[name] = value - - def getUrlParameter(self, name): - """ - Gets a URL parameter - - @param name: name of parameter - - @return: value of parameter - """ - if name in self.urlParameters.keys(): - return self.urlParameters[name] - else: - return None - - def clearUrlParameters(self): - """ - Clears all options - """ - self.urlParameters.clear() - - def setCustomHeaders(self, name, value): - """ - Sets custom headers - - @param headers: array of custom headers to be set - """ - if value is None: - self.customHeaders.pop(name, None) - else: - self.customHeaders[name] = value - - def getCustomHeaders(self): - """ - Get custom headers - """ - return self.customHeaders - - def clearCustomHeaders(self): - """ - Clears custom headers - """ - - self.customHeaders.clear() - - def ping(self): - """ - Create a ping L{EndpointCaller} for the server and ping it. - @return: A python dictionary including the ping message of the L{API} - """ - return EndpointCaller(self, None).ping() - - def info(self): - """ - Create a ping L{EndpointCaller} for the server and ping it. - @return: A python dictionary including the ping message of the L{API} - """ - return EndpointCaller(self, None).info() - - def language(self, parameters): - """ - Create an L{EndpointCaller} for language identification and call it. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the language identifier. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of language - identification.""" - return EndpointCaller(self, "language").call(parameters) - - def sentences(self, parameters): - """ - Create an L{EndpointCaller} to break a text into sentences and call it. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the sentence identifier. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of sentence identification.""" - return EndpointCaller(self, "sentences").call(parameters) - - def tokens(self, parameters): - """ - Create an L{EndpointCaller} to break a text into tokens and call it. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the tokens identifier. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of tokenization.""" - return EndpointCaller(self, "tokens").call(parameters) - - def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): - """ - Create an L{EndpointCaller} to returns a specific facet - of the morphological analyses of texts to which it is applied and call it. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the morphology analyzer. - @type parameters: L{DocumentParameters} or L{str} - @param facet: The facet desired, to be returned by the created L{EndpointCaller}. - @type facet: An element of L{MorphologyOutput}. - @return: A python dictionary containing the results of morphological analysis.""" - return EndpointCaller(self, "morphology/" + facet).call(parameters) - - def entities(self, parameters, resolve_entities=False): - """ - Create an L{EndpointCaller} to identify named entities found in the texts - to which it is applied and call it. Linked entity information is optional, and - its need must be specified at the time the operator is created. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the entity identifier. - @type parameters: L{DocumentParameters} or L{str} - @param resolve_entities: Specifies whether or not linked entity information will - be wanted. - @type resolve_entities: Boolean - @return: A python dictionary containing the results of entity extraction.""" - if resolve_entities: - warnings.warn("entities(params,resolve_entities) is deprecated and replaced by entities(params).", DeprecationWarning) - return EndpointCaller(self, "entities/linked").call(parameters) - else: - return EndpointCaller(self, "entities").call(parameters) - - def categories(self, parameters): - """ - Create an L{EndpointCaller} to identify the category of the text to which - it is applied and call it. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the category identifier. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of categorization.""" - return EndpointCaller(self, "categories").call(parameters) - - def sentiment(self, parameters): - """ - Create an L{EndpointCaller} to identify the sentiment of the text to - which it is applied and call it. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the sentiment identifier. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of sentiment identification.""" - """Create an L{EndpointCaller} to identify sentiments of the texts - to which is applied. - @return: An L{EndpointCaller} object which can return sentiments - of texts to which it is applied.""" - return EndpointCaller(self, "sentiment").call(parameters) - - def relationships(self, parameters): - """ - Create an L{EndpointCaller} to identify the relationships between entities in the text to - which it is applied and call it. - @param parameters: An object specifying the data, - and possible metadata, to be processed by the relationships identifier. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of relationship extraction.""" - return EndpointCaller(self, "relationships").call(parameters) - - def name_translation(self, parameters): - """ - Create an L{EndpointCaller} to perform name analysis and translation - upon the name to which it is applied and call it. - @param parameters: An object specifying the data, - 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, "name-translation").call(parameters) - - def translated_name(self, parameters): - """ deprecated - Call name_translation to perform name analysis and translation - upon the name to which it is applied. - @param parameters: An object specifying the data, - 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 self.name_translation(parameters) - - def name_similarity(self, parameters): - """ - Create an L{EndpointCaller} to perform name similarity scoring and call it. - @param parameters: An object specifying the data, - 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, "name-similarity").call(parameters) - - def matched_name(self, parameters): - """ deprecated - Call name_similarity to perform name matching. - @param parameters: An object specifying the data, - 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 self.name_similarity(parameters) - - def text_embedding(self, parameters): - """ - Create an L{EndpointCaller} to identify text vectors found in the texts - to which it is applied and call it. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of text embedding.""" - return EndpointCaller(self, "text-embedding").call(parameters) - - def syntax_dependencies(self, parameters): - """ - Create an L{EndpointCaller} to identify the syntactic dependencies in the texts - to which it is applied and call it. - @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of syntactic dependencies identification""" - return EndpointCaller(self, "syntax/dependencies").call(parameters) From 746752f60cbe086be03e47efb005a62f5cd20a06 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 18 Nov 2016 08:10:41 -0500 Subject: [PATCH 022/247] Added setUrlParameter logic to multipart - In the python binding, multipart is handled separately from normal requests --- rosette/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 9079b37..c4455aa 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -456,6 +456,10 @@ def call(self, parameters): headers["X-RosetteAPI-Binding-Version"] = _BINDING_VERSION if self.useMultipart: + payload = None + if (self.api.urlParameters): + payload = self.api.urlParameters + params = dict( (key, value) for key, @@ -471,7 +475,7 @@ def call(self, parameters): json.dumps(params), 'application/json')} request = requests.Request( - 'POST', url, files=files, headers=headers) + 'POST', url, files=files, headers=headers, params=payload) session = requests.Session() prepared_request = session.prepare_request(request) resp = session.send(prepared_request) From e12b4e9bb567ef11800d636e2822bfe8ea6b20a9 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 18 Nov 2016 08:14:48 -0500 Subject: [PATCH 023/247] Re-added __init__.py - it was deleted by a git pull --- rosette/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 rosette/__init__.py diff --git a/rosette/__init__.py b/rosette/__init__.py new file mode 100644 index 0000000..72500fc --- /dev/null +++ b/rosette/__init__.py @@ -0,0 +1,15 @@ +""" +Python client for the Rosette API. +Copyright (c) 2014-2015 Basis Technology Corporation. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +__version__ = '1.4.1' From 1874e6ac39344734464749a259d914f4dc6413ca Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 18 Nov 2016 13:15:35 +0000 Subject: [PATCH 024/247] Version 1.4.2 --- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index 72500fc..7b49a91 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.4.1' +__version__ = '1.4.2' diff --git a/rosette/api.py b/rosette/api.py index 64adbb8..7295b77 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import re import warnings -_BINDING_VERSION = '1.4.1' +_BINDING_VERSION = '1.4.2' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _IsPy3 = sys.version_info[0] == 3 From 67b2a57656c6e03f2fbe8fea2534ff772e41ff6f Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 21 Nov 2016 09:37:14 -0500 Subject: [PATCH 025/247] Removed entities/linked - Removed example - Removed resolve_entities parameter and check - Updated README - tests pass --- README.md | 2 +- examples/README.md | 1 - examples/entities_linked.py | 33 --------------------------------- rosette/api.py | 12 +++--------- tests/test_rosette_api.py | 15 --------------- 5 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 examples/entities_linked.py diff --git a/README.md b/README.md index 12608c6..5eb67ab 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ The samples use the following procedure: `NameSimilarityParameters`; Other parameters are optional. 6. Invoke the `API` method for the endpoint you are calling. The methods are - * `entities(linked)` where `linked` is `False` for entity extraction and `True` for entity linking. + * `entities()` * `categories()` * `sentiment()` * `language()` diff --git a/examples/README.md b/examples/README.md index 5413e59..38b87fd 100644 --- a/examples/README.md +++ b/examples/README.md @@ -24,7 +24,6 @@ Each example, when run, prints its output to the console. | ------------- |------------- | | categories.py | Gets the category of a document at a URL | | entities.py | Gets the entities from a piece of text | -| entities_linked.py | Gets the linked (to Wikipedia) entities from a piece of text | | info.py | Gets information about Rosette API | | language.py | Gets the language of a piece of text | | matched-name.py | Gets the similarity score of two names | diff --git a/examples/entities_linked.py b/examples/entities_linked.py deleted file mode 100644 index 512f7f5..0000000 --- a/examples/entities_linked.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text. -""" - -import argparse -import json -import os - -from rosette.api import API, DocumentParameters - - -def run(key, altUrl='https://api.rosette.com/rest/v1/'): - # Create an API instance - api = API(user_key=key, service_url=altUrl) - - entities_linked_text_data = "Last month director Paul Feig announced the movie will have an all-star female cast including Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon." - params = DocumentParameters() - params["content"] = entities_linked_text_data - params["genre"] = "social-media" - # This syntax is deprecated, call api.entities(params) - return api.entities(params, True) - - -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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index 7295b77..f081372 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -777,7 +777,7 @@ def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): @return: A python dictionary containing the results of morphological analysis.""" return EndpointCaller(self, "morphology/" + facet).call(parameters) - def entities(self, parameters, resolve_entities=False): + def entities(self, parameters): """ Create an L{EndpointCaller} to identify named entities found in the texts to which it is applied and call it. Linked entity information is optional, and @@ -785,15 +785,9 @@ def entities(self, parameters, resolve_entities=False): @param parameters: An object specifying the data, and possible metadata, to be processed by the entity identifier. @type parameters: L{DocumentParameters} or L{str} - @param resolve_entities: Specifies whether or not linked entity information will - be wanted. - @type resolve_entities: Boolean @return: A python dictionary containing the results of entity extraction.""" - if resolve_entities: - warnings.warn("entities(params,resolve_entities) is deprecated and replaced by entities(params).", DeprecationWarning) - return EndpointCaller(self, "entities/linked").call(parameters) - else: - return EndpointCaller(self, "entities").call(parameters) + + return EndpointCaller(self, "entities").call(parameters) def categories(self, parameters): """ diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index cb0e793..67bd92e 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -323,21 +323,6 @@ def test_the_entities_endpoint(api, json_response, doc_params): httpretty.disable() httpretty.reset() -# Test the entities/linked endpoint - - -def test_the_entities_linked_endpoint(api, json_response, doc_params): - 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/entities/linked", - body=json_response, status=200, content_type="application/json") - - result = api.entities(doc_params, True) - assert result["name"] == "Rosette API" - httpretty.disable() - httpretty.reset() - # Test the categories endpoint From dc91d4f363b407ca3b662d1d613be1bc73327a9c Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 29 Nov 2016 13:35:11 -0500 Subject: [PATCH 026/247] Removed unnecessary doc directory - updated .gitignore to ignore doc/ directory --- .gitignore | 1 + doc/api.html | 576 --------------------------------------------------- 2 files changed, 1 insertion(+), 576 deletions(-) delete mode 100644 doc/api.html diff --git a/.gitignore b/.gitignore index ea16fe4..e579830 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ __pycache__/ # Distribution / packaging .Python +doc/ env/ build/ develop-eggs/ diff --git a/doc/api.html b/doc/api.html deleted file mode 100644 index a6ab71f..0000000 --- a/doc/api.html +++ /dev/null @@ -1,576 +0,0 @@ - -Python: module api - - - - - -
 
- 
api
index
/python/rosette/api.py
-

Python client for the Rosette API.

-Copyright (c) 2014-2015 Basis Technology Corporation.

-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-http://www.apache.org/licenses/LICENSE-2.0

-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.

-

- - - - - -
 
-Modules
       
gzip
-json
-logging
-
os
-re
-requests
-
sys
-time
-warnings
-

- - - - - -
 
-Classes
       
-
_DocumentParamSetBase(builtins.object) -
-
-
DocumentParameters -
NameSimilarityParameters -
NameTranslationParameters -
-
-
_PseudoEnum(builtins.object) -
-
-
MorphologyOutput -
-
-
builtins.Exception(builtins.BaseException) -
-
-
RosetteException -
-
-
builtins.object -
-
-
API -
EndpointCaller -
-
-
-

- - - - - - - -
 
-class API(builtins.object)
   Rosette Python Client Binding API; representation of a Rosette server.
-Call instance methods upon this object to obtain L{EndpointCaller} objects
-which can communicate with particular Rosette server endpoints.
 
 Methods defined here:
-
__init__(self, user_key=None, service_url='https://api.rosette.com/rest/v1/', retries=5, refresh_duration=0.5, debug=False)
Create an L{APIobject.
-@param user_key: (Optional; required for servers requiring authentication.) An authentication string to be sent
- as user_key with all requests.  The default Rosette server requires authentication.
- to the server.
- -
categories(self, parameters)
Create an L{EndpointCaller} to identify the category of the text to which
-it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the category identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of categorization.
- -
clearCustomHeaders(self)
Clears custom headers
- -
clearOptions(self)
Clears all options
- -
clearUrlParameters(self)
Clears all options
- -
entities(self, parameters, resolve_entities=False)
Create an L{EndpointCaller}  to identify named entities found in the texts
-to which it is applied and call it. Linked entity information is optional, and
-its need must be specified at the time the operator is created.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the entity identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@param resolve_entities: Specifies whether or not linked entity information will
-be wanted.
-@type resolve_entities: Boolean
-@return: A python dictionary containing the results of entity extraction.
- -
getCustomHeaders(self)
Get custom headers
- -
getOption(self, name)
Gets an option

-@param name: name of option

-@return: value of option
- -
getPoolSize(self)
Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value
- -
getUrlParameter(self, name)
Gets a URL parameter

-@param name: name of parameter

-@return: value of parameter
- -
info(self)
Create a ping L{EndpointCaller} for the server and ping it.
-@return: A python dictionary including the ping message of the L{API}
- -
language(self, parameters)
Create an L{EndpointCaller} for language identification and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the language identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of language
-identification.
- -
matched_name(self, parameters)
deprecated
-Call name_similarity to perform name matching.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name matcher.
-@type parameters: L{NameSimilarityParameters}
-@return: A python dictionary containing the results of name matching.
- -
morphology(self, parameters, facet='complete')
Create an L{EndpointCaller} to returns a specific facet
-of the morphological analyses of texts to which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the morphology analyzer.
-@type parameters: L{DocumentParameters} or L{str}
-@param facet: The facet desired, to be returned by the created L{EndpointCaller}.
-@type facet: An element of L{MorphologyOutput}.
-@return: A python dictionary containing the results of morphological analysis.
- -
name_similarity(self, parameters)
Create an L{EndpointCaller} to perform name similarity scoring and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name matcher.
-@type parameters: L{NameSimilarityParameters}
-@return: A python dictionary containing the results of name matching.
- -
name_translation(self, parameters)
Create an L{EndpointCaller} to perform name analysis and translation
-upon the name to which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name translator.
-@type parameters: L{NameTranslationParameters}
-@return: A python dictionary containing the results of name translation.
- -
ping(self)
Create a ping L{EndpointCaller} for the server and ping it.
-@return: A python dictionary including the ping message of the L{API}
- -
relationships(self, parameters)
Create an L{EndpointCaller} to identify the relationships between entities in the text to
-which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the relationships identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of relationship extraction.
- -
sentences(self, parameters)
Create an L{EndpointCaller} to break a text into sentences and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the sentence identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of sentence identification.
- -
sentiment(self, parameters)
Create an L{EndpointCaller} to identify the sentiment of the text to
-which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the sentiment identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of sentiment identification.
- -
setCustomHeaders(self, name, value)
Sets custom headers

-@param headers: array of custom headers to be set
- -
setOption(self, name, value)
Sets an option

-@param name: name of option
-@param value: value of option
- -
setUrlParameter(self, name, value)
Sets a URL parameter

-@param name: name of parameter
-@param value: value of parameter
- -
syntax_dependencies(self, parameters)
Create an L{EndpointCaller} to identify the syntactic dependencies in the texts
-to which it is applied and call it.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of syntactic dependencies identification
- -
text_embedding(self, parameters)
Create an L{EndpointCaller}  to identify text vectors found in the texts
-to which it is applied and call it.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of text embedding.
- -
tokens(self, parameters)
Create an L{EndpointCaller} to break a text into tokens and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the tokens identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of tokenization.
- -
translated_name(self, parameters)
deprecated
-Call name_translation to perform name analysis and translation
-upon the name to which it is applied.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name translator.
-@type parameters: L{NameTranslationParameters}
-@return: A python dictionary containing the results of name translation.
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class DocumentParameters(_DocumentParamSetBase)
   Parameter object for all operations requiring input other than
-translated_name.
-Two fields, C{content} and C{inputUri}, are set via
-the subscript operator, e.g., C{params["content"]}, or the
-convenience instance methods L{DocumentParameters.load_document_file}
-and L{DocumentParameters.load_document_string}.

-Using subscripts instead of instance variables facilitates diagnosis.

-If the field C{contentUri} is set to the URL of a web page (only
-protocols C{http, https, ftp, ftps} are accepted), the server will
-fetch the content from that web page.  In this case, C{content} may not be set.
 
 
Method resolution order:
-
DocumentParameters
-
_DocumentParamSetBase
-
builtins.object
-
-
-Methods defined here:
-
__init__(self)
Create a L{DocumentParametersobject.
- -
load_document_file(self, path)
Loads a file into the object.
-The file will be read as bytes; the appropriate conversion will
-be determined by the server.
-@parameter path: Pathname of a file acceptable to the C{open} function.
- -
load_document_string(self, s)
Loads a string into the object.
-The string will be taken as bytes or as Unicode dependent upon
-its native python type.
-@parameter s: A string, possibly a unicode-string, to be loaded
-for subsequent analysis.
- -
serialize(self, options)
Internal. Do not use.
- -
validate(self)
Internal. Do not use.
- -
-Methods inherited from _DocumentParamSetBase:
-
__getitem__(self, key)
- -
__setitem__(self, key, val)
- -
-Data descriptors inherited from _DocumentParamSetBase:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class EndpointCaller(builtins.object)
   L{EndpointCaller} objects are invoked via their instance methods to obtain results
-from the Rosette server described by the L{APIobject from which they
-are created.  Each L{EndpointCallerobject communicates with a specific endpoint
-of the Rosette server, specified at its creation.  Use the specific
-instance methods of the L{APIobject to create L{EndpointCaller} objects bound to
-corresponding endpoints.

-Use L{EndpointCaller.ping} to ping, and L{EndpointCaller.info} to retrieve server info.
-For all other types of requests, use L{EndpointCaller.call}, which accepts
-an argument specifying the data to be processed and certain metadata.

-The results of all operations are returned as python dictionaries, whose
-keys and values correspond exactly to those of the corresponding
-JSON return value described in the Rosette web service documentation.
 
 Methods defined here:
-
__init__(self, api, suburl)
This method should not be invoked by the user.  Creation is reserved
-for internal use by API objects.
- -
call(self, parameters)
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{EndpointCallerobject is bound.  For all
-endpoints except C{name-translation} and C{name-similarity}, it must be a L{DocumentParameters}
-object or a string; for C{name-translation}, it must be an L{NameTranslationParametersobject;
-for C{name-similarity}, it must be an L{NameSimilarityParametersobject. For relationships,
-it may be an L(DocumentParameters).

-In all cases, the result is returned as a python dictionary
-conforming to the JSON object described in the endpoint's entry
-in the Rosette web service documentation.

-@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}
-@return: A python dictionary expressing the result of the invocation.
- -
info(self)
Issues an "info" request to the L{EndpointCaller}'s specific endpoint.
-@return: A dictionary telling server version and other
-identifying data.
- -
ping(self)
Issues a "ping" request to the L{EndpointCaller}'s (server-wide) endpoint.
-@return: A dictionary if OK.  If the server cannot be reached,
-or is not the right server or some other error occurs, it will be
-signalled.
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - -
 
-class MorphologyOutput(_PseudoEnum)
    
Method resolution order:
-
MorphologyOutput
-
_PseudoEnum
-
builtins.object
-
-
-Data and other attributes defined here:
-
COMPLETE = 'complete'
- -
COMPOUND_COMPONENTS = 'compound-components'
- -
HAN_READINGS = 'han-readings'
- -
LEMMAS = 'lemmas'
- -
PARTS_OF_SPEECH = 'parts-of-speech'
- -
-Methods inherited from _PseudoEnum:
-
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
- -
-Class methods inherited from _PseudoEnum:
-
validate(value, name) from builtins.type
- -
-Data descriptors inherited from _PseudoEnum:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class NameSimilarityParameters(_DocumentParamSetBase)
   Parameter object for C{name-similarity} endpoint.
-All are required.

-C{name1} The name to be matched, a C{name} object.

-C{name2} The name to be matched, a C{name} object.

-The C{name} object contains these fields:

-C{text} Text of the name, required.

-C{language} Language of the name in ISO639 three-letter code, optional.

-C{script} The ISO15924 code of the name, optional.

-C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional.
 
 
Method resolution order:
-
NameSimilarityParameters
-
_DocumentParamSetBase
-
builtins.object
-
-
-Methods defined here:
-
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
- -
validate(self)
Internal. Do not use.
- -
-Methods inherited from _DocumentParamSetBase:
-
__getitem__(self, key)
- -
__setitem__(self, key, val)
- -
serialize(self, options)
- -
-Data descriptors inherited from _DocumentParamSetBase:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class NameTranslationParameters(_DocumentParamSetBase)
   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}).
-All are optional except C{name} and C{targetLanguage}.  Scripts are in
-ISO15924 codes, and languages in ISO639 (two- or three-letter) codes.  See the Name Translation documentation for
-more description of these terms, as well as the content of the return result.

-C{name} The name to be translated.

-C{targetLangauge} The language into which the name is to be translated.

-C{entityType} The entity type (TBD) of the name.

-C{sourceLanguageOfOrigin} The language of origin of the name.

-C{sourceLanguageOfUse} The language of use of the name.

-C{sourceScript} The script in which the name is supplied.

-C{targetScript} The script into which the name should be translated.

-C{targetScheme} The transliteration scheme by which the translated name should be rendered.
 
 
Method resolution order:
-
NameTranslationParameters
-
_DocumentParamSetBase
-
builtins.object
-
-
-Methods defined here:
-
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
- -
validate(self)
Internal. Do not use.
- -
-Methods inherited from _DocumentParamSetBase:
-
__getitem__(self, key)
- -
__setitem__(self, key, val)
- -
serialize(self, options)
- -
-Data descriptors inherited from _DocumentParamSetBase:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class RosetteException(builtins.Exception)
   Exception thrown by all Rosette API operations for errors local and remote.

-TBD. Right now, the only valid operation is conversion to __str__.
 
 
Method resolution order:
-
RosetteException
-
builtins.Exception
-
builtins.BaseException
-
builtins.object
-
-
-Methods defined here:
-
__init__(self, status, message, response_message)
Initialize self.  See help(type(self)) for accurate signature.
- -
__str__(self)
Return str(self).
- -
-Data descriptors defined here:
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Methods inherited from builtins.Exception:
-
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
- -
-Methods inherited from builtins.BaseException:
-
__delattr__(self, name, /)
Implement delattr(self, name).
- -
__getattribute__(self, name, /)
Return getattr(self, name).
- -
__reduce__(...)
helper for pickle
- -
__repr__(self, /)
Return repr(self).
- -
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
- -
__setstate__(...)
- -
with_traceback(...)
Exception.with_traceback(tb) --
-set self.__traceback__ to tb and return self.
- -
-Data descriptors inherited from builtins.BaseException:
-
__cause__
-
exception cause
-
-
__context__
-
exception context
-
-
__dict__
-
-
__suppress_context__
-
-
__traceback__
-
-
args
-
-

- \ No newline at end of file From 37ae9051db2fca4aef589c5d1cb6a1fc152cb5f9 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 29 Nov 2016 13:37:11 -0500 Subject: [PATCH 027/247] Removed linked entities in comment --- rosette/api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index f081372..242e5c1 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -780,8 +780,7 @@ def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): def entities(self, parameters): """ Create an L{EndpointCaller} to identify named entities found in the texts - to which it is applied and call it. Linked entity information is optional, and - its need must be specified at the time the operator is created. + to which it is applied and call it. @param parameters: An object specifying the data, and possible metadata, to be processed by the entity identifier. @type parameters: L{DocumentParameters} or L{str} From c581263d24d995385885329de335f99895b33964 Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Wed, 30 Nov 2016 14:05:49 -0500 Subject: [PATCH 028/247] Removed entities/linked (#59) * Removed entities/linked - Removed example - Removed resolve_entities parameter and check - Updated README - tests pass * Removed unnecessary doc directory - updated .gitignore to ignore doc/ directory * Removed linked entities in comment --- .gitignore | 1 + README.md | 2 +- doc/api.html | 576 ------------------------------------ examples/README.md | 1 - examples/entities_linked.py | 33 --- rosette/api.py | 15 +- tests/test_rosette_api.py | 15 - 7 files changed, 6 insertions(+), 637 deletions(-) delete mode 100644 doc/api.html delete mode 100644 examples/entities_linked.py diff --git a/.gitignore b/.gitignore index ea16fe4..e579830 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ __pycache__/ # Distribution / packaging .Python +doc/ env/ build/ develop-eggs/ diff --git a/README.md b/README.md index 12608c6..5eb67ab 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ The samples use the following procedure: `NameSimilarityParameters`; Other parameters are optional. 6. Invoke the `API` method for the endpoint you are calling. The methods are - * `entities(linked)` where `linked` is `False` for entity extraction and `True` for entity linking. + * `entities()` * `categories()` * `sentiment()` * `language()` diff --git a/doc/api.html b/doc/api.html deleted file mode 100644 index a6ab71f..0000000 --- a/doc/api.html +++ /dev/null @@ -1,576 +0,0 @@ - -Python: module api - - - - - -
 
- 
api
index
/python/rosette/api.py
-

Python client for the Rosette API.

-Copyright (c) 2014-2015 Basis Technology Corporation.

-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-http://www.apache.org/licenses/LICENSE-2.0

-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.

-

- - - - - -
 
-Modules
       
gzip
-json
-logging
-
os
-re
-requests
-
sys
-time
-warnings
-

- - - - - -
 
-Classes
       
-
_DocumentParamSetBase(builtins.object) -
-
-
DocumentParameters -
NameSimilarityParameters -
NameTranslationParameters -
-
-
_PseudoEnum(builtins.object) -
-
-
MorphologyOutput -
-
-
builtins.Exception(builtins.BaseException) -
-
-
RosetteException -
-
-
builtins.object -
-
-
API -
EndpointCaller -
-
-
-

- - - - - - - -
 
-class API(builtins.object)
   Rosette Python Client Binding API; representation of a Rosette server.
-Call instance methods upon this object to obtain L{EndpointCaller} objects
-which can communicate with particular Rosette server endpoints.
 
 Methods defined here:
-
__init__(self, user_key=None, service_url='https://api.rosette.com/rest/v1/', retries=5, refresh_duration=0.5, debug=False)
Create an L{APIobject.
-@param user_key: (Optional; required for servers requiring authentication.) An authentication string to be sent
- as user_key with all requests.  The default Rosette server requires authentication.
- to the server.
- -
categories(self, parameters)
Create an L{EndpointCaller} to identify the category of the text to which
-it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the category identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of categorization.
- -
clearCustomHeaders(self)
Clears custom headers
- -
clearOptions(self)
Clears all options
- -
clearUrlParameters(self)
Clears all options
- -
entities(self, parameters, resolve_entities=False)
Create an L{EndpointCaller}  to identify named entities found in the texts
-to which it is applied and call it. Linked entity information is optional, and
-its need must be specified at the time the operator is created.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the entity identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@param resolve_entities: Specifies whether or not linked entity information will
-be wanted.
-@type resolve_entities: Boolean
-@return: A python dictionary containing the results of entity extraction.
- -
getCustomHeaders(self)
Get custom headers
- -
getOption(self, name)
Gets an option

-@param name: name of option

-@return: value of option
- -
getPoolSize(self)
Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value
- -
getUrlParameter(self, name)
Gets a URL parameter

-@param name: name of parameter

-@return: value of parameter
- -
info(self)
Create a ping L{EndpointCaller} for the server and ping it.
-@return: A python dictionary including the ping message of the L{API}
- -
language(self, parameters)
Create an L{EndpointCaller} for language identification and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the language identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of language
-identification.
- -
matched_name(self, parameters)
deprecated
-Call name_similarity to perform name matching.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name matcher.
-@type parameters: L{NameSimilarityParameters}
-@return: A python dictionary containing the results of name matching.
- -
morphology(self, parameters, facet='complete')
Create an L{EndpointCaller} to returns a specific facet
-of the morphological analyses of texts to which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the morphology analyzer.
-@type parameters: L{DocumentParameters} or L{str}
-@param facet: The facet desired, to be returned by the created L{EndpointCaller}.
-@type facet: An element of L{MorphologyOutput}.
-@return: A python dictionary containing the results of morphological analysis.
- -
name_similarity(self, parameters)
Create an L{EndpointCaller} to perform name similarity scoring and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name matcher.
-@type parameters: L{NameSimilarityParameters}
-@return: A python dictionary containing the results of name matching.
- -
name_translation(self, parameters)
Create an L{EndpointCaller} to perform name analysis and translation
-upon the name to which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name translator.
-@type parameters: L{NameTranslationParameters}
-@return: A python dictionary containing the results of name translation.
- -
ping(self)
Create a ping L{EndpointCaller} for the server and ping it.
-@return: A python dictionary including the ping message of the L{API}
- -
relationships(self, parameters)
Create an L{EndpointCaller} to identify the relationships between entities in the text to
-which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the relationships identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of relationship extraction.
- -
sentences(self, parameters)
Create an L{EndpointCaller} to break a text into sentences and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the sentence identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of sentence identification.
- -
sentiment(self, parameters)
Create an L{EndpointCaller} to identify the sentiment of the text to
-which it is applied and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the sentiment identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of sentiment identification.
- -
setCustomHeaders(self, name, value)
Sets custom headers

-@param headers: array of custom headers to be set
- -
setOption(self, name, value)
Sets an option

-@param name: name of option
-@param value: value of option
- -
setUrlParameter(self, name, value)
Sets a URL parameter

-@param name: name of parameter
-@param value: value of parameter
- -
syntax_dependencies(self, parameters)
Create an L{EndpointCaller} to identify the syntactic dependencies in the texts
-to which it is applied and call it.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of syntactic dependencies identification
- -
text_embedding(self, parameters)
Create an L{EndpointCaller}  to identify text vectors found in the texts
-to which it is applied and call it.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of text embedding.
- -
tokens(self, parameters)
Create an L{EndpointCaller} to break a text into tokens and call it.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the tokens identifier.
-@type parameters: L{DocumentParameters} or L{str}
-@return: A python dictionary containing the results of tokenization.
- -
translated_name(self, parameters)
deprecated
-Call name_translation to perform name analysis and translation
-upon the name to which it is applied.
-@param parameters: An object specifying the data,
-and possible metadata, to be processed by the name translator.
-@type parameters: L{NameTranslationParameters}
-@return: A python dictionary containing the results of name translation.
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class DocumentParameters(_DocumentParamSetBase)
   Parameter object for all operations requiring input other than
-translated_name.
-Two fields, C{content} and C{inputUri}, are set via
-the subscript operator, e.g., C{params["content"]}, or the
-convenience instance methods L{DocumentParameters.load_document_file}
-and L{DocumentParameters.load_document_string}.

-Using subscripts instead of instance variables facilitates diagnosis.

-If the field C{contentUri} is set to the URL of a web page (only
-protocols C{http, https, ftp, ftps} are accepted), the server will
-fetch the content from that web page.  In this case, C{content} may not be set.
 
 
Method resolution order:
-
DocumentParameters
-
_DocumentParamSetBase
-
builtins.object
-
-
-Methods defined here:
-
__init__(self)
Create a L{DocumentParametersobject.
- -
load_document_file(self, path)
Loads a file into the object.
-The file will be read as bytes; the appropriate conversion will
-be determined by the server.
-@parameter path: Pathname of a file acceptable to the C{open} function.
- -
load_document_string(self, s)
Loads a string into the object.
-The string will be taken as bytes or as Unicode dependent upon
-its native python type.
-@parameter s: A string, possibly a unicode-string, to be loaded
-for subsequent analysis.
- -
serialize(self, options)
Internal. Do not use.
- -
validate(self)
Internal. Do not use.
- -
-Methods inherited from _DocumentParamSetBase:
-
__getitem__(self, key)
- -
__setitem__(self, key, val)
- -
-Data descriptors inherited from _DocumentParamSetBase:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class EndpointCaller(builtins.object)
   L{EndpointCaller} objects are invoked via their instance methods to obtain results
-from the Rosette server described by the L{APIobject from which they
-are created.  Each L{EndpointCallerobject communicates with a specific endpoint
-of the Rosette server, specified at its creation.  Use the specific
-instance methods of the L{APIobject to create L{EndpointCaller} objects bound to
-corresponding endpoints.

-Use L{EndpointCaller.ping} to ping, and L{EndpointCaller.info} to retrieve server info.
-For all other types of requests, use L{EndpointCaller.call}, which accepts
-an argument specifying the data to be processed and certain metadata.

-The results of all operations are returned as python dictionaries, whose
-keys and values correspond exactly to those of the corresponding
-JSON return value described in the Rosette web service documentation.
 
 Methods defined here:
-
__init__(self, api, suburl)
This method should not be invoked by the user.  Creation is reserved
-for internal use by API objects.
- -
call(self, parameters)
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{EndpointCallerobject is bound.  For all
-endpoints except C{name-translation} and C{name-similarity}, it must be a L{DocumentParameters}
-object or a string; for C{name-translation}, it must be an L{NameTranslationParametersobject;
-for C{name-similarity}, it must be an L{NameSimilarityParametersobject. For relationships,
-it may be an L(DocumentParameters).

-In all cases, the result is returned as a python dictionary
-conforming to the JSON object described in the endpoint's entry
-in the Rosette web service documentation.

-@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}
-@return: A python dictionary expressing the result of the invocation.
- -
info(self)
Issues an "info" request to the L{EndpointCaller}'s specific endpoint.
-@return: A dictionary telling server version and other
-identifying data.
- -
ping(self)
Issues a "ping" request to the L{EndpointCaller}'s (server-wide) endpoint.
-@return: A dictionary if OK.  If the server cannot be reached,
-or is not the right server or some other error occurs, it will be
-signalled.
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - -
 
-class MorphologyOutput(_PseudoEnum)
    
Method resolution order:
-
MorphologyOutput
-
_PseudoEnum
-
builtins.object
-
-
-Data and other attributes defined here:
-
COMPLETE = 'complete'
- -
COMPOUND_COMPONENTS = 'compound-components'
- -
HAN_READINGS = 'han-readings'
- -
LEMMAS = 'lemmas'
- -
PARTS_OF_SPEECH = 'parts-of-speech'
- -
-Methods inherited from _PseudoEnum:
-
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
- -
-Class methods inherited from _PseudoEnum:
-
validate(value, name) from builtins.type
- -
-Data descriptors inherited from _PseudoEnum:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class NameSimilarityParameters(_DocumentParamSetBase)
   Parameter object for C{name-similarity} endpoint.
-All are required.

-C{name1} The name to be matched, a C{name} object.

-C{name2} The name to be matched, a C{name} object.

-The C{name} object contains these fields:

-C{text} Text of the name, required.

-C{language} Language of the name in ISO639 three-letter code, optional.

-C{script} The ISO15924 code of the name, optional.

-C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional.
 
 
Method resolution order:
-
NameSimilarityParameters
-
_DocumentParamSetBase
-
builtins.object
-
-
-Methods defined here:
-
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
- -
validate(self)
Internal. Do not use.
- -
-Methods inherited from _DocumentParamSetBase:
-
__getitem__(self, key)
- -
__setitem__(self, key, val)
- -
serialize(self, options)
- -
-Data descriptors inherited from _DocumentParamSetBase:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class NameTranslationParameters(_DocumentParamSetBase)
   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}).
-All are optional except C{name} and C{targetLanguage}.  Scripts are in
-ISO15924 codes, and languages in ISO639 (two- or three-letter) codes.  See the Name Translation documentation for
-more description of these terms, as well as the content of the return result.

-C{name} The name to be translated.

-C{targetLangauge} The language into which the name is to be translated.

-C{entityType} The entity type (TBD) of the name.

-C{sourceLanguageOfOrigin} The language of origin of the name.

-C{sourceLanguageOfUse} The language of use of the name.

-C{sourceScript} The script in which the name is supplied.

-C{targetScript} The script into which the name should be translated.

-C{targetScheme} The transliteration scheme by which the translated name should be rendered.
 
 
Method resolution order:
-
NameTranslationParameters
-
_DocumentParamSetBase
-
builtins.object
-
-
-Methods defined here:
-
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
- -
validate(self)
Internal. Do not use.
- -
-Methods inherited from _DocumentParamSetBase:
-
__getitem__(self, key)
- -
__setitem__(self, key, val)
- -
serialize(self, options)
- -
-Data descriptors inherited from _DocumentParamSetBase:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class RosetteException(builtins.Exception)
   Exception thrown by all Rosette API operations for errors local and remote.

-TBD. Right now, the only valid operation is conversion to __str__.
 
 
Method resolution order:
-
RosetteException
-
builtins.Exception
-
builtins.BaseException
-
builtins.object
-
-
-Methods defined here:
-
__init__(self, status, message, response_message)
Initialize self.  See help(type(self)) for accurate signature.
- -
__str__(self)
Return str(self).
- -
-Data descriptors defined here:
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Methods inherited from builtins.Exception:
-
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
- -
-Methods inherited from builtins.BaseException:
-
__delattr__(self, name, /)
Implement delattr(self, name).
- -
__getattribute__(self, name, /)
Return getattr(self, name).
- -
__reduce__(...)
helper for pickle
- -
__repr__(self, /)
Return repr(self).
- -
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
- -
__setstate__(...)
- -
with_traceback(...)
Exception.with_traceback(tb) --
-set self.__traceback__ to tb and return self.
- -
-Data descriptors inherited from builtins.BaseException:
-
__cause__
-
exception cause
-
-
__context__
-
exception context
-
-
__dict__
-
-
__suppress_context__
-
-
__traceback__
-
-
args
-
-

- \ No newline at end of file diff --git a/examples/README.md b/examples/README.md index 5413e59..38b87fd 100644 --- a/examples/README.md +++ b/examples/README.md @@ -24,7 +24,6 @@ Each example, when run, prints its output to the console. | ------------- |------------- | | categories.py | Gets the category of a document at a URL | | entities.py | Gets the entities from a piece of text | -| entities_linked.py | Gets the linked (to Wikipedia) entities from a piece of text | | info.py | Gets information about Rosette API | | language.py | Gets the language of a piece of text | | matched-name.py | Gets the similarity score of two names | diff --git a/examples/entities_linked.py b/examples/entities_linked.py deleted file mode 100644 index 512f7f5..0000000 --- a/examples/entities_linked.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text. -""" - -import argparse -import json -import os - -from rosette.api import API, DocumentParameters - - -def run(key, altUrl='https://api.rosette.com/rest/v1/'): - # Create an API instance - api = API(user_key=key, service_url=altUrl) - - entities_linked_text_data = "Last month director Paul Feig announced the movie will have an all-star female cast including Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon." - params = DocumentParameters() - params["content"] = entities_linked_text_data - params["genre"] = "social-media" - # This syntax is deprecated, call api.entities(params) - return api.entities(params, True) - - -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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index 7295b77..242e5c1 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -777,23 +777,16 @@ def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): @return: A python dictionary containing the results of morphological analysis.""" return EndpointCaller(self, "morphology/" + facet).call(parameters) - def entities(self, parameters, resolve_entities=False): + def entities(self, parameters): """ Create an L{EndpointCaller} to identify named entities found in the texts - to which it is applied and call it. Linked entity information is optional, and - its need must be specified at the time the operator is created. + to which it is applied and call it. @param parameters: An object specifying the data, and possible metadata, to be processed by the entity identifier. @type parameters: L{DocumentParameters} or L{str} - @param resolve_entities: Specifies whether or not linked entity information will - be wanted. - @type resolve_entities: Boolean @return: A python dictionary containing the results of entity extraction.""" - if resolve_entities: - warnings.warn("entities(params,resolve_entities) is deprecated and replaced by entities(params).", DeprecationWarning) - return EndpointCaller(self, "entities/linked").call(parameters) - else: - return EndpointCaller(self, "entities").call(parameters) + + return EndpointCaller(self, "entities").call(parameters) def categories(self, parameters): """ diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index cb0e793..67bd92e 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -323,21 +323,6 @@ def test_the_entities_endpoint(api, json_response, doc_params): httpretty.disable() httpretty.reset() -# Test the entities/linked endpoint - - -def test_the_entities_linked_endpoint(api, json_response, doc_params): - 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/entities/linked", - body=json_response, status=200, content_type="application/json") - - result = api.entities(doc_params, True) - assert result["name"] == "Rosette API" - httpretty.disable() - httpretty.reset() - # Test the categories endpoint From 17277ac34de0b18732dd289031adc935456c35ce Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 1 Dec 2016 10:46:19 -0500 Subject: [PATCH 029/247] Added simple exception handling to examples --- examples/categories.py | 7 +++++-- examples/entities.py | 7 +++++-- examples/info.py | 8 +++++--- examples/language.py | 7 +++++-- examples/morphology_complete.py | 7 +++++-- examples/morphology_compound-components.py | 7 +++++-- examples/morphology_han-readings.py | 7 +++++-- examples/morphology_lemmas.py | 7 +++++-- examples/morphology_parts-of-speech.py | 7 +++++-- examples/name_similarity.py | 7 +++++-- examples/name_translation.py | 7 +++++-- examples/ping.py | 7 +++++-- examples/relationships.py | 7 +++++-- examples/sentences.py | 7 +++++-- examples/sentiment.py | 13 ++++++++----- examples/syntax_dependencies.py | 7 +++++-- examples/text_embedding.py | 8 ++++++-- examples/tokens.py | 7 +++++-- 18 files changed, 94 insertions(+), 40 deletions(-) diff --git a/examples/categories.py b/examples/categories.py index 4731edb..c7a54eb 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -20,7 +20,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Use a URL to input data instead of a string params["contentUri"] = url - return api.categories(params) + try: + return api.categories(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/entities.py b/examples/entities.py index 1029913..1ad0f26 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = entities_text_data params["genre"] = "social-media" - return api.entities(params) + try: + return api.entities(params) + except RosetteException as e: + print(e) 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) diff --git a/examples/info.py b/examples/info.py index a4c0bd5..b83dbcb 100644 --- a/examples/info.py +++ b/examples/info.py @@ -8,14 +8,16 @@ import json import os -from rosette.api import API, DocumentParameters - +from rosette.api import API, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) - return api.info() + try: + return api.info() + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/language.py b/examples/language.py index 30e886b..345fe30 100644 --- a/examples/language.py +++ b/examples/language.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -19,7 +19,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = language_data api.setCustomHeaders("X-RosetteAPI-App", "python-app") - return api.language(params) + try: + return api.language(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index 6e3dc40..ee9bf6b 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did." params = DocumentParameters() params["content"] = morphology_complete_data - return api.morphology(params) + try: + return api.morphology(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index 596f39d..8847c9e 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput +from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): morphology_compound_components_data = "Rechtsschutzversicherungsgesellschaften" params = DocumentParameters() params["content"] = morphology_compound_components_data - return api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS) + try: + return api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index 535b314..6f0149f 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput +from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): morphology_han_readings_data = "北京大学生物系主任办公室内部会议" params = DocumentParameters() params["content"] = morphology_han_readings_data - return api.morphology(params, MorphologyOutput.HAN_READINGS) + try: + return api.morphology(params, MorphologyOutput.HAN_READINGS) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index 9617712..63ee26a 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput +from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): morphology_lemmas_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" params = DocumentParameters() params["content"] = morphology_lemmas_data - return api.morphology(params, MorphologyOutput.LEMMAS) + try: + return api.morphology(params, MorphologyOutput.LEMMAS) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index 69dbcdb..a10bb43 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput +from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): morphology_parts_of_speech_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" params = DocumentParameters() params["content"] = morphology_parts_of_speech_data - return api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH) + try: + return api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/name_similarity.py b/examples/name_similarity.py index b4ed053..159f8fd 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, NameSimilarityParameters +from rosette.api import API, NameSimilarityParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -20,7 +20,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = NameSimilarityParameters() params["name1"] = {"text": matched_name_data1, "language": "eng", "entityType": "PERSON"} params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} - return api.name_similarity(params) + try: + return api.name_similarity(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/name_translation.py b/examples/name_translation.py index c6704e4..84ab35b 100644 --- a/examples/name_translation.py +++ b/examples/name_translation.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, NameTranslationParameters +from rosette.api import API, NameTranslationParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -21,7 +21,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params["entityType"] = "PERSON" params["targetLanguage"] = "eng" params["targetScript"] = "Latn" - return api.name_translation(params) + try: + return api.name_translation(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/ping.py b/examples/ping.py index 98506f3..7cbeea2 100644 --- a/examples/ping.py +++ b/examples/ping.py @@ -8,14 +8,17 @@ import json import os -from rosette.api import API +from rosette.api import API, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) - return api.ping() + try: + return api.ping() + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/relationships.py b/examples/relationships.py index 86aefec..a7db2cc 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = relationships_text_data api.setOption('accuracyMode', 'PRECISION') - return api.relationships(params) + try: + return api.relationships(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/sentences.py b/examples/sentences.py index b1b682d..28a5a36 100644 --- a/examples/sentences.py +++ b/examples/sentences.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -19,7 +19,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = sentences_data - return api.sentences(params) + try: + return api.sentences(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/sentiment.py b/examples/sentiment.py index c43074c..aa96d47 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -9,7 +9,7 @@ import os import tempfile -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -28,10 +28,13 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Use an HTML file to load data instead of a string params.load_document_file(f.name) - result = api.sentiment(params) - - # Clean up the file - f.close() + try: + result = api.sentiment(params) + except RosetteException as e: + print(e) + finally: + # Clean up the file + f.close() return result diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index 1f5f511..c0d956e 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params["genre"] = "social-media" # Create an API instance api = API(user_key=key, service_url=altUrl) - return api.syntax_dependencies(params) + try: + return api.syntax_dependencies(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') diff --git a/examples/text_embedding.py b/examples/text_embedding.py index c91ae82..fc1a6c4 100644 --- a/examples/text_embedding.py +++ b/examples/text_embedding.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -17,7 +17,11 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): embeddings_data = "Cambridge, Massachusetts" params = DocumentParameters() params["content"] = embeddings_data - return api.text_embedding(params) + try: + return api.text_embedding(params) + except RosetteException as e: + print(e) + 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) diff --git a/examples/tokens.py b/examples/tokens.py index 128a23c..2453230 100644 --- a/examples/tokens.py +++ b/examples/tokens.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -18,7 +18,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): tokens_data = "北京大学生物系主任办公室内部会议" params = DocumentParameters() params["content"] = tokens_data - return api.tokens(params) + try: + return api.tokens(params) + except RosetteException as e: + print(e) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') From 22fe618f46d086be5a5f3b3b3839a359adc3df59 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 6 Dec 2016 08:33:11 -0500 Subject: [PATCH 030/247] Fixed PEP8-check - info missing two lines above run --- examples/info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/info.py b/examples/info.py index b83dbcb..4e4c9e2 100644 --- a/examples/info.py +++ b/examples/info.py @@ -10,6 +10,7 @@ from rosette.api import API, RosetteException + def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) From 27aed24b297ba3c741e0f59cce02b69b74cdc768 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 19 Dec 2016 15:22:59 +0000 Subject: [PATCH 031/247] Version 1.5.0 --- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index 7b49a91..fe9b4db 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.4.2' +__version__ = '1.5.0' diff --git a/rosette/api.py b/rosette/api.py index 242e5c1..9f329f5 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import re import warnings -_BINDING_VERSION = '1.4.2' +_BINDING_VERSION = '1.5.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _IsPy3 = sys.version_info[0] == 3 From 1207df6507853942e7917e3e6f3ff5eee3894d3b Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 9 Jan 2017 09:26:34 -0500 Subject: [PATCH 032/247] RCB-488 - Removed social-media from syntax_dependencies example --- examples/syntax_dependencies.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index c0d956e..d553d76 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -15,7 +15,6 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday." params = DocumentParameters() params["content"] = syntax_dependencies_data - params["genre"] = "social-media" # Create an API instance api = API(user_key=key, service_url=altUrl) try: From b601157d07f4806db2ca90b55b8d5cdea1e4ea76 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 14 Apr 2017 12:46:11 -0400 Subject: [PATCH 033/247] Dedup - First pass - Added endpoint and parameter for dedup - Added unit test - Updated Example README - Added example - Updated gitignore --- .gitignore | 3 +++ examples/README.md | 41 +++++++++++++++++----------------- examples/name_deduplication.py | 36 +++++++++++++++++++++++++++++ rosette/api.py | 29 ++++++++++++++++++++++++ tests/test_rosette_api.py | 21 +++++++++++++++++ 5 files changed, 110 insertions(+), 20 deletions(-) create mode 100644 examples/name_deduplication.py diff --git a/.gitignore b/.gitignore index e579830..b53e254 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,6 @@ docs/_build/ # PyBuilder target/ + +settings.json +*.orig diff --git a/examples/README.md b/examples/README.md index 38b87fd..f1b9f79 100644 --- a/examples/README.md +++ b/examples/README.md @@ -12,30 +12,31 @@ You can now run your desired _endpoint_.py file to see it in action. For example, run `python/examples/categories.py` if you want to see the categories functionality demonstrated. -All files require you to input your Rosette API User Key after --key to run. -For example: `python ping.py --key 1234567890` -All also allow you to input your own service URL if desired. -For example: `python ping.py --key 1234567890 --service_url http://www.myurl.com` +All files require you to input your Rosette API User Key after --key to run. +For example: `python ping.py --key 1234567890` +All also allow you to input your own service URL if desired. +For example: `python ping.py --key 1234567890 --service_url http://www.myurl.com` Some (specified below) allow an additional input of either a file (.html or .txt) or a URL with `--file` or `--url` Each example, when run, prints its output to the console. -| File Name | What it does | -| ------------- |------------- | -| categories.py | Gets the category of a document at a URL | -| entities.py | Gets the entities from a piece of text | -| info.py | Gets information about Rosette API | -| language.py | Gets the language of a piece of text | -| matched-name.py | Gets the similarity score of two names | -| morphology_complete.py | Gets the complete morphological analysis of a piece of text| -| morphology_compound-components.py | Gets the de-compounded words from a piece of text | -| morphology_han-readings.py | Gets the Chinese words from a piece of text | -| morphology_lemmas.py | Gets the lemmas of words from a piece of text | -| morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text | -| ping.py | Pings the Rosette API to check for reachability | -| relationships.py | Gets the relationships between entities from a piece of text | +| File Name | What it does | +| ------------- |------------- | +| categories.py | Gets the category of a document at a URL | +| entities.py | Gets the entities from a piece of text | +| info.py | Gets information about Rosette API | +| language.py | Gets the language of a piece of text | +| matched-name.py | Gets the similarity score of two names | +| morphology_complete.py | Gets the complete morphological analysis of a piece of text| +| morphology_compound-components.py | Gets the de-compounded words from a piece of text | +| morphology_han-readings.py | Gets the Chinese words from a piece of text | +| morphology_lemmas.py | Gets the lemmas of words from a piece of text | +| morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text | +| name_deduplication.py | De-duplicates a list of names | +| ping.py | Pings the Rosette API to check for reachability | +| relationships.py | Gets the relationships between entities from a piece of text | | sentences.py | Gets the sentences from a piece of text | -| sentiment.py | Gets the sentiment of a local file | -| tokens.py | Gets the tokens (words) from a piece of text | +| sentiment.py | Gets the sentiment of a local file | +| tokens.py | Gets the tokens (words) from a piece of text | | translated-name.py | Translates a name from one language to another | diff --git a/examples/name_deduplication.py b/examples/name_deduplication.py new file mode 100644 index 0000000..291f183 --- /dev/null +++ b/examples/name_deduplication.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +""" +Example code to call Rosette API to deduplicate a list of names. +""" + +import argparse +import json +import os + +from rosette.api import API, NameDeduplicationParameters, RosetteException + + +def run(key, altUrl='https://api.rosette.com/rest/v1/'): + # Create an API instance + api = API(user_key=key, service_url=altUrl) + + dedup_list = ["John Smith", "Johnathon Smith", "Fred Jones"] + threshold = 0.75 + params = NameDeduplicationParameters() + params["names"] = dedup_list + params["threshold"] = threshold + try: + return api.name_deduplication(params) + except RosetteException as e: + print(e) + + +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index 9f329f5..dbb4dcb 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -304,6 +304,26 @@ def validate(self): "Required Name Similarity parameter not supplied", repr(n)) +class NameDeduplicationParameters(_DocumentParamSetBase): + """Parameter object for C{name-deduplication} endpoint. + Required: + C{names} A list of C{name} objects + C{threshold} Threshold to use to restrict cluster size + """ + + def __init__(self): + self.useMultipart = False + _DocumentParamSetBase.__init__(self, ("names", "threshold")) + + def validate(self): + """Internal. Do not use.""" + for n in ("names", "threshold"): # required + if self[n] is None: + raise RosetteException( + "missingParameter", + "Required Name De-Duplication parameter not supplied", + repr(n)) + class EndpointCaller: """L{EndpointCaller} objects are invoked via their instance methods to obtain results @@ -860,6 +880,15 @@ def matched_name(self, parameters): @return: A python dictionary containing the results of name matching.""" return self.name_similarity(parameters) + def name_deduplication(self, parameters): + """ + Fuzzy de-duplication of a list of names + @param parameters: An object specifying a list of names as well + as a threshold + @type parameters: L{NameDeduplicationParameters} + @return: A python dictionary containing the results of de-duplication""" + return EndpointCaller(self, "name-deduplication").call(parameters) + def text_embedding(self, parameters): """ Create an L{EndpointCaller} to identify text vectors found in the texts diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 67bd92e..b27158c 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -415,6 +415,27 @@ def test_the_name_similarity_endpoint(api, json_response): httpretty.disable() httpretty.reset() +# Test the name deduplication endpoint + + +def test_the_name_deduplication_endpoint(api, json_response): + 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-deduplication", + body=json_response, status=200, content_type="application/json") + + dedup_list = ["John Smith", "Johnathon Smith", "Fred Jones"] + threshold = 0.75 + params = NameDeduplicationParameters() + params["names"] = dedup_list + params["threshold"] = threshold + + result = api.name_deduplication(params) + assert result["name"] == "Rosette API" + httpretty.disable() + httpretty.reset() + # Test the relationships endpoint From 9c4e43166b612617002bab1dad92c40fbbd9bcab Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 14 Apr 2017 13:26:23 -0400 Subject: [PATCH 034/247] Dedup - Round 2 - PEP8 fixes - Unit test fix --- rosette/api.py | 3 ++- tests/test_rosette_api.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index dbb4dcb..beba80c 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -304,6 +304,7 @@ def validate(self): "Required Name Similarity parameter not supplied", repr(n)) + class NameDeduplicationParameters(_DocumentParamSetBase): """Parameter object for C{name-deduplication} endpoint. Required: @@ -317,7 +318,7 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for n in ("names", "threshold"): # required + for n in ("names", "threshold"): # required if self[n] is None: raise RosetteException( "missingParameter", diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index b27158c..6e4b6d8 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -30,7 +30,7 @@ except ImportError: from io import BytesIO as streamIO import gzip -from rosette.api import API, DocumentParameters, NameTranslationParameters, NameSimilarityParameters, RosetteException +from rosette.api import API, DocumentParameters, NameTranslationParameters, NameSimilarityParameters, NameDeduplicationParameters, RosetteException _IsPy3 = sys.version_info[0] == 3 From 50715b9b5b8b222486df943744812705ea8c7282 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 14 Apr 2017 14:40:40 -0400 Subject: [PATCH 035/247] RCT (first pass) - transliteration logic - parameter object - unit test - updated README - initial example --- examples/README.md | 1 + examples/transliteration.py | 39 ++++++++++++ rosette/api.py | 91 ++++++++++++++++++++++------ tests/test_rosette_api.py | 115 +++++++++++++++++++++++++++++++++++- 4 files changed, 226 insertions(+), 20 deletions(-) create mode 100644 examples/transliteration.py diff --git a/examples/README.md b/examples/README.md index f1b9f79..2a391fd 100644 --- a/examples/README.md +++ b/examples/README.md @@ -39,4 +39,5 @@ Each example, when run, prints its output to the console. | sentiment.py | Gets the sentiment of a local file | | tokens.py | Gets the tokens (words) from a piece of text | | translated-name.py | Translates a name from one language to another | +| transliteration.py | Transliterates the given text | diff --git a/examples/transliteration.py b/examples/transliteration.py new file mode 100644 index 0000000..c6b5a85 --- /dev/null +++ b/examples/transliteration.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +""" +Example code to call Rosette API to transliterate a piece of text. +""" + +import argparse +import json +import os + +from rosette.api import API, TransliterationParameters, RosetteException + + +def run(key, altUrl='https://api.rosette.com/rest/v1/'): + # Create an API instance + api = API(user_key=key, service_url=altUrl) + + transliteration_data = "Some random text" + params = TransliterationParameters() + params["content"] = transliteration_data + params["sourceLanguage"] = "eng" + params["sourceScript"] = "Latn" + params["targetLanguage"] = "zho" + params["targetScript"] = "Hani" + + try: + return api.transliterate(params) + except RosetteException as e: + print(e) + + +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index beba80c..f826c15 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -113,6 +113,25 @@ class MorphologyOutput(_PseudoEnum): COMPLETE = "complete" +class Endpoints(_PseudoEnum): + CATEGORIES = "categories" + ENTITIES = "entities" + INFO = "info" + LANGUAGE = "language" + MORPHOLOGY = "morphology" + NAME_TRANSLATION = "name-translation" + NAME_SIMILARITY = "name-similarity" + NAME_DEDUPLICATION = "name-deduplication" + PING = "ping" + RELATIONSHIPS = "relationships" + SENTENCES = "sentences" + SENTIMENT = "sentiment" + SYNTAX_DEPENDENCIES = "syntax/dependencies" + TEXT_EMBEDDING = "text-embedding" + TOKENS = "tokens" + TRANSLITERATION = "transliteration" + + class _DocumentParamSetBase(object): def __init__(self, repertoire): @@ -268,7 +287,7 @@ def validate(self): if self[n] is None: raise RosetteException( "missingParameter", - "Required Name Translation parameter not supplied", + "Required Name Translation parameter," + n + ", not supplied", repr(n)) @@ -301,7 +320,7 @@ def validate(self): if self[n] is None: raise RosetteException( "missingParameter", - "Required Name Similarity parameter not supplied", + "Required Name Similarity parameter," + n + ", not supplied", repr(n)) @@ -322,7 +341,31 @@ def validate(self): if self[n] is None: raise RosetteException( "missingParameter", - "Required Name De-Duplication parameter not supplied", + "Required Name De-Duplication parameter," + n + ", not supplied", + repr(n)) + + +class TransliterationParameters(_DocumentParamSetBase): + """Parameter object for C{transliteration} endpoint. + Required: + C{content} Textual content + C{sourceLanguage} Source language code + C{sourceScript} Source language script + C{targetLanguage} Target language code + C{targetScript} Target language script + """ + + def __init__(self): + self.useMultipart = False + _DocumentParamSetBase.__init__(self, ("content", "sourceLanguage", "sourceScript", "targetLanguage", "targetScript")) + + def validate(self): + """Internal. Do not use.""" + for n in ("content", "sourceLanguage", "sourceScript", "targetLanguage", "targetScript"): # required + if self[n] is None: + raise RosetteException( + "missingParameter", + "Required Transliteration parameter," + n + ", not supplied", repr(n)) @@ -377,7 +420,7 @@ def info(self): """Issues an "info" request to the L{EndpointCaller}'s specific endpoint. @return: A dictionary telling server version and other identifying data.""" - url = self.service_url + "info" + url = self.service_url + Endpoints.INFO headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} customHeaders = self.api.getCustomHeaders() @@ -404,7 +447,7 @@ def ping(self): or is not the right server or some other error occurs, it will be signalled.""" - url = self.service_url + 'ping' + url = self.service_url + Endpoints.PING headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} customHeaders = self.api.getCustomHeaders() @@ -446,7 +489,10 @@ def call(self, parameters): """ if not isinstance(parameters, _DocumentParamSetBase): - if self.suburl != "name-similarity" and self.suburl != "name-translation": + if self.suburl != Endpoints.NAME_SIMILARITY + and self.suburl != Endpoints.NAME_TRANSLATION + and self.suburl != Endpoints.NAME_DEDUPLICATION + and self.suburl != Endpoints.TRANSLITERATION: text = parameters parameters = DocumentParameters() parameters['content'] = text @@ -766,7 +812,7 @@ def language(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of language identification.""" - return EndpointCaller(self, "language").call(parameters) + return EndpointCaller(self, Endpoints.LANGUAGE).call(parameters) def sentences(self, parameters): """ @@ -775,7 +821,7 @@ def sentences(self, parameters): and possible metadata, to be processed by the sentence identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of sentence identification.""" - return EndpointCaller(self, "sentences").call(parameters) + return EndpointCaller(self, Endpoints.SENTENCES).call(parameters) def tokens(self, parameters): """ @@ -784,7 +830,7 @@ def tokens(self, parameters): and possible metadata, to be processed by the tokens identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of tokenization.""" - return EndpointCaller(self, "tokens").call(parameters) + return EndpointCaller(self, Endpoints.TOKENS).call(parameters) def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): """ @@ -796,7 +842,7 @@ def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): @param facet: The facet desired, to be returned by the created L{EndpointCaller}. @type facet: An element of L{MorphologyOutput}. @return: A python dictionary containing the results of morphological analysis.""" - return EndpointCaller(self, "morphology/" + facet).call(parameters) + return EndpointCaller(self, Endpoints.MORPHOLOGY + "/" + facet).call(parameters) def entities(self, parameters): """ @@ -807,7 +853,7 @@ def entities(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of entity extraction.""" - return EndpointCaller(self, "entities").call(parameters) + return EndpointCaller(self, Endpoints.ENTITIES).call(parameters) def categories(self, parameters): """ @@ -817,7 +863,7 @@ def categories(self, parameters): and possible metadata, to be processed by the category identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of categorization.""" - return EndpointCaller(self, "categories").call(parameters) + return EndpointCaller(self, Endpoints.CATEGORIES).call(parameters) def sentiment(self, parameters): """ @@ -831,7 +877,7 @@ def sentiment(self, parameters): to which is applied. @return: An L{EndpointCaller} object which can return sentiments of texts to which it is applied.""" - return EndpointCaller(self, "sentiment").call(parameters) + return EndpointCaller(self, Endpoints.SENTIMENT).call(parameters) def relationships(self, parameters): """ @@ -841,7 +887,7 @@ def relationships(self, parameters): and possible metadata, to be processed by the relationships identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of relationship extraction.""" - return EndpointCaller(self, "relationships").call(parameters) + return EndpointCaller(self, Endpoints.RELATIONSHIPS).call(parameters) def name_translation(self, parameters): """ @@ -851,7 +897,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, "name-translation").call(parameters) + return EndpointCaller(self, Endpoints.NAME_TRANSLATION).call(parameters) def translated_name(self, parameters): """ deprecated @@ -870,7 +916,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, "name-similarity").call(parameters) + return EndpointCaller(self, Endpoints.NAME_SIMILARITY).call(parameters) def matched_name(self, parameters): """ deprecated @@ -888,7 +934,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, "name-deduplication").call(parameters) + return EndpointCaller(self, Endpoints.NAME_DEDUPLICATION).call(parameters) def text_embedding(self, parameters): """ @@ -896,7 +942,7 @@ def text_embedding(self, parameters): to which it is applied and call it. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of text embedding.""" - return EndpointCaller(self, "text-embedding").call(parameters) + return EndpointCaller(self, Endpoints.TEXT_EMBEDDING).call(parameters) def syntax_dependencies(self, parameters): """ @@ -904,4 +950,11 @@ def syntax_dependencies(self, parameters): to which it is applied and call it. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of syntactic dependencies identification""" - return EndpointCaller(self, "syntax/dependencies").call(parameters) + return EndpointCaller(self, Endpoints.SYNTAX_DEPENDENCIES).call(parameters) + + def transliteration(self, parameters): + """ + Transliterate given context + @type parameters: L{TransliterationParameters} + @return: A python dictionary containing the results of the transliteration""" + return EndpointCaller(self, Endpoints.TRANSLITERATION).call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 6e4b6d8..5aee240 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -30,7 +30,13 @@ except ImportError: from io import BytesIO as streamIO import gzip -from rosette.api import API, DocumentParameters, NameTranslationParameters, NameSimilarityParameters, NameDeduplicationParameters, RosetteException +from rosette.api import API, + DocumentParameters, + NameTranslationParameters, + NameSimilarityParameters, + NameDeduplicationParameters, + TransliterationParameters, + RosetteException _IsPy3 = sys.version_info[0] == 3 @@ -418,6 +424,40 @@ def test_the_name_similarity_endpoint(api, json_response): # Test the name deduplication endpoint +def test_for_name_deduplicatation_required_parameters(api, json_response): + 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-deduplication", + body=json_response, status=200, content_type="application/json") + + params = NameDeduplicationParameters() + + with pytest.raises(RosetteException) as e_rosette: + result = api.name_deduplication(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Name De-Duplication parameter, names, not supplied' + + params["names"] = ["John Smith", "Johnathon Smith", "Fred Jones"] + + with pytest.raises(RosetteException) as e_rosette: + result = api.name_deduplication(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Name De-Duplication parameter, threshold, not supplied' + + params["threshold"] = 0.75 + + with pytest.raises(RosetteException) as e_rosette: + result = api.name_deduplication(params) + + result = api.name_deduplication(params) + assert result["name"] == "Rosette API" + + httpretty.disable() + httpretty.reset() + def test_the_name_deduplication_endpoint(api, json_response): httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", @@ -605,3 +645,76 @@ def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): assert result["name"] == "Rosette API" httpretty.disable() httpretty.reset() + + +# Test the transliteration endpoint + + +def test_for_transliteration_required_parameters(api, json_response): + 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/transliteration", + body=json_response, status=200, content_type="application/json") + + params = TransliterateParameters() + params["content"] = "Random text" + + with pytest.raises(RosetteException) as e_rosette: + result = api.transliteration(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Transliteration parameter, sourceLanguage, not supplied' + + params["sourceLanguage"] = "eng" + + with pytest.raises(RosetteException) as e_rosette: + result = api.transliteration(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Transliteration parameter, sourceScript, not supplied' + + params["sourceScript"] = "Latn" + + with pytest.raises(RosetteException) as e_rosette: + result = api.transliteration(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Transliteration parameter, targetLanguage, not supplied' + + params["targetLanguage"] = "zho" + + with pytest.raises(RosetteException) as e_rosette: + result = api.transliteration(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Transliteration parameter, targetScript, not supplied' + + params["targetScript"] = "Hani" + + with pytest.raises(RosetteException) as e_rosette: + result = api.transliteration(params) + + result = api.transliteration(params) + assert result["name"] == "Rosette API" + + httpretty.disable() + httpretty.reset() + +def test_the_transliteration_endpoint(api, json_response, doc_params): + 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/transliteration", + body=json_response, status=200, content_type="application/json") + + params = TransliterationParameters() + params["content"] = "Some test content" + params["sourceLanguage"] = "eng" + params["sourceScript"] = "Latn" + params["targetLanguage"] = "zho" + params["targetScript"] = "Hani" + result = api.transliteration(doc_params) + assert result["name"] == "Rosette API" + httpretty.disable() + httpretty.reset() From 7e564d759a778a7f185bd690a0de53835598ddea Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 14 Apr 2017 14:46:51 -0400 Subject: [PATCH 036/247] Indentation --- tests/test_rosette_api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 5aee240..01dc8b4 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -31,12 +31,12 @@ from io import BytesIO as streamIO import gzip from rosette.api import API, - DocumentParameters, - NameTranslationParameters, - NameSimilarityParameters, - NameDeduplicationParameters, - TransliterationParameters, - RosetteException + DocumentParameters, + NameTranslationParameters, + NameSimilarityParameters, + NameDeduplicationParameters, + TransliterationParameters, + RosetteException _IsPy3 = sys.version_info[0] == 3 From baf8ccf745eaac2b3c079a4618493f26ad5ee468 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 10:14:02 -0400 Subject: [PATCH 037/247] Code Cleanup - per pep8 --- examples/language.py | 2 +- examples/relationships.py | 2 +- rosette/api.py | 407 +++++++++++++++++++------------------- setup.py | 14 +- tests/test_rosette_api.py | 79 ++++---- 5 files changed, 251 insertions(+), 253 deletions(-) diff --git a/examples/language.py b/examples/language.py index 345fe30..1ebb927 100644 --- a/examples/language.py +++ b/examples/language.py @@ -18,7 +18,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): language_data = "Por favor Señorita, says the man." params = DocumentParameters() params["content"] = language_data - api.setCustomHeaders("X-RosetteAPI-App", "python-app") + api.setcustom_headers("X-RosetteAPI-App", "python-app") try: return api.language(params) except RosetteException as e: diff --git a/examples/relationships.py b/examples/relationships.py index a7db2cc..ca9b504 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -17,7 +17,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." params = DocumentParameters() params["content"] = relationships_text_data - api.setOption('accuracyMode', 'PRECISION') + api.set_option('accuracyMode', 'PRECISION') try: return api.relationships(params) except RosetteException as e: diff --git a/rosette/api.py b/rosette/api.py index f826c15..71e3a7d 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -22,19 +22,17 @@ import json import logging import sys -import time import os -import requests import re -import warnings +import requests _BINDING_VERSION = '1.5.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) -_IsPy3 = sys.version_info[0] == 3 +_ISPY3 = sys.version_info[0] == 3 -if _IsPy3: +if _ISPY3: _GZIP_SIGNATURE = _GZIP_BYTEARRAY else: _GZIP_SIGNATURE = str(_GZIP_BYTEARRAY) @@ -47,18 +45,19 @@ def __init__(self, js, code): self.status_code = code def json(self): + """ return json""" return self._json def _my_loads(obj, response_headers): - if _IsPy3: - d1 = json.loads(obj.decode("utf-8")).copy() - d1.update(response_headers) - return d1 # if py3, need chars. + if _ISPY3: + temp = json.loads(obj.decode("utf-8")).copy() + temp.update(response_headers) + return temp # if py3, need chars. else: - d2 = json.loads(obj).copy() - d2.update(response_headers) - return d2 + temp = json.loads(obj).copy() + temp.update(response_headers) + return temp class RosetteException(Exception): @@ -68,68 +67,43 @@ class RosetteException(Exception): """ def __init__(self, status, message, response_message): + super(RosetteException, self).__init__(message) self.status = status self.message = message self.response_message = response_message def __str__(self): sst = self.status - if not (isinstance(sst, str)): + if not isinstance(sst, str): sst = repr(sst) return sst + ": " + self.message + ":\n " + self.response_message - -class _PseudoEnum: - - def __init__(self): - pass - - @classmethod - def validate(cls, value, name): - values = [] - for (k, v) in vars(cls).items(): - if not k.startswith("__"): - values += [v] - - # this is still needed to make sure that the parameter NAMES are known. - # If python didn't allow setting unknown values, this would be a - # language error. - if value not in values: - raise RosetteException( - "unknownVariable", - "The value supplied for " + - name + - " is not one of " + - ", ".join(values) + - ".", - repr(value)) - - -class MorphologyOutput(_PseudoEnum): - LEMMAS = "lemmas" - PARTS_OF_SPEECH = "parts-of-speech" - COMPOUND_COMPONENTS = "compound-components" - HAN_READINGS = "han-readings" - COMPLETE = "complete" - - -class Endpoints(_PseudoEnum): - CATEGORIES = "categories" - ENTITIES = "entities" - INFO = "info" - LANGUAGE = "language" - MORPHOLOGY = "morphology" - NAME_TRANSLATION = "name-translation" - NAME_SIMILARITY = "name-similarity" - NAME_DEDUPLICATION = "name-deduplication" - PING = "ping" - RELATIONSHIPS = "relationships" - SENTENCES = "sentences" - SENTIMENT = "sentiment" - SYNTAX_DEPENDENCIES = "syntax/dependencies" - TEXT_EMBEDDING = "text-embedding" - TOKENS = "tokens" - TRANSLITERATION = "transliteration" +MORPHOLOGY_OUTPUT = { + 'LEMMAS': 'lemmas', + 'PARTS_OF_SPEECH': 'parts-of-speech', + 'COMPOUND_COMPONENTS': 'compound-components', + 'HAN_READINGS': 'han-readings', + 'COMPLETE': 'complete' +} + +ENDPOINTS = { + 'CATEGORIES': 'categories', + 'ENTITIES': 'entities', + 'INFO': 'info', + 'LANGUAGE': 'language', + 'MORPHOLOGY': 'morphology', + 'NAME_TRANSLATION': 'name-translation', + 'NAME_SIMILARITY': 'name-similarity', + 'NAME_DEDUPLICATION': 'name-deduplication', + 'PING': 'ping', + 'RELATIONSHIPS': 'relationships', + 'SENTENCES': 'sentences', + 'SENTIMENT': 'sentiment', + 'SYNTAX_DEPENDENCIES': 'syntax/dependencies', + 'TEXT_EMBEDDING': 'text-embedding', + 'TOKENS': 'tokens', + 'TRANSLITERATION': 'transliteration' +} class _DocumentParamSetBase(object): @@ -152,31 +126,33 @@ def __getitem__(self, key): return self.__params[key] def validate(self): + """validation""" pass def serialize(self, options): + """serialize keys with values""" self.validate() - v = {} + values = {} for (key, val) in self.__params.items(): if val is None: pass else: - v[key] = val + values[key] = val if options is not None and len(options) > 0: - v['options'] = options + values['options'] = options - return v + return values -def _byteify(s): # py 3 only - l = len(s) - b = bytearray(l) - for ix in range(l): - oc = ord(s[ix]) - assert (oc < 256) - b[ix] = oc - return b +def _byteify(value): # py 3 only + length = len(value) + byte_array = bytearray(length) + for index in range(length): + ordinal = ord(value[index]) + assert ordinal < 256 + byte_array[index] = ordinal + return byte_array class DocumentParameters(_DocumentParamSetBase): @@ -199,7 +175,7 @@ def __init__(self): _DocumentParamSetBase.__init__( self, ("content", "contentUri", "language", "genre")) self.file_name = "" - self.useMultipart = False + self.use_multipart = False def validate(self): """Internal. Do not use.""" @@ -228,27 +204,28 @@ def load_document_file(self, path): be determined by the server. @parameter path: Pathname of a file acceptable to the C{open} function. """ - self.useMultipart = True + self.use_multipart = True self.file_name = path self.load_document_string(open(path, "rb").read()) - def load_document_string(self, s): + def load_document_string(self, content_as_string): """Loads a string into the object. The string will be taken as bytes or as Unicode dependent upon its native python type. @parameter s: A string, possibly a unicode-string, to be loaded for subsequent analysis. """ - self["content"] = s + self["content"] = content_as_string class NameTranslationParameters(_DocumentParamSetBase): """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}). + The following values may be set by the indexing (i.e.,C{ parms["name"]}) operator. + The values are all strings (when not C{None}). All are optional except C{name} and C{targetLanguage}. Scripts are in - ISO15924 codes, and languages in ISO639 (two- or three-letter) codes. See the Name Translation documentation for - more description of these terms, as well as the content of the return result. + ISO15924 codes, and languages in ISO639 (two- or three-letter) codes. See the Name + Translation documentation for more description of these terms, as well as the + content of the return result. C{name} The name to be translated. @@ -268,7 +245,7 @@ class NameTranslationParameters(_DocumentParamSetBase): """ def __init__(self): - self.useMultipart = False + self.use_multipart = False _DocumentParamSetBase.__init__( self, ("name", @@ -283,12 +260,12 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for n in ("name", "targetLanguage"): # required - if self[n] is None: + for option in ("name", "targetLanguage"): # required + if self[option] is None: raise RosetteException( "missingParameter", - "Required Name Translation parameter," + n + ", not supplied", - repr(n)) + "Required Name Translation parameter," + option + ", not supplied", + repr(option)) class NameSimilarityParameters(_DocumentParamSetBase): @@ -311,17 +288,17 @@ class NameSimilarityParameters(_DocumentParamSetBase): """ def __init__(self): - self.useMultipart = False + self.use_multipart = False _DocumentParamSetBase.__init__(self, ("name1", "name2")) def validate(self): """Internal. Do not use.""" - for n in ("name1", "name2"): # required - if self[n] is None: + for option in ("name1", "name2"): # required + if self[option] is None: raise RosetteException( "missingParameter", - "Required Name Similarity parameter," + n + ", not supplied", - repr(n)) + "Required Name Similarity parameter," + option + ", not supplied", + repr(option)) class NameDeduplicationParameters(_DocumentParamSetBase): @@ -332,17 +309,17 @@ class NameDeduplicationParameters(_DocumentParamSetBase): """ def __init__(self): - self.useMultipart = False + self.use_multipart = False _DocumentParamSetBase.__init__(self, ("names", "threshold")) def validate(self): """Internal. Do not use.""" - for n in ("names", "threshold"): # required - if self[n] is None: + for option in ("names", "threshold"): # required + if self[option] is None: raise RosetteException( "missingParameter", - "Required Name De-Duplication parameter," + n + ", not supplied", - repr(n)) + "Required Name De-Duplication parameter," + option + ", not supplied", + repr(option)) class TransliterationParameters(_DocumentParamSetBase): @@ -356,17 +333,19 @@ class TransliterationParameters(_DocumentParamSetBase): """ def __init__(self): - self.useMultipart = False - _DocumentParamSetBase.__init__(self, ("content", "sourceLanguage", "sourceScript", "targetLanguage", "targetScript")) + self.use_multipart = False + _DocumentParamSetBase.__init__(self, ("content", "sourceLanguage", "sourceScript", + "targetLanguage", "targetScript")) def validate(self): """Internal. Do not use.""" - for n in ("content", "sourceLanguage", "sourceScript", "targetLanguage", "targetScript"): # required - if self[n] is None: + for option in ("content", "sourceLanguage", "sourceScript", "targetLanguage", + "targetScript"): + if self[option] is None: raise RosetteException( "missingParameter", - "Required Transliteration parameter," + n + ", not supplied", - repr(n)) + "Required Transliteration parameter," + option + ", not supplied", + repr(option)) class EndpointCaller: @@ -393,14 +372,14 @@ def __init__(self, api, suburl): self.service_url = api.service_url self.user_key = api.user_key self.logger = api.logger - self.useMultipart = False + self.use_multipart = False self.suburl = suburl self.debug = api.debug self.api = api - def __finish_result(self, r, ename): - code = r.status_code - the_json = r.json() + def __finish_result(self, response, ename): + code = response.status_code + the_json = response.json() if code == 200: return the_json else: @@ -420,26 +399,29 @@ def info(self): """Issues an "info" request to the L{EndpointCaller}'s specific endpoint. @return: A dictionary telling server version and other identifying data.""" - url = self.service_url + Endpoints.INFO - headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} + url = self.service_url + ENDPOINTS["INFO"] + headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', + 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} - customHeaders = self.api.getCustomHeaders() + custom_headers = self.api.getcustom_headers() pattern = re.compile('^X-RosetteAPI-') - if customHeaders is not None: - for key in customHeaders.keys(): + if custom_headers is not None: + for key in custom_headers.keys(): if pattern.match(key) is not None: - headers[key] = customHeaders[key] + headers[key] = custom_headers[key] else: - raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearCustomHeaders() + raise RosetteException("badHeader", + "Custom header name must begin with \"X-RosetteAPI-\"", + key) + self.api.clearcustom_headers() if self.debug: headers['X-RosetteAPI-Devel'] = 'true' self.logger.info('info: ' + url) if self.user_key is not None: headers["X-RosetteAPI-Key"] = self.user_key - r = self.api._get_http(url, headers=headers) - return self.__finish_result(r, "info") + response = self.api.get_http(url, headers=headers) + return self.__finish_result(response, "info") def ping(self): """Issues a "ping" request to the L{EndpointCaller}'s (server-wide) endpoint. @@ -447,34 +429,38 @@ def ping(self): or is not the right server or some other error occurs, it will be signalled.""" - url = self.service_url + Endpoints.PING - headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} + url = self.service_url + ENDPOINTS['PING'] + headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', + 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} - customHeaders = self.api.getCustomHeaders() + custom_headers = self.api.getcustom_headers() pattern = re.compile('^X-RosetteAPI-') - if customHeaders is not None: - for key in customHeaders.keys(): + if custom_headers is not None: + for key in custom_headers.keys(): if pattern.match(key) is not None: - headers[key] = customHeaders[key] + headers[key] = custom_headers[key] else: - raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearCustomHeaders() + raise RosetteException("badHeader", + "Custom header name must begin with \"X-RosetteAPI-\"", + key) + self.api.clearcustom_headers() if self.debug: headers['X-RosetteAPI-Devel'] = 'true' self.logger.info('Ping: ' + url) if self.user_key is not None: headers["X-RosetteAPI-Key"] = self.user_key - r = self.api._get_http(url, headers=headers) - return self.__finish_result(r, "ping") + response = self.api.get_http(url, headers=headers) + return self.__finish_result(response, "ping") def call(self, parameters): """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 - endpoints except C{name-translation} and C{name-similarity}, it must be a L{DocumentParameters} - object or a string; for C{name-translation}, it must be an L{NameTranslationParameters} object; - for C{name-similarity}, it must be an L{NameSimilarityParameters} object. For relationships, + endpoints except C{name-translation} and C{name-similarity}, it must be + a L{DocumentParameters} object or a string; for C{name-translation}, it + must be an L{NameTranslationParameters} object; for C{name-similarity}, + it must be an L{NameSimilarityParameters} object. For relationships, it may be an L(DocumentParameters). In all cases, the result is returned as a python dictionary @@ -484,15 +470,15 @@ 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: For C{name-translation}, L{NameTranslationParameters}, + otherwise L{DocumentParameters} or L{str} @return: A python dictionary expressing the result of the invocation. """ if not isinstance(parameters, _DocumentParamSetBase): - if self.suburl != Endpoints.NAME_SIMILARITY - and self.suburl != Endpoints.NAME_TRANSLATION - and self.suburl != Endpoints.NAME_DEDUPLICATION - and self.suburl != Endpoints.TRANSLITERATION: + if self.suburl != ENDPOINTS['NAME_SIMILARITY'] \ + and self.suburl != ENDPOINTS['NAME_TRANSLATION'] \ + and self.suburl != ENDPOINTS['NAME_DEDUPLICATION']: text = parameters parameters = DocumentParameters() parameters['content'] = text @@ -502,35 +488,37 @@ def call(self, parameters): "Text-only input only works for DocumentParameter endpoints", self.suburl) - self.useMultipart = parameters.useMultipart + self.use_multipart = parameters.use_multipart url = self.service_url + self.suburl params_to_serialize = parameters.serialize(self.api.options) headers = {} if self.user_key is not None: - - customHeaders = self.api.getCustomHeaders() + custom_headers = self.api.getcustom_headers() pattern = re.compile('^X-RosetteAPI-') - if customHeaders is not None: - for key in customHeaders.keys(): + if custom_headers is not None: + for key in custom_headers.keys(): if pattern.match(key) is not None: - headers[key] = customHeaders[key] + headers[key] = custom_headers[key] else: - raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearCustomHeaders() + raise RosetteException("badHeader", + "Custom header name must " + "begin with \"X-RosetteAPI-\"", + key) + self.api.clearcustom_headers() headers["X-RosetteAPI-Key"] = self.user_key headers["X-RosetteAPI-Binding"] = "python" headers["X-RosetteAPI-Binding-Version"] = _BINDING_VERSION - if self.useMultipart: + if self.use_multipart: payload = None - if (self.api.urlParameters): - payload = self.api.urlParameters + if self.api.url_parameters: + payload = self.api.url_parameters params = dict( (key, value) for key, - value in params_to_serialize.iteritems() if key == 'language') + value in params_to_serialize.items() if key == 'language') files = { 'content': ( os.path.basename( @@ -549,7 +537,7 @@ def call(self, parameters): rdata = resp.content response_headers = {"responseHeaders": dict(resp.headers)} status = resp.status_code - r = _ReturnObject(_my_loads(rdata, response_headers), status) + response = _ReturnObject(_my_loads(rdata, response_headers), status) else: if self.debug: headers['X-RosetteAPI-Devel'] = True @@ -557,8 +545,8 @@ def call(self, parameters): headers['Accept'] = "application/json" headers['Accept-Encoding'] = "gzip" headers['Content-Type'] = "application/json" - r = self.api._post_http(url, params_to_serialize, headers) - return self.__finish_result(r, "operate") + response = self.api.post_http(url, params_to_serialize, headers) + return self.__finish_result(response, "operate") class API: @@ -576,9 +564,9 @@ def __init__( refresh_duration=0.5, debug=False): """ Create an L{API} object. - @param user_key: (Optional; required for servers requiring authentication.) An authentication string to be sent - as user_key with all requests. The default Rosette server requires authentication. - to the server. + @param user_key: (Optional; required for servers requiring authentication.) + An authentication string to be sent as user_key with all requests. The + default Rosette server requires authentication to the server. """ # logging.basicConfig(filename="binding.log", filemode="w", level=logging.DEBUG) self.user_key = user_key @@ -588,28 +576,28 @@ def __init__( self.logger.info('Initialized on ' + self.service_url) self.debug = debug - if (retries < 1): + if retries < 1: retries = 1 - if (refresh_duration < 0): + if refresh_duration < 0: refresh_duration = 0 self.connection_refresh_duration = refresh_duration self.options = {} - self.customHeaders = {} - self.urlParameters = {} - self.maxPoolSize = 1 + self.custom_headers = {} + self.url_parameters = {} + self.max_pool_size = 1 self.session = requests.Session() def _set_pool_size(self): - adapter = requests.adapters.HTTPAdapter(pool_maxsize=self.maxPoolSize) + adapter = requests.adapters.HTTPAdapter(pool_maxsize=self.max_pool_size) if 'https:' in self.service_url: self.session.mount('https://', adapter) else: self.session.mount('http://', adapter) - def _make_request(self, op, url, data, headers): + def _make_request(self, operation, url, data, headers): """ - @param op: POST or GET + @param operation: POST or GET @param url: endpoing URL @param data: request data @param headers: request headers @@ -622,10 +610,10 @@ def _make_request(self, op, url, data, headers): response_headers = {} payload = None - if (self.urlParameters): - payload = self.urlParameters + if self.url_parameters: + payload = self.url_parameters - request = requests.Request(op, url, data=data, headers=headers, params=payload) + request = requests.Request(operation, url, data=data, headers=headers, params=payload) session = requests.Session() prepared_request = session.prepare_request(request) @@ -636,8 +624,8 @@ def _make_request(self, op, url, data, headers): dict_headers = dict(response.headers) response_headers = {"responseHeaders": dict_headers} if 'x-rosetteapi-concurrency' in dict_headers: - if dict_headers['x-rosetteapi-concurrency'] != self.maxPoolSize: - self.maxPoolSize = dict_headers['x-rosetteapi-concurrency'] + if dict_headers['x-rosetteapi-concurrency'] != self.max_pool_size: + self.max_pool_size = dict_headers['x-rosetteapi-concurrency'] self._set_pool_size() if status == 200: @@ -657,15 +645,15 @@ def _make_request(self, op, url, data, headers): except: raise - except requests.exceptions.RequestException as e: + except requests.exceptions.RequestException as exception: raise RosetteException( - e.message, + exception, "Unable to establish connection to the Rosette API server", url) raise RosetteException(code, message, url) - def _get_http(self, url, headers): + def get_http(self, url, headers): """ Simple wrapper for the GET request @@ -676,7 +664,7 @@ def _get_http(self, url, headers): "GET", url, None, headers) return _ReturnObject(_my_loads(rdata, response_headers), status) - def _post_http(self, url, data, headers): + def post_http(self, url, data, headers): """ Simple wrapper for the POST request @@ -698,13 +686,13 @@ def _post_http(self, url, data, headers): return _ReturnObject(_my_loads(rdata, response_headers), status) - def getPoolSize(self): + def get_pool_size(self): """ Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value """ - return int(self.maxPoolSize) + return int(self.max_pool_size) - def setOption(self, name, value): + def set_option(self, name, value): """ Sets an option @@ -716,7 +704,7 @@ def setOption(self, name, value): else: self.options[name] = value - def getOption(self, name): + def get_option(self, name): """ Gets an option @@ -729,13 +717,13 @@ def getOption(self, name): else: return None - def clearOptions(self): + def clear_options(self): """ Clears all options """ self.options.clear() - def setUrlParameter(self, name, value): + def set_url_parameter(self, name, value): """ Sets a URL parameter @@ -743,11 +731,11 @@ def setUrlParameter(self, name, value): @param value: value of parameter """ if value is None: - self.urlParameters.pop(name, None) + self.url_parameters.pop(name, None) else: - self.urlParameters[name] = value + self.url_parameters[name] = value - def getUrlParameter(self, name): + def get_url_parameter(self, name): """ Gets a URL parameter @@ -755,40 +743,40 @@ def getUrlParameter(self, name): @return: value of parameter """ - if name in self.urlParameters.keys(): - return self.urlParameters[name] + if name in self.url_parameters.keys(): + return self.url_parameters[name] else: return None - def clearUrlParameters(self): + def clearurl_parameters(self): """ Clears all options """ - self.urlParameters.clear() + self.url_parameters.clear() - def setCustomHeaders(self, name, value): + def setcustom_headers(self, name, value): """ Sets custom headers @param headers: array of custom headers to be set """ if value is None: - self.customHeaders.pop(name, None) + self.custom_headers.pop(name, None) else: - self.customHeaders[name] = value + self.custom_headers[name] = value - def getCustomHeaders(self): + def getcustom_headers(self): """ Get custom headers """ - return self.customHeaders + return self.custom_headers - def clearCustomHeaders(self): + def clearcustom_headers(self): """ Clears custom headers """ - self.customHeaders.clear() + self.custom_headers.clear() def ping(self): """ @@ -812,7 +800,7 @@ def language(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of language identification.""" - return EndpointCaller(self, Endpoints.LANGUAGE).call(parameters) + return EndpointCaller(self, ENDPOINTS['LANGUAGE']).call(parameters) def sentences(self, parameters): """ @@ -821,7 +809,7 @@ def sentences(self, parameters): and possible metadata, to be processed by the sentence identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of sentence identification.""" - return EndpointCaller(self, Endpoints.SENTENCES).call(parameters) + return EndpointCaller(self, ENDPOINTS['SENTENCES']).call(parameters) def tokens(self, parameters): """ @@ -830,9 +818,9 @@ def tokens(self, parameters): and possible metadata, to be processed by the tokens identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of tokenization.""" - return EndpointCaller(self, Endpoints.TOKENS).call(parameters) + return EndpointCaller(self, ENDPOINTS['TOKENS']).call(parameters) - def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): + def morphology(self, parameters, facet=MORPHOLOGY_OUTPUT['COMPLETE']): """ Create an L{EndpointCaller} to returns a specific facet of the morphological analyses of texts to which it is applied and call it. @@ -842,7 +830,7 @@ def morphology(self, parameters, facet=MorphologyOutput.COMPLETE): @param facet: The facet desired, to be returned by the created L{EndpointCaller}. @type facet: An element of L{MorphologyOutput}. @return: A python dictionary containing the results of morphological analysis.""" - return EndpointCaller(self, Endpoints.MORPHOLOGY + "/" + facet).call(parameters) + return EndpointCaller(self, ENDPOINTS['MORPHOLOGY'] + "/" + facet).call(parameters) def entities(self, parameters): """ @@ -853,7 +841,7 @@ def entities(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of entity extraction.""" - return EndpointCaller(self, Endpoints.ENTITIES).call(parameters) + return EndpointCaller(self, ENDPOINTS['ENTITIES']).call(parameters) def categories(self, parameters): """ @@ -863,7 +851,7 @@ def categories(self, parameters): and possible metadata, to be processed by the category identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of categorization.""" - return EndpointCaller(self, Endpoints.CATEGORIES).call(parameters) + return EndpointCaller(self, ENDPOINTS['CATEGORIES']).call(parameters) def sentiment(self, parameters): """ @@ -877,7 +865,7 @@ def sentiment(self, parameters): to which is applied. @return: An L{EndpointCaller} object which can return sentiments of texts to which it is applied.""" - return EndpointCaller(self, Endpoints.SENTIMENT).call(parameters) + return EndpointCaller(self, ENDPOINTS['SENTIMENT']).call(parameters) def relationships(self, parameters): """ @@ -887,7 +875,7 @@ def relationships(self, parameters): and possible metadata, to be processed by the relationships identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of relationship extraction.""" - return EndpointCaller(self, Endpoints.RELATIONSHIPS).call(parameters) + return EndpointCaller(self, ENDPOINTS['RELATIONSHIPS']).call(parameters) def name_translation(self, parameters): """ @@ -897,7 +885,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, Endpoints.NAME_TRANSLATION).call(parameters) + return EndpointCaller(self, ENDPOINTS['NAME_TRANSLATION']).call(parameters) def translated_name(self, parameters): """ deprecated @@ -916,7 +904,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, Endpoints.NAME_SIMILARITY).call(parameters) + return EndpointCaller(self, ENDPOINTS['NAME_SIMILARITY']).call(parameters) def matched_name(self, parameters): """ deprecated @@ -934,7 +922,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, Endpoints.NAME_DEDUPLICATION).call(parameters) + return EndpointCaller(self, ENDPOINTS['NAME_DEDUPLICATION']).call(parameters) def text_embedding(self, parameters): """ @@ -942,19 +930,20 @@ def text_embedding(self, parameters): to which it is applied and call it. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of text embedding.""" - return EndpointCaller(self, Endpoints.TEXT_EMBEDDING).call(parameters) + return EndpointCaller(self, ENDPOINTS['TEXT_EMBEDDING']).call(parameters) def syntax_dependencies(self, parameters): """ Create an L{EndpointCaller} to identify the syntactic dependencies in the texts to which it is applied and call it. @type parameters: L{DocumentParameters} or L{str} - @return: A python dictionary containing the results of syntactic dependencies identification""" - return EndpointCaller(self, Endpoints.SYNTAX_DEPENDENCIES).call(parameters) + @return: A python dictionary containing the results of syntactic dependencies + identification""" + return EndpointCaller(self, ENDPOINTS['SYNTAX_DEPENDENCIES']).call(parameters) def transliteration(self, parameters): """ Transliterate given context @type parameters: L{TransliterationParameters} @return: A python dictionary containing the results of the transliteration""" - return EndpointCaller(self, Endpoints.TRANSLITERATION).call(parameters) + return EndpointCaller(self, ENDPOINTS['TRANSLITERATION']).call(parameters) diff --git a/setup.py b/setup.py index 25f8d39..e60910c 100755 --- a/setup.py +++ b/setup.py @@ -1,8 +1,9 @@ #!/usr/bin/env python -from setuptools import setup -import rosette +"""setup.py""" import os import io +from setuptools import setup +import rosette NAME = "rosette_api" DESCRIPTION = "Rosette API Python client SDK" @@ -11,10 +12,11 @@ HOMEPAGE = "https://developer.rosette.com" VERSION = rosette.__version__ -here = os.path.abspath(os.path.dirname(__file__)) +HERE = os.path.abspath(os.path.dirname(__file__)) def read(*filenames, **kwargs): + """read function""" encoding = kwargs.get('encoding', 'utf-8') sep = kwargs.get('sep', '\n') buf = [] @@ -23,14 +25,14 @@ def read(*filenames, **kwargs): buf.append(f.read()) return sep.join(buf) -long_description = read('README.md') +LONG_DESCRIPTION = read('README.md') setup(name=NAME, author=AUTHOR, author_email=AUTHOR_EMAIL, description=DESCRIPTION, license='Apache License', - long_description=long_description, + long_description=LONG_DESCRIPTION, packages=['rosette'], install_requires=['requests'], platforms='any', @@ -45,4 +47,4 @@ def read(*filenames, **kwargs): 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Topic :: Software Development :: Libraries :: Python Modules'] - ) + ) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 01dc8b4..cf06218 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -30,81 +30,86 @@ except ImportError: from io import BytesIO as streamIO import gzip -from rosette.api import API, - DocumentParameters, - NameTranslationParameters, - NameSimilarityParameters, - NameDeduplicationParameters, - TransliterationParameters, - RosetteException +from rosette.api import(API, +DocumentParameters, +NameTranslationParameters, +NameSimilarityParameters, +NameDeduplicationParameters, +TransliterationParameters, +RosetteException) _IsPy3 = sys.version_info[0] == 3 @pytest.fixture def json_response(scope="module"): + """ fixture to return info body""" body = json.dumps({'name': 'Rosette API', 'versionChecked': True}) return body @pytest.fixture def api(): + """ fixture to return api key""" api = API('bogus_key') return api @pytest.fixture def json_409(scope="module"): - body = json.dumps({'code': 'incompatibleClientVersion', 'message': 'the version of client library used is not compatible with this server', 'versionChecked': True}) + """ fixture to return 409 body""" + body = json.dumps({'code': 'incompatibleClientVersion', + 'message': 'the version of client library used is not compatible with this server', 'versionChecked': True}) return body @pytest.fixture def doc_params(scope="module"): + """ fixture to return basic DocumentParameters""" params = DocumentParameters() params['content'] = 'Sample test string' return params # 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. Use the old -# enable/disable to avoid this. +# 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. +# Use the old enable/disable to avoid this. # Test the option set/get/clear def test_option_get_set_clear(api): - api.setOption('test', 'foo') - assert 'foo' == api.getOption('test') + api.set_option('test', 'foo') + assert 'foo' == api.get_option('test') - api.clearOptions() - assert api.getOption('test') is None + api.clear_options() + assert api.get_option('test') is None def test_option_clear_single_option(api): - api.setOption('test', 'foo') - assert 'foo' == api.getOption('test') + api.set_option('test', 'foo') + assert 'foo' == api.get_option('test') - api.setOption('test', None) - assert api.getOption('test') is None + api.set_option('test', None) + assert api.get_option('test') is None # Test the URL parameter set/get/clear def test_UrlParameter_get_set_clear(api): - api.setUrlParameter('test', 'foo') - assert 'foo' == api.getUrlParameter('test') + api.set_url_parameter('test', 'foo') + assert 'foo' == api.get_url_parameter('test') - api.clearUrlParameters() - assert api.getUrlParameter('test') is None + api.clearurl_parameters() + assert api.get_url_parameter('test') is None def test_UrlParameter_clear_single_option(api): - api.setUrlParameter('test', 'foo') - assert 'foo' == api.getUrlParameter('test') + api.set_url_parameter('test', 'foo') + assert 'foo' == api.get_url_parameter('test') - api.setUrlParameter('test', None) - assert api.getUrlParameter('test') is None + api.set_url_parameter('test', None) + assert api.get_url_parameter('test') is None # Test the custom header set/get/clear @@ -112,11 +117,11 @@ def test_UrlParameter_clear_single_option(api): def test_custom_header_get_set_clear(api): key = 'X-RosetteAPI-Test' value = 'foo' - api.setCustomHeaders(key, value) - assert value == api.getCustomHeaders()[key] + api.setcustom_headers(key, value) + assert value == api.getcustom_headers()[key] - api.clearCustomHeaders() - assert len(api.getCustomHeaders()) is 0 + api.clearcustom_headers() + assert len(api.getcustom_headers()) is 0 # Test for invalid header name @@ -124,7 +129,7 @@ def test_custom_header_get_set_clear(api): def test_invalid_header(api): key = 'test' value = 'foo' - api.setCustomHeaders(key, value) + api.setcustom_headers(key, value) with pytest.raises(RosetteException) as e_rosette: result = api.info() @@ -174,7 +179,7 @@ def test_for_409(api, json_409): httpretty.disable() httpretty.reset() -# Test the maxPoolSize +# Test the max_pool_size def test_the_max_pool_size(json_response, doc_params): @@ -185,10 +190,10 @@ def test_the_max_pool_size(json_response, doc_params): 'x-rosetteapi-concurrency': 5 }) api = API('bogus_key') - assert api.getPoolSize() == 1 + assert api.get_pool_size() == 1 result = api.language(doc_params) assert result["name"] == "Rosette API" - assert api.getPoolSize() == 5 + assert api.get_pool_size() == 5 httpretty.disable() httpretty.reset() @@ -458,6 +463,7 @@ def test_for_name_deduplicatation_required_parameters(api, json_response): httpretty.disable() httpretty.reset() + def test_the_name_deduplication_endpoint(api, json_response): httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", @@ -488,7 +494,7 @@ def test_the_relationships_endpoint(api, json_response): params = DocumentParameters() params["content"] = "some text data" - api.setOption('accuracyMode', 'PRECISION') + api.set_option('accuracyMode', 'PRECISION') result = api.relationships(params) assert result["name"] == "Rosette API" httpretty.disable() @@ -701,6 +707,7 @@ def test_for_transliteration_required_parameters(api, json_response): httpretty.disable() httpretty.reset() + def test_the_transliteration_endpoint(api, json_response, doc_params): httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", From 1ac7fdd4db15b710cef8fa84c8f06a174d67f997 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 10:25:30 -0400 Subject: [PATCH 038/247] pep8 cleanup --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index e60910c..eabd606 100755 --- a/setup.py +++ b/setup.py @@ -21,8 +21,8 @@ def read(*filenames, **kwargs): sep = kwargs.get('sep', '\n') buf = [] for filename in filenames: - with io.open(filename, encoding=encoding) as f: - buf.append(f.read()) + with io.open(filename, encoding=encoding) as the_file: + buf.append(the_file.read()) return sep.join(buf) LONG_DESCRIPTION = read('README.md') From acdb344222bcdcd6ec5adc8d8d1287614c2cc27b Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 11:13:51 -0400 Subject: [PATCH 039/247] More code cleanup - per pep8 - fixed typo in test --- rosette/api.py | 6 +- tests/test_rosette_api.py | 131 ++++++++++++++++++++++++-------------- 2 files changed, 85 insertions(+), 52 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 71e3a7d..e1f2cdd 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -318,7 +318,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Name De-Duplication parameter," + option + ", not supplied", + "Required Name De-Duplication parameter, " + option + ", not supplied", repr(option)) @@ -477,8 +477,8 @@ def call(self, parameters): if not isinstance(parameters, _DocumentParamSetBase): if self.suburl != ENDPOINTS['NAME_SIMILARITY'] \ - and self.suburl != ENDPOINTS['NAME_TRANSLATION'] \ - and self.suburl != ENDPOINTS['NAME_DEDUPLICATION']: + and self.suburl != ENDPOINTS['NAME_TRANSLATION'] \ + and self.suburl != ENDPOINTS['NAME_DEDUPLICATION']: text = parameters parameters = DocumentParameters() parameters['content'] = text diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index cf06218..1de8bc4 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -18,31 +18,23 @@ # To run tests, run `py.test test_rosette_api.py` -import glob -import httpretty import json -import os -import pytest -import re import sys -try: - from StringIO import StringIO as streamIO -except ImportError: - from io import BytesIO as streamIO -import gzip +import httpretty +import pytest from rosette.api import(API, -DocumentParameters, -NameTranslationParameters, -NameSimilarityParameters, -NameDeduplicationParameters, -TransliterationParameters, -RosetteException) + DocumentParameters, + NameTranslationParameters, + NameSimilarityParameters, + NameDeduplicationParameters, + TransliterationParameters, + RosetteException) -_IsPy3 = sys.version_info[0] == 3 +_ISPY3 = sys.version_info[0] == 3 @pytest.fixture -def json_response(scope="module"): +def json_response(): """ fixture to return info body""" body = json.dumps({'name': 'Rosette API', 'versionChecked': True}) return body @@ -51,20 +43,22 @@ def json_response(scope="module"): @pytest.fixture def api(): """ fixture to return api key""" - api = API('bogus_key') - return api + tmp_api = API('bogus_key') + return tmp_api @pytest.fixture -def json_409(scope="module"): +def json_409(): """ fixture to return 409 body""" body = json.dumps({'code': 'incompatibleClientVersion', - 'message': 'the version of client library used is not compatible with this server', 'versionChecked': True}) + 'message': 'the version of client library used' + ' is not compatible with this server', + 'versionChecked': True}) return body @pytest.fixture -def doc_params(scope="module"): +def doc_params(): """ fixture to return basic DocumentParameters""" params = DocumentParameters() params['content'] = 'Sample test string' @@ -79,16 +73,18 @@ def doc_params(scope="module"): def test_option_get_set_clear(api): + """Tests the get/set/clear methods""" api.set_option('test', 'foo') - assert 'foo' == api.get_option('test') + assert api.get_option('test') == 'foo' api.clear_options() assert api.get_option('test') is None def test_option_clear_single_option(api): + """Test the clear single option""" api.set_option('test', 'foo') - assert 'foo' == api.get_option('test') + assert api.get_option('test') == 'foo' api.set_option('test', None) assert api.get_option('test') is None @@ -96,17 +92,19 @@ def test_option_clear_single_option(api): # Test the URL parameter set/get/clear -def test_UrlParameter_get_set_clear(api): +def test_url_parameter_getsetclear(api): + """Tests get/set/clear url parameter""" api.set_url_parameter('test', 'foo') - assert 'foo' == api.get_url_parameter('test') + assert api.get_url_parameter('test') == 'foo' api.clearurl_parameters() assert api.get_url_parameter('test') is None -def test_UrlParameter_clear_single_option(api): +def test_url_parameter_clear_single(api): + """Test the clearing of a single url parameter""" api.set_url_parameter('test', 'foo') - assert 'foo' == api.get_url_parameter('test') + assert api.get_url_parameter('test') == 'foo' api.set_url_parameter('test', None) assert api.get_url_parameter('test') is None @@ -114,7 +112,8 @@ def test_UrlParameter_clear_single_option(api): # Test the custom header set/get/clear -def test_custom_header_get_set_clear(api): +def test_custom_header_props(api): + """Test custom header get/set/clear""" key = 'X-RosetteAPI-Test' value = 'foo' api.setcustom_headers(key, value) @@ -127,12 +126,13 @@ def test_custom_header_get_set_clear(api): def test_invalid_header(api): + """Test for invalid header""" key = 'test' value = 'foo' api.setcustom_headers(key, value) with pytest.raises(RosetteException) as e_rosette: - result = api.info() + api.info() assert e_rosette.value.status == 'badHeader' @@ -141,6 +141,7 @@ def test_invalid_header(api): def test_ping(api, json_response): + """Test ping""" httpretty.enable() httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/ping", body=json_response, status=200, content_type="application/json") @@ -154,6 +155,7 @@ def test_ping(api, json_response): def test_info(api, json_response): + """Test info""" httpretty.enable() httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -168,6 +170,7 @@ def test_info(api, json_response): def test_for_409(api, json_409): + """Test for 409 handling""" httpretty.enable() httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info", body=json_409, status=409, content_type="application/json") @@ -183,6 +186,7 @@ def test_for_409(api, json_409): def test_the_max_pool_size(json_response, doc_params): + """Test max pool size""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/language", body=json_response, status=200, content_type="application/json", @@ -201,6 +205,7 @@ def test_the_max_pool_size(json_response, doc_params): def test_the_language_endpoint(api, json_response, doc_params): + """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") @@ -216,6 +221,7 @@ def test_the_language_endpoint(api, json_response, doc_params): def test_the_sentences_endpoint(api, json_response, doc_params): + """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") @@ -231,6 +237,7 @@ 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") @@ -246,6 +253,7 @@ def test_the_tokens_endpoint(api, json_response, doc_params): def test_the_morphology_complete_endpoint(api, json_response, doc_params): + """Test the morphology complete endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -261,6 +269,7 @@ def test_the_morphology_complete_endpoint(api, json_response, doc_params): def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): + """Test the morphology lemmas endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -275,8 +284,8 @@ def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): # Test the morphology parts-of-speech endpoint -def test_the_morphology_parts_of_speech_endpoint( - api, json_response, doc_params): +def test_the_morphology_parts_of_speech_endpoint(api, json_response, doc_params): + """Test the morphology parts-of-speech endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -291,8 +300,8 @@ def test_the_morphology_parts_of_speech_endpoint( # Test the morphology compound-components endpoint -def test_the_morphology_compound_components_endpoint( - api, json_response, doc_params): +def test_the_morphology_compound_components_endpoint(api, json_response, doc_params): + """Test the morphology compound-components endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -308,6 +317,7 @@ def test_the_morphology_compound_components_endpoint( def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): + """Test the morphology han-reading endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -323,6 +333,7 @@ def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): def test_the_entities_endpoint(api, json_response, doc_params): + """Test the entities endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -338,6 +349,7 @@ def test_the_entities_endpoint(api, json_response, doc_params): def test_the_categories_endpoint(api, json_response, doc_params): + """Test the categories endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -353,6 +365,7 @@ def test_the_categories_endpoint(api, json_response, doc_params): def test_the_sentiment_endpoint(api, json_response, doc_params): + """Test the sentiment endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -368,15 +381,16 @@ def test_the_sentiment_endpoint(api, json_response, doc_params): def test_the_multipart_operation(api, json_response, doc_params, tmpdir): + """Test multipart""" 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/sentiment", body=json_response, status=200, content_type="application/json") - p = tmpdir.mkdir("sub").join("testfile.txt") - p.write(json_response) - doc_params.load_document_file = p + tmp_file = tmpdir.mkdir("sub").join("testfile.txt") + tmp_file.write(json_response) + doc_params.load_document_file = tmp_file result = api.sentiment(doc_params) assert result["name"] == "Rosette API" httpretty.disable() @@ -386,6 +400,7 @@ def test_the_multipart_operation(api, json_response, doc_params, tmpdir): def test_the_name_translation_endpoint(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") @@ -406,6 +421,7 @@ def test_the_name_translation_endpoint(api, json_response): def test_the_name_similarity_endpoint(api, json_response): + """Test the name similarity endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -429,7 +445,8 @@ def test_the_name_similarity_endpoint(api, json_response): # Test the name deduplication endpoint -def test_for_name_deduplicatation_required_parameters(api, json_response): +def test_name_deduplicatation_parameters(api, json_response): + """Test the Name Deduplication Parameters""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -450,7 +467,8 @@ def test_for_name_deduplicatation_required_parameters(api, json_response): result = api.name_deduplication(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name De-Duplication parameter, threshold, not supplied' + assert e_rosette.value.message == ('Required Name De-Duplication parameter,' + ' threshold, not supplied') params["threshold"] = 0.75 @@ -465,6 +483,7 @@ def test_for_name_deduplicatation_required_parameters(api, json_response): def test_the_name_deduplication_endpoint(api, json_response): + """Test the name deduplication endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -486,6 +505,7 @@ def test_the_name_deduplication_endpoint(api, json_response): def test_the_relationships_endpoint(api, json_response): + """Test the relationships endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -504,6 +524,7 @@ def test_the_relationships_endpoint(api, json_response): def test_for_404(api, json_response): + """Test for 404 handling""" httpretty.enable() body = json.dumps({'message': 'not found'}) httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", @@ -512,7 +533,7 @@ def test_for_404(api, json_response): body=body, status=404, content_type="application/json") with pytest.raises(RosetteException) as e_rosette: - result = api.info() + api.info() assert e_rosette.value.status == 404 assert e_rosette.value.message == 'not found' @@ -523,6 +544,7 @@ def test_for_404(api, json_response): def test_for_content_and_contentUri(api, json_response, doc_params): + """Test for content and contentUri in DocumentParameters""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -531,7 +553,7 @@ def test_for_content_and_contentUri(api, json_response, doc_params): doc_params['contentUri'] = 'http://google.com' with pytest.raises(RosetteException) as e_rosette: - result = api.entities(doc_params) + api.entities(doc_params) assert e_rosette.value.status == 'badArgument' assert e_rosette.value.message == 'Cannot supply both Content and ContentUri' @@ -542,6 +564,7 @@ def test_for_content_and_contentUri(api, json_response, doc_params): def test_for_no_content_or_contentUri(api, json_response, doc_params): + """Test for missing content and contentUri in DocumentParameters""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -550,7 +573,7 @@ def test_for_no_content_or_contentUri(api, json_response, doc_params): doc_params['content'] = None with pytest.raises(RosetteException) as e_rosette: - result = api.entities(doc_params) + api.entities(doc_params) assert e_rosette.value.status == 'badArgument' assert e_rosette.value.message == 'Must supply one of Content or ContentUri' @@ -561,6 +584,7 @@ def test_for_no_content_or_contentUri(api, json_response, doc_params): def test_for_name_similarity_required_parameters(api, json_response): + """Test 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") @@ -598,6 +622,7 @@ def test_for_name_similarity_required_parameters(api, json_response): def test_for_name_translation_required_parameters(api, json_response): + """Test name translation parameters""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") @@ -632,6 +657,7 @@ def test_for_name_translation_required_parameters(api, json_response): def test_the_text_embedded_endpoint(api, json_response, doc_params): + """Test text embedded endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/text-embedding", body=json_response, status=200, content_type="application/json") @@ -643,6 +669,7 @@ def test_the_text_embedded_endpoint(api, json_response, doc_params): def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): + """Test syntax dependencies endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/syntax/dependencies", body=json_response, status=200, content_type="application/json") @@ -657,20 +684,22 @@ def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): def test_for_transliteration_required_parameters(api, json_response): + """Test transliteration 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/transliteration", body=json_response, status=200, content_type="application/json") - params = TransliterateParameters() + params = TransliterationParameters() params["content"] = "Random text" with pytest.raises(RosetteException) as e_rosette: result = api.transliteration(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Transliteration parameter, sourceLanguage, not supplied' + assert e_rosette.value.message == ('Required Transliteration parameter, ' + 'sourceLanguage, not supplied') params["sourceLanguage"] = "eng" @@ -678,7 +707,8 @@ def test_for_transliteration_required_parameters(api, json_response): result = api.transliteration(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Transliteration parameter, sourceScript, not supplied' + assert e_rosette.value.message == ('Required Transliteration parameter, ' + 'sourceScript, not supplied') params["sourceScript"] = "Latn" @@ -686,7 +716,8 @@ def test_for_transliteration_required_parameters(api, json_response): result = api.transliteration(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Transliteration parameter, targetLanguage, not supplied' + assert e_rosette.value.message == ('Required Transliteration parameter, ' + 'targetLanguage, not supplied') params["targetLanguage"] = "zho" @@ -694,7 +725,8 @@ def test_for_transliteration_required_parameters(api, json_response): result = api.transliteration(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Transliteration parameter, targetScript, not supplied' + assert e_rosette.value.message == ('Required Transliteration parameter, ' + 'targetScript, not supplied') params["targetScript"] = "Hani" @@ -708,7 +740,8 @@ def test_for_transliteration_required_parameters(api, json_response): httpretty.reset() -def test_the_transliteration_endpoint(api, json_response, doc_params): +def test_the_transliteration_endpoint(api, json_response): + """Test the transliteration endpoint""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", body=json_response, status=200, content_type="application/json") From 07a9eba01c0a7ce3a83bd785fb24d02eebdc3c6f Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 11:15:34 -0400 Subject: [PATCH 040/247] Missing space - in exception testing --- rosette/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index e1f2cdd..c02d8e2 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -264,7 +264,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Name Translation parameter," + option + ", not supplied", + "Required Name Translation parameter, " + option + ", not supplied", repr(option)) @@ -297,7 +297,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Name Similarity parameter," + option + ", not supplied", + "Required Name Similarity parameter, " + option + ", not supplied", repr(option)) From 5c0331c5c15001c0d8f2519f8ef132b27d9dc619 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 11:25:59 -0400 Subject: [PATCH 041/247] Unit test fixes --- rosette/api.py | 2 +- tests/test_rosette_api.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index c02d8e2..daf2588 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -344,7 +344,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Transliteration parameter," + option + ", not supplied", + "Required Transliteration parameter, " + option + ", not supplied", repr(option)) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 1de8bc4..4e470e2 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -472,9 +472,6 @@ def test_name_deduplicatation_parameters(api, json_response): params["threshold"] = 0.75 - with pytest.raises(RosetteException) as e_rosette: - result = api.name_deduplication(params) - result = api.name_deduplication(params) assert result["name"] == "Rosette API" @@ -599,7 +596,7 @@ def test_for_name_similarity_required_parameters(api, json_response): result = api.name_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Similarity parameter not supplied' + assert e_rosette.value.message == 'Required Name Similarity parameter, name1, not supplied' params["name1"] = { "text": matched_name_data1, @@ -609,7 +606,7 @@ def test_for_name_similarity_required_parameters(api, json_response): result = api.name_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Similarity parameter not supplied' + assert e_rosette.value.message == 'Required Name Similarity parameter, name2, not supplied' params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} @@ -637,7 +634,7 @@ def test_for_name_translation_required_parameters(api, json_response): result = api.name_translation(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Translation parameter not supplied' + assert e_rosette.value.message == 'Required Name Translation parameter, name, not supplied' params["name"] = "some data to translate" @@ -645,7 +642,8 @@ def test_for_name_translation_required_parameters(api, json_response): result = api.name_translation(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Translation parameter not supplied' + assert e_rosette.value.message == ('Required Name Translation parameter, ' + 'targetLanguage, not supplied') params["targetLanguage"] = "eng" From 91d29e5f31f5bc95ddd0779634cb4ed11e799a7b Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 11:30:14 -0400 Subject: [PATCH 042/247] Another unit test fix - and an indentation issue --- setup.py | 2 +- tests/test_rosette_api.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/setup.py b/setup.py index eabd606..1745ee5 100755 --- a/setup.py +++ b/setup.py @@ -47,4 +47,4 @@ def read(*filenames, **kwargs): 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Topic :: Software Development :: Libraries :: Python Modules'] - ) +) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 4e470e2..172b767 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -728,9 +728,6 @@ def test_for_transliteration_required_parameters(api, json_response): params["targetScript"] = "Hani" - with pytest.raises(RosetteException) as e_rosette: - result = api.transliteration(params) - result = api.transliteration(params) assert result["name"] == "Rosette API" From 36e1745e99372ffdc8bde3a58e698e0428e00b5d Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 11:35:53 -0400 Subject: [PATCH 043/247] Wrong argument to transliteration --- tests/test_rosette_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 172b767..2353833 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -749,7 +749,7 @@ def test_the_transliteration_endpoint(api, json_response): params["sourceScript"] = "Latn" params["targetLanguage"] = "zho" params["targetScript"] = "Hani" - result = api.transliteration(doc_params) + result = api.transliteration(params) assert result["name"] == "Rosette API" httpretty.disable() httpretty.reset() From 7c168616374c413fd8036db834ad8e4ae7475a5f Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 13:41:41 -0400 Subject: [PATCH 044/247] Fiddling with an indent --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1745ee5..eabd606 100755 --- a/setup.py +++ b/setup.py @@ -47,4 +47,4 @@ def read(*filenames, **kwargs): 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Topic :: Software Development :: Libraries :: Python Modules'] -) + ) From a9d400ba09ddde45d455f3a4b9131066eeef26c6 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 14:03:56 -0400 Subject: [PATCH 045/247] Conversion - Moved class definitions for MorphologyOptions and Endpoints to Api dictionaries in accordance with Python best practices --- examples/morphology_compound-components.py | 4 +- examples/morphology_han-readings.py | 4 +- examples/morphology_lemmas.py | 4 +- examples/morphology_parts-of-speech.py | 4 +- rosette/api.py | 105 +++++++++++---------- setup.py | 1 + 6 files changed, 64 insertions(+), 58 deletions(-) diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index 8847c9e..ff8c6c4 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = morphology_compound_components_data try: - return api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS) + return api.morphology(params, api.morphology_output['COMPOUND_COMPONENTS']) except RosetteException as e: print(e) diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index 6f0149f..830d2ea 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = morphology_han_readings_data try: - return api.morphology(params, MorphologyOutput.HAN_READINGS) + return api.morphology(params, api.morphology_output['HAN_READINGS']) except RosetteException as e: print(e) diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index 63ee26a..053e4f3 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = morphology_lemmas_data try: - return api.morphology(params, MorphologyOutput.LEMMAS) + return api.morphology(params, api.morphology_output['LEMMAS']) except RosetteException as e: print(e) diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index a10bb43..12b4f10 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, DocumentParameters, MorphologyOutput, RosetteException +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -19,7 +19,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params = DocumentParameters() params["content"] = morphology_parts_of_speech_data try: - return api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH) + return api.morphology(params, api.morphology_output['PARTS_OF_SPEECH']) except RosetteException as e: print(e) diff --git a/rosette/api.py b/rosette/api.py index daf2588..6a50427 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -78,33 +78,6 @@ def __str__(self): sst = repr(sst) return sst + ": " + self.message + ":\n " + self.response_message -MORPHOLOGY_OUTPUT = { - 'LEMMAS': 'lemmas', - 'PARTS_OF_SPEECH': 'parts-of-speech', - 'COMPOUND_COMPONENTS': 'compound-components', - 'HAN_READINGS': 'han-readings', - 'COMPLETE': 'complete' -} - -ENDPOINTS = { - 'CATEGORIES': 'categories', - 'ENTITIES': 'entities', - 'INFO': 'info', - 'LANGUAGE': 'language', - 'MORPHOLOGY': 'morphology', - 'NAME_TRANSLATION': 'name-translation', - 'NAME_SIMILARITY': 'name-similarity', - 'NAME_DEDUPLICATION': 'name-deduplication', - 'PING': 'ping', - 'RELATIONSHIPS': 'relationships', - 'SENTENCES': 'sentences', - 'SENTIMENT': 'sentiment', - 'SYNTAX_DEPENDENCIES': 'syntax/dependencies', - 'TEXT_EMBEDDING': 'text-embedding', - 'TOKENS': 'tokens', - 'TRANSLITERATION': 'transliteration' -} - class _DocumentParamSetBase(object): @@ -399,7 +372,7 @@ def info(self): """Issues an "info" request to the L{EndpointCaller}'s specific endpoint. @return: A dictionary telling server version and other identifying data.""" - url = self.service_url + ENDPOINTS["INFO"] + url = self.service_url + self.api.endpoints["INFO"] headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} @@ -429,7 +402,7 @@ def ping(self): or is not the right server or some other error occurs, it will be signalled.""" - url = self.service_url + ENDPOINTS['PING'] + url = self.service_url + self.api.endpoints['PING'] headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} @@ -476,9 +449,9 @@ def call(self, parameters): """ if not isinstance(parameters, _DocumentParamSetBase): - if self.suburl != ENDPOINTS['NAME_SIMILARITY'] \ - and self.suburl != ENDPOINTS['NAME_TRANSLATION'] \ - and self.suburl != ENDPOINTS['NAME_DEDUPLICATION']: + 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']: text = parameters parameters = DocumentParameters() parameters['content'] = text @@ -537,7 +510,8 @@ def call(self, parameters): rdata = resp.content response_headers = {"responseHeaders": dict(resp.headers)} status = resp.status_code - response = _ReturnObject(_my_loads(rdata, response_headers), status) + response = _ReturnObject( + _my_loads(rdata, response_headers), status) else: if self.debug: headers['X-RosetteAPI-Devel'] = True @@ -588,8 +562,36 @@ def __init__( self.max_pool_size = 1 self.session = requests.Session() + self.morphology_output = { + 'LEMMAS': 'lemmas', + 'PARTS_OF_SPEECH': 'parts-of-speech', + 'COMPOUND_COMPONENTS': 'compound-components', + 'HAN_READINGS': 'han-readings', + 'COMPLETE': 'complete' + } + + self.endpoints = { + 'CATEGORIES': 'categories', + 'ENTITIES': 'entities', + 'INFO': 'info', + 'LANGUAGE': 'language', + 'MORPHOLOGY': 'morphology', + 'NAME_TRANSLATION': 'name-translation', + 'NAME_SIMILARITY': 'name-similarity', + 'NAME_DEDUPLICATION': 'name-deduplication', + 'PING': 'ping', + 'RELATIONSHIPS': 'relationships', + 'SENTENCES': 'sentences', + 'SENTIMENT': 'sentiment', + 'SYNTAX_DEPENDENCIES': 'syntax/dependencies', + 'TEXT_EMBEDDING': 'text-embedding', + 'TOKENS': 'tokens', + 'TRANSLITERATION': 'transliteration' + } + def _set_pool_size(self): - adapter = requests.adapters.HTTPAdapter(pool_maxsize=self.max_pool_size) + adapter = requests.adapters.HTTPAdapter( + pool_maxsize=self.max_pool_size) if 'https:' in self.service_url: self.session.mount('https://', adapter) else: @@ -613,7 +615,8 @@ def _make_request(self, operation, url, data, headers): if self.url_parameters: payload = self.url_parameters - request = requests.Request(operation, url, data=data, headers=headers, params=payload) + request = requests.Request( + operation, url, data=data, headers=headers, params=payload) session = requests.Session() prepared_request = session.prepare_request(request) @@ -800,7 +803,7 @@ def language(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of language identification.""" - return EndpointCaller(self, ENDPOINTS['LANGUAGE']).call(parameters) + return EndpointCaller(self, self.endpoints['LANGUAGE']).call(parameters) def sentences(self, parameters): """ @@ -809,7 +812,7 @@ def sentences(self, parameters): and possible metadata, to be processed by the sentence identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of sentence identification.""" - return EndpointCaller(self, ENDPOINTS['SENTENCES']).call(parameters) + return EndpointCaller(self, self.endpoints['SENTENCES']).call(parameters) def tokens(self, parameters): """ @@ -818,9 +821,9 @@ def tokens(self, parameters): and possible metadata, to be processed by the tokens identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of tokenization.""" - return EndpointCaller(self, ENDPOINTS['TOKENS']).call(parameters) + return EndpointCaller(self, self.endpoints['TOKENS']).call(parameters) - def morphology(self, parameters, facet=MORPHOLOGY_OUTPUT['COMPLETE']): + def morphology(self, parameters, facet=""): """ Create an L{EndpointCaller} to returns a specific facet of the morphological analyses of texts to which it is applied and call it. @@ -830,7 +833,9 @@ def morphology(self, parameters, facet=MORPHOLOGY_OUTPUT['COMPLETE']): @param facet: The facet desired, to be returned by the created L{EndpointCaller}. @type facet: An element of L{MorphologyOutput}. @return: A python dictionary containing the results of morphological analysis.""" - return EndpointCaller(self, ENDPOINTS['MORPHOLOGY'] + "/" + facet).call(parameters) + if facet == "": + facet = self.morphology_output['COMPLETE'] + return EndpointCaller(self, self.endpoints['MORPHOLOGY'] + "/" + facet).call(parameters) def entities(self, parameters): """ @@ -841,7 +846,7 @@ def entities(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of entity extraction.""" - return EndpointCaller(self, ENDPOINTS['ENTITIES']).call(parameters) + return EndpointCaller(self, self.endpoints['ENTITIES']).call(parameters) def categories(self, parameters): """ @@ -851,7 +856,7 @@ def categories(self, parameters): and possible metadata, to be processed by the category identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of categorization.""" - return EndpointCaller(self, ENDPOINTS['CATEGORIES']).call(parameters) + return EndpointCaller(self, self.endpoints['CATEGORIES']).call(parameters) def sentiment(self, parameters): """ @@ -865,7 +870,7 @@ def sentiment(self, parameters): to which is applied. @return: An L{EndpointCaller} object which can return sentiments of texts to which it is applied.""" - return EndpointCaller(self, ENDPOINTS['SENTIMENT']).call(parameters) + return EndpointCaller(self, self.endpoints['SENTIMENT']).call(parameters) def relationships(self, parameters): """ @@ -875,7 +880,7 @@ def relationships(self, parameters): and possible metadata, to be processed by the relationships identifier. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of relationship extraction.""" - return EndpointCaller(self, ENDPOINTS['RELATIONSHIPS']).call(parameters) + return EndpointCaller(self, self.endpoints['RELATIONSHIPS']).call(parameters) def name_translation(self, parameters): """ @@ -885,7 +890,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, ENDPOINTS['NAME_TRANSLATION']).call(parameters) + return EndpointCaller(self, self.endpoints['NAME_TRANSLATION']).call(parameters) def translated_name(self, parameters): """ deprecated @@ -904,7 +909,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, ENDPOINTS['NAME_SIMILARITY']).call(parameters) + return EndpointCaller(self, self.endpoints['NAME_SIMILARITY']).call(parameters) def matched_name(self, parameters): """ deprecated @@ -922,7 +927,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, ENDPOINTS['NAME_DEDUPLICATION']).call(parameters) + return EndpointCaller(self, self.endpoints['NAME_DEDUPLICATION']).call(parameters) def text_embedding(self, parameters): """ @@ -930,7 +935,7 @@ def text_embedding(self, parameters): to which it is applied and call it. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of text embedding.""" - return EndpointCaller(self, ENDPOINTS['TEXT_EMBEDDING']).call(parameters) + return EndpointCaller(self, self.endpoints['TEXT_EMBEDDING']).call(parameters) def syntax_dependencies(self, parameters): """ @@ -939,11 +944,11 @@ def syntax_dependencies(self, parameters): @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of syntactic dependencies identification""" - return EndpointCaller(self, ENDPOINTS['SYNTAX_DEPENDENCIES']).call(parameters) + return EndpointCaller(self, self.endpoints['SYNTAX_DEPENDENCIES']).call(parameters) def transliteration(self, parameters): """ Transliterate given context @type parameters: L{TransliterationParameters} @return: A python dictionary containing the results of the transliteration""" - return EndpointCaller(self, ENDPOINTS['TRANSLITERATION']).call(parameters) + return EndpointCaller(self, self.endpoints['TRANSLITERATION']).call(parameters) diff --git a/setup.py b/setup.py index eabd606..6538310 100755 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ def read(*filenames, **kwargs): buf.append(the_file.read()) return sep.join(buf) + LONG_DESCRIPTION = read('README.md') setup(name=NAME, From c6a59740d8133d9ffc05e639646ecb005e155625 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 17 Apr 2017 14:15:18 -0400 Subject: [PATCH 046/247] Another stab at E124 --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 6538310..0a8f59b 100755 --- a/setup.py +++ b/setup.py @@ -47,5 +47,4 @@ def read(*filenames, **kwargs): 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', - 'Topic :: Software Development :: Libraries :: Python Modules'] - ) + 'Topic :: Software Development :: Libraries :: Python Modules']) From 50f251fc4691351a67c65357cf574fe4aea35f41 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 2 May 2017 08:32:07 -0400 Subject: [PATCH 047/247] Transliteration update - Removed TransliterationParameters and unit test - Updated example to use DocumentParameters - Updated unit test to use DocumentParameters --- examples/transliteration.py | 8 ++--- rosette/api.py | 28 +---------------- tests/test_rosette_api.py | 61 +------------------------------------ 3 files changed, 4 insertions(+), 93 deletions(-) diff --git a/examples/transliteration.py b/examples/transliteration.py index c6b5a85..eace93e 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -8,7 +8,7 @@ import json import os -from rosette.api import API, TransliterationParameters, RosetteException +from rosette.api import API, DocumentParameters, RosetteException def run(key, altUrl='https://api.rosette.com/rest/v1/'): @@ -16,12 +16,8 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): api = API(user_key=key, service_url=altUrl) transliteration_data = "Some random text" - params = TransliterationParameters() + params = DocumentParameters() params["content"] = transliteration_data - params["sourceLanguage"] = "eng" - params["sourceScript"] = "Latn" - params["targetLanguage"] = "zho" - params["targetScript"] = "Hani" try: return api.transliterate(params) diff --git a/rosette/api.py b/rosette/api.py index 6a50427..b7b75ff 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -295,32 +295,6 @@ def validate(self): repr(option)) -class TransliterationParameters(_DocumentParamSetBase): - """Parameter object for C{transliteration} endpoint. - Required: - C{content} Textual content - C{sourceLanguage} Source language code - C{sourceScript} Source language script - C{targetLanguage} Target language code - C{targetScript} Target language script - """ - - def __init__(self): - self.use_multipart = False - _DocumentParamSetBase.__init__(self, ("content", "sourceLanguage", "sourceScript", - "targetLanguage", "targetScript")) - - def validate(self): - """Internal. Do not use.""" - for option in ("content", "sourceLanguage", "sourceScript", "targetLanguage", - "targetScript"): - if self[option] is None: - raise RosetteException( - "missingParameter", - "Required Transliteration parameter, " + option + ", not supplied", - repr(option)) - - class EndpointCaller: """L{EndpointCaller} objects are invoked via their instance methods to obtain results from the Rosette server described by the L{API} object from which they @@ -949,6 +923,6 @@ def syntax_dependencies(self, parameters): def transliteration(self, parameters): """ Transliterate given context - @type parameters: L{TransliterationParameters} + @type parameters: L{DocumentParameters} @return: A python dictionary containing the results of the transliteration""" return EndpointCaller(self, self.endpoints['TRANSLITERATION']).call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 2353833..27b5ff8 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -680,61 +680,6 @@ def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): # Test the transliteration endpoint - -def test_for_transliteration_required_parameters(api, json_response): - """Test transliteration 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/transliteration", - body=json_response, status=200, content_type="application/json") - - params = TransliterationParameters() - params["content"] = "Random text" - - with pytest.raises(RosetteException) as e_rosette: - result = api.transliteration(params) - - assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == ('Required Transliteration parameter, ' - 'sourceLanguage, not supplied') - - params["sourceLanguage"] = "eng" - - with pytest.raises(RosetteException) as e_rosette: - result = api.transliteration(params) - - assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == ('Required Transliteration parameter, ' - 'sourceScript, not supplied') - - params["sourceScript"] = "Latn" - - with pytest.raises(RosetteException) as e_rosette: - result = api.transliteration(params) - - assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == ('Required Transliteration parameter, ' - 'targetLanguage, not supplied') - - params["targetLanguage"] = "zho" - - with pytest.raises(RosetteException) as e_rosette: - result = api.transliteration(params) - - assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == ('Required Transliteration parameter, ' - 'targetScript, not supplied') - - params["targetScript"] = "Hani" - - result = api.transliteration(params) - assert result["name"] == "Rosette API" - - httpretty.disable() - httpretty.reset() - - def test_the_transliteration_endpoint(api, json_response): """Test the transliteration endpoint""" httpretty.enable() @@ -743,12 +688,8 @@ def test_the_transliteration_endpoint(api, json_response): httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/transliteration", body=json_response, status=200, content_type="application/json") - params = TransliterationParameters() + params = DocumentParameters() params["content"] = "Some test content" - params["sourceLanguage"] = "eng" - params["sourceScript"] = "Latn" - params["targetLanguage"] = "zho" - params["targetScript"] = "Hani" result = api.transliteration(params) assert result["name"] == "Rosette API" httpretty.disable() From 4a2cf258c325c1f0ce80bbe357e5c8c892bb4096 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 2 May 2017 08:42:32 -0400 Subject: [PATCH 048/247] Transliteration cleanup - Forgot to remove TransliterationParameters import --- tests/test_rosette_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 27b5ff8..c0924ac 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -27,7 +27,6 @@ NameTranslationParameters, NameSimilarityParameters, NameDeduplicationParameters, - TransliterationParameters, RosetteException) _ISPY3 = sys.version_info[0] == 3 From d2c030e55fc86782b9b3fd5b35cad6449c468d8d Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 4 May 2017 08:37:21 -0400 Subject: [PATCH 049/247] Transliterate example - fixed syntax error --- examples/transliteration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/transliteration.py b/examples/transliteration.py index eace93e..37ebd46 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -20,7 +20,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params["content"] = transliteration_data try: - return api.transliterate(params) + return api.transliteration(params) except RosetteException as e: print(e) From a76df1ceb333d4b77839cabb2ba0262d43ed7aba Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 15 May 2017 09:27:19 -0400 Subject: [PATCH 050/247] Updated name_deduplication example - Using name_dedupe_data token - Splits string of comma separated names --- examples/name_deduplication.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/name_deduplication.py b/examples/name_deduplication.py index 291f183..042d9df 100644 --- a/examples/name_deduplication.py +++ b/examples/name_deduplication.py @@ -15,10 +15,10 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) - dedup_list = ["John Smith", "Johnathon Smith", "Fred Jones"] + name_dedupe_data = 'John Smith,Johnathon Smith,Fred Jones' threshold = 0.75 params = NameDeduplicationParameters() - params["names"] = dedup_list + params["names"] = name_dedupe_data.split(',') params["threshold"] = threshold try: return api.name_deduplication(params) From 31cd91fa6d50fdf29b768afc87075d3553da98f2 Mon Sep 17 00:00:00 2001 From: Brian Sawyer Date: Wed, 31 May 2017 14:31:56 -0400 Subject: [PATCH 051/247] WS-1138 Allow name deduplication threshold to be null as default (#65) --- rosette/api.py | 15 +++++++-------- tests/test_rosette_api.py | 9 --------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index b7b75ff..12d68b0 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -3,7 +3,7 @@ """ Python client for the Rosette API. -Copyright (c) 2014-2015 Basis Technology Corporation. +Copyright (c) 2014-2017 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -278,7 +278,7 @@ class NameDeduplicationParameters(_DocumentParamSetBase): """Parameter object for C{name-deduplication} endpoint. Required: C{names} A list of C{name} objects - C{threshold} Threshold to use to restrict cluster size + C{threshold} Threshold to use to restrict cluster size. Can be null to use default value. """ def __init__(self): @@ -287,12 +287,11 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for option in ("names", "threshold"): # required - if self[option] is None: - raise RosetteException( - "missingParameter", - "Required Name De-Duplication parameter, " + option + ", not supplied", - repr(option)) + if self["names"] is None: # required + raise RosetteException( + "missingParameter", + "Required Name De-Duplication parameter, names, not supplied", + repr("names")) class EndpointCaller: diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index c0924ac..b1df23b 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -462,15 +462,6 @@ def test_name_deduplicatation_parameters(api, json_response): params["names"] = ["John Smith", "Johnathon Smith", "Fred Jones"] - with pytest.raises(RosetteException) as e_rosette: - result = api.name_deduplication(params) - - assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == ('Required Name De-Duplication parameter,' - ' threshold, not supplied') - - params["threshold"] = 0.75 - result = api.name_deduplication(params) assert result["name"] == "Rosette API" From eba1109090d47dd011fd7013f3c35b21e8a79877 Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Tue, 13 Jun 2017 17:40:59 -0400 Subject: [PATCH 052/247] Backward Compatibility (#66) - Brought back removed functions and noted as deprecated - Updated unit tests to still test them - Updated some Copyright dates --- examples/language.py | 2 +- rosette/__init__.py | 2 +- rosette/api.py | 163 +++++++++++++++++++++++++++++++++++--- tests/__init__.py | 2 +- tests/test_rosette_api.py | 72 +++++++++++++++-- 5 files changed, 220 insertions(+), 21 deletions(-) diff --git a/examples/language.py b/examples/language.py index 1ebb927..bdc979c 100644 --- a/examples/language.py +++ b/examples/language.py @@ -18,7 +18,7 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): language_data = "Por favor Señorita, says the man." params = DocumentParameters() params["content"] = language_data - api.setcustom_headers("X-RosetteAPI-App", "python-app") + api.set_custom_headers("X-RosetteAPI-App", "python-app") try: return api.language(params) except RosetteException as e: diff --git a/rosette/__init__.py b/rosette/__init__.py index fe9b4db..f62a6fb 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.5.0' +__version__ = '1.6.0' diff --git a/rosette/api.py b/rosette/api.py index 12d68b0..5c449e0 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -24,9 +24,10 @@ import sys import os import re +import warnings import requests -_BINDING_VERSION = '1.5.0' +_BINDING_VERSION = '1.6.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 @@ -37,6 +38,8 @@ else: _GZIP_SIGNATURE = str(_GZIP_BYTEARRAY) +warnings.simplefilter('always') + class _ReturnObject: @@ -79,6 +82,46 @@ def __str__(self): return sst + ": " + self.message + ":\n " + self.response_message +class _PseudoEnum: + """ Base class for MorphologyOutput """ + + def __init__(self): + pass + + @classmethod + def validate(cls, value, name): + """ validation method """ + values = [] + for (key, value) in vars(cls).items(): + if not key.startswith("__"): + values += [value] + + # this is still needed to make sure that the parameter NAMES are known. + # If python didn't allow setting unknown values, this would be a + # language error. + if value not in values: + raise RosetteException( + "unknownVariable", + "The value supplied for " + + name + + " is not one of " + + ", ".join(values) + + ".", + repr(value)) + + +class MorphologyOutput(_PseudoEnum): + """ Class to provide Morphology sub-endpoints """ + warnings.warn('MorphologyOutput to be removed in version 1.9.0. ' + 'Please use API.morphology_output', + DeprecationWarning) + LEMMAS = "lemmas" + PARTS_OF_SPEECH = "parts-of-speech" + COMPOUND_COMPONENTS = "compound-components" + HAN_READINGS = "han-readings" + COMPLETE = "complete" + + class _DocumentParamSetBase(object): def __init__(self, repertoire): @@ -349,7 +392,7 @@ def info(self): headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} - custom_headers = self.api.getcustom_headers() + custom_headers = self.api.get_custom_headers() pattern = re.compile('^X-RosetteAPI-') if custom_headers is not None: for key in custom_headers.keys(): @@ -359,7 +402,7 @@ def info(self): raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearcustom_headers() + self.api.clear_custom_headers() if self.debug: headers['X-RosetteAPI-Devel'] = 'true' @@ -379,7 +422,7 @@ def ping(self): headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} - custom_headers = self.api.getcustom_headers() + custom_headers = self.api.get_custom_headers() pattern = re.compile('^X-RosetteAPI-') if custom_headers is not None: for key in custom_headers.keys(): @@ -389,7 +432,7 @@ def ping(self): raise RosetteException("badHeader", "Custom header name must begin with \"X-RosetteAPI-\"", key) - self.api.clearcustom_headers() + self.api.clear_custom_headers() if self.debug: headers['X-RosetteAPI-Devel'] = 'true' @@ -439,7 +482,7 @@ def call(self, parameters): params_to_serialize = parameters.serialize(self.api.options) headers = {} if self.user_key is not None: - custom_headers = self.api.getcustom_headers() + custom_headers = self.api.get_custom_headers() pattern = re.compile('^X-RosetteAPI-') if custom_headers is not None: for key in custom_headers.keys(): @@ -450,7 +493,7 @@ def call(self, parameters): "Custom header name must " "begin with \"X-RosetteAPI-\"", key) - self.api.clearcustom_headers() + self.api.clear_custom_headers() headers["X-RosetteAPI-Key"] = self.user_key headers["X-RosetteAPI-Binding"] = "python" @@ -662,12 +705,31 @@ def post_http(self, url, data, headers): return _ReturnObject(_my_loads(rdata, response_headers), status) + def getPoolSize(self): + """ + Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value + """ + warnings.warn('Method renamed to API.get_pool_size(). To be removed in version 1.9.0', + DeprecationWarning) + return self.get_pool_size() + def get_pool_size(self): """ Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value """ return int(self.max_pool_size) + def setOption(self, name, value): + """ + Sets an option + + @param name: name of option + @param value: value of option + """ + warnings.warn('Method renamed to API.set_option(). To be removed in version 1.9.0', + DeprecationWarning) + return self.set_option(name, value) + def set_option(self, name, value): """ Sets an option @@ -680,6 +742,18 @@ def set_option(self, name, value): else: self.options[name] = value + def getOption(self, name): + """ + Gets an option + + @param name: name of option + + @return: value of option + """ + warnings.warn('Method renamed to API.get_option(). To be removed in version 1.9.0', + DeprecationWarning) + return self.get_option(name) + def get_option(self, name): """ Gets an option @@ -693,12 +767,31 @@ def get_option(self, name): else: return None + def clearOptions(self): + """ + Clears all options + """ + warnings.warn('Method renamed to API.clear_options(). To be removed in version 1.9.0', + DeprecationWarning) + self.clear_options() + def clear_options(self): """ Clears all options """ self.options.clear() + def setUrlParameter(self, name, value): + """ + Sets a URL parameter + + @param name: name of parameter + @param value: value of parameter + """ + warnings.warn('Method renamed to API.set_url_parameter(). To be removed in version 1.9.0', + DeprecationWarning) + return self.set_url_parameter(name, value) + def set_url_parameter(self, name, value): """ Sets a URL parameter @@ -711,6 +804,18 @@ def set_url_parameter(self, name, value): else: self.url_parameters[name] = value + def getUrlParameter(self, name): + """ + Gets a URL parameter + + @param name: name of parameter + + @return: value of parameter + """ + warnings.warn('Method renamed to API.get_url_parameter(). To be removed in version 1.9.0', + DeprecationWarning) + return self.get_url_parameter(name) + def get_url_parameter(self, name): """ Gets a URL parameter @@ -724,13 +829,32 @@ def get_url_parameter(self, name): else: return None - def clearurl_parameters(self): + def clearUrlParameters(self): + """ + Clears all options + """ + warnings.warn('Method renamed to API.clear_url_parameters(). ' + 'To be removed in version 1.9.0', + DeprecationWarning) + self.clear_url_parameters() + + def clear_url_parameters(self): """ Clears all options """ self.url_parameters.clear() - def setcustom_headers(self, name, value): + def setCustomHeaders(self, name, value): + """ + Sets custom headers + + @param headers: array of custom headers to be set + """ + warnings.warn('Method renamed to API.set_custom_headers(). To be removed in version 1.9.0', + DeprecationWarning) + return self.set_custom_headers(name, value) + + def set_custom_headers(self, name, value): """ Sets custom headers @@ -741,13 +865,30 @@ def setcustom_headers(self, name, value): else: self.custom_headers[name] = value - def getcustom_headers(self): + def getCustomHeaders(self): + """ + Get custom headers + """ + warnings.warn('Method renamed to API.get_custom_headers(). To be removed in version 1.9.0', + DeprecationWarning) + return self.get_custom_headers() + + def get_custom_headers(self): """ Get custom headers """ return self.custom_headers - def clearcustom_headers(self): + def clearCustomHeaders(self): + """ + Clears custom headers + """ + warnings.warn('Method renamed to API.clear_custom_headers(). ' + 'To be removed in version 1.9.0', + DeprecationWarning) + self.clear_custom_headers() + + def clear_custom_headers(self): """ Clears custom headers """ diff --git a/tests/__init__.py b/tests/__init__.py index 35f570e..d96e183 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Copyright (c) 2014-2015 Basis Technology Corporation. +Copyright (c) 2014-2017 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index b1df23b..c22010f 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Copyright (c) 2014-2015 Basis Technology Corporation. +Copyright (c) 2014-2017 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -71,6 +71,15 @@ def doc_params(): # Test the option set/get/clear +def test_option_get_set_clear_deprecated(api): + """Tests the deprecated get/set/clear Options methods""" + api.setOption('test', 'foo') + assert api.getOption('test') == 'foo' + + api.clearOptions() + assert api.getOption('test') is None + + def test_option_get_set_clear(api): """Tests the get/set/clear methods""" api.set_option('test', 'foo') @@ -80,6 +89,15 @@ def test_option_get_set_clear(api): assert api.get_option('test') is None +def test_option_clear_single_option_deprecated(api): + """Test the deprecated clear single option""" + api.setOption('test', 'foo') + assert api.getOption('test') == 'foo' + + api.set_option('test', None) + assert api.get_option('test') is None + + def test_option_clear_single_option(api): """Test the clear single option""" api.set_option('test', 'foo') @@ -88,7 +106,15 @@ def test_option_clear_single_option(api): api.set_option('test', None) assert api.get_option('test') is None + # Test the URL parameter set/get/clear +def test_url_parameter_getsetclear_deprecated(api): + """Tests get/set/clear url parameter""" + api.setUrlParameter('test', 'foo') + assert api.getUrlParameter('test') == 'foo' + + api.clearUrlParameters() + assert api.getUrlParameter('test') is None def test_url_parameter_getsetclear(api): @@ -96,10 +122,19 @@ def test_url_parameter_getsetclear(api): api.set_url_parameter('test', 'foo') assert api.get_url_parameter('test') == 'foo' - api.clearurl_parameters() + api.clear_url_parameters() assert api.get_url_parameter('test') is None +def test_url_parameter_clear_single_deprecated(api): + """Test the deprecated clearing of a single url parameter""" + api.setUrlParameter('test', 'foo') + assert api.getUrlParameter('test') == 'foo' + + api.setUrlParameter('test', None) + assert api.getUrlParameter('test') is None + + def test_url_parameter_clear_single(api): """Test the clearing of a single url parameter""" api.set_url_parameter('test', 'foo') @@ -111,24 +146,47 @@ def test_url_parameter_clear_single(api): # Test the custom header set/get/clear +def test_custom_header_props_deprecated(api): + """Test custom header get/set/clear""" + key = 'X-RosetteAPI-Test' + value = 'foo' + api.setCustomHeaders(key, value) + assert value == api.getCustomHeaders()[key] + + api.clearCustomHeaders() + assert len(api.getCustomHeaders()) is 0 + + def test_custom_header_props(api): """Test custom header get/set/clear""" key = 'X-RosetteAPI-Test' value = 'foo' - api.setcustom_headers(key, value) - assert value == api.getcustom_headers()[key] + api.set_custom_headers(key, value) + assert value == api.get_custom_headers()[key] - api.clearcustom_headers() - assert len(api.getcustom_headers()) is 0 + api.clear_custom_headers() + assert len(api.get_custom_headers()) is 0 # Test for invalid header name +def test_invalid_header_deprecated(api): + """Test for invalid header""" + key = 'test' + value = 'foo' + api.setCustomHeaders(key, value) + + with pytest.raises(RosetteException) as e_rosette: + api.info() + + assert e_rosette.value.status == 'badHeader' + + def test_invalid_header(api): """Test for invalid header""" key = 'test' value = 'foo' - api.setcustom_headers(key, value) + api.set_custom_headers(key, value) with pytest.raises(RosetteException) as e_rosette: api.info() From 82dac038f12d32b925b2d27c6d30ff3c10061c3a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 14 Jun 2017 12:50:30 +0000 Subject: [PATCH 053/247] Version 1.7.0 --- rosette/__init__.py | 2 +- rosette/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index f62a6fb..452b9cf 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.6.0' +__version__ = '1.7.0' diff --git a/rosette/api.py b/rosette/api.py index 5c449e0..a9c0ac7 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -27,7 +27,7 @@ import warnings import requests -_BINDING_VERSION = '1.6.0' +_BINDING_VERSION = '1.7.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 From c6f7375ae0644e33c70066cd6c32f25c2c9ba76c Mon Sep 17 00:00:00 2001 From: Li Xu Date: Wed, 21 Jun 2017 16:17:28 -0400 Subject: [PATCH 054/247] No-Jira: try to clean up and close socket (#67) * No-Jira: try to clean up and close socket so that garbage collection doesn't complain * No-Jira: move warning to constructor --- rosette/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index a9c0ac7..c5ac405 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -112,9 +112,12 @@ def validate(cls, value, name): class MorphologyOutput(_PseudoEnum): """ Class to provide Morphology sub-endpoints """ - warnings.warn('MorphologyOutput to be removed in version 1.9.0. ' - 'Please use API.morphology_output', - DeprecationWarning) + + def __init__(self): + warnings.warn('MorphologyOutput to be removed in version 1.9.0. ' + 'Please use API.morphology_output', + DeprecationWarning) + LEMMAS = "lemmas" PARTS_OF_SPEECH = "parts-of-speech" COMPOUND_COMPONENTS = "compound-components" @@ -605,6 +608,9 @@ def __init__( 'TRANSLITERATION': 'transliteration' } + def __del__(self): + self.session.close() + def _set_pool_size(self): adapter = requests.adapters.HTTPAdapter( pool_maxsize=self.max_pool_size) From 439341f568ade9672cbc6fe9f1d4b1e6c314274a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 18 Jul 2017 10:38:26 -0400 Subject: [PATCH 055/247] Fixed reference error exception - Since self.session.close() in __del__ is a weak reference, python 3 may issue an uncaught exception since it has already been cleared. The try/except handles it. --- rosette/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index c5ac405..288dc85 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -609,7 +609,10 @@ def __init__( } def __del__(self): - self.session.close() + try: + self.session.close() + except ReferenceError: + pass def _set_pool_size(self): adapter = requests.adapters.HTTPAdapter( From 53fb72c924196a4138a556192001029e6c7c0339 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 28 Jul 2017 10:50:20 -0400 Subject: [PATCH 056/247] Initial sphinx configuration --- docs/Makefile | 20 ++++ docs/source/conf.py | 172 +++++++++++++++++++++++++++++++++++ docs/source/index.rst | 22 +++++ docs/source/modules.rst | 7 ++ docs/source/rosette-logo.svg | 35 +++++++ docs/source/rosette.rst | 22 +++++ 6 files changed, 278 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/source/conf.py create mode 100644 docs/source/index.rst create mode 100644 docs/source/modules.rst create mode 100644 docs/source/rosette-logo.svg create mode 100644 docs/source/rosette.rst diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d8f4f61 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = python3 -msphinx +SPHINXPROJ = PythonBinding +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..080b595 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Python Binding documentation build configuration file, created by +# sphinx-quickstart on Fri Jul 28 09:16:12 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +sys.path.insert(0, os.path.abspath('../..')) + + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = ['sphinx.ext.autodoc'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = '' +copyright = '2017, Basis Technology' +author = 'Basis Technology' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '1.7.0' +# The full version, including alpha/beta/rc tags. +release = '1.7.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] +html_logo = 'rosette-logo.svg' + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# This is required for the alabaster theme +# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars +html_sidebars = { + '**': [ + 'about.html', + 'relations.html', # needs 'show_related': True theme option to display + 'searchbox.html', + 'donate.html', + ] +} + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = 'PythonBindingdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'PythonBinding.tex', 'Python Binding Documentation', + 'Basis Technology', 'manual'), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'pythonbinding', 'Python Binding Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'PythonBinding', 'Python Binding Documentation', + author, 'PythonBinding', 'One line description of project.', + 'Miscellaneous'), +] + + + diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..40ebcf1 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,22 @@ +.. Python Binding documentation master file, created by + sphinx-quickstart on Fri Jul 28 09:16:12 2017. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + + +Python Binding +========================================== +This is the API documentation for the Rosette API Python Binding. For examples and usage, please refer to our `API Guide `_. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 0000000..7a6d415 --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,7 @@ +rosette +======= + +.. toctree:: + :maxdepth: 4 + + rosette diff --git a/docs/source/rosette-logo.svg b/docs/source/rosette-logo.svg new file mode 100644 index 0000000..4c69ed4 --- /dev/null +++ b/docs/source/rosette-logo.svg @@ -0,0 +1,35 @@ + + + + + +rosette2 + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/source/rosette.rst b/docs/source/rosette.rst new file mode 100644 index 0000000..a6f70fb --- /dev/null +++ b/docs/source/rosette.rst @@ -0,0 +1,22 @@ +rosette package +=============== + +Submodules +---------- + +rosette\.api module +------------------- + +.. automodule:: rosette.api + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: rosette + :members: + :undoc-members: + :show-inheritance: From cfab202f36f7a85232455bb53740bd8844cc2300 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 28 Jul 2017 11:12:55 -0400 Subject: [PATCH 057/247] Added docs README --- docs/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..8555068 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,17 @@ +## Generating documentation with Sphinx + +The best tutorial for generating documentation can be found [here](http://gisellezeno.com/tutorials/sphinx-for-python-documentation.html) + +Files in the source directory are generally static and should not need to be updated. If another python module is created in `../rosette`, then the source may need to be regenerated using + +`sphinx-apidoc -f -o source/ ../rosette/` + +This will overwrite the *.rst files, which may then require some editing to provide the desired look. Edits to date: +1. index.rst: Changed the `Welcome ...` title to `Python Binding` +1. index.rst: Added minor summary, "This is the API documentation for the Rosette API Python Binding. For examples and usage, please refer to our `API Guide `_." + +To change the logo, edit conf.py, `html_logo` + +To generate the html run `make html`. The output will be written to `build/html`. This is the step that is run by the `publish.sh` script when publishing the Python binding. Note that the version, which is noted in `conf.py` is not displayed anywhere, but is updated during the publish phase. + +You can view the generated html locally, by navigating to `docs/build/html` and opening `index.html` \ No newline at end of file From 0d88edc938aef1671a5b00f95a9d19cb84116732 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 28 Jul 2017 12:49:22 -0400 Subject: [PATCH 058/247] Added READMEs to - _static - _templates --- docs/source/_static/README.md | 1 + docs/source/_templates/README.md | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 docs/source/_static/README.md create mode 100644 docs/source/_templates/README.md diff --git a/docs/source/_static/README.md b/docs/source/_static/README.md new file mode 100644 index 0000000..6fa98c9 --- /dev/null +++ b/docs/source/_static/README.md @@ -0,0 +1 @@ +### Place static sphinx files here if needed \ No newline at end of file diff --git a/docs/source/_templates/README.md b/docs/source/_templates/README.md new file mode 100644 index 0000000..055e18a --- /dev/null +++ b/docs/source/_templates/README.md @@ -0,0 +1,3 @@ +### Place sphinx templates here (if desired) + +Default is alabaster \ No newline at end of file From 1749ee1f3cbe2edfd995faa11748ee710af892ef Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 28 Jul 2017 13:07:04 -0400 Subject: [PATCH 059/247] Removed blank at end of conf.py --- docs/README.md | 6 ++++++ docs/source/conf.py | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8555068..2ca7a5b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,6 +9,12 @@ Files in the source directory are generally static and should not need to be upd This will overwrite the *.rst files, which may then require some editing to provide the desired look. Edits to date: 1. index.rst: Changed the `Welcome ...` title to `Python Binding` 1. index.rst: Added minor summary, "This is the API documentation for the Rosette API Python Binding. For examples and usage, please refer to our `API Guide `_." +1. conf.py: removed blank line at end of file +1. conf.py: added rosette logo +1. conf.py: blank project (let logo handle it) +1. conf.py: added version (auto updated by publish) +1. conf.py: added author +1. conf.py: enabled `sys.path.insert(0, os.path.abspath('../..'))` To change the logo, edit conf.py, `html_logo` diff --git a/docs/source/conf.py b/docs/source/conf.py index 080b595..5c463eb 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -167,6 +167,3 @@ author, 'PythonBinding', 'One line description of project.', 'Miscellaneous'), ] - - - From b6586ba7bdd4177d85e07c0b4e30743188dbf9ac Mon Sep 17 00:00:00 2001 From: Li Xu Date: Thu, 3 Aug 2017 16:03:13 -0400 Subject: [PATCH 060/247] Update with binding version compatibility info --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 5eb67ab..d0df3a5 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,15 @@ The Python binding requires Python 2.6 or greater and is available through pip: `pip install rosette_api` +If the version you are using is not [the latest from PyPI](https://pypi.org/project/rosette_api/#history), +please check for its [**compatibilty with api.rosette.com**](https://developer.rosette.com/features-and-functions?python). +If you have an on-premise version of Rosette API server, please contact support for +binding compatibility with your installation. + +To check your installed version: + +`pip show rosette_api` + Basic Usage ----------- From 03708add62222aac585e9c9155581745972d4a0a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 09:27:07 -0400 Subject: [PATCH 061/247] First pass at Jenkinsfile --- Jenkinsfile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..65e8a7e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,29 @@ +node { + try { + stage("Clean up") { + step([$class: 'WsCleanup']) + } + stage("Checkout Code") { + checkout scm + } + stage("Test with Docker") { + withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { + docker.image('rosetteapi/docker-python').inside { + sh '.docker-entrypoint.sh' + } + } + } + slack(true) + } catch (e) { + currentBuild.result = "FAILED" + slack(false) + throw e + } +} + +def slack(boolean success) { + 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 From 564fb6711af4e26283e75e55768db7e0a16bdd20 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 11:29:54 -0400 Subject: [PATCH 062/247] Second pass - fixed typo in path --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 65e8a7e..76b8896 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ node { stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { docker.image('rosetteapi/docker-python').inside { - sh '.docker-entrypoint.sh' + sh './docker-entrypoint.sh' } } } From 643211054c59765628c64bfb422797e6bbb07c01 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 12:28:28 -0400 Subject: [PATCH 063/247] Third pass - Try running empty --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 76b8896..42fe8a7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,6 @@ node { stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { docker.image('rosetteapi/docker-python').inside { - sh './docker-entrypoint.sh' } } } From dc8bd462e976022bccbba8b48fc014717c78cae2 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 14:06:00 -0400 Subject: [PATCH 064/247] Fourth pass - changed inside to withRun --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 42fe8a7..a9e7162 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { - docker.image('rosetteapi/docker-python').inside { + docker.image('rosetteapi/docker-python').withRun { } } } From 9d270f3270dad2968e1be4abaef1032de6ecce1a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 14:43:05 -0400 Subject: [PATCH 065/247] Fifth pass - Change withRun to Run - Add arguments --- Jenkinsfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a9e7162..dbe8768 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,8 +8,11 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { - docker.image('rosetteapi/docker-python').withRun { - } + def sourceDir = pwd() + docker.image('rosetteapi/docker-python').run([ + "-e API_KEY=${API_KEY}", + "-v ${sourceDir}:/source" + ]) } } slack(true) From 80890bddd876da5d6c4ce250391d0a11211b25d0 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 14:46:22 -0400 Subject: [PATCH 066/247] Sixth pass - Fix type for pwd --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index dbe8768..60e3a32 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,10 +8,9 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { - def sourceDir = pwd() docker.image('rosetteapi/docker-python').run([ "-e API_KEY=${API_KEY}", - "-v ${sourceDir}:/source" + "-v ${pwd}:/source" ]) } } From 201f414c79cc36df63a17ca63725379cd9fe8628 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 14:57:07 -0400 Subject: [PATCH 067/247] Pass 7 - parens instead of curlies --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 60e3a32..e4c21ab 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ node { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { docker.image('rosetteapi/docker-python').run([ "-e API_KEY=${API_KEY}", - "-v ${pwd}:/source" + "-v $(pwd):/source" ]) } } From 3def4d6284823454581cf597dcb938371fa405b8 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 15:17:52 -0400 Subject: [PATCH 068/247] Still fiddling with pwd --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e4c21ab..6c88766 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ node { + def sourceDir = pwd() try { stage("Clean up") { step([$class: 'WsCleanup']) @@ -7,10 +8,10 @@ node { checkout scm } stage("Test with Docker") { - withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { + withEnv(["API_KEY=env.ROSETTE_API_KEY", "sourceDir=${pwd()}"]) { docker.image('rosetteapi/docker-python').run([ "-e API_KEY=${API_KEY}", - "-v $(pwd):/source" + "-v ${sourceDir}:/source" ]) } } From 65d44fc9a41032994363a02a79b8b866020e6b35 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 15:51:15 -0400 Subject: [PATCH 069/247] Another attempt at assigning pwd --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6c88766..0947e50 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ node { checkout scm } stage("Test with Docker") { - withEnv(["API_KEY=env.ROSETTE_API_KEY", "sourceDir=${pwd()}"]) { + withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { docker.image('rosetteapi/docker-python').run([ "-e API_KEY=${API_KEY}", "-v ${sourceDir}:/source" From fc386a0b6d6bdd368119668a91d717be10d6a5ca Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 15:57:17 -0400 Subject: [PATCH 070/247] Trying environment block --- Jenkinsfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0947e50..3d6018e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,17 +1,20 @@ node { - def sourceDir = pwd() + environment { + SOURCEDIR = pwd() + } try { stage("Clean up") { step([$class: 'WsCleanup']) } stage("Checkout Code") { checkout scm + echo ${sourceDir} } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { docker.image('rosetteapi/docker-python').run([ "-e API_KEY=${API_KEY}", - "-v ${sourceDir}:/source" + "-v ${SOURCEDIR}:/source" ]) } } From 95ba5bbbb9f96ea7b881baa961f104467c1de47c Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 16:09:49 -0400 Subject: [PATCH 071/247] Missing quotes --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3d6018e..a6b4627 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ node { } stage("Checkout Code") { checkout scm - echo ${sourceDir} + echo "${sourceDir}" } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { From 5ee34e7d666afeda65f1128c3efc72d7994e66b2 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 25 Aug 2017 17:27:27 -0400 Subject: [PATCH 072/247] case sensitivity --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a6b4627..e4ef264 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ node { } stage("Checkout Code") { checkout scm - echo "${sourceDir}" + echo "${SOURCEDIR}" } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { From 40f7105a8349a04fafcf764baa7b0384375d4995 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 09:40:03 -0400 Subject: [PATCH 073/247] Work in progress - trying to figure out the proper placement of the variable --- Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e4ef264..cbe0809 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,5 @@ node { - environment { - SOURCEDIR = pwd() - } + def SOURCEDIR = pwd() try { stage("Clean up") { step([$class: 'WsCleanup']) From 7b201aad400f3e934d55764462d96fd89472d819 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 10:02:37 -0400 Subject: [PATCH 074/247] Working on docker call --- Jenkinsfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cbe0809..d7f16e2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,10 +10,7 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { - docker.image('rosetteapi/docker-python').run([ - "-e API_KEY=${API_KEY}", - "-v ${SOURCEDIR}:/source" - ]) + docker.image('rosetteapi/docker-python').run() } } slack(true) From 37d55efd191ea375e1a4d6e5ef8f915eb639df8f Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 10:08:41 -0400 Subject: [PATCH 075/247] Fiddling with docker calls --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d7f16e2..ffd7df5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { - docker.image('rosetteapi/docker-python').run() + sh "docker run --rm -it -e API_KEY=${API_KEY} -v ${SOURCEDIR}:/source rosetteapi/docker-python" } } slack(true) From baf678126734a98305bd027d133de502a7bd61bf Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 10:28:41 -0400 Subject: [PATCH 076/247] Not a tty --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ffd7df5..eadb65f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { - sh "docker run --rm -it -e API_KEY=${API_KEY} -v ${SOURCEDIR}:/source rosetteapi/docker-python" + sh "docker run --rm -e API_KEY=${API_KEY} -v ${SOURCEDIR}:/source rosetteapi/docker-python" } } slack(true) From 2d3ff9632cb5dbbf189f701800d68bdf4589e41f Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 10:47:55 -0400 Subject: [PATCH 077/247] env var fix --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index eadb65f..e098184 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ node { echo "${SOURCEDIR}" } stage("Test with Docker") { - withEnv(["API_KEY=env.ROSETTE_API_KEY"]) { + withEnv(["API_KEY=${env.ROSETTE_API_KEY}"]) { sh "docker run --rm -e API_KEY=${API_KEY} -v ${SOURCEDIR}:/source rosetteapi/docker-python" } } From 854b88d9bc5cb20cd2553fb55c88fc44e2be2419 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 11:07:47 -0400 Subject: [PATCH 078/247] Added BINDING_TEST_URL --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e098184..890291b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,8 +9,8 @@ node { echo "${SOURCEDIR}" } stage("Test with Docker") { - withEnv(["API_KEY=${env.ROSETTE_API_KEY}"]) { - sh "docker run --rm -e API_KEY=${API_KEY} -v ${SOURCEDIR}:/source rosetteapi/docker-python" + withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { + sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" } } slack(true) From ac3a813b6bf92a3a193f52b62c96422bfd61bc12 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 12:40:28 -0400 Subject: [PATCH 079/247] One last try to use docker.image --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 890291b..fa4ef76 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,8 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { - sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" + //sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" + docker.image("rosetteapi/docker-python").run("-e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source") {} } } slack(true) From 66db929d81ca50b9479ebf0b4e9379293140b021 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 12:49:31 -0400 Subject: [PATCH 080/247] One last try --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index fa4ef76..42d478a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ node { stage("Test with Docker") { withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { //sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" - docker.image("rosetteapi/docker-python").run("-e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source") {} + docker.image("rosetteapi/docker-python").run("-e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source") } } slack(true) From 7bf0d32b1dedc4d628742543ecbffb6e3a6b67a3 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Mon, 28 Aug 2017 12:55:11 -0400 Subject: [PATCH 081/247] Use command line approach - docker.Image.run uses -d, which doesn't wait for completion. As a shell command it's fewer lines and works --- Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 42d478a..4d07afe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,12 +6,10 @@ node { } stage("Checkout Code") { checkout scm - echo "${SOURCEDIR}" } stage("Test with Docker") { withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { - //sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" - docker.image("rosetteapi/docker-python").run("-e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source") + sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" } } slack(true) From eaabbb9eaefd87316523cbb49a80e97212259e95 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 29 Aug 2017 10:18:50 -0400 Subject: [PATCH 082/247] Testing examples against published --- Jenkinsfile.examples | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Jenkinsfile.examples diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples new file mode 100644 index 0000000..1b35e44 --- /dev/null +++ b/Jenkinsfile.examples @@ -0,0 +1,34 @@ +node { + def SOURCEDIR = pwd() + def TEST_CONTAINER = 'examples/python-test' + try { + stage("Clean up") { + step([$class: 'WsCleanup']) + } + stage("Checkout Code") { + checkout scm + } + stage("Build Dockerfile") { + dir ('./docker') { + docker.build("${TEST_CONTAINER}") + } + } + stage("Run Tests") { + withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { + sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source ${TEST_CONTAINER}" + } + } + slack(true) + } catch (e) { + currentBuild.result = "FAILED" + slack(false) + throw e + } +} + +def slack(boolean success) { + 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 From d57f7770c2e02ccf68fa1d6c845db63d8152a27b Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 29 Aug 2017 10:22:23 -0400 Subject: [PATCH 083/247] Wrong path to Dockerfile --- Jenkinsfile.examples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples index 1b35e44..70f1391 100644 --- a/Jenkinsfile.examples +++ b/Jenkinsfile.examples @@ -9,7 +9,7 @@ node { checkout scm } stage("Build Dockerfile") { - dir ('./docker') { + dir ('./examples/docker') { docker.build("${TEST_CONTAINER}") } } From 0577a7d636c5896475f27c8192a693e6b1966850 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 29 Aug 2017 11:00:10 -0400 Subject: [PATCH 084/247] Move names and paths into variables --- Jenkinsfile.examples | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples index 70f1391..1b6f894 100644 --- a/Jenkinsfile.examples +++ b/Jenkinsfile.examples @@ -1,6 +1,7 @@ node { def SOURCEDIR = pwd() def TEST_CONTAINER = 'examples/python-test' + def DOCKERFILE_DIR = './examples/docker' try { stage("Clean up") { step([$class: 'WsCleanup']) @@ -9,11 +10,11 @@ node { checkout scm } stage("Build Dockerfile") { - dir ('./examples/docker') { + dir ("${DOCKERFILE_DIR}") { docker.build("${TEST_CONTAINER}") } } - stage("Run Tests") { + stage("Run Examples") { withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source ${TEST_CONTAINER}" } From 4a9953e0e8bb434f1059b33cfaf11305991e9fca Mon Sep 17 00:00:00 2001 From: seth-basistech Date: Thu, 7 Sep 2017 08:45:32 -0400 Subject: [PATCH 085/247] Specify python versions for TravisCI. (#70) * Tell Travis which Python versions to test. Remove old Slack settings. * Try harder at Slack status. Specify specific py environments only in travis. * Remove Python 3.2. --- .travis.yml | 11 +++++++++-- tox.ini | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd2b691..077ede1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,11 @@ language: python +python: + - "2.6" + - "2.7" + - "3.3" + - "3.4" + - "3.5" + - "3.6" install: - pip install tox script: @@ -8,6 +15,6 @@ notifications: slack: rooms: - secure: 4FRaTAAiYyeUvgw2RhmblgbNiJO4wmd34OBgWcwURjP9oVmFfSwR9r1LNCdUGxrPOghexSY2DjXIuvIrfTfi/xYbhHb3Kw7PEAyB8IuBMlKtY4NSFou62S2VhYpxyg58T+C7P2zi0eDnDE06pwTCoGPaimxMZQY91yQ0yPYDPVXbwe5SjEgamzlwGBxlS/0A6w1iCPHg27/iO2hXtdW3oLS2I0F/Q8Q95RBkX9hpg6yqHlTV7jRbSqvQ9OFBqk/tXMHQvhoPDGgCgQDuykJuaAYx7g9d0YL0eEYYOh9B/TJ/kNOwdRFBu5kuQ2/nFS5Z0S3Y3UIhdYjUmm9gSMnwIbYnrW22EqDJLoT9Zi3Gv7Prg/8/fSkWsof7BJTMSuXUqO1AxDGKIxFv9uSF1daZoY+AC1ooU1xDu1nNvWVYPlkwEdDxxmHpFkGT3ESTZYccPovQl8Z5K0I1BBAVdJKDzm07lE6VHbxkKcvK6gG0TN3uLxnSlQtjkfJ+aVMq1kxeVsB9lEsKs9oezsKzzbftMm525aXPg+OAv+31CUFWxvT/p4ps8Q+AV6aZpoPHkpK8VryyNirUeZ/m4m4ebDHhD9vcN+JqE9gzshT+0U3g19SvLiUMQtbuZ2BUvrq2hh2LEGs03AFZaNg9AEUVA1PQRhV5NILyoS/lbiBYJPT39Sg= -# - secure: D4VxkkZlj7uaaFbqEBITkJCusVeii436N8X6GijuosUSaee9lqGYUF5ZS9lV6VGMKs719IfSJsCc2v/N4nc9Y/8AKgXd7AWHUwaRR+MC6rLwv9xqH8ZlkTPUKHUXkUQe1f9042PcMxzYa9r0+uKniM9l915Yx0PLaawJrWe3ZVig/uBhn5FueLhtUACzLJcjNcri/BKEgmP2+EgUsupUhujd0MsQd8xN5YIIv6VM5oD0XWXZCnBqHoZK+Qq7LfwDnTmUk7juqTOAjefF6v8IJTDELvSdK9QW7f9x7h0ICabIrI+Gl4IbNLJYEnELBi+X7da2YJUTgUoQrlBB4z+T8KybD8myqV/pJc1n0xrk84g1MtYQ3ahZn7eD3DTjIvK+ML8qAAGwxibF8VsV+GSoo5FcB6e3vV+glHODlwszstVs11PpL1grurVdoa5HPhUbm1jtQixOwO7h8GgGpwO20PuMLfyOfTjfoMcJ3ISjGNHRmUwcCH9avcaHqMLPLHht0z+8inVlDZeTcN+Wi8tk1YXwuQYUkTW46iFmoZNGdygRjTu43h9hCqdG7vcoKrR8oDbMT8X/sfs+z/UaBbuYBr9dT8rrdKJoa9115PaYpCs529DLrw1iGmzr5CkAXDElc1y2F352nwVS+dX7/OIQz1/dbT1ozWQ9Blx6ez5XN84= -# - secure: g/eOC2QCn7oUW234u/P1kmh9OASO9t5g6iC+DflNdnedHnpw8IEG9CsLAnNynOY0KvC/2/Q6BAIFpT/qO8BPdaC2eQnd9LDurOXExxvjKZgTujhqgzijJGzVPSL8//hafj0Ec2+iJZFo/DYMPqUpYDsiKxX53+SMz9/GN/PKVKsI7bzuaOm04xXktU0A76pVfaG0N/qFSVHI64SShACoUXRpTzyUbmksRgzk7FB162R+TH1soPsR3vPh8c2SSWC9msrDc4iljcBhSFTdjL68z+srjDPYMSoOcFXXFNP+dmL+Q0veL/E4e40e7CWIU1O3grOcEcCkaSoZVSpGduNnCst8h6MpgauPtrgwHk4zGMoSl+L6al+nFo/3h2dXeebrQ0tY/hRfZi4Q8xwqG9083TBqi71fTpoFZ7sNtrY4Kdtl5Oa2CFUo7lVn1JB9qQwSa0eai3Whv0RyRqqQe77aDUj0dfD2R3Q61rX5OF/f++W0XtNwHQubzmj8HD/cFneShIQsbl9KgYXoR6HiXcbBiNdmmZjSrzkPYh7vlsujYrz6Cg2msKybWJ/FfOz0tS1cjlCtiCMOTExN6tEF8YCp9l+s+5RLe61pgFPy4Snr9pEjuTS5DYliTyZMY2ZZC1clBQtgE8E2qCG1QSzqnqqiGxj2K4zmLPpB4y1XpW8e3yk= + on_success: always + on_failure: always diff --git a/tox.ini b/tox.ini index bc1dadf..16c1f23 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ [tox] skipsdist = True -envlist = py26, py27, py33, py34 +envlist = py2, py3 [testenv] commands = From fede73f4dc1cb82244f27105188cbddc41aab4b7 Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Tue, 19 Sep 2017 13:03:34 -0400 Subject: [PATCH 086/247] RCB-527 topics (#71) * RCB-527 Topics - Added topics to Api.py - Created topics example - Code cleanup on all examples - Passed against jugmaster * Updated README - cleaned up obsolete instructions - added list of available endpoints - added release notes reference * Updated examples README * Added topics to unit tests --- README.md | 113 ++++++--------------- examples/README.md | 1 + examples/categories.py | 26 +++-- examples/entities.py | 26 +++-- examples/info.py | 26 +++-- examples/language.py | 26 +++-- examples/morphology_complete.py | 26 +++-- examples/morphology_compound-components.py | 26 +++-- examples/morphology_han-readings.py | 26 +++-- examples/morphology_lemmas.py | 26 +++-- examples/morphology_parts-of-speech.py | 26 +++-- examples/name_deduplication.py | 26 +++-- examples/name_similarity.py | 26 +++-- examples/name_translation.py | 26 +++-- examples/ping.py | 26 +++-- examples/relationships.py | 26 +++-- examples/sentences.py | 26 +++-- examples/sentiment.py | 37 ++++--- examples/syntax_dependencies.py | 27 +++-- examples/text_embedding.py | 27 +++-- examples/tokens.py | 26 +++-- examples/topics.py | 38 +++++++ examples/transliteration.py | 27 +++-- rosette/api.py | 17 +++- tests/test_rosette_api.py | 16 +++ 25 files changed, 409 insertions(+), 310 deletions(-) create mode 100644 examples/topics.py diff --git a/README.md b/README.md index d0df3a5..46b1c5c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ [![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=master)](https://travis-ci.org/rosette-api/python) -# This is the Python client binding for Rosette API. -See the wiki for more information. +## This is the Python client binding for Rosette API. +Please check out the [wiki](https://github.com/rosette-api/python/wiki) for additional information -Installation ------------- +### Installation The Python binding requires Python 2.6 or greater and is available through pip: @@ -19,79 +18,30 @@ To check your installed version: `pip show rosette_api` -Basic Usage ------------ - -```python -# 1. Set utf-8 encoding. -# -*- coding: utf-8 -*- - -# 2. Imports from rosette.api. -from rosette.api import API, DocumentParameters, MorphologyOutput - -# 3. Create API object. -api = API("[your_api-key]") - -# 4. Create parameters object -params = DocumentParameters() - -# 5. Set parameters. -params["content"] = "The quick brown fox jumped over the lazy dog. Yes he did." - -# 6. Make a call. -result = api.morphology(params) - -# result is a Python dictionary that contains - -{u'tokens': [u'The', u'quick', u'brown', u'fox', u'jumped', u'over', u'the', u'lazy', u'dog', u'.', u'Yes', u'he', u'did', u'.'], u'posTags': [u'DET', u'ADJ', u'ADJ', u'NOUN', u'VERB', u'ADP', u'DET', u'ADJ', u'NOUN', u'PUNCT', u'VERB', u'PRON', u'VERB', u'PUNCT'], u'compoundComponents': [None, None, None, None, None, None, None, None, None, None, None, None, None, None], u'lemmas': [u'the', u'quick', u'brown', u'fox', u'jump', u'over', u'the', u'lazy', u'dog', u'.', u'yes', u'he', u'do', u'.'], u'hanReadings': [None, None, None, None, None, None, None, None, None, None, None, None, None, None]} -``` - -The samples use the following procedure: - -1. If the application reads text in, set encoding to utf-8 in the first line of the script. - -2. Import the `rosette.api` packages that your application needs. The `rosette.api` packages include - * `API` - * `DocumentParameters` - * `NameSimilarityParameters` - * `NameTranslationParameters` - * `MorphologyOutput` - * `DataFormat` - -3. Create an `API` object with the `user_key` parameter. - -4. Create a parameters object for your request input: - - | Parameter | Endpoint | - | ----|----| - | `NameSimilarityParameters` | for `/name-similarity` | - | `NameTranslationParameters` | for `/translated-name` | - | `DocumentParameters` | for all other endpoints | - - -5. Set the parameters required for your operation: "`content`" or "`contentUri`" for `DocumentParameters`; -"`name`" and "`targetLanguage`" for `NameTranslationParameters`; "`name1.text`" and "`name2.text`" for - `NameSimilarityParameters`; Other parameters are optional. - -6. Invoke the `API` method for the endpoint you are calling. The methods are - * `entities()` - * `categories()` - * `sentiment()` - * `language()` - * `morphology(tag)` where tag is a member of `MorphologyOutput`: `LEMMAS`, `PARTS_OF_SPEECH`, `COMPOUND_COMPONENTS`, `HAN_READINGS`, or `COMPLETE`. An empty tag is equivalent to `COMPLETE`. - * `sentences()` - * `tokens()` - * `relationships()` - * `name_translation()` - * `name_similarity()` - * `matched_name()` *deprecated - * `translated_name()` *deprecated - -7. The API will return a dictionary with the results. - -See [examples](examples) for more request samples. - -## Docker ## +### Basic Usage + +For help in how to call the various endpoints, please refer to the [examples](https://github.com/rosette-api/python/tree/develop/examples). + +### Supported Endpoints +- categories +- entities +- info +- language +- morphology (complete, compound components, han readings, lemmas, parts of speech) +- name deduplication +- name similarity +- name translation +- ping +- relationships +- sentences +- sentiment +- syntax dependencies +- text embedding +- tokens +- topics +- transliteration + +### Docker A Docker image for running the examples against the compiled source library is available on Docker Hub. Command: `docker run -e API_KEY=api-key -v ":/source" rosetteapi/docker-python` @@ -100,12 +50,11 @@ Additional environment settings: `-e ALT_URL=` `-e FILENAME=` -API Documentation ------------------ - +### API Documentation See [documentation](http://rosette-api.github.io/python) -Additional Information ----------------------- +### Release Notes +See [wiki](https://github.com/rosette-api/python/wiki/Release-Notes) +### Additional Information Visit [Rosette API site](https://developer.rosette.com) diff --git a/examples/README.md b/examples/README.md index 2a391fd..10fed1a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -38,6 +38,7 @@ Each example, when run, prints its output to the console. | sentences.py | Gets the sentences from a piece of text | | sentiment.py | Gets the sentiment of a local file | | tokens.py | Gets the tokens (words) from a piece of text | +| topics.py | Returns key phrases and concepts from provided content | | translated-name.py | Translates a name from one language to another | | transliteration.py | Transliterates the given text | diff --git a/examples/categories.py b/examples/categories.py index c7a54eb..8bc6344 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -3,34 +3,40 @@ """ Example code to call Rosette API to get the category of a document (at a given URL). """ +from __future__ import print_function import argparse import json import os + from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://api.rosette.com/rest/v1/'): + """ Run the example """ categories_url_data = "http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/" url = categories_url_data # Create an API instance - api = API(user_key=key, service_url=altUrl) + api = API(user_key=key, service_url=alt_url) params = DocumentParameters() # Use a URL to input data instead of a string params["contentUri"] = url try: return api.categories(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/entities.py b/examples/entities.py index 1ad0f26..bbd0499 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get entities from a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,23 +11,27 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS" params = DocumentParameters() params["content"] = entities_text_data params["genre"] = "social-media" try: return api.entities(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/info.py b/examples/info.py index 4e4c9e2..ab7159f 100644 --- a/examples/info.py +++ b/examples/info.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get information such as version and build """ +from __future__ import print_function import argparse import json @@ -11,21 +11,25 @@ from rosette.api import API, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) try: return api.info() - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/language.py b/examples/language.py index bdc979c..c8d82d0 100644 --- a/examples/language.py +++ b/examples/language.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to determine the language of a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,9 +11,10 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) language_data = "Por favor Señorita, says the man." params = DocumentParameters() @@ -21,15 +22,18 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): api.set_custom_headers("X-RosetteAPI-App", "python-app") try: return api.language(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index ee9bf6b..10db4ca 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get the complete morphological analysis of a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,24 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did." params = DocumentParameters() params["content"] = morphology_complete_data try: return api.morphology(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index ff8c6c4..48d6f9c 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get de-compounded words from a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,24 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) morphology_compound_components_data = "Rechtsschutzversicherungsgesellschaften" params = DocumentParameters() params["content"] = morphology_compound_components_data try: return api.morphology(params, api.morphology_output['COMPOUND_COMPONENTS']) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index 830d2ea..eb008c9 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get Chinese readings of words in a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,24 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) morphology_han_readings_data = "北京大学生物系主任办公室内部会议" params = DocumentParameters() params["content"] = morphology_han_readings_data try: return api.morphology(params, api.morphology_output['HAN_READINGS']) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index 053e4f3..0aad1db 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get lemmas for words in a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,24 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) morphology_lemmas_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" params = DocumentParameters() params["content"] = morphology_lemmas_data try: return api.morphology(params, api.morphology_output['LEMMAS']) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index 12b4f10..066a592 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get part-of-speech tags for words in a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,24 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) morphology_parts_of_speech_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" params = DocumentParameters() params["content"] = morphology_parts_of_speech_data try: return api.morphology(params, api.morphology_output['PARTS_OF_SPEECH']) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/name_deduplication.py b/examples/name_deduplication.py index 042d9df..bf079ea 100644 --- a/examples/name_deduplication.py +++ b/examples/name_deduplication.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to deduplicate a list of names. """ +from __future__ import print_function import argparse import json @@ -11,9 +11,10 @@ from rosette.api import API, NameDeduplicationParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) name_dedupe_data = 'John Smith,Johnathon Smith,Fred Jones' threshold = 0.75 @@ -22,15 +23,18 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params["threshold"] = threshold try: return api.name_deduplication(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/name_similarity.py b/examples/name_similarity.py index 159f8fd..0020fae 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get match score (similarity) of two names. """ +from __future__ import print_function import argparse import json @@ -11,9 +11,10 @@ from rosette.api import API, NameSimilarityParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) matched_name_data1 = "Michael Jackson" matched_name_data2 = "迈克尔·杰克逊" @@ -22,15 +23,18 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} try: return api.name_similarity(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/name_translation.py b/examples/name_translation.py index 84ab35b..7f7372d 100644 --- a/examples/name_translation.py +++ b/examples/name_translation.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to translate a name from one language to another. """ +from __future__ import print_function import argparse import json @@ -11,9 +11,10 @@ from rosette.api import API, NameTranslationParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) translated_name_data = "معمر محمد أبو منيار القذاف" params = NameTranslationParameters() @@ -23,15 +24,18 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params["targetScript"] = "Latn" try: return api.name_translation(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/ping.py b/examples/ping.py index 7cbeea2..75aa02b 100644 --- a/examples/ping.py +++ b/examples/ping.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to send Rosette API a ping to check its reachability. """ +from __future__ import print_function import argparse import json @@ -11,21 +11,25 @@ from rosette.api import API, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) try: return api.ping() - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/relationships.py b/examples/relationships.py index ca9b504..fa1d915 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get entities's relationships from a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,24 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." params = DocumentParameters() params["content"] = relationships_text_data api.set_option('accuracyMode', 'PRECISION') try: return api.relationships(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/sentences.py b/examples/sentences.py index 28a5a36..9032c06 100644 --- a/examples/sentences.py +++ b/examples/sentences.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get sentences in a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,9 +11,10 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) sentences_data = "This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me." params = DocumentParameters() @@ -21,15 +22,18 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): try: return api.sentences(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/sentiment.py b/examples/sentiment.py index aa96d47..afaa008 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get the sentiment of a local file. """ +from __future__ import print_function import argparse import json @@ -12,38 +12,43 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://api.rosette.com/rest/v1/'): + """ Run the example """ # Create default file to read from - f = tempfile.NamedTemporaryFile(suffix=".html") + temp_file = tempfile.NamedTemporaryFile(suffix=".html") sentiment_file_data = "New Ghostbusters Film

Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”

" message = sentiment_file_data - f.write(message) - f.seek(0) + temp_file.write(message) + temp_file.seek(0) # Create an API instance - api = API(user_key=key, service_url=altUrl) + api = API(user_key=key, service_url=alt_url) params = DocumentParameters() params["language"] = "eng" # Use an HTML file to load data instead of a string - params.load_document_file(f.name) + params.load_document_file(temp_file.name) try: result = api.sentiment(params) - except RosetteException as e: - print(e) + except RosetteException as exception: + print(exception) finally: # Clean up the file - f.close() + temp_file.close() return result -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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, + sort_keys=True).encode("utf8")) diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index d553d76..1790729 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get the syntactic dependencies of a document (at a given URL). """ +from __future__ import print_function import argparse import json @@ -11,23 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://api.rosette.com/rest/v1/'): + """ Run the example """ syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday." params = DocumentParameters() params["content"] = syntax_dependencies_data # Create an API instance - api = API(user_key=key, service_url=altUrl) + api = API(user_key=key, service_url=alt_url) try: return api.syntax_dependencies(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, + sort_keys=True).encode("utf8")) diff --git a/examples/text_embedding.py b/examples/text_embedding.py index fc1a6c4..c9cf360 100644 --- a/examples/text_embedding.py +++ b/examples/text_embedding.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get text vectors from a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,23 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) embeddings_data = "Cambridge, Massachusetts" params = DocumentParameters() params["content"] = embeddings_data try: return api.text_embedding(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, + sort_keys=True).encode("utf8")) diff --git a/examples/tokens.py b/examples/tokens.py index 2453230..99bfe17 100644 --- a/examples/tokens.py +++ b/examples/tokens.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to get the tokens (words) in a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,24 +11,28 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) tokens_data = "北京大学生物系主任办公室内部会议" params = DocumentParameters() params["content"] = tokens_data try: return api.tokens(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/topics.py b/examples/topics.py new file mode 100644 index 0000000..d7545d3 --- /dev/null +++ b/examples/topics.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Example code to call Rosette API to get the topics (key phrases and concepts) in a piece of text. +""" +from __future__ import print_function + +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) + + topics_data = "Lily Collins is in talks to join Nicholas Hoult in Chernin Entertainment and Fox Searchlight's J.R.R. Tolkien biopic Tolkien. Anthony Boyle, known for playing Scorpius Malfoy in the British play Harry Potter and the Cursed Child, also has signed on for the film centered on the famed author. In Tolkien, Hoult will play the author of the Hobbit and Lord of the Rings book series that were later adapted into two Hollywood trilogies from Peter Jackson. Dome Karukoski is directing the project." + params = DocumentParameters() + params["content"] = topics_data + try: + return api.topics(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(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/transliteration.py b/examples/transliteration.py index 37ebd46..dd084ec 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - """ Example code to call Rosette API to transliterate a piece of text. """ +from __future__ import print_function import argparse import json @@ -11,9 +11,10 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, altUrl='https://api.rosette.com/rest/v1/'): +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=altUrl) + api = API(user_key=key, service_url=alt_url) transliteration_data = "Some random text" params = DocumentParameters() @@ -21,15 +22,19 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): try: return api.transliteration(params) - except RosetteException as e: - print(e) + 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/') +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(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) + print(json.dumps(RESULT, indent=2, ensure_ascii=False, + sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index 288dc85..32b6948 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -41,7 +41,7 @@ warnings.simplefilter('always') -class _ReturnObject: +class _ReturnObject(object): def __init__(self, js, code): self._json = js @@ -82,7 +82,7 @@ def __str__(self): return sst + ": " + self.message + ":\n " + self.response_message -class _PseudoEnum: +class _PseudoEnum(object): """ Base class for MorphologyOutput """ def __init__(self): @@ -117,6 +117,7 @@ def __init__(self): warnings.warn('MorphologyOutput to be removed in version 1.9.0. ' 'Please use API.morphology_output', DeprecationWarning) + _PseudoEnum.__init__() LEMMAS = "lemmas" PARTS_OF_SPEECH = "parts-of-speech" @@ -340,7 +341,7 @@ def validate(self): repr("names")) -class EndpointCaller: +class EndpointCaller(object): """L{EndpointCaller} objects are invoked via their instance methods to obtain results from the Rosette server described by the L{API} object from which they are created. Each L{EndpointCaller} object communicates with a specific endpoint @@ -542,7 +543,7 @@ def call(self, parameters): return self.__finish_result(response, "operate") -class API: +class API(object): """ Rosette Python Client Binding API; representation of a Rosette server. Call instance methods upon this object to obtain L{EndpointCaller} objects @@ -605,6 +606,7 @@ def __init__( 'SYNTAX_DEPENDENCIES': 'syntax/dependencies', 'TEXT_EMBEDDING': 'text-embedding', 'TOKENS': 'tokens', + 'TOPICS': 'topics', 'TRANSLITERATION': 'transliteration' } @@ -1075,3 +1077,10 @@ def transliteration(self, parameters): @type parameters: L{DocumentParameters} @return: A python dictionary containing the results of the transliteration""" return EndpointCaller(self, self.endpoints['TRANSLITERATION']).call(parameters) + + def topics(self, parameters): + """ + Topics returns keyphrases and concepts related to the provided content + @type parameters: DocumentParameters + @return; A python dictionary containing the results""" + return EndpointCaller(self, self.endpoints['TOPICS']).call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index c22010f..b98cc86 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -742,3 +742,19 @@ def test_the_transliteration_endpoint(api, json_response): assert result["name"] == "Rosette API" httpretty.disable() httpretty.reset() + + +# Test the topics endpoint + +def test_the_topics_endpoint(api, json_response, doc_params): + """Test the topics 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/topics", + body=json_response, status=200, content_type="application/json") + + result = api.topics(doc_params) + assert result["name"] == "Rosette API" + httpretty.disable() + httpretty.reset() From 42f6fc14288793d350c5fa96a740f995047744ef Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Wed, 20 Sep 2017 13:38:28 -0400 Subject: [PATCH 087/247] RCB-530 Proxy (#72) * RCB-530 Proxy Fix - Modified the requests code to include proxies if they are set in environment - Created a simple docker-compose file that can be used to test against a proxy * Minor comment * PEP8 fix on comment * Updated multi-part with proxy change * Tox related changes - Running py2 and py3 exposed a bug in sentiment.py, which is fixed - api.py updated - tox.ini added to tests directory * Cleaned up proxy code * Additional proxy cleanup * Final linefeed on docker-compose * Updated examples Dockerfile * Missed a module in Dockerfile * Mod to Jenkinsfile - force pull of latest docker image * Removed kitchen requirement * Fixed pep8 miscue * Fixed unclosed connection warning - In python3. _make_requests was using a local session, not the class level one --- Jenkinsfile | 1 + docker-compose.yml | 15 +++++++++++++++ examples/docker/Dockerfile | 29 ++++++++++++++++++++++++----- examples/sentiment.py | 3 ++- rosette/api.py | 19 ++++++++++--------- tests/tox.ini | 13 +++++++++++++ 6 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 docker-compose.yml create mode 100644 tests/tox.ini diff --git a/Jenkinsfile b/Jenkinsfile index 4d07afe..f0c57ed 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,6 +9,7 @@ node { } stage("Test with Docker") { withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { + sh "docker pull rosetteapi/docker-python" sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3cc15a6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +application: + image: rosetteapi/docker-python + environment: + - API_KEY=$API_KEY + - HTTP_PROXY=http://squid:3128 + - HTTPS_PROXY=https://squid:3128 + volumes: + - .:/source + links: + - proxy:squid + +proxy: + image: datadog/squid + ports: + - 3128:3128 diff --git a/examples/docker/Dockerfile b/examples/docker/Dockerfile index 7b46dbe..8ff8899 100644 --- a/examples/docker/Dockerfile +++ b/examples/docker/Dockerfile @@ -1,9 +1,28 @@ -FROM python:2.7.11 -MAINTAINER Fiona Hasanaj -ENV MAINTENANCE_DATE 03.28.2016 +FROM python +MAINTAINER Chris Park +LABEL SOURCE="https://github.com/rosette-api/python/blob/develop/examples/docker/Dockerfile" +LABEL VERSION="1.7.1" +ENV LANGUAGE=python -# install necessary software -RUN apt-get -y update && apt-get install -y vim && apt-get install -y git && pip install rosette_api +ENV LANG en_US.UTF-8 + +RUN apt-get update && \ + apt-get -y install \ + wget \ + curl \ + libssl-dev \ + libffi-dev \ + git \ + vim && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# required for pip to run as non-root +RUN mkdir -p /.cache && chmod 777 /.cache +RUN mkdir -p /.local && chmod 777 /.local + +RUN pip install --upgrade tox +RUN pip install --upgrade autopep8 requests rosette_api COPY run_python.sh /python/examples/run_python.sh RUN chmod 755 /python/examples/run_python.sh diff --git a/examples/sentiment.py b/examples/sentiment.py index afaa008..6c5baf5 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # -*- coding: utf-8 -*- """ Example code to call Rosette API to get the sentiment of a local file. @@ -18,7 +19,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): temp_file = tempfile.NamedTemporaryFile(suffix=".html") sentiment_file_data = "New Ghostbusters Film

Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”

" message = sentiment_file_data - temp_file.write(message) + temp_file.write(message if isinstance(message, bytes) else message.encode()) temp_file.seek(0) # Create an API instance diff --git a/rosette/api.py b/rosette/api.py index 32b6948..60d6033 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -524,12 +524,12 @@ def call(self, parameters): 'application/json')} request = requests.Request( 'POST', url, files=files, headers=headers, params=payload) - session = requests.Session() - prepared_request = session.prepare_request(request) - resp = session.send(prepared_request) - rdata = resp.content - response_headers = {"responseHeaders": dict(resp.headers)} - status = resp.status_code + prepared_request = self.api.session.prepare_request(request) + settings = self.api.session.merge_environment_settings(prepared_request.url, {}, {}, {}, {}) + response = self.api.session.send(prepared_request, **settings) + rdata = response.content + response_headers = {"responseHeaders": dict(response.headers)} + status = response.status_code response = _ReturnObject( _my_loads(rdata, response_headers), status) else: @@ -644,11 +644,12 @@ def _make_request(self, operation, url, data, headers): request = requests.Request( operation, url, data=data, headers=headers, params=payload) - session = requests.Session() - prepared_request = session.prepare_request(request) + prepared_request = self.session.prepare_request(request) + # Take into account environment settings, e.g. HTTP_PROXY and HTTPS_PROXY + settings = self.session.merge_environment_settings(prepared_request.url, {}, {}, {}, {}) try: - response = session.send(prepared_request) + response = self.session.send(prepared_request, **settings) status = response.status_code rdata = response.content dict_headers = dict(response.headers) diff --git a/tests/tox.ini b/tests/tox.ini new file mode 100644 index 0000000..9bd4a1b --- /dev/null +++ b/tests/tox.ini @@ -0,0 +1,13 @@ +[tox] +skipsdist = True +envlist = py2, py3 + +[testenv] +commands = + pytest -s --pep8 +deps = + pytest + pytest-pep8 + httpretty + epydoc + requests From 163ff74958d16294f4180f1d56e490556fedf3f4 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 24 Oct 2017 13:16:57 +0000 Subject: [PATCH 088/247] Version 1.8.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 5c463eb..50d75c9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.7.0' +version = '1.8.0' # The full version, including alpha/beta/rc tags. -release = '1.7.0' +release = '1.8.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 452b9cf..8b3da0e 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.7.0' +__version__ = '1.8.0' diff --git a/rosette/api.py b/rosette/api.py index 60d6033..6c5ba0f 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -27,7 +27,7 @@ import warnings import requests -_BINDING_VERSION = '1.7.0' +_BINDING_VERSION = '1.8.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 From 4b9cea951337116f1bce01fbce2b629fa53ee418 Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Thu, 26 Oct 2017 15:35:18 -0400 Subject: [PATCH 089/247] RCB-536 Fixed InsecureRequestWarning (#73) * Fixed InsecureRequestWarning - merge_environment_settings, verify needs to be True or None * Fixed Jenkinsfile.examples - build Dockerfile --no-cache * Forgot . --- Jenkinsfile.examples | 2 +- rosette/api.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples index 1b6f894..236b9a1 100644 --- a/Jenkinsfile.examples +++ b/Jenkinsfile.examples @@ -11,7 +11,7 @@ node { } stage("Build Dockerfile") { dir ("${DOCKERFILE_DIR}") { - docker.build("${TEST_CONTAINER}") + sh "docker build --no-cache -t ${TEST_CONTAINER} ." } } stage("Run Examples") { diff --git a/rosette/api.py b/rosette/api.py index 6c5ba0f..79cfac4 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -525,7 +525,7 @@ def call(self, parameters): request = requests.Request( 'POST', url, files=files, headers=headers, params=payload) prepared_request = self.api.session.prepare_request(request) - settings = self.api.session.merge_environment_settings(prepared_request.url, {}, {}, {}, {}) + settings = self.api.session.merge_environment_settings(prepared_request.url, {}, {}, None, {}) response = self.api.session.send(prepared_request, **settings) rdata = response.content response_headers = {"responseHeaders": dict(response.headers)} @@ -646,7 +646,7 @@ def _make_request(self, operation, url, data, headers): operation, url, data=data, headers=headers, params=payload) prepared_request = self.session.prepare_request(request) # Take into account environment settings, e.g. HTTP_PROXY and HTTPS_PROXY - settings = self.session.merge_environment_settings(prepared_request.url, {}, {}, {}, {}) + settings = self.session.merge_environment_settings(prepared_request.url, {}, {}, None, {}) try: response = self.session.send(prepared_request, **settings) From 7be1f0012d15f2f1323486c614016ee0cb7254c4 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Thu, 26 Oct 2017 19:43:15 +0000 Subject: [PATCH 090/247] Version 1.8.1 --- 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 50d75c9..1a0017c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.8.0' +version = '1.8.1' # The full version, including alpha/beta/rc tags. -release = '1.8.0' +release = '1.8.1' # 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 8b3da0e..54e77ac 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.8.0' +__version__ = '1.8.1' diff --git a/rosette/api.py b/rosette/api.py index 79cfac4..e281f08 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -27,7 +27,7 @@ import warnings import requests -_BINDING_VERSION = '1.8.0' +_BINDING_VERSION = '1.8.1' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 From b1eb3908c2f66666dd1a0436b70912b9f06a9d6a Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 27 Oct 2017 14:05:13 -0400 Subject: [PATCH 091/247] Updated Jenkinsfiles - to look for upstream ALT_URL --- Jenkinsfile | 4 +++- Jenkinsfile.examples | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f0c57ed..7e8daf8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,9 @@ node { checkout scm } stage("Test with Docker") { - withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { + echo "${env.ALT_URL}" + def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}" + withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) { sh "docker pull rosetteapi/docker-python" sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" } diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples index 236b9a1..652bea6 100644 --- a/Jenkinsfile.examples +++ b/Jenkinsfile.examples @@ -15,7 +15,9 @@ node { } } stage("Run Examples") { - withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { + echo "${env.ALT_URL}" + def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}" + withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) { sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source ${TEST_CONTAINER}" } } From a1c7a22a97e8bcea41810e01dd9f11afa804b4d9 Mon Sep 17 00:00:00 2001 From: Li Xu Date: Wed, 13 Dec 2017 13:27:24 -0500 Subject: [PATCH 092/247] ISSUE-74: close file after reading (#75) --- rosette/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index e281f08..d20708b 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -226,7 +226,8 @@ def load_document_file(self, path): """ self.use_multipart = True self.file_name = path - self.load_document_string(open(path, "rb").read()) + with open(path, "rb") as f: + self.load_document_string(f.read()) def load_document_string(self, content_as_string): """Loads a string into the object. From d686992a3097a88397d1de83e241f05639b4f9d5 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 13 Dec 2017 18:39:28 +0000 Subject: [PATCH 093/247] Version 1.8.2 --- 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 1a0017c..d726d9c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.8.1' +version = '1.8.2' # The full version, including alpha/beta/rc tags. -release = '1.8.1' +release = '1.8.2' # 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 54e77ac..29a0ce9 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.8.1' +__version__ = '1.8.2' diff --git a/rosette/api.py b/rosette/api.py index d20708b..e948fc5 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -27,7 +27,7 @@ import warnings import requests -_BINDING_VERSION = '1.8.1' +_BINDING_VERSION = '1.8.2' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 From 294be0b75ec314a398bf5f250dae73df365129a3 Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Mon, 18 Dec 2017 13:08:29 -0500 Subject: [PATCH 094/247] Remove travis test for 2.6 and 3.3 (#76) - update README accordingly --- .travis.yml | 4 +--- README.md | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 077ede1..6a85dd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,11 @@ language: python python: - - "2.6" - "2.7" - - "3.3" - "3.4" - "3.5" - "3.6" install: - - pip install tox + - pip install tox script: - tox diff --git a/README.md b/README.md index 46b1c5c..c72b41d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Please check out the [wiki](https://github.com/rosette-api/python/wiki) for addi ### Installation -The Python binding requires Python 2.6 or greater and is available through pip: +The Python binding requires Python 2.7+ or 3.4+ and is available through pip: `pip install rosette_api` From f4d93951621d038ebc2928f9fc2e3d811361b83f Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Wed, 3 Jan 2018 14:32:29 -0500 Subject: [PATCH 095/247] RCB-542 1.9 release (#77) * Added runtime version - Removed deprecated methods and messages - Added method for returning User-Agent string - Added unit test for User-Agent string - Removed deprecated tests * WS-1272 Multilingual example * Example updates * Update multilingual to True --- examples/entities.py | 2 +- examples/language_multilingual.py | 41 ++++++++ examples/morphology_complete.py | 2 +- examples/name_deduplication.py | 2 +- examples/relationships.py | 2 +- examples/sentences.py | 2 +- examples/transliteration.py | 2 +- rosette/api.py | 150 ++---------------------------- tests/test_rosette_api.py | 68 ++------------ 9 files changed, 62 insertions(+), 209 deletions(-) create mode 100644 examples/language_multilingual.py diff --git a/examples/entities.py b/examples/entities.py index bbd0499..32b7baa 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -15,7 +15,7 @@ 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) - entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS" + entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country." params = DocumentParameters() params["content"] = entities_text_data params["genre"] = "social-media" diff --git a/examples/language_multilingual.py b/examples/language_multilingual.py new file mode 100644 index 0000000..84f5933 --- /dev/null +++ b/examples/language_multilingual.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +""" +Example code to call Rosette API to determine the language of a piece of text. +""" +from __future__ import print_function + +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) + + language_multilingual_data = "On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان." + params = DocumentParameters() + params["content"] = language_multilingual_data + api.set_custom_headers("X-RosetteAPI-App", "python-app") + api.set_option('multilingual', True) + + try: + return api.language(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(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index 10db4ca..d41d7c0 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -16,7 +16,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) - morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did." + morphology_complete_data = "The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)" params = DocumentParameters() params["content"] = morphology_complete_data try: diff --git a/examples/name_deduplication.py b/examples/name_deduplication.py index bf079ea..0392898 100644 --- a/examples/name_deduplication.py +++ b/examples/name_deduplication.py @@ -16,7 +16,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) - name_dedupe_data = 'John Smith,Johnathon Smith,Fred Jones' + name_dedupe_data = "Alice Terry,Alice Thierry,Betty Grable,Betty Gable,Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,Julie Halliday" threshold = 0.75 params = NameDeduplicationParameters() params["names"] = name_dedupe_data.split(',') diff --git a/examples/relationships.py b/examples/relationships.py index fa1d915..7ce342f 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -15,7 +15,7 @@ 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) - relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." + relationships_text_data = "FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai." params = DocumentParameters() params["content"] = relationships_text_data api.set_option('accuracyMode', 'PRECISION') diff --git a/examples/sentences.py b/examples/sentences.py index 9032c06..44ea8eb 100644 --- a/examples/sentences.py +++ b/examples/sentences.py @@ -16,7 +16,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) - sentences_data = "This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me." + sentences_data = "This land is your land. This land is my land, from California to the New York island; from the red wood forest to the Gulf Stream waters. This land was made for you and Me. As I was walking that ribbon of highway, I saw above me that endless skyway: I saw below me that golden valley: This land was made for you and me." params = DocumentParameters() params["content"] = sentences_data diff --git a/examples/transliteration.py b/examples/transliteration.py index dd084ec..6cd9d0b 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -16,7 +16,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) - transliteration_data = "Some random text" + transliteration_data = "ana r2ye7 el gam3a el sa3a 3 el 3asr" params = DocumentParameters() params["content"] = transliteration_data diff --git a/rosette/api.py b/rosette/api.py index e948fc5..2992e3d 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -26,6 +26,7 @@ import re import warnings import requests +import platform _BINDING_VERSION = '1.8.2' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) @@ -82,50 +83,6 @@ def __str__(self): return sst + ": " + self.message + ":\n " + self.response_message -class _PseudoEnum(object): - """ Base class for MorphologyOutput """ - - def __init__(self): - pass - - @classmethod - def validate(cls, value, name): - """ validation method """ - values = [] - for (key, value) in vars(cls).items(): - if not key.startswith("__"): - values += [value] - - # this is still needed to make sure that the parameter NAMES are known. - # If python didn't allow setting unknown values, this would be a - # language error. - if value not in values: - raise RosetteException( - "unknownVariable", - "The value supplied for " + - name + - " is not one of " + - ", ".join(values) + - ".", - repr(value)) - - -class MorphologyOutput(_PseudoEnum): - """ Class to provide Morphology sub-endpoints """ - - def __init__(self): - warnings.warn('MorphologyOutput to be removed in version 1.9.0. ' - 'Please use API.morphology_output', - DeprecationWarning) - _PseudoEnum.__init__() - - LEMMAS = "lemmas" - PARTS_OF_SPEECH = "parts-of-speech" - COMPOUND_COMPONENTS = "compound-components" - HAN_READINGS = "han-readings" - COMPLETE = "complete" - - class _DocumentParamSetBase(object): def __init__(self, repertoire): @@ -582,6 +539,7 @@ def __init__( self.url_parameters = {} self.max_pool_size = 1 self.session = requests.Session() + self.user_agent_string = 'RosetteAPIPython/' + _BINDING_VERSION + '/' + platform.python_version() self.morphology_output = { 'LEMMAS': 'lemmas', @@ -617,6 +575,10 @@ def __del__(self): except ReferenceError: pass + def get_user_agent_string(self): + """ Return the User-Agent string """ + return self.user_agent_string + def _set_pool_size(self): adapter = requests.adapters.HTTPAdapter( pool_maxsize=self.max_pool_size) @@ -632,7 +594,7 @@ def _make_request(self, operation, url, data, headers): @param data: request data @param headers: request headers """ - headers['User-Agent'] = "RosetteAPIPython/" + _BINDING_VERSION + headers['User-Agent'] = self.get_user_agent_string() message = None code = "unknownError" @@ -718,31 +680,12 @@ def post_http(self, url, data, headers): return _ReturnObject(_my_loads(rdata, response_headers), status) - def getPoolSize(self): - """ - Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value - """ - warnings.warn('Method renamed to API.get_pool_size(). To be removed in version 1.9.0', - DeprecationWarning) - return self.get_pool_size() - def get_pool_size(self): """ Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value """ return int(self.max_pool_size) - def setOption(self, name, value): - """ - Sets an option - - @param name: name of option - @param value: value of option - """ - warnings.warn('Method renamed to API.set_option(). To be removed in version 1.9.0', - DeprecationWarning) - return self.set_option(name, value) - def set_option(self, name, value): """ Sets an option @@ -755,18 +698,6 @@ def set_option(self, name, value): else: self.options[name] = value - def getOption(self, name): - """ - Gets an option - - @param name: name of option - - @return: value of option - """ - warnings.warn('Method renamed to API.get_option(). To be removed in version 1.9.0', - DeprecationWarning) - return self.get_option(name) - def get_option(self, name): """ Gets an option @@ -780,31 +711,12 @@ def get_option(self, name): else: return None - def clearOptions(self): - """ - Clears all options - """ - warnings.warn('Method renamed to API.clear_options(). To be removed in version 1.9.0', - DeprecationWarning) - self.clear_options() - def clear_options(self): """ Clears all options """ self.options.clear() - def setUrlParameter(self, name, value): - """ - Sets a URL parameter - - @param name: name of parameter - @param value: value of parameter - """ - warnings.warn('Method renamed to API.set_url_parameter(). To be removed in version 1.9.0', - DeprecationWarning) - return self.set_url_parameter(name, value) - def set_url_parameter(self, name, value): """ Sets a URL parameter @@ -817,18 +729,6 @@ def set_url_parameter(self, name, value): else: self.url_parameters[name] = value - def getUrlParameter(self, name): - """ - Gets a URL parameter - - @param name: name of parameter - - @return: value of parameter - """ - warnings.warn('Method renamed to API.get_url_parameter(). To be removed in version 1.9.0', - DeprecationWarning) - return self.get_url_parameter(name) - def get_url_parameter(self, name): """ Gets a URL parameter @@ -842,31 +742,12 @@ def get_url_parameter(self, name): else: return None - def clearUrlParameters(self): - """ - Clears all options - """ - warnings.warn('Method renamed to API.clear_url_parameters(). ' - 'To be removed in version 1.9.0', - DeprecationWarning) - self.clear_url_parameters() - def clear_url_parameters(self): """ Clears all options """ self.url_parameters.clear() - def setCustomHeaders(self, name, value): - """ - Sets custom headers - - @param headers: array of custom headers to be set - """ - warnings.warn('Method renamed to API.set_custom_headers(). To be removed in version 1.9.0', - DeprecationWarning) - return self.set_custom_headers(name, value) - def set_custom_headers(self, name, value): """ Sets custom headers @@ -878,29 +759,12 @@ def set_custom_headers(self, name, value): else: self.custom_headers[name] = value - def getCustomHeaders(self): - """ - Get custom headers - """ - warnings.warn('Method renamed to API.get_custom_headers(). To be removed in version 1.9.0', - DeprecationWarning) - return self.get_custom_headers() - def get_custom_headers(self): """ Get custom headers """ return self.custom_headers - def clearCustomHeaders(self): - """ - Clears custom headers - """ - warnings.warn('Method renamed to API.clear_custom_headers(). ' - 'To be removed in version 1.9.0', - DeprecationWarning) - self.clear_custom_headers() - def clear_custom_headers(self): """ Clears custom headers diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index b98cc86..365193d 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -20,6 +20,7 @@ import json import sys +import platform import httpretty import pytest from rosette.api import(API, @@ -30,6 +31,7 @@ RosetteException) _ISPY3 = sys.version_info[0] == 3 +_BINDING_VERSION = '1.8.2' @pytest.fixture @@ -71,15 +73,6 @@ def doc_params(): # Test the option set/get/clear -def test_option_get_set_clear_deprecated(api): - """Tests the deprecated get/set/clear Options methods""" - api.setOption('test', 'foo') - assert api.getOption('test') == 'foo' - - api.clearOptions() - assert api.getOption('test') is None - - def test_option_get_set_clear(api): """Tests the get/set/clear methods""" api.set_option('test', 'foo') @@ -89,15 +82,6 @@ def test_option_get_set_clear(api): assert api.get_option('test') is None -def test_option_clear_single_option_deprecated(api): - """Test the deprecated clear single option""" - api.setOption('test', 'foo') - assert api.getOption('test') == 'foo' - - api.set_option('test', None) - assert api.get_option('test') is None - - def test_option_clear_single_option(api): """Test the clear single option""" api.set_option('test', 'foo') @@ -107,16 +91,6 @@ def test_option_clear_single_option(api): assert api.get_option('test') is None -# Test the URL parameter set/get/clear -def test_url_parameter_getsetclear_deprecated(api): - """Tests get/set/clear url parameter""" - api.setUrlParameter('test', 'foo') - assert api.getUrlParameter('test') == 'foo' - - api.clearUrlParameters() - assert api.getUrlParameter('test') is None - - def test_url_parameter_getsetclear(api): """Tests get/set/clear url parameter""" api.set_url_parameter('test', 'foo') @@ -126,15 +100,6 @@ def test_url_parameter_getsetclear(api): assert api.get_url_parameter('test') is None -def test_url_parameter_clear_single_deprecated(api): - """Test the deprecated clearing of a single url parameter""" - api.setUrlParameter('test', 'foo') - assert api.getUrlParameter('test') == 'foo' - - api.setUrlParameter('test', None) - assert api.getUrlParameter('test') is None - - def test_url_parameter_clear_single(api): """Test the clearing of a single url parameter""" api.set_url_parameter('test', 'foo') @@ -146,17 +111,6 @@ def test_url_parameter_clear_single(api): # Test the custom header set/get/clear -def test_custom_header_props_deprecated(api): - """Test custom header get/set/clear""" - key = 'X-RosetteAPI-Test' - value = 'foo' - api.setCustomHeaders(key, value) - assert value == api.getCustomHeaders()[key] - - api.clearCustomHeaders() - assert len(api.getCustomHeaders()) is 0 - - def test_custom_header_props(api): """Test custom header get/set/clear""" key = 'X-RosetteAPI-Test' @@ -170,18 +124,6 @@ def test_custom_header_props(api): # Test for invalid header name -def test_invalid_header_deprecated(api): - """Test for invalid header""" - key = 'test' - value = 'foo' - api.setCustomHeaders(key, value) - - with pytest.raises(RosetteException) as e_rosette: - api.info() - - assert e_rosette.value.status == 'badHeader' - - def test_invalid_header(api): """Test for invalid header""" key = 'test' @@ -193,6 +135,12 @@ def test_invalid_header(api): assert e_rosette.value.status == 'badHeader' + +def test_user_agent(api): + """ Test user agent """ + value = "RosetteAPIPython/" + _BINDING_VERSION + "/" + platform.python_version() + assert value == api.get_user_agent_string() + # Test that pinging the API is working properly # @httpretty.activate From 05c1f4a85da1014aed427f79ca6ffbb7b0a35c59 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 17 Jan 2018 19:51:03 +0000 Subject: [PATCH 096/247] Version 1.9.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 d726d9c..072625e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.8.2' +version = '1.9.0' # The full version, including alpha/beta/rc tags. -release = '1.8.2' +release = '1.9.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 29a0ce9..4db448e 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.8.2' +__version__ = '1.9.0' diff --git a/rosette/api.py b/rosette/api.py index 2992e3d..77e9377 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import requests import platform -_BINDING_VERSION = '1.8.2' +_BINDING_VERSION = '1.9.0' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 From 49da3d11748df425130cba9b135710bb454773aa Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 24 Jan 2018 09:04:37 -0500 Subject: [PATCH 097/247] RCB-547 Remove hardcoded version from test - Added a method off of api to return currrent binding version - Replaced the hardcoded version in the test with the api call --- rosette/api.py | 4 ++++ tests/test_rosette_api.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 77e9377..244dacb 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -575,6 +575,10 @@ def __del__(self): except ReferenceError: pass + def get_binding_version(self): + """ Return the current binding version """ + return _BINDING_VERSION + def get_user_agent_string(self): """ Return the User-Agent string """ return self.user_agent_string diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 365193d..0c3cfbb 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -31,7 +31,6 @@ RosetteException) _ISPY3 = sys.version_info[0] == 3 -_BINDING_VERSION = '1.8.2' @pytest.fixture @@ -138,7 +137,7 @@ def test_invalid_header(api): def test_user_agent(api): """ Test user agent """ - value = "RosetteAPIPython/" + _BINDING_VERSION + "/" + platform.python_version() + value = "RosetteAPIPython/" + api.get_binding_version() + "/" + platform.python_version() assert value == api.get_user_agent_string() # Test that pinging the API is working properly From eed5f29c0c17e00740e3a78565a29544b13bf771 Mon Sep 17 00:00:00 2001 From: Karin Lin Date: Tue, 30 Jan 2018 14:56:08 -0500 Subject: [PATCH 098/247] meaningless change to test jenkins scan --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c72b41d..47ee4a0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=master)](https://travis-ci.org/rosette-api/python) - + ## This is the Python client binding for Rosette API. Please check out the [wiki](https://github.com/rosette-api/python/wiki) for additional information From 38872ba677980804d40403257986e91f674b2879 Mon Sep 17 00:00:00 2001 From: Karin Lin Date: Tue, 30 Jan 2018 16:04:16 -0500 Subject: [PATCH 099/247] WS-1294: try SCM trigger in Jenkinsfile --- Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 7e8daf8..7b0eef1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,7 @@ +properties([ + pipelineTriggers([[$class: "SCMTrigger", scmpoll_spec: "H/5 * * * *"]]) +]) + node { def SOURCEDIR = pwd() try { From ac18585c0728f116b17a50e8409bacab87561878 Mon Sep 17 00:00:00 2001 From: Karin Lin Date: Tue, 30 Jan 2018 16:09:05 -0500 Subject: [PATCH 100/247] another meaningless change to test jenkins scm trigger --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47ee4a0..0d3a572 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## This is the Python client binding for Rosette API. Please check out the [wiki](https://github.com/rosette-api/python/wiki) for additional information - + ### Installation The Python binding requires Python 2.7+ or 3.4+ and is available through pip: From 9ba63b69341b386e0e43c118a0e3622091511b16 Mon Sep 17 00:00:00 2001 From: Karin Lin Date: Tue, 30 Jan 2018 16:24:15 -0500 Subject: [PATCH 101/247] WS-1294: change polling interval from 5 to 15 minutes --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7b0eef1..f427181 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ properties([ - pipelineTriggers([[$class: "SCMTrigger", scmpoll_spec: "H/5 * * * *"]]) + pipelineTriggers([[$class: "SCMTrigger", scmpoll_spec: "H/15 * * * *"]]) ]) node { @@ -32,4 +32,4 @@ def slack(boolean success) { 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 +} From 8bb8529017fb230eec4bfaac03107cd71fda6ad6 Mon Sep 17 00:00:00 2001 From: Christopher Park Date: Tue, 10 Apr 2018 17:11:51 -0400 Subject: [PATCH 102/247] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d3a572..60462a6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=master)](https://travis-ci.org/rosette-api/python) +[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) ## This is the Python client binding for Rosette API. Please check out the [wiki](https://github.com/rosette-api/python/wiki) for additional information From f52bca8479a01d3eb56133213a3a4f6239736e8e Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 25 Apr 2018 10:22:37 -0400 Subject: [PATCH 103/247] WS-1377 expanded-smoke-tests - route to docker-light --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f427181..42eec0f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ properties([ pipelineTriggers([[$class: "SCMTrigger", scmpoll_spec: "H/15 * * * *"]]) ]) -node { +node ("docker-light") { def SOURCEDIR = pwd() try { stage("Clean up") { From a447668466636ac52aee5e034eb24eec9488c937 Mon Sep 17 00:00:00 2001 From: Ian Redpath Date: Tue, 27 Nov 2018 16:12:12 -0500 Subject: [PATCH 104/247] DOC-246 remove undocumented option --- examples/relationships.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/relationships.py b/examples/relationships.py index 7ce342f..c59861d 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -18,7 +18,6 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): relationships_text_data = "FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai." params = DocumentParameters() params["content"] = relationships_text_data - api.set_option('accuracyMode', 'PRECISION') try: return api.relationships(params) except RosetteException as exception: From 97b339af300570db28f25df6258c2354941b14d4 Mon Sep 17 00:00:00 2001 From: seth-basistech Date: Wed, 5 Dec 2018 12:05:11 -0500 Subject: [PATCH 105/247] Fix URL. --- examples/categories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index 8bc6344..c087a0a 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -15,7 +15,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ - categories_url_data = "http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/" + categories_url_data = "https://onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/" url = categories_url_data # Create an API instance api = API(user_key=key, service_url=alt_url) From d18d3d6e643d6b0143e11b8ed1a5da35d05eff56 Mon Sep 17 00:00:00 2001 From: Ian Redpath Date: Wed, 16 Jan 2019 17:50:57 -0500 Subject: [PATCH 106/247] RD-2427 related terms endpoint (#84) * RD-2427 related terms endpoint * RD-2427 missing newline * RD-2427 related_terms -> similar_terms, add semantic_vectors * RD-2427 similar terms unit test, checkstyle --- ...{text_embedding.py => semantic_vectors.py} | 10 +++- examples/similar_terms.py | 46 +++++++++++++++++++ rosette/api.py | 21 ++++++++- tests/test_rosette_api.py | 23 ++++++++-- 4 files changed, 94 insertions(+), 6 deletions(-) rename examples/{text_embedding.py => semantic_vectors.py} (79%) create mode 100644 examples/similar_terms.py diff --git a/examples/text_embedding.py b/examples/semantic_vectors.py similarity index 79% rename from examples/text_embedding.py rename to examples/semantic_vectors.py index c9cf360..2645e2d 100644 --- a/examples/text_embedding.py +++ b/examples/semantic_vectors.py @@ -15,11 +15,19 @@ 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#semantic-vectors + + # api.set_option('perToken', 'true') + embeddings_data = "Cambridge, Massachusetts" params = DocumentParameters() params["content"] = embeddings_data try: - return api.text_embedding(params) + return api.semantic_vectors(params) except RosetteException as exception: print(exception) diff --git a/examples/similar_terms.py b/examples/similar_terms.py new file mode 100644 index 0000000..5a1fc2a --- /dev/null +++ b/examples/similar_terms.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +""" +Example code to call Rosette API to get similar terms for an input. +""" +from __future__ import print_function + +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#similar-terms + + api.set_option("resultLanguages", ['spa', 'deu', 'jpn']) + + term = "spy" + params = DocumentParameters() + params["content"] = term + try: + return api.similar_terms(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(json.dumps(RESULT, indent=2, ensure_ascii=False, + sort_keys=True).encode("utf8")) diff --git a/rosette/api.py b/rosette/api.py index 244dacb..4960a1f 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -560,10 +560,12 @@ def __init__( 'NAME_DEDUPLICATION': 'name-deduplication', 'PING': 'ping', 'RELATIONSHIPS': 'relationships', + 'SEMANTIC_VECTORS': 'semantics/vector', 'SENTENCES': 'sentences', 'SENTIMENT': 'sentiment', + 'SIMILAR_TERMS': 'semantics/similar', 'SYNTAX_DEPENDENCIES': 'syntax/dependencies', - 'TEXT_EMBEDDING': 'text-embedding', + 'TEXT_EMBEDDING': 'semantics/vector', 'TOKENS': 'tokens', 'TOPICS': 'topics', 'TRANSLITERATION': 'transliteration' @@ -932,6 +934,14 @@ def text_embedding(self, parameters): @return: A python dictionary containing the results of text embedding.""" return EndpointCaller(self, self.endpoints['TEXT_EMBEDDING']).call(parameters) + def semantic_vectors(self, parameters): + """ + Create an L{EndpointCaller} to identify text vectors found in the texts + to which it is applied and call it. + @type parameters: L{DocumentParameters} or L{str} + @return: A python dictionary containing the results of semantic vectors.""" + return EndpointCaller(self, self.endpoints['SEMANTIC_VECTORS']).call(parameters) + def syntax_dependencies(self, parameters): """ Create an L{EndpointCaller} to identify the syntactic dependencies in the texts @@ -954,3 +964,12 @@ def topics(self, parameters): @type parameters: DocumentParameters @return; A python dictionary containing the results""" return EndpointCaller(self, self.endpoints['TOPICS']).call(parameters) + + def similar_terms(self, parameters): + """ + Create an L{EndpointCaller} to identify terms most similar to the input in + the requested languages + :param parameters: DocumentParameters + :return: A python dictionary containing the similar terms and their similarity + """ + return EndpointCaller(self, self.endpoints['SIMILAR_TERMS']).call(parameters) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 0c3cfbb..cd0611f 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -649,13 +649,13 @@ def test_for_name_translation_required_parameters(api, json_response): httpretty.reset() -def test_the_text_embedded_endpoint(api, json_response, doc_params): - """Test text embedded endpoint""" +def test_the_semantic_vectors_endpoint(api, json_response, doc_params): + """Test semantic vectors endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/text-embedding", + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/semantics/vector", body=json_response, status=200, content_type="application/json") - result = api.text_embedding(doc_params) + result = api.semantic_vectors(doc_params) assert result["name"] == "Rosette API" httpretty.disable() httpretty.reset() @@ -705,3 +705,18 @@ def test_the_topics_endpoint(api, json_response, doc_params): assert result["name"] == "Rosette API" httpretty.disable() httpretty.reset() + + +# Test the similar-terms endpoint + +def test_the_similar_terms_endpoint(api, json_response, doc_params): + """Test the similar terms endpoint""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/semantics/similar", + body=json_response, status=200, content_type="application/json") + + api.set_option("resultLanguages", ["spa", "jpn", "deu"]) + result = api.similar_terms(doc_params) + assert result["name"] == "Rosette API" + httpretty.disable() + httpretty.reset() From 5411cd3b45f42cf1d1bc332d89c5218c35c80f17 Mon Sep 17 00:00:00 2001 From: krczeck <37711286+krczeck@users.noreply.github.com> Date: Thu, 17 Jan 2019 11:33:28 -0500 Subject: [PATCH 107/247] added comments to show options (#85) * added comments to show options * fixing travis error * fixing travis errors * travis error file --- examples/categories.py | 11 ++++++++++- examples/entities.py | 9 +++++++++ examples/morphology_complete.py | 7 +++++++ examples/morphology_compound-components.py | 7 +++++++ examples/morphology_han-readings.py | 6 ++++++ examples/morphology_lemmas.py | 7 +++++++ examples/morphology_parts-of-speech.py | 7 +++++++ examples/sentiment.py | 6 ++++++ examples/tokens.py | 7 +++++++ examples/topics.py | 8 ++++++++ examples/transliteration.py | 8 ++++++++ 11 files changed, 82 insertions(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index c087a0a..c02de34 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -15,10 +15,19 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ - categories_url_data = "https://onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/" + categories_url_data = "https://onlocationvacations.com/2018/02/06/downton-abbey-exhibition-extended-april-2-nyc/" url = categories_url_data # 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#categorization + + # api.set_option('singleLabel', 'true') + # api.set_option('scoreThreshold',- 0.20) + params = DocumentParameters() # Use a URL to input data instead of a string diff --git a/examples/entities.py b/examples/entities.py index 32b7baa..e8191e2 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -15,6 +15,15 @@ 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') + entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country." params = DocumentParameters() params["content"] = entities_text_data diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index d41d7c0..b1781d3 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -16,6 +16,13 @@ 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#morphological-analysis-introduction + + # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only + morphology_complete_data = "The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)" params = DocumentParameters() params["content"] = morphology_complete_data diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index 48d6f9c..3020e60 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -16,6 +16,13 @@ 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#morphological-analysis-introduction + + # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only + morphology_compound_components_data = "Rechtsschutzversicherungsgesellschaften" params = DocumentParameters() params["content"] = morphology_compound_components_data diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index eb008c9..bc1c9ea 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -15,6 +15,12 @@ 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#morphological-analysis-introduction + + # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only morphology_han_readings_data = "北京大学生物系主任办公室内部会议" params = DocumentParameters() diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index 0aad1db..ae6fe57 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -16,6 +16,13 @@ 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#morphological-analysis-introduction + + # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only + morphology_lemmas_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" params = DocumentParameters() params["content"] = morphology_lemmas_data diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index 066a592..011b37a 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -16,6 +16,13 @@ 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#morphological-analysis-introduction + + # api.set_option('modelType','perceptron') # Valid for Chinese and Japanese only + morphology_parts_of_speech_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" params = DocumentParameters() params["content"] = morphology_parts_of_speech_data diff --git a/examples/sentiment.py b/examples/sentiment.py index 6c5baf5..0b6da36 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -24,6 +24,12 @@ 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#sentiment-analysis + + # api.set_option('modelType','dnn') #Valid for English only params = DocumentParameters() params["language"] = "eng" diff --git a/examples/tokens.py b/examples/tokens.py index 99bfe17..a1fedd3 100644 --- a/examples/tokens.py +++ b/examples/tokens.py @@ -16,6 +16,13 @@ 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#tokenization + + # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only + tokens_data = "北京大学生物系主任办公室内部会议" params = DocumentParameters() params["content"] = tokens_data diff --git a/examples/topics.py b/examples/topics.py index d7545d3..25d768a 100644 --- a/examples/topics.py +++ b/examples/topics.py @@ -16,6 +16,14 @@ 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#topic-extraction + + # api.set_option('keyphraseSalienceThreshold','.5') + # api.set_option('conceptSalienceThreshold','.1') + topics_data = "Lily Collins is in talks to join Nicholas Hoult in Chernin Entertainment and Fox Searchlight's J.R.R. Tolkien biopic Tolkien. Anthony Boyle, known for playing Scorpius Malfoy in the British play Harry Potter and the Cursed Child, also has signed on for the film centered on the famed author. In Tolkien, Hoult will play the author of the Hobbit and Lord of the Rings book series that were later adapted into two Hollywood trilogies from Peter Jackson. Dome Karukoski is directing the project." params = DocumentParameters() params["content"] = topics_data diff --git a/examples/transliteration.py b/examples/transliteration.py index 6cd9d0b..9fdab66 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -16,6 +16,14 @@ 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#transliteration + + # To transliterate from native Arabic script to Arabizi add: + # api.set_option('reversed','True') + transliteration_data = "ana r2ye7 el gam3a el sa3a 3 el 3asr" params = DocumentParameters() params["content"] = transliteration_data From 2a80c10eee0eb47bbc5845baf6a1be4c4ed89eab Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 21 Jan 2019 17:36:15 -0600 Subject: [PATCH 108/247] RD-2427: Test example data string for replacement. --- examples/semantic_vectors.py | 2 +- examples/similar_terms.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/semantic_vectors.py b/examples/semantic_vectors.py index 2645e2d..7f44022 100644 --- a/examples/semantic_vectors.py +++ b/examples/semantic_vectors.py @@ -23,7 +23,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): # api.set_option('perToken', 'true') - embeddings_data = "Cambridge, Massachusetts" + semantic_vectors_data = "Cambridge, England" params = DocumentParameters() params["content"] = embeddings_data try: diff --git a/examples/similar_terms.py b/examples/similar_terms.py index 5a1fc2a..e3d3f48 100644 --- a/examples/similar_terms.py +++ b/examples/similar_terms.py @@ -23,7 +23,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): api.set_option("resultLanguages", ['spa', 'deu', 'jpn']) - term = "spy" + similar_terms_data = "spook" params = DocumentParameters() params["content"] = term try: From 4052f963163f2dba0bafccf29c438fff0fa4ed1d Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 21 Jan 2019 19:40:39 -0600 Subject: [PATCH 109/247] RD-2427: Use the renamed var. --- examples/semantic_vectors.py | 2 +- examples/similar_terms.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/semantic_vectors.py b/examples/semantic_vectors.py index 7f44022..9a1fc31 100644 --- a/examples/semantic_vectors.py +++ b/examples/semantic_vectors.py @@ -25,7 +25,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): semantic_vectors_data = "Cambridge, England" params = DocumentParameters() - params["content"] = embeddings_data + params["content"] = semantic_vectors_data try: return api.semantic_vectors(params) except RosetteException as exception: diff --git a/examples/similar_terms.py b/examples/similar_terms.py index e3d3f48..ac16741 100644 --- a/examples/similar_terms.py +++ b/examples/similar_terms.py @@ -25,7 +25,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): similar_terms_data = "spook" params = DocumentParameters() - params["content"] = term + params["content"] = similar_terms_data try: return api.similar_terms(params) except RosetteException as exception: From c78825ba071cdcb1403cfdd3aed5106972e3e2cf Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 22 Jan 2019 10:32:21 -0600 Subject: [PATCH 110/247] RD-2427: Example data replacement vars. --- examples/semantic_vectors.py | 2 +- examples/similar_terms.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/semantic_vectors.py b/examples/semantic_vectors.py index 9a1fc31..066d920 100644 --- a/examples/semantic_vectors.py +++ b/examples/semantic_vectors.py @@ -23,7 +23,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): # api.set_option('perToken', 'true') - semantic_vectors_data = "Cambridge, England" + semantic_vectors_data = "Cambridge, Massachusetts" params = DocumentParameters() params["content"] = semantic_vectors_data try: diff --git a/examples/similar_terms.py b/examples/similar_terms.py index ac16741..9695aa7 100644 --- a/examples/similar_terms.py +++ b/examples/similar_terms.py @@ -23,7 +23,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): api.set_option("resultLanguages", ['spa', 'deu', 'jpn']) - similar_terms_data = "spook" + similar_terms_data = "spy" params = DocumentParameters() params["content"] = similar_terms_data try: From adca7ca4178a4a788df0feffdefa2b3c02872933 Mon Sep 17 00:00:00 2001 From: Karin-Basis Date: Fri, 1 Feb 2019 17:21:10 -0500 Subject: [PATCH 111/247] NO-JIRA: add profileId to list of accepted parameters (#87) --- rosette/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 4960a1f..fbe407d 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -150,7 +150,7 @@ class DocumentParameters(_DocumentParamSetBase): def __init__(self): """Create a L{DocumentParameters} object.""" _DocumentParamSetBase.__init__( - self, ("content", "contentUri", "language", "genre")) + self, ("content", "contentUri", "language", "genre", "profileId")) self.file_name = "" self.use_multipart = False From 2ee4456323a41df8afcbef28bb9b23f519e2e166 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 8 Feb 2019 00:54:06 +0000 Subject: [PATCH 112/247] Version 1.12.1 --- 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 072625e..58fd9b9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.9.0' +version = '1.12.1' # The full version, including alpha/beta/rc tags. -release = '1.9.0' +release = '1.12.1' # 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 4db448e..b04d320 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.9.0' +__version__ = '1.12.1' diff --git a/rosette/api.py b/rosette/api.py index fbe407d..2c76b33 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import requests import platform -_BINDING_VERSION = '1.9.0' +_BINDING_VERSION = '1.12.1' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 From b89c1daec802bf25dca950dae9902d1abc97a2d9 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Sun, 10 Feb 2019 19:28:21 -0600 Subject: [PATCH 113/247] Check return codes not strings. --- examples/docker/run_python.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/docker/run_python.sh b/examples/docker/run_python.sh index 84ec092..786e0e2 100644 --- a/examples/docker/run_python.sh +++ b/examples/docker/run_python.sh @@ -42,11 +42,13 @@ function cleanURL() { } function validateURL() { - match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" -H "user_key: ${API_KEY}" | grep -o "Rosette API") - if [ "${match}" = "" ]; then - echo -e "\n${ping_url} server not responding\n" + output_file=validate_url_out.log + http_status_code=$(curl -s -o "${output_file}" -w "%{http_code}" -H "X-RosetteAPI-Key: ${API_KEY}" "${ping_url}/ping") + if [ "${http_status_code}" != "200" ]; then + echo -e "\n${ping_url} server not responding. Output is:\n" + cat "${output_file}" exit 1 - fi + fi } function runExample() { From 8ce14234144dbe2e0c8ad923d922d1d661446999 Mon Sep 17 00:00:00 2001 From: seth-basistech Date: Mon, 11 Feb 2019 14:58:55 -0600 Subject: [PATCH 114/247] DEVOPS-210: Review for migration to twine. (#88) * Tell PyPi we're using markdown for rendering. * An email address that works. * Github as homepage. * Move developer.rosette.com references to the top of the README. * The package is stable. * semantics endpoints in README. * PyPi badge. * Bump travis to xenial * Issue id for Python 3.7 support * Copyright years --- .travis.yml | 5 ++++ LICENSE.txt | 2 +- README.md | 26 ++++++++++---------- docs/source/conf.py | 2 +- rosette/__init__.py | 2 +- rosette/api.py | 2 +- setup.py | 52 ++++++++++++++++++++++----------------- tests/__init__.py | 2 +- tests/test_rosette_api.py | 2 +- 9 files changed, 54 insertions(+), 41 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a85dd5..68b6589 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,9 @@ language: python +dist: xenial +# Reflect version changes in setup.py classifiers +# 2.7 EOL - January 2020 +# 3.4 EOL - March 2019 +# RCB-562 for 3.7 support python: - "2.7" - "3.4" diff --git a/LICENSE.txt b/LICENSE.txt index 8e1eca0..5723e02 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2014-2016 Basis Technology Corporation. +Copyright (c) 2014-2019 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 60462a6..a948bd1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) +[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette_api.svg)](https://badge.fury.io/py/rosette_api) ## This is the Python client binding for Rosette API. -Please check out the [wiki](https://github.com/rosette-api/python/wiki) for additional information +You can get an API Key and learn more [here](https://developer.rosette.com). +For more detailed information check out our [features and functions page](https://developer.rosette.com/features-and-functions). ### Installation @@ -33,28 +34,27 @@ For help in how to call the various endpoints, please refer to the [examples](ht - name translation - ping - relationships +- semantic similarity +- semantic vectors - sentences - sentiment - syntax dependencies -- text embedding - tokens - topics - transliteration +### API Documentation +See [documentation](http://rosette-api.github.io/python) + +### Release Notes +See [wiki](https://github.com/rosette-api/python/wiki/Release-Notes) + ### Docker A Docker image for running the examples against the compiled source library is available on Docker Hub. Command: `docker run -e API_KEY=api-key -v ":/source" rosetteapi/docker-python` Additional environment settings: -`-e ALT_URL=` -`-e FILENAME=` - -### API Documentation -See [documentation](http://rosette-api.github.io/python) - -### Release Notes -See [wiki](https://github.com/rosette-api/python/wiki/Release-Notes) +- `-e ALT_URL=` +- `-e FILENAME=` -### Additional Information -Visit [Rosette API site](https://developer.rosette.com) diff --git a/docs/source/conf.py b/docs/source/conf.py index 58fd9b9..87f7fcc 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -47,7 +47,7 @@ # General information about the project. project = '' -copyright = '2017, Basis Technology' +copyright = '2019, Basis Technology' author = 'Basis Technology' # The version info for the project you're documenting, acts as replacement for diff --git a/rosette/__init__.py b/rosette/__init__.py index b04d320..fff5933 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -1,6 +1,6 @@ """ Python client for the Rosette API. -Copyright (c) 2014-2015 Basis Technology Corporation. +Copyright (c) 2014-2019 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at diff --git a/rosette/api.py b/rosette/api.py index 2c76b33..892fb7e 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -3,7 +3,7 @@ """ Python client for the Rosette API. -Copyright (c) 2014-2017 Basis Technology Corporation. +Copyright (c) 2014-2019 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index 0a8f59b..10a57e0 100755 --- a/setup.py +++ b/setup.py @@ -8,8 +8,8 @@ NAME = "rosette_api" DESCRIPTION = "Rosette API Python client SDK" AUTHOR = "Basis Technology Corp." -AUTHOR_EMAIL = "rosette_api@basistech.com" -HOMEPAGE = "https://developer.rosette.com" +AUTHOR_EMAIL = "support@rosette.com" +HOMEPAGE = "https://github.com/rosette-api/python" VERSION = rosette.__version__ HERE = os.path.abspath(os.path.dirname(__file__)) @@ -28,23 +28,31 @@ def read(*filenames, **kwargs): LONG_DESCRIPTION = read('README.md') -setup(name=NAME, - author=AUTHOR, - author_email=AUTHOR_EMAIL, - description=DESCRIPTION, - license='Apache License', - long_description=LONG_DESCRIPTION, - packages=['rosette'], - install_requires=['requests'], - platforms='any', - url=HOMEPAGE, - version=VERSION, - classifiers=[ - 'Programming Language :: Python', - 'Development Status :: 4 - Beta', - 'Natural Language :: English', - 'Environment :: Web Environment', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Topic :: Software Development :: Libraries :: Python Modules']) +setup( + name=NAME, + author=AUTHOR, + author_email=AUTHOR_EMAIL, + description=DESCRIPTION, + license='Apache License', + long_description=LONG_DESCRIPTION, + long_description_content_type='text/markdown', + packages=['rosette'], + install_requires=['requests'], + platforms='any', + url=HOMEPAGE, + version=VERSION, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Topic :: Software Development :: Libraries :: Python Modules' + ] +) diff --git a/tests/__init__.py b/tests/__init__.py index d96e183..9d1fe1d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Copyright (c) 2014-2017 Basis Technology Corporation. +Copyright (c) 2014-2019 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index cd0611f..256283a 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Copyright (c) 2014-2017 Basis Technology Corporation. +Copyright (c) 2014-2019 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 951a1dd7ab5f64d3b94bde4dd2d9a0f8b3a58b5c Mon Sep 17 00:00:00 2001 From: seth-basistech Date: Mon, 11 Feb 2019 15:53:29 -0600 Subject: [PATCH 115/247] fix pypi badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a948bd1..74115ce 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette_api.svg)](https://badge.fury.io/py/rosette_api) +[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) ## This is the Python client binding for Rosette API. You can get an API Key and learn more [here](https://developer.rosette.com). From ad3beaaaf516c6d471503e4da9e87b5ead556bf9 Mon Sep 17 00:00:00 2001 From: seth-basistech Date: Wed, 8 May 2019 11:13:18 -0500 Subject: [PATCH 116/247] Add Python versions badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 74115ce..d0a4343 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) +[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) ## This is the Python client binding for Rosette API. You can get an API Key and learn more [here](https://developer.rosette.com). From 5fa7e8ee886223a6586b0aa4138daa942eb6252e Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 17 May 2019 17:32:27 -0500 Subject: [PATCH 117/247] RCB-562: Tests work with 3.7. --- .travis.yml | 2 +- setup.py | 1 + tests/test_rosette_api.py | 56 +++++++++++++++++++-------------------- tox.ini | 2 +- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 68b6589..b841de1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ dist: xenial # Reflect version changes in setup.py classifiers # 2.7 EOL - January 2020 # 3.4 EOL - March 2019 -# RCB-562 for 3.7 support python: - "2.7" - "3.4" - "3.5" - "3.6" + - "3.7" install: - pip install tox script: diff --git a/setup.py b/setup.py index 10a57e0..edd7e16 100755 --- a/setup.py +++ b/setup.py @@ -53,6 +53,7 @@ def read(*filenames, **kwargs): 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 256283a..ca14c90 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -36,7 +36,7 @@ @pytest.fixture def json_response(): """ fixture to return info body""" - body = json.dumps({'name': 'Rosette API', 'versionChecked': True}) + body = json.dumps({'name': 'Rosette', 'versionChecked': True}) return body @@ -151,7 +151,7 @@ def test_ping(api, json_response): body=json_response, status=200, content_type="application/json") result = api.ping() - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -165,7 +165,7 @@ def test_info(api, json_response): body=json_response, status=200, content_type="application/json") result = api.info() - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -200,7 +200,7 @@ def test_the_max_pool_size(json_response, doc_params): api = API('bogus_key') assert api.get_pool_size() == 1 result = api.language(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" assert api.get_pool_size() == 5 httpretty.disable() httpretty.reset() @@ -217,7 +217,7 @@ def test_the_language_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.language(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -233,7 +233,7 @@ def test_the_sentences_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.sentences(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -249,7 +249,7 @@ def test_the_tokens_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.tokens(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -265,7 +265,7 @@ def test_the_morphology_complete_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -281,7 +281,7 @@ def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'lemmas') - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -297,7 +297,7 @@ def test_the_morphology_parts_of_speech_endpoint(api, json_response, doc_params) body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'parts-of-speech') - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -313,7 +313,7 @@ def test_the_morphology_compound_components_endpoint(api, json_response, doc_par body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'compound-components') - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -329,7 +329,7 @@ def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'han-readings') - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -345,7 +345,7 @@ def test_the_entities_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.entities(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -361,7 +361,7 @@ def test_the_categories_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.categories(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -377,7 +377,7 @@ def test_the_sentiment_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.sentiment(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -396,7 +396,7 @@ def test_the_multipart_operation(api, json_response, doc_params, tmpdir): tmp_file.write(json_response) doc_params.load_document_file = tmp_file result = api.sentiment(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -417,7 +417,7 @@ def test_the_name_translation_endpoint(api, json_response): params["targetLanguage"] = "eng" params["targetScript"] = "Latn" result = api.name_translation(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -442,7 +442,7 @@ def test_the_name_similarity_endpoint(api, json_response): params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} result = api.name_similarity(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -468,7 +468,7 @@ def test_name_deduplicatation_parameters(api, json_response): params["names"] = ["John Smith", "Johnathon Smith", "Fred Jones"] result = api.name_deduplication(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -489,7 +489,7 @@ def test_the_name_deduplication_endpoint(api, json_response): params["threshold"] = threshold result = api.name_deduplication(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -508,7 +508,7 @@ def test_the_relationships_endpoint(api, json_response): params["content"] = "some text data" api.set_option('accuracyMode', 'PRECISION') result = api.relationships(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -606,7 +606,7 @@ def test_for_name_similarity_required_parameters(api, json_response): params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} result = api.name_similarity(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -643,7 +643,7 @@ def test_for_name_translation_required_parameters(api, json_response): params["targetLanguage"] = "eng" result = api.name_translation(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -656,7 +656,7 @@ def test_the_semantic_vectors_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.semantic_vectors(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -668,7 +668,7 @@ def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.syntax_dependencies(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -686,7 +686,7 @@ def test_the_transliteration_endpoint(api, json_response): params = DocumentParameters() params["content"] = "Some test content" result = api.transliteration(params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -702,7 +702,7 @@ def test_the_topics_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.topics(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() @@ -717,6 +717,6 @@ def test_the_similar_terms_endpoint(api, json_response, doc_params): api.set_option("resultLanguages", ["spa", "jpn", "deu"]) result = api.similar_terms(doc_params) - assert result["name"] == "Rosette API" + assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() diff --git a/tox.ini b/tox.ini index 16c1f23..249a088 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,6 @@ deps = pytest pep8 pytest-pep8 - httpretty==0.8.14 + httpretty epydoc requests From 4a5efa702c619df9469d69fc6403e98f17ab06d0 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 4 Jun 2019 16:40:57 -0400 Subject: [PATCH 118/247] SUPPO-1256: Doc clean up first pass. --- DEVELOPER.md | 0 README.md | 79 ++++++++++++++++++---------------------------------- 2 files changed, 27 insertions(+), 52 deletions(-) create mode 100644 DEVELOPER.md diff --git a/DEVELOPER.md b/DEVELOPER.md new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index d0a4343..6303596 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,35 @@ -[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) - -## This is the Python client binding for Rosette API. -You can get an API Key and learn more [here](https://developer.rosette.com). -For more detailed information check out our [features and functions page](https://developer.rosette.com/features-and-functions). - -### Installation +[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) +[![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) +[![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) -The Python binding requires Python 2.7+ or 3.4+ and is available through pip: +--- +:/source" rosetteapi/docker-python` +#### Documentation & Support +- [Binding API](https://rosette-api.github.io/python/) +- [Rosette Platform API](https://developer.rosette.com/features-and-functions) +- [Release Notes](https://github.com/rosette-api/python/wiki/Release-Notes) +- [Binding/Platform Compatibility](https://developer.rosette.com/features-and-functions?python#) +- [Support](https://support.rosette.com) -Additional environment settings: -- `-e ALT_URL=` -- `-e FILENAME=` +## Rosette API Access +- Rosette Cloud [Sign Up](https://developer.rosette.com/signup) +- Rosette Enterprise [Evaluation](https://www.rosette.com/product-eval/) +## Developer Information +If you are modifying the binding code, please refer to the [developer README](https://github.com/rosette-api/python/tree/develop/DEVELOPER.md) file. From 48cc94ff308f7205032c925bc77ea94b34f24238 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 4 Jun 2019 16:44:09 -0400 Subject: [PATCH 119/247] SUPPO-1256: Missing quote. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6303596..a9635a1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) --- - ## Rosette API The Rosette Text Analytics Platform uses natural language processing, statistical modeling, and machine learning to @@ -31,5 +31,5 @@ in the [examples](https://github.com/rosette-api/python/tree/develop/examples) d - Rosette Cloud [Sign Up](https://developer.rosette.com/signup) - Rosette Enterprise [Evaluation](https://www.rosette.com/product-eval/) -## Developer Information +## Binding Developer Information If you are modifying the binding code, please refer to the [developer README](https://github.com/rosette-api/python/tree/develop/DEVELOPER.md) file. From 61cb7216ff939d912f1dc9334e66c875f8644ffe Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 4 Jun 2019 16:50:45 -0400 Subject: [PATCH 120/247] SUPPO-1256: Resize logo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9635a1..ef570ff 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) --- - + ## Rosette API The Rosette Text Analytics Platform uses natural language processing, statistical modeling, and machine learning to From 7e39e1ff4bda0e07bb5600be3096e70b81dfbe75 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 4 Jun 2019 16:55:32 -0400 Subject: [PATCH 121/247] SUPPO-1256: Swap logo and badges. Call out binding license. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef570ff..585b09e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ + + +--- + [![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) ---- - - ## Rosette API The Rosette Text Analytics Platform uses natural language processing, statistical modeling, and machine learning to analyze unstructured and semi-structured text across 364 language-encoding-script combinations, revealing valuable @@ -26,6 +27,7 @@ in the [examples](https://github.com/rosette-api/python/tree/develop/examples) d - [Release Notes](https://github.com/rosette-api/python/wiki/Release-Notes) - [Binding/Platform Compatibility](https://developer.rosette.com/features-and-functions?python#) - [Support](https://support.rosette.com) +- [Binding License: Apache 2.0](https://github.com/rosette-api/python/blob/develop/LICENSE.txt) ## Rosette API Access - Rosette Cloud [Sign Up](https://developer.rosette.com/signup) From 63eb1040ded20770c2774974cc3a72992dd7b165 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 7 Jun 2019 10:38:51 -0400 Subject: [PATCH 122/247] SUPPO-1256: Checkpoint. --- DEVELOPER.md | 22 ++++++++++++++++++++++ README.md | 10 +++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index e69de29..100bf23 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -0,0 +1,22 @@ +## Developer Information + +### +Docker +A Docker image for running the examples against the compiled source library is available on Docker Hub. + +Command: docker run -e API_KEY=api-key -v ":/source" rosetteapi/docker-python + +Additional environment settings: + +-e ALT_URL= +-e FILENAME= + + +### Doc README + + +### Examples README + + +### Build Release +... diff --git a/README.md b/README.md index 585b09e..eef028f 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,17 @@ analyze unstructured and semi-structured text across 364 language-encoding-scrip information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and comparing the similarity of names, categorizing and adding linguistic tags to text and more. +## Rosette API Access +- Rosette Cloud [Sign Up](https://developer.rosette.com/signup) +- Rosette Enterprise [Evaluation](https://www.rosette.com/product-eval/) + ## Quick Start #### Installation `pip install rosette_api` #### Examples -There is an example call for each Rosette endpoint, using this binding, +View small example programs for each Rosette endpoint in the [examples](https://github.com/rosette-api/python/tree/develop/examples) directory. #### Documentation & Support @@ -29,9 +33,5 @@ in the [examples](https://github.com/rosette-api/python/tree/develop/examples) d - [Support](https://support.rosette.com) - [Binding License: Apache 2.0](https://github.com/rosette-api/python/blob/develop/LICENSE.txt) -## Rosette API Access -- Rosette Cloud [Sign Up](https://developer.rosette.com/signup) -- Rosette Enterprise [Evaluation](https://www.rosette.com/product-eval/) - ## Binding Developer Information If you are modifying the binding code, please refer to the [developer README](https://github.com/rosette-api/python/tree/develop/DEVELOPER.md) file. From d9f44869da41ab34433a2c51dc94a66e1eaddb35 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 10 Jun 2019 12:19:22 -0500 Subject: [PATCH 123/247] SUPPO-1256: Add platform release notes. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eef028f..6005c81 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ in the [examples](https://github.com/rosette-api/python/tree/develop/examples) d #### Documentation & Support - [Binding API](https://rosette-api.github.io/python/) - [Rosette Platform API](https://developer.rosette.com/features-and-functions) -- [Release Notes](https://github.com/rosette-api/python/wiki/Release-Notes) +- [Binding Release Notes](https://github.com/rosette-api/python/wiki/Release-Notes) +- [Platform Release Notes](https://support.rosette.com/hc/en-us/articles/360018354971-Release-Notes) - [Binding/Platform Compatibility](https://developer.rosette.com/features-and-functions?python#) - [Support](https://support.rosette.com) - [Binding License: Apache 2.0](https://github.com/rosette-api/python/blob/develop/LICENSE.txt) From 3ef949b16ba0f796cdc4609e8dd0df79f71203b0 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 10 Jun 2019 14:23:50 -0500 Subject: [PATCH 124/247] SUPPO-1256: Another small tweak. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6005c81..a15f1e3 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ in the [examples](https://github.com/rosette-api/python/tree/develop/examples) d - [Binding API](https://rosette-api.github.io/python/) - [Rosette Platform API](https://developer.rosette.com/features-and-functions) - [Binding Release Notes](https://github.com/rosette-api/python/wiki/Release-Notes) -- [Platform Release Notes](https://support.rosette.com/hc/en-us/articles/360018354971-Release-Notes) -- [Binding/Platform Compatibility](https://developer.rosette.com/features-and-functions?python#) +- [Rosette Platform Release Notes](https://support.rosette.com/hc/en-us/articles/360018354971-Release-Notes) +- [Binding/Rosette Platform Compatibility](https://developer.rosette.com/features-and-functions?python#) - [Support](https://support.rosette.com) - [Binding License: Apache 2.0](https://github.com/rosette-api/python/blob/develop/LICENSE.txt) From 8397ffea68af539bf2a13dfe17ea5849a2eac027 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 10 Jun 2019 17:52:28 -0500 Subject: [PATCH 125/247] SUPPO-1256: Wrap up Developer README. Clean up examples README. --- DEVELOPER.md | 52 +++++++++++++++++-------- examples/README.md | 94 ++++++++++++++++++++++++---------------------- 2 files changed, 86 insertions(+), 60 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 100bf23..f605739 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -1,22 +1,42 @@ ## Developer Information -### -Docker -A Docker image for running the examples against the compiled source library is available on Docker Hub. - -Command: docker run -e API_KEY=api-key -v ":/source" rosetteapi/docker-python - -Additional environment settings: - --e ALT_URL= --e FILENAME= - - -### Doc README - +### Testing +To test changes you have made to the binding, you can use a pre-configured Docker environment. This environment will: +- Compile the binding within the container. +- Install the binding within the container. +- Execute one or more example files using the installed binding. +- The example files can be executed against a Cloud release or an Enterprise release. +- If a test suite exists, it will also be executed. + +``` +git clone git@github.com:rosette-api/python.git +cd python +# Modify the binding... +docker run -e API_KEY=$API_KEY -v $(pwd):/source rosetteapi/docker-python +``` + +Optional parameters for the `docker run` execution are: + +- `-e ALT_URL=` + - For testing against an Enterprise environment or the staging environment. +- `-e FILENAME=` + - For testing a single example file instead of all the example files. + +To alter the behavior of the pre-configured Docker environment, you can see the Dockerfile source and entry-point +script [here](https://git.basistech.net/raas/rapid-development-tools/tree/master/binding-dockerfiles). + +### Documentation Generation +The existing README for documentation generation is [here](docs/README.md). +The next time the API documentation is touched, please refresh the README and migrate it here. ### Examples README +There's an old [Docker README](examples/docker) in the examples directory that might be a candidate for removal. +### Building A Release +See the [instructions](https://git.basistech.net/raas/rapid-development-tools/tree/master/publish) -### Build Release -... +### TODOs +- Inconsistent references with `rosette_api` and `rosette-api` +- Doc generation README cleanup? +- Example Docker file still needed? +- `docker-compose.yaml` still needed? diff --git a/examples/README.md b/examples/README.md index 10fed1a..052bb67 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,44 +1,50 @@ -Python Examples -================== - -These examples are scripts that can be run independently to demonstrate the Rosette API functionality. - -Prerequisite: Either run `pip install rosette_api` or run `python setup.py install` in the python top level folder. - -Alternatively, you can run all the examples with the command line: -`find -maxdepth 1 -name "*.py" -exec tox -- {} --key api-key --url alternate_url \;` - -You can now run your desired _endpoint_.py file to see it in action. -For example, run `python/examples/categories.py` if you want to see the categories -functionality demonstrated. - -All files require you to input your Rosette API User Key after --key to run. -For example: `python ping.py --key 1234567890` -All also allow you to input your own service URL if desired. -For example: `python ping.py --key 1234567890 --service_url http://www.myurl.com` -Some (specified below) allow an additional input of either a file (.html or .txt) or a URL with `--file` or `--url` - -Each example, when run, prints its output to the console. - -| File Name | What it does | -| ------------- |------------- | -| categories.py | Gets the category of a document at a URL | -| entities.py | Gets the entities from a piece of text | -| info.py | Gets information about Rosette API | -| language.py | Gets the language of a piece of text | -| matched-name.py | Gets the similarity score of two names | -| morphology_complete.py | Gets the complete morphological analysis of a piece of text| -| morphology_compound-components.py | Gets the de-compounded words from a piece of text | -| morphology_han-readings.py | Gets the Chinese words from a piece of text | -| morphology_lemmas.py | Gets the lemmas of words from a piece of text | -| morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text | -| name_deduplication.py | De-duplicates a list of names | -| ping.py | Pings the Rosette API to check for reachability | -| relationships.py | Gets the relationships between entities from a piece of text | -| sentences.py | Gets the sentences from a piece of text | -| sentiment.py | Gets the sentiment of a local file | -| tokens.py | Gets the tokens (words) from a piece of text | -| topics.py | Returns key phrases and concepts from provided content | -| translated-name.py | Translates a name from one language to another | -| transliteration.py | Transliterates the given text | - +## Endpoint Examples + +Each example file demonstrates one of the capabilities of the Rosette Platform. + +Here are some methods for running the examples. Each example will also accept an optional `--url` parameter for +overriding the default URL. + +A note on pre-requisites. Rosette API only supports TLS 1.2 so ensure your toolchain also supports it. + +#### Virtualenv/Latest Release +``` +git clone git@github.com:rosette-api/python.git +cd python/examples +virtualenv rosette_venv +source rosette_venv/bin/activate +pip install rosette_api +python ping.py -k $API_KEY +``` + +#### Virtualenv/Local Source +``` +git clone git@github.com:rosette-api/python.git +cd python +virtualenv rosette_venv +source rosette_venv/bin/activate +python setup.py install +cd examples +python ping.py -k $API_KEY +``` + +#### Docker/Latest Release +``` +git clone git@github.com:rosette-api/python.git +cd python/examples +docker run -it -v $(pwd):/source --entrypoint bash python:3.6-slim +cd /source +pip install rosette_api +python ping.py -k $API_KEY +``` + +#### Docker/Local Source +``` +git clone git@github.com:rosette-api/python.git +cd python +docker run -it -v $(pwd):/source --entrypoint bash python:3.6-slim +cd /source +python setup.py install +cd examples +python ping.py -k $API_KEY +``` From 4fd0f2e7ece23e7f557a20597c4464ef5ac08c23 Mon Sep 17 00:00:00 2001 From: Kathy Czeck Date: Wed, 12 Jun 2019 16:58:32 -0400 Subject: [PATCH 126/247] fixed typo --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 052bb67..5928376 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,7 +5,7 @@ Each example file demonstrates one of the capabilities of the Rosette Platform. Here are some methods for running the examples. Each example will also accept an optional `--url` parameter for overriding the default URL. -A note on pre-requisites. Rosette API only supports TLS 1.2 so ensure your toolchain also supports it. +A note on prerequisites. Rosette API only supports TLS 1.2 so ensure your toolchain also supports it. #### Virtualenv/Latest Release ``` From b4837491e8c528fc1b1a22bc2034c3fc53b2b02c Mon Sep 17 00:00:00 2001 From: Katsuya Tomioka Date: Thu, 24 Oct 2019 09:44:36 -0400 Subject: [PATCH 127/247] DEVOPS-247: add address-similarity --- docs/source/conf.py | 4 ++-- examples/address_similarity.py | 38 ++++++++++++++++++++++++++++++++++ rosette/__init__.py | 2 +- rosette/api.py | 38 +++++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 examples/address_similarity.py diff --git a/docs/source/conf.py b/docs/source/conf.py index 87f7fcc..8fd66eb 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.12.1' +version = '1.14.3' # The full version, including alpha/beta/rc tags. -release = '1.12.1' +release = '1.14.3' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/examples/address_similarity.py b/examples/address_similarity.py new file mode 100644 index 0000000..5da72bd --- /dev/null +++ b/examples/address_similarity.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Example code to call Rosette API to get match score (similarity) of two addresses. +""" +from __future__ import print_function + +import argparse +import json +import os + +from rosette.api import API, AddressSimilarityParameters, 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) + + params = AddressSimilarityParameters() + params["address1"] = {"city": "Cambridge", "state": "MA"} + params["address2"] = {"city": "cambridge", "state": "massachusetts"} + try: + return api.address_similarity(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(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) diff --git a/rosette/__init__.py b/rosette/__init__.py index fff5933..c6d8f0c 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.12.1' +__version__ = '1.14.3' diff --git a/rosette/api.py b/rosette/api.py index 892fb7e..6fb6c59 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import requests import platform -_BINDING_VERSION = '1.12.1' +_BINDING_VERSION = '1.14.3' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 @@ -246,6 +246,32 @@ def validate(self): repr(option)) +class AddressSimilarityParameters(_DocumentParamSetBase): + """Parameter object for C{address-similarity} endpoint. + All are required. + + C{address1} The address to be matched, a C{address} object. + + C{address2} The address to be matched, a C{address} object. + + The C{address} object contains these optional fields: + city, island, district, stateDistrict, state, countryRegion, country, worldRegion, postCode, poBox + """ + + def __init__(self): + self.use_multipart = False + _DocumentParamSetBase.__init__(self, ("address1", "address2")) + + def validate(self): + """Internal. Do not use.""" + for option in ("address1", "address2"): # required + if self[option] is None: + raise RosetteException( + "missingParameter", + "Required Address Similarity parameter, " + option + ", not supplied", + repr(option)) + + class NameSimilarityParameters(_DocumentParamSetBase): """Parameter object for C{name-similarity} endpoint. All are required. @@ -550,6 +576,7 @@ def __init__( } self.endpoints = { + 'ADDRESS_SIMILARITY': 'address-similarity', 'CATEGORIES': 'categories', 'ENTITIES': 'entities', 'INFO': 'info', @@ -879,6 +906,15 @@ def relationships(self, parameters): @return: A python dictionary containing the results of relationship extraction.""" return EndpointCaller(self, self.endpoints['RELATIONSHIPS']).call(parameters) + def address_similarity(self, parameters): + """ + Create an L{EndpointCaller} to perform address similarity scoring and call it. + @param parameters: An object specifying the data, + 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) + def name_translation(self, parameters): """ Create an L{EndpointCaller} to perform name analysis and translation From c32c6949c5f59dd3219048a7ff6337401a61c10c Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 29 Oct 2019 15:43:00 -0500 Subject: [PATCH 128/247] NO-JIRA: Remove example docker files. --- examples/docker/Dockerfile | 34 ----------- examples/docker/README.md | 14 ----- examples/docker/run_python.sh | 111 ---------------------------------- 3 files changed, 159 deletions(-) delete mode 100644 examples/docker/Dockerfile delete mode 100644 examples/docker/README.md delete mode 100644 examples/docker/run_python.sh diff --git a/examples/docker/Dockerfile b/examples/docker/Dockerfile deleted file mode 100644 index 8ff8899..0000000 --- a/examples/docker/Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -FROM python -MAINTAINER Chris Park -LABEL SOURCE="https://github.com/rosette-api/python/blob/develop/examples/docker/Dockerfile" -LABEL VERSION="1.7.1" -ENV LANGUAGE=python - -ENV LANG en_US.UTF-8 - -RUN apt-get update && \ - apt-get -y install \ - wget \ - curl \ - libssl-dev \ - libffi-dev \ - git \ - vim && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -# required for pip to run as non-root -RUN mkdir -p /.cache && chmod 777 /.cache -RUN mkdir -p /.local && chmod 777 /.local - -RUN pip install --upgrade tox -RUN pip install --upgrade autopep8 requests rosette_api - -COPY run_python.sh /python/examples/run_python.sh -RUN chmod 755 /python/examples/run_python.sh -WORKDIR /python/examples - -# allow interactive bash inside docker container -CMD ./run_python.sh - -VOLUME ["/source"] diff --git a/examples/docker/README.md b/examples/docker/README.md deleted file mode 100644 index 8335d53..0000000 --- a/examples/docker/README.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -# Docker Image for Python Examples ---- -### Summary -To simplify the running of the Python examples, the Dockerfile will build an image and install the latest rosette-api library. - -### Basic Usage -Build the docker image, e.g. `docker build -t basistech/python:1.1 .` - -Run an example as `docker run -e API_KEY=api-key -v "path-to-example-source:/source" basistech/python:1.1` - -To test against a specific source file, add `-e FILENAME=filename` before the `-v` - -Also, to test against an alternate url, add `-e ALT_URL=alternate_url` before the `-v` \ No newline at end of file diff --git a/examples/docker/run_python.sh b/examples/docker/run_python.sh deleted file mode 100644 index 786e0e2..0000000 --- a/examples/docker/run_python.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/bash - -retcode=0 -ping_url="https://api.rosette.com/rest/v1" -errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" ) - -#------------------ Functions ---------------------------------------------------- - -#Gets called when the user doesn't provide any args -function HELP { - echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]" - echo " API_KEY - Rosette API key (required)" - echo " FILENAME - Python source file (optional)" - echo " ALT_URL - Alternate service URL (optional)" - echo "Compiles and runs the source file(s) using the published rosette-api" - exit 1 -} - -if [ ! -z ${ALT_URL} ]; then - ping_url=${ALT_URL} -fi - -#Checks if Rosette API key is valid -function checkAPI() { - match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden") - if [ ! -z $match ]; then - echo -e "\nInvalid Rosette API Key" - exit 1 - fi -} - -function cleanURL() { - # strip the trailing slash off of the alt_url if necessary - if [ ! -z "${ALT_URL}" ]; then - case ${ALT_URL} in - */) ALT_URL=${ALT_URL::-1} - echo "Slash detected" - ;; - esac - ping_url=${ALT_URL} - fi -} - -function validateURL() { - output_file=validate_url_out.log - http_status_code=$(curl -s -o "${output_file}" -w "%{http_code}" -H "X-RosetteAPI-Key: ${API_KEY}" "${ping_url}/ping") - if [ "${http_status_code}" != "200" ]; then - echo -e "\n${ping_url} server not responding. Output is:\n" - cat "${output_file}" - exit 1 - fi -} - -function runExample() { - echo -e "\n---------- ${1} start -------------" - result="" - if [ -z ${ALT_URL} ]; then - result="$(python ${1} --key ${API_KEY} 2>&1 )" - else - result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )" - fi - echo "${result}" - echo -e "\n---------- ${1} end -------------" - for err in "${errors[@]}"; do - if [[ ${result} == *"${err}"* ]]; then - retcode=1 - fi - done -} - -#------------------ Functions End ------------------------------------------------ - -#Gets API_KEY, FILENAME and ALT_URL if present -while getopts ":API_KEY:FILENAME:ALT_URL" arg; do - case "${arg}" in - API_KEY) - API_KEY=${OPTARG} - ;; - FILENAME) - FILENAME=${OPTARG} - ;; - ALT_URL) - ALT_URL=${OPTARG} - ;; - esac -done - -cleanURL - -validateURL - -#Copy the examples from the mounted content in /source to current WORKDIR -cp /source/examples/*.* . - -#Run the examples -if [ ! -z ${API_KEY} ]; then - checkAPI - if [ ! -z ${FILENAME} ]; then - echo -e "\nRunning example against: ${ping_url}\n" - runExample ${FILENAME} - else - echo -e "\nRunning examples against: ${ping_url}\n" - for file in *.py; do - runExample ${file} - done - fi -else - HELP -fi - -exit ${retcode} From b1253b4206b0da5e37dbb1c1376f967548855197 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 30 Oct 2019 16:08:51 -0500 Subject: [PATCH 129/247] NO-JIRA: Try 3.8 with Travis. --- .travis.yml | 1 + setup.py | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index b841de1..e0a39f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ python: - "3.5" - "3.6" - "3.7" + - "3.8" install: - pip install tox script: diff --git a/setup.py b/setup.py index edd7e16..d9b6755 100755 --- a/setup.py +++ b/setup.py @@ -54,6 +54,7 @@ def read(*filenames, **kwargs): 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) From b97dd17f60df4ef6a4e536d2e2d878c8102ef6c6 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 7 Nov 2019 16:53:56 -0600 Subject: [PATCH 130/247] Update example data. --- examples/address_similarity.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/address_similarity.py b/examples/address_similarity.py index 5da72bd..c693aac 100644 --- a/examples/address_similarity.py +++ b/examples/address_similarity.py @@ -17,8 +17,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): api = API(user_key=key, service_url=alt_url) params = AddressSimilarityParameters() - params["address1"] = {"city": "Cambridge", "state": "MA"} - params["address2"] = {"city": "cambridge", "state": "massachusetts"} + params["address1"] = {"houseNumber": "1600", "road": "Pennsylvania Ave NW", "city": "Washington", "state": "DC", "postCode": "20500"} + params["address2"] = {"houseNumber": "160", "road": "Pennsilvana Avenue", "city": "Washington", "state": "D.C.", "postCode": "20500"} + try: return api.address_similarity(params) except RosetteException as exception: From a3ac82e9677a701878348c4cf25a7b3ffd8f1e2f Mon Sep 17 00:00:00 2001 From: Ian Redpath Date: Mon, 8 Jun 2020 14:51:38 -0400 Subject: [PATCH 131/247] RLPNC-5319: update example, support unfielded addresses --- examples/address_similarity.py | 2 +- rosette/api.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/address_similarity.py b/examples/address_similarity.py index c693aac..9ffe3a6 100644 --- a/examples/address_similarity.py +++ b/examples/address_similarity.py @@ -18,7 +18,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): params = AddressSimilarityParameters() params["address1"] = {"houseNumber": "1600", "road": "Pennsylvania Ave NW", "city": "Washington", "state": "DC", "postCode": "20500"} - params["address2"] = {"houseNumber": "160", "road": "Pennsilvana Avenue", "city": "Washington", "state": "D.C.", "postCode": "20500"} + params["address2"] = "160 Pennsilvana Avenue, Washington, D.C., 20500" try: return api.address_similarity(params) diff --git a/rosette/api.py b/rosette/api.py index 6fb6c59..897aaf7 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -250,9 +250,9 @@ class AddressSimilarityParameters(_DocumentParamSetBase): """Parameter object for C{address-similarity} endpoint. All are required. - C{address1} The address to be matched, a C{address} object. + C{address1} The address to be matched, a C{address} object or address string. - C{address2} The address to be matched, a C{address} object. + C{address2} The address to be matched, a C{address} object or address string. The C{address} object contains these optional fields: city, island, district, stateDistrict, state, countryRegion, country, worldRegion, postCode, poBox @@ -455,7 +455,8 @@ def call(self, parameters): 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['NAME_DEDUPLICATION'] \ + and self.suburl != self.api.self.api.endpoints['ADDRESS_SIMILARITY']: text = parameters parameters = DocumentParameters() parameters['content'] = text From 69ef90f3133408519895fceb571460a541720f91 Mon Sep 17 00:00:00 2001 From: Joe Ho Date: Tue, 9 Jun 2020 17:03:16 -0400 Subject: [PATCH 132/247] Remove python 3.4 support --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index d9b6755..017af14 100755 --- a/setup.py +++ b/setup.py @@ -50,7 +50,6 @@ def read(*filenames, **kwargs): 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', From 4e7470ce1fd58cdec1756467173a09e5391b81b8 Mon Sep 17 00:00:00 2001 From: Joe Ho Date: Tue, 9 Jun 2020 17:03:38 -0400 Subject: [PATCH 133/247] Remove python 3.4 support --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e0a39f7..7128c50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ dist: xenial # 3.4 EOL - March 2019 python: - "2.7" - - "3.4" - "3.5" - "3.6" - "3.7" From 6a0d4712ff4297dc4cd9457ba8d3e71b89b91cca Mon Sep 17 00:00:00 2001 From: "jkho@basistech.com" Date: Tue, 16 Jun 2020 23:45:25 +0000 Subject: [PATCH 134/247] Version 1.14.4 --- 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 8fd66eb..2e30ba6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.14.3' +version = '1.14.4' # The full version, including alpha/beta/rc tags. -release = '1.14.3' +release = '1.14.4' # 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 c6d8f0c..544db30 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.14.3' +__version__ = '1.14.4' diff --git a/rosette/api.py b/rosette/api.py index 897aaf7..887cede 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,7 +28,7 @@ import requests import platform -_BINDING_VERSION = '1.14.3' +_BINDING_VERSION = '1.14.4' _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 From 13a931726d32803eee7ba902c4987267b1a569a3 Mon Sep 17 00:00:00 2001 From: Katsuya Tomioka Date: Tue, 14 Dec 2021 17:23:32 -0500 Subject: [PATCH 135/247] RCB-596: expose set_pool_size; remove pep8 plugin from pytest --- pytest.ini | 3 +-- rosette/api.py | 11 +++++------ tests/tox.ini | 3 +-- tox.ini | 3 +-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pytest.ini b/pytest.ini index fc6bcc6..b37e476 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,4 @@ [pytest] -pep8ignore = E501 norecursedirs = .tox - target \ No newline at end of file + target diff --git a/rosette/api.py b/rosette/api.py index 887cede..ab7dbeb 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -613,9 +613,10 @@ def get_user_agent_string(self): """ Return the User-Agent string """ return self.user_agent_string - def _set_pool_size(self): + def set_pool_size(self, new_pool_size): + self.max_pool_size = new_pool_size adapter = requests.adapters.HTTPAdapter( - pool_maxsize=self.max_pool_size) + pool_maxsize=new_pool_size) if 'https:' in self.service_url: self.session.mount('https://', adapter) else: @@ -651,10 +652,8 @@ def _make_request(self, operation, url, data, headers): rdata = response.content dict_headers = dict(response.headers) response_headers = {"responseHeaders": dict_headers} - if 'x-rosetteapi-concurrency' in dict_headers: - if dict_headers['x-rosetteapi-concurrency'] != self.max_pool_size: - self.max_pool_size = dict_headers['x-rosetteapi-concurrency'] - self._set_pool_size() + if 'x-rosetteapi-concurrency' in dict_headers and dict_headers['x-rosetteapi-concurrency'] != self.max_pool_size: + self.set_pool_size(dict_headers['x-rosetteapi-concurrency']) if status == 200: return rdata, status, response_headers diff --git a/tests/tox.ini b/tests/tox.ini index 9bd4a1b..bdf6e7d 100644 --- a/tests/tox.ini +++ b/tests/tox.ini @@ -4,10 +4,9 @@ envlist = py2, py3 [testenv] commands = - pytest -s --pep8 + pytest -s deps = pytest - pytest-pep8 httpretty epydoc requests diff --git a/tox.ini b/tox.ini index 249a088..23301ee 100644 --- a/tox.ini +++ b/tox.ini @@ -10,11 +10,10 @@ envlist = py2, py3 [testenv] commands = {envpython} setup.py install - {envbindir}/py.test --pep8 + {envbindir}/py.test deps = pytest pep8 - pytest-pep8 httpretty epydoc requests From 73c15244bba82081d6ecce86d4f8b1cf1129b3cf Mon Sep 17 00:00:00 2001 From: Katsuya Tomioka Date: Wed, 15 Dec 2021 13:32:44 -0500 Subject: [PATCH 136/247] RCB-596: fix docstring --- rosette/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rosette/api.py b/rosette/api.py index ab7dbeb..1a0e4fc 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -614,6 +614,9 @@ def get_user_agent_string(self): return self.user_agent_string def set_pool_size(self, new_pool_size): + """Sets the connection pool size. + @parameter new_pool_size: pool size to set + """ self.max_pool_size = new_pool_size adapter = requests.adapters.HTTPAdapter( pool_maxsize=new_pool_size) From 845df6ac6acbeb9d432bee449df3e8b193c0adbe Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 4 Jan 2022 19:18:18 -0600 Subject: [PATCH 137/247] RCB-596: Sonar issues. Add coverage for AddressSimilarity. --- rosette/api.py | 117 ++++++++++++++++---------------------- tests/test_rosette_api.py | 72 +++++++++++++++++------ 2 files changed, 103 insertions(+), 86 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 1a0e4fc..23ce179 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -28,12 +28,16 @@ import requests import platform +_APPLICATION_JSON = 'application/json' +_BINDING_LANGUAGE = 'python' _BINDING_VERSION = '1.14.4' +_CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' +_CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' +_CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX) _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 - if _ISPY3: _GZIP_SIGNATURE = _GZIP_BYTEARRAY else: @@ -49,7 +53,6 @@ def __init__(self, js, code): self.status_code = code def json(self): - """ return json""" return self._json @@ -112,7 +115,7 @@ def serialize(self, options): values = {} for (key, val) in self.__params.items(): if val is None: - pass + continue else: values[key] = val @@ -242,7 +245,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Name Translation parameter, " + option + ", not supplied", + "Required Name Translation parameter is missing: " + option, repr(option)) @@ -268,7 +271,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Address Similarity parameter, " + option + ", not supplied", + "Required Address Similarity parameter is missing: " + option, repr(option)) @@ -301,7 +304,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Name Similarity parameter, " + option + ", not supplied", + "Required Name Similarity parameter is missing: " + option, repr(option)) @@ -321,7 +324,7 @@ def validate(self): if self["names"] is None: # required raise RosetteException( "missingParameter", - "Required Name De-Duplication parameter, names, not supplied", + "Required Name De-Duplication parameter is missing: names", repr("names")) @@ -372,31 +375,37 @@ def __finish_result(self, response, ename): raise RosetteException(code, complaint_url + " : failed to communicate with Rosette", msg) - def info(self): - """Issues an "info" request to the L{EndpointCaller}'s specific endpoint. - @return: A dictionary telling server version and other - identifying data.""" - url = self.service_url + self.api.endpoints["INFO"] - headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', - 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} + def __set_headers(self): + headers = {'Accept': _APPLICATION_JSON, + _CUSTOM_HEADER_PREFIX + 'Binding': _BINDING_LANGUAGE, + _CUSTOM_HEADER_PREFIX + 'Binding-Version': _BINDING_VERSION} custom_headers = self.api.get_custom_headers() - pattern = re.compile('^X-RosetteAPI-') if custom_headers is not None: for key in custom_headers.keys(): - if pattern.match(key) is not None: + if _CUSTOM_HEADER_PATTERN.match(key) is not None: headers[key] = custom_headers[key] else: raise RosetteException("badHeader", - "Custom header name must begin with \"X-RosetteAPI-\"", + "Custom header name must begin with \"" + _CUSTOM_HEADER_PREFIX + "\"", key) self.api.clear_custom_headers() if self.debug: - headers['X-RosetteAPI-Devel'] = 'true' - self.logger.info('info: ' + url) + headers[_CUSTOM_HEADER_PREFIX + 'Devel'] = 'true' + if self.user_key is not None: - headers["X-RosetteAPI-Key"] = self.user_key + headers[_CUSTOM_HEADER_PREFIX + "Key"] = self.user_key + + return headers + + def info(self): + """Issues an "info" request to the L{EndpointCaller}'s specific endpoint. + @return: A dictionary telling server version and other + identifying data.""" + url = self.service_url + self.api.endpoints["INFO"] + headers = self.__set_headers() + self.logger.info('info: ' + url) response = self.api.get_http(url, headers=headers) return self.__finish_result(response, "info") @@ -407,26 +416,8 @@ def ping(self): signalled.""" url = self.service_url + self.api.endpoints['PING'] - headers = {'Accept': 'application/json', 'X-RosetteAPI-Binding': 'python', - 'X-RosetteAPI-Binding-Version': _BINDING_VERSION} - - custom_headers = self.api.get_custom_headers() - pattern = re.compile('^X-RosetteAPI-') - if custom_headers is not None: - for key in custom_headers.keys(): - if pattern.match(key) is not None: - headers[key] = custom_headers[key] - else: - raise RosetteException("badHeader", - "Custom header name must begin with \"X-RosetteAPI-\"", - key) - self.api.clear_custom_headers() - - if self.debug: - headers['X-RosetteAPI-Devel'] = 'true' + headers = self.__set_headers() self.logger.info('Ping: ' + url) - if self.user_key is not None: - headers["X-RosetteAPI-Key"] = self.user_key response = self.api.get_http(url, headers=headers) return self.__finish_result(response, "ping") @@ -454,9 +445,9 @@ def call(self, parameters): 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']: + 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 @@ -471,22 +462,7 @@ def call(self, parameters): params_to_serialize = parameters.serialize(self.api.options) headers = {} if self.user_key is not None: - custom_headers = self.api.get_custom_headers() - pattern = re.compile('^X-RosetteAPI-') - if custom_headers is not None: - for key in custom_headers.keys(): - if pattern.match(key) is not None: - headers[key] = custom_headers[key] - else: - raise RosetteException("badHeader", - "Custom header name must " - "begin with \"X-RosetteAPI-\"", - key) - self.api.clear_custom_headers() - - headers["X-RosetteAPI-Key"] = self.user_key - headers["X-RosetteAPI-Binding"] = "python" - headers["X-RosetteAPI-Binding-Version"] = _BINDING_VERSION + headers = self.__set_headers() if self.use_multipart: payload = None @@ -496,7 +472,7 @@ def call(self, parameters): params = dict( (key, value) for key, - value in params_to_serialize.items() if key == 'language') + value in params_to_serialize.items() if key == 'language') files = { 'content': ( os.path.basename( @@ -506,7 +482,7 @@ def call(self, parameters): 'request': ( 'request_options', json.dumps(params), - 'application/json')} + _APPLICATION_JSON)} request = requests.Request( 'POST', url, files=files, headers=headers, params=payload) prepared_request = self.api.session.prepare_request(request) @@ -519,11 +495,11 @@ def call(self, parameters): _my_loads(rdata, response_headers), status) else: if self.debug: - headers['X-RosetteAPI-Devel'] = True + headers[_CUSTOM_HEADER_PREFIX + 'Devel'] = True self.logger.info('operate: ' + url) - headers['Accept'] = "application/json" + headers['Accept'] = _APPLICATION_JSON headers['Accept-Encoding'] = "gzip" - headers['Content-Type'] = "application/json" + headers['Content-Type'] = _APPLICATION_JSON response = self.api.post_http(url, params_to_serialize, headers) return self.__finish_result(response, "operate") @@ -625,6 +601,10 @@ def set_pool_size(self, new_pool_size): else: self.session.mount('http://', adapter) + def __adjust_concurrency(self, dict_headers): + if _CONCURRENCY_HEADER in dict_headers and dict_headers[_CONCURRENCY_HEADER] != self.max_pool_size: + self.set_pool_size(dict_headers[_CONCURRENCY_HEADER]) + def _make_request(self, operation, url, data, headers): """ @param operation: POST or GET @@ -654,9 +634,8 @@ def _make_request(self, operation, url, data, headers): status = response.status_code rdata = response.content dict_headers = dict(response.headers) + self.__adjust_concurrency(dict_headers) response_headers = {"responseHeaders": dict_headers} - if 'x-rosetteapi-concurrency' in dict_headers and dict_headers['x-rosetteapi-concurrency'] != self.max_pool_size: - self.set_pool_size(dict_headers['x-rosetteapi-concurrency']) if status == 200: return rdata, status, response_headers @@ -672,9 +651,11 @@ def _make_request(self, operation, url, data, headers): if not message: message = rdata raise RosetteException(code, message, url) - - except: - raise + except json.JSONDecodeError as exception: + raise RosetteException( + exception, + "Problem decoding JSON", + rdata) except requests.exceptions.RequestException as exception: raise RosetteException( exception, diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index ca14c90..41c4fc7 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -23,12 +23,12 @@ import platform import httpretty import pytest -from rosette.api import(API, - DocumentParameters, - NameTranslationParameters, - NameSimilarityParameters, - NameDeduplicationParameters, - RosetteException) +from rosette.api import (API, + DocumentParameters, + NameTranslationParameters, + NameSimilarityParameters, + NameDeduplicationParameters, + RosetteException, AddressSimilarityParameters) _ISPY3 = sys.version_info[0] == 3 @@ -118,7 +118,7 @@ def test_custom_header_props(api): assert value == api.get_custom_headers()[key] api.clear_custom_headers() - assert len(api.get_custom_headers()) is 0 + assert len(api.get_custom_headers()) == 0 # Test for invalid header name @@ -460,10 +460,10 @@ def test_name_deduplicatation_parameters(api, json_response): params = NameDeduplicationParameters() with pytest.raises(RosetteException) as e_rosette: - result = api.name_deduplication(params) + api.name_deduplication(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name De-Duplication parameter, names, not supplied' + assert e_rosette.value.message == 'Required Name De-Duplication parameter is missing: names' params["names"] = ["John Smith", "Johnathon Smith", "Fred Jones"] @@ -572,6 +572,43 @@ def test_for_no_content_or_contentUri(api, json_response, doc_params): httpretty.disable() httpretty.reset() + +def test_for_address_similarity_required_parameters(api, json_response): + """Test address 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/address-similarity", + body=json_response, status=200, content_type="application/json") + + params = AddressSimilarityParameters() + + with pytest.raises(RosetteException) as e_rosette: + api.address_similarity(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Address Similarity parameter is missing: address1' + + params["address1"] = {"houseNumber": "1600", + "road": "Pennsylvania Ave NW", + "city": "Washington", + "state": "DC", + "postCode": "20500"} + + with pytest.raises(RosetteException) as e_rosette: + api.address_similarity(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Address Similarity parameter is missing: address2' + + params["address2"] = {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"} + + result = api.address_similarity(params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() + + # Test for required Name Similarity parameters @@ -588,20 +625,20 @@ def test_for_name_similarity_required_parameters(api, json_response): params = NameSimilarityParameters() with pytest.raises(RosetteException) as e_rosette: - result = api.name_similarity(params) + api.name_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Similarity parameter, name1, not supplied' + assert e_rosette.value.message == 'Required Name Similarity parameter is missing: name1' params["name1"] = { "text": matched_name_data1, "language": "eng", "entityType": "PERSON"} with pytest.raises(RosetteException) as e_rosette: - result = api.name_similarity(params) + api.name_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Similarity parameter, name2, not supplied' + assert e_rosette.value.message == 'Required Name Similarity parameter is missing: name2' params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} @@ -626,19 +663,18 @@ def test_for_name_translation_required_parameters(api, json_response): params["targetScript"] = "Latn" with pytest.raises(RosetteException) as e_rosette: - result = api.name_translation(params) + api.name_translation(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Translation parameter, name, not supplied' + assert e_rosette.value.message == 'Required Name Translation parameter is missing: name' params["name"] = "some data to translate" with pytest.raises(RosetteException) as e_rosette: - result = api.name_translation(params) + api.name_translation(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == ('Required Name Translation parameter, ' - 'targetLanguage, not supplied') + assert e_rosette.value.message == 'Required Name Translation parameter is missing: targetLanguage' params["targetLanguage"] = "eng" From 46239eace8121f1df984b8e98bd3678de032b017 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 5 Jan 2022 13:49:50 -0600 Subject: [PATCH 138/247] RCB-596: Sonar instructions. Copyrights. Test coverage. --- .gitignore | 3 ++ DEVELOPER.md | 32 +++++++++++++++++++++ docs/source/conf.py | 2 +- rosette/__init__.py | 2 +- rosette/api.py | 8 +++--- sonar-project.properties | 4 +++ tests/__init__.py | 2 +- tests/test_rosette_api.py | 58 ++++++++++++++++++++++++++++++++++++++- 8 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 sonar-project.properties diff --git a/.gitignore b/.gitignore index b53e254..f2480a7 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,6 @@ target/ settings.json *.orig + +# Sonar +.scannerwork/ diff --git a/DEVELOPER.md b/DEVELOPER.md index f605739..90af8d8 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -1,5 +1,37 @@ ## Developer Information +#### Sonar Scanning +* Uncomment the `sonar.branch.name` line in `sonar-project.properties` and adjust the value to match your branch name. +* Install the `coverage` module in to your virtual environment. + ``` + virtualenv -p python3 ~/venvs/python-binding-development + source ~/venvs/python-binding-development/bin/activate + pip install --upgrade pip + pip install coverage + ``` +* Generate the coverage data. + ``` + coverage run --source=rosette -m pytest + ``` +* Check the results locally + ``` + coverage report + ``` +* Generate the XML coverage report + ``` + coverage xml + ``` +* Push the results to Sonar + ``` + docker run \ + --rm \ + -e SONAR_HOST_URL="${sonar_host}" \ + -e SONAR_LOGIN="${sonar_token}" \ + -v "$(pwd):/usr/src" \ + sonarsource/sonar-scanner-cli + + ``` + ### Testing To test changes you have made to the binding, you can use a pre-configured Docker environment. This environment will: - Compile the binding within the container. diff --git a/docs/source/conf.py b/docs/source/conf.py index 2e30ba6..ff6c823 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -47,7 +47,7 @@ # General information about the project. project = '' -copyright = '2019, Basis Technology' +copyright = '2022, Basis Technology' author = 'Basis Technology' # The version info for the project you're documenting, acts as replacement for diff --git a/rosette/__init__.py b/rosette/__init__.py index 544db30..9384e6e 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -1,6 +1,6 @@ """ Python client for the Rosette API. -Copyright (c) 2014-2019 Basis Technology Corporation. +Copyright (c) 2014-2022 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at diff --git a/rosette/api.py b/rosette/api.py index 23ce179..f93a3d2 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -3,7 +3,7 @@ """ Python client for the Rosette API. -Copyright (c) 2014-2019 Basis Technology Corporation. +Copyright (c) 2014-2022 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -599,7 +599,7 @@ def set_pool_size(self, new_pool_size): if 'https:' in self.service_url: self.session.mount('https://', adapter) else: - self.session.mount('http://', adapter) + self.session.mount('http://', adapter) # NOSONAR def __adjust_concurrency(self, dict_headers): if _CONCURRENCY_HEADER in dict_headers and dict_headers[_CONCURRENCY_HEADER] != self.max_pool_size: @@ -947,12 +947,12 @@ def name_deduplication(self, parameters): return EndpointCaller(self, self.endpoints['NAME_DEDUPLICATION']).call(parameters) def text_embedding(self, parameters): - """ + """ deprecated Create an L{EndpointCaller} to identify text vectors found in the texts to which it is applied and call it. @type parameters: L{DocumentParameters} or L{str} @return: A python dictionary containing the results of text embedding.""" - return EndpointCaller(self, self.endpoints['TEXT_EMBEDDING']).call(parameters) + return self.semantic_vectors(parameters) def semantic_vectors(self, parameters): """ diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..fb71b92 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,4 @@ +sonar.projectKey=rosette-api-python-binding +sonar.sources=rosette +sonar.python.coverage.reportPaths=coverage.xml +#sonar.branch.name=RCB-596-pool-size diff --git a/tests/__init__.py b/tests/__init__.py index 9d1fe1d..4256e37 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Copyright (c) 2014-2019 Basis Technology Corporation. +Copyright (c) 2014-2022 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 41c4fc7..318c506 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Copyright (c) 2014-2019 Basis Technology Corporation. +Copyright (c) 2014-2022 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -202,6 +202,8 @@ def test_the_max_pool_size(json_response, doc_params): result = api.language(doc_params) assert result["name"] == "Rosette" assert api.get_pool_size() == 5 + api.set_pool_size(11) + assert api.get_pool_size() == 11 httpretty.disable() httpretty.reset() @@ -756,3 +758,57 @@ def test_the_similar_terms_endpoint(api, json_response, doc_params): assert result["name"] == "Rosette" httpretty.disable() httpretty.reset() + + +def test_the_deprecated_endpoints(api, json_response, doc_params): + """There are three deprecated endpoints. Exercise them until they are deleted.""" + + # TEXT_EMBEDDING calls SEMANTIC_VECTORS + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/semantics/vector", + body=json_response, status=200, content_type="application/json") + + result = api.text_embedding(doc_params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() + + # MATCHED_NAME calls NAME_SIMILARITY + 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") + + name_similarity_params = NameSimilarityParameters() + + name_similarity_params["name1"] = { + "text": "Michael Jackson", + "language": "eng", + "entityType": "PERSON"} + + name_similarity_params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"} + + result = api.matched_name(name_similarity_params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() + + # TRANSLATED_NAME calls NAME_TRANSLATION + 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-translation", + body=json_response, status=200, content_type="application/json") + + name_translation_params = NameTranslationParameters() + name_translation_params["entityType"] = "PERSON" + name_translation_params["targetScript"] = "Latn" + name_translation_params["name"] = "some data to translate" + name_translation_params["targetLanguage"] = "eng" + + result = api.translated_name(name_translation_params) + assert result["name"] == "Rosette" + + httpretty.disable() + httpretty.reset() From 57600693cefc049cf80c6bcfee1756b3b05f61bf Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 5 Jan 2022 13:56:02 -0600 Subject: [PATCH 139/247] RCB-596: Some final tweaks. --- DEVELOPER.md | 3 +++ tests/test_rosette_api.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 90af8d8..43d2168 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -23,6 +23,9 @@ ``` * Push the results to Sonar ``` + sonar_host=https://sonar.basistech.net + sonar_token= # Generate a token at https://sonar.basistech.net/account/security/ + docker run \ --rm \ -e SONAR_HOST_URL="${sonar_host}" \ diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 318c506..0770bec 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -23,12 +23,13 @@ import platform import httpretty import pytest -from rosette.api import (API, +from rosette.api import (AddressSimilarityParameters, + API, DocumentParameters, NameTranslationParameters, NameSimilarityParameters, NameDeduplicationParameters, - RosetteException, AddressSimilarityParameters) + RosetteException) _ISPY3 = sys.version_info[0] == 3 From 7f8e2272d831b54a18ec572ba9f0351f516aa7fa Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 12 Jan 2022 16:02:12 -0600 Subject: [PATCH 140/247] RCB-596: Add sonar ignore and add some more Python version support. --- .gitignore | 1 + setup.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b53e254..3996c93 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ htmlcov/ nosetests.xml coverage.xml *,cover +.scannerwork/ # Translations *.mo diff --git a/setup.py b/setup.py index 017af14..b581082 100755 --- a/setup.py +++ b/setup.py @@ -54,6 +54,8 @@ def read(*filenames, **kwargs): 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) From f0fee54a24e964b97e0c2c7939dd63e464f49d7d Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 12 Jan 2022 22:24:07 +0000 Subject: [PATCH 141/247] Version 1.20.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 ff6c823..0846005 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.14.4' +version = '1.20.0' # The full version, including alpha/beta/rc tags. -release = '1.14.4' +release = '1.20.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 9384e6e..bbeb61e 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.14.4' +__version__ = '1.20.0' diff --git a/rosette/api.py b/rosette/api.py index f93a3d2..a85a49f 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -30,7 +30,7 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' -_BINDING_VERSION = '1.14.4' +_BINDING_VERSION = '1.20.0' _CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' _CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' _CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX) From 85e14c37af42af9a4006b027657ad338378eca73 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 13 Jan 2022 12:45:27 -0600 Subject: [PATCH 142/247] NO-JIRA: Replace defunct website in categories example. --- examples/categories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index c02de34..0f92957 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -15,7 +15,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ - categories_url_data = "https://onlocationvacations.com/2018/02/06/downton-abbey-exhibition-extended-april-2-nyc/" + categories_url_data = "https://rosette.com/about" url = categories_url_data # Create an API instance api = API(user_key=key, service_url=alt_url) From f8d2f7a9effd880f5f6bafbee93298919f9cc488 Mon Sep 17 00:00:00 2001 From: seth-basistech Date: Wed, 17 Aug 2022 17:24:35 -0500 Subject: [PATCH 143/247] Fix broken URL --- examples/categories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index c02de34..774488a 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -15,7 +15,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ - categories_url_data = "https://onlocationvacations.com/2018/02/06/downton-abbey-exhibition-extended-april-2-nyc/" + categories_url_data = "https://www.rosette.com/about/" url = categories_url_data # Create an API instance api = API(user_key=key, service_url=alt_url) From d9888b5ca497b87df6b61baf4bea22d28f8ee649 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 9 Nov 2022 19:01:24 -0400 Subject: [PATCH 144/247] WS-2589: removing genre from doc & future print_function --- examples/address_similarity.py | 3 +-- examples/categories.py | 3 +-- examples/entities.py | 5 ++--- examples/info.py | 3 +-- examples/language.py | 3 +-- examples/language_multilingual.py | 3 +-- examples/morphology_complete.py | 3 +-- examples/morphology_compound-components.py | 3 +-- examples/morphology_han-readings.py | 3 +-- examples/morphology_lemmas.py | 3 +-- examples/morphology_parts-of-speech.py | 3 +-- examples/name_deduplication.py | 3 +-- examples/name_similarity.py | 1 - examples/name_translation.py | 3 +-- examples/ping.py | 3 +-- examples/relationships.py | 3 +-- examples/semantic_vectors.py | 4 +--- examples/sentences.py | 3 +-- examples/sentiment.py | 4 +--- examples/similar_terms.py | 4 +--- examples/syntax_dependencies.py | 4 +--- examples/tokens.py | 3 +-- examples/topics.py | 3 +-- examples/transliteration.py | 4 +--- 24 files changed, 24 insertions(+), 53 deletions(-) diff --git a/examples/address_similarity.py b/examples/address_similarity.py index 9ffe3a6..a245636 100644 --- a/examples/address_similarity.py +++ b/examples/address_similarity.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get match score (similarity) of two addresses. """ -from __future__ import print_function import argparse import json @@ -36,4 +35,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/categories.py b/examples/categories.py index 774488a..b032488 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -3,7 +3,6 @@ """ Example code to call Rosette API to get the category of a document (at a given URL). """ -from __future__ import print_function import argparse import json @@ -48,4 +47,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/entities.py b/examples/entities.py index e8191e2..e6e2a50 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get entities from a piece of text. """ -from __future__ import print_function import argparse import json @@ -27,7 +26,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country." params = DocumentParameters() params["content"] = entities_text_data - params["genre"] = "social-media" + try: return api.entities(params) except RosetteException as exception: @@ -43,4 +42,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/info.py b/examples/info.py index ab7159f..9684088 100644 --- a/examples/info.py +++ b/examples/info.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get information such as version and build """ -from __future__ import print_function import argparse import json @@ -32,4 +31,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/language.py b/examples/language.py index c8d82d0..fbfc936 100644 --- a/examples/language.py +++ b/examples/language.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to determine the language of a piece of text. """ -from __future__ import print_function import argparse import json @@ -36,4 +35,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/language_multilingual.py b/examples/language_multilingual.py index 84f5933..c442b76 100644 --- a/examples/language_multilingual.py +++ b/examples/language_multilingual.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to determine the language of a piece of text. """ -from __future__ import print_function import argparse import json @@ -38,4 +37,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index b1781d3..b1c0880 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the complete morphological analysis of a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index 3020e60..3332e71 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get de-compounded words from a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index bc1c9ea..b140969 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get Chinese readings of words in a piece of text. """ -from __future__ import print_function import argparse import json @@ -41,4 +40,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index ae6fe57..20921cb 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get lemmas for words in a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index 011b37a..48e3a07 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get part-of-speech tags for words in a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/name_deduplication.py b/examples/name_deduplication.py index 0392898..3c56fa9 100644 --- a/examples/name_deduplication.py +++ b/examples/name_deduplication.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to deduplicate a list of names. """ -from __future__ import print_function import argparse import json @@ -37,4 +36,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/name_similarity.py b/examples/name_similarity.py index 0020fae..9f5cd79 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get match score (similarity) of two names. """ -from __future__ import print_function import argparse import json diff --git a/examples/name_translation.py b/examples/name_translation.py index 7f7372d..fd9a753 100644 --- a/examples/name_translation.py +++ b/examples/name_translation.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to translate a name from one language to another. """ -from __future__ import print_function import argparse import json @@ -38,4 +37,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/ping.py b/examples/ping.py index 75aa02b..89d0925 100644 --- a/examples/ping.py +++ b/examples/ping.py @@ -2,7 +2,6 @@ """ Example code to send Rosette API a ping to check its reachability. """ -from __future__ import print_function import argparse import json @@ -32,4 +31,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/relationships.py b/examples/relationships.py index c59861d..a04651c 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get entities's relationships from a piece of text. """ -from __future__ import print_function import argparse import json @@ -34,4 +33,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/semantic_vectors.py b/examples/semantic_vectors.py index 066d920..c67e326 100644 --- a/examples/semantic_vectors.py +++ b/examples/semantic_vectors.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get text vectors from a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,5 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/sentences.py b/examples/sentences.py index 44ea8eb..747db2e 100644 --- a/examples/sentences.py +++ b/examples/sentences.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get sentences in a piece of text. """ -from __future__ import print_function import argparse import json @@ -36,4 +35,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/sentiment.py b/examples/sentiment.py index 0b6da36..dd5b52e 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -3,7 +3,6 @@ """ Example code to call Rosette API to get the sentiment of a local file. """ -from __future__ import print_function import argparse import json @@ -57,5 +56,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/similar_terms.py b/examples/similar_terms.py index 9695aa7..88f2940 100644 --- a/examples/similar_terms.py +++ b/examples/similar_terms.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get similar terms for an input. """ -from __future__ import print_function import argparse import json @@ -42,5 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index 1790729..38a86b0 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the syntactic dependencies of a document (at a given URL). """ -from __future__ import print_function import argparse import json @@ -34,5 +33,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/tokens.py b/examples/tokens.py index a1fedd3..a7f47a6 100644 --- a/examples/tokens.py +++ b/examples/tokens.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the tokens (words) in a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/topics.py b/examples/topics.py index 25d768a..55fa627 100644 --- a/examples/topics.py +++ b/examples/topics.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the topics (key phrases and concepts) in a piece of text. """ -from __future__ import print_function import argparse import json @@ -43,4 +42,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/transliteration.py b/examples/transliteration.py index 9fdab66..be9aa82 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to transliterate a piece of text. """ -from __future__ import print_function import argparse import json @@ -44,5 +43,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) From 6f680a84d0097af1a75de95db66f497b203f1d94 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 15 Nov 2022 12:35:37 -0400 Subject: [PATCH 145/247] WS-2589: fix print for name_similarity.py --- examples/name_similarity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/name_similarity.py b/examples/name_similarity.py index 9f5cd79..1e81ba8 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -36,4 +36,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) From 1c7f34cc893350b7952e0429e49783e26f96978a Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 15 Nov 2022 18:01:54 -0400 Subject: [PATCH 146/247] WS-2589: removing the genre field --- rosette/api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index a85a49f..88bf653 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -153,7 +153,7 @@ class DocumentParameters(_DocumentParamSetBase): def __init__(self): """Create a L{DocumentParameters} object.""" _DocumentParamSetBase.__init__( - self, ("content", "contentUri", "language", "genre", "profileId")) + self, ("content", "contentUri", "language", "profileId")) self.file_name = "" self.use_multipart = False @@ -236,8 +236,7 @@ def __init__(self): "sourceLanguageOfUse", "sourceScript", "targetScript", - "targetScheme", - "genre")) + "targetScheme")) def validate(self): """Internal. Do not use.""" From 91b2e2b418981369b375fd396057531abe7e9449 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 16 Nov 2022 22:10:39 -0400 Subject: [PATCH 147/247] WS-2589: log warning if genre is present --- rosette/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 88bf653..e729624 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -153,12 +153,14 @@ class DocumentParameters(_DocumentParamSetBase): def __init__(self): """Create a L{DocumentParameters} object.""" _DocumentParamSetBase.__init__( - self, ("content", "contentUri", "language", "profileId")) + self, ("content", "contentUri", "genre", "language", "profileId")) self.file_name = "" self.use_multipart = False def validate(self): """Internal. Do not use.""" + if self["genre"] is not None: + warnings.warn("genre is deprecated and will be removed in the next release.") if self["content"] is None: if self["contentUri"] is None: raise RosetteException( From 9cb45c5a4ec11b718f7653adf672ea1ce7d400e1 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 13 Jan 2023 14:14:04 -0400 Subject: [PATCH 148/247] RCB-616: removing travis badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index a15f1e3..bf603fa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ --- -[![Build Status](https://travis-ci.org/rosette-api/python.svg?branch=develop)](https://travis-ci.org/rosette-api/python) [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) From 72a5d015676958d94fbb38dac8997e159f690b42 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 13 Jan 2023 14:15:22 -0400 Subject: [PATCH 149/247] RCB-616: removing travis file --- .travis.yml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7128c50..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: python -dist: xenial -# Reflect version changes in setup.py classifiers -# 2.7 EOL - January 2020 -# 3.4 EOL - March 2019 -python: - - "2.7" - - "3.5" - - "3.6" - - "3.7" - - "3.8" -install: - - pip install tox -script: - - tox - -notifications: - slack: - rooms: - - secure: 4FRaTAAiYyeUvgw2RhmblgbNiJO4wmd34OBgWcwURjP9oVmFfSwR9r1LNCdUGxrPOghexSY2DjXIuvIrfTfi/xYbhHb3Kw7PEAyB8IuBMlKtY4NSFou62S2VhYpxyg58T+C7P2zi0eDnDE06pwTCoGPaimxMZQY91yQ0yPYDPVXbwe5SjEgamzlwGBxlS/0A6w1iCPHg27/iO2hXtdW3oLS2I0F/Q8Q95RBkX9hpg6yqHlTV7jRbSqvQ9OFBqk/tXMHQvhoPDGgCgQDuykJuaAYx7g9d0YL0eEYYOh9B/TJ/kNOwdRFBu5kuQ2/nFS5Z0S3Y3UIhdYjUmm9gSMnwIbYnrW22EqDJLoT9Zi3Gv7Prg/8/fSkWsof7BJTMSuXUqO1AxDGKIxFv9uSF1daZoY+AC1ooU1xDu1nNvWVYPlkwEdDxxmHpFkGT3ESTZYccPovQl8Z5K0I1BBAVdJKDzm07lE6VHbxkKcvK6gG0TN3uLxnSlQtjkfJ+aVMq1kxeVsB9lEsKs9oezsKzzbftMm525aXPg+OAv+31CUFWxvT/p4ps8Q+AV6aZpoPHkpK8VryyNirUeZ/m4m4ebDHhD9vcN+JqE9gzshT+0U3g19SvLiUMQtbuZ2BUvrq2hh2LEGs03AFZaNg9AEUVA1PQRhV5NILyoS/lbiBYJPT39Sg= - on_success: always - on_failure: always - From 2ad3f69c52d2395ebd607ac6ca34a1f33fe0e540 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 24 Jan 2023 09:40:36 -0400 Subject: [PATCH 150/247] RCB-616: adding CI.Jenkinsfile --- CI.Jenkinsfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 CI.Jenkinsfile diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile new file mode 100644 index 0000000..c68d9a7 --- /dev/null +++ b/CI.Jenkinsfile @@ -0,0 +1,48 @@ +node ("docker-light") { + def sourceDir = pwd() + try { + stage("Clean up") { + step([$class: 'WsCleanup']) + } + stage("Checkout Code") { + checkout scm + } + stage("Build & Test") { + withSonarQubeEnv { + sh "docker run -it --env PATH=\"/root/sonar-scanner/bin:${PATH}\" --volume /Users/yaison/work/basis/git/rosette-api/python/rosette:/source python:3.6-slim bash -c \"apt-get update && \ + apt-get install -y python3-pip && \ + apt-get install -y wget unzip && \ + cd / && \ + wget https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz && \ + tar -xvf openjdk-19.0.2_linux-x64_bin.tar.gz && \ + export JAVA_HOME=/jdk-19.0.2 && \ + export PATH=\"/jdk-19.0.2/bin:$PATH\" && \ + pip3 install tox && \ + cd /root/ && \ + wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ + unzip sonar-scanner-cli-4.8.0.2856-linux.zip && \ + rm sonar-scanner-cli-4.8.0.2856-linux.zip && \ + ln -s sonar-scanner-4.8.0.2856/ sonar-scanner && \ + apt-get purge -y --auto-remove unzip && \ + rm -rf /var/lib/apt/lists/* && \ + echo \"------finish setup------\" && \ + /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ + -Dsonar.sources=/source \ + -Dsonar.host.url=${sonar_host} \ + -Dsonar.login=${sonar_token}\"" + } + } + slack(true) + } catch (e) { + currentBuild.result = "FAILED" + slack(false) + throw e + } +} + +def slack(boolean success) { + 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: "#p-n-c_jenkins", message: message) +} \ No newline at end of file From dfdf72d41547dd663c50703801af421c4e77aac7 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 24 Jan 2023 14:46:36 -0400 Subject: [PATCH 151/247] RCB-616: fix source param --- CI.Jenkinsfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index c68d9a7..4213541 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -9,14 +9,9 @@ node ("docker-light") { } stage("Build & Test") { withSonarQubeEnv { - sh "docker run -it --env PATH=\"/root/sonar-scanner/bin:${PATH}\" --volume /Users/yaison/work/basis/git/rosette-api/python/rosette:/source python:3.6-slim bash -c \"apt-get update && \ + sh "docker run -it --env PATH=\"/root/sonar-scanner/bin:${PATH}\" --volume ${sourceDir}:/source python:3.6-slim bash -c \"apt-get update && \ apt-get install -y python3-pip && \ apt-get install -y wget unzip && \ - cd / && \ - wget https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz && \ - tar -xvf openjdk-19.0.2_linux-x64_bin.tar.gz && \ - export JAVA_HOME=/jdk-19.0.2 && \ - export PATH=\"/jdk-19.0.2/bin:$PATH\" && \ pip3 install tox && \ cd /root/ && \ wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ From fbef54fe54cdd0a097b0adc40d9b3a46070f8184 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 24 Jan 2023 14:52:08 -0400 Subject: [PATCH 152/247] RCB-616: fix env variable --- CI.Jenkinsfile | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 4213541..cb8bbc0 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -23,21 +23,12 @@ node ("docker-light") { echo \"------finish setup------\" && \ /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ -Dsonar.sources=/source \ - -Dsonar.host.url=${sonar_host} \ - -Dsonar.login=${sonar_token}\"" + -Dsonar.host.url=${env.SONAR_HOST_URL} \ + -Dsonar.login=${env.SONAR_AUTH_TOKEN}\"" } } - slack(true) } catch (e) { currentBuild.result = "FAILED" - slack(false) throw e } -} - -def slack(boolean success) { - 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: "#p-n-c_jenkins", message: message) } \ No newline at end of file From ab0f3f0a07375346357f8c3049d65bf6f1dade57 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 25 Jan 2023 11:36:22 -0400 Subject: [PATCH 153/247] RCB-616: simpler command --- .vscode/launch.json | 16 ++++++++++++++++ CI.Jenkinsfile | 7 +++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2b2502c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false + } + ] +} \ No newline at end of file diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index cb8bbc0..3bcdd2a 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -16,10 +16,9 @@ node ("docker-light") { cd /root/ && \ wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ unzip sonar-scanner-cli-4.8.0.2856-linux.zip && \ - rm sonar-scanner-cli-4.8.0.2856-linux.zip && \ - ln -s sonar-scanner-4.8.0.2856/ sonar-scanner && \ - apt-get purge -y --auto-remove unzip && \ - rm -rf /var/lib/apt/lists/* && \ + echo \"------about to build------\" && \ + cd /source && \ + tox && \ echo \"------finish setup------\" && \ /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ -Dsonar.sources=/source \ From 60e4653538fafdc03677c7230ef7888c84c2562b Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 25 Jan 2023 18:23:40 -0400 Subject: [PATCH 154/247] RCB-616: simpler commands --- CI.Jenkinsfile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 3bcdd2a..ac5f4d0 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -9,7 +9,7 @@ node ("docker-light") { } stage("Build & Test") { withSonarQubeEnv { - sh "docker run -it --env PATH=\"/root/sonar-scanner/bin:${PATH}\" --volume ${sourceDir}:/source python:3.6-slim bash -c \"apt-get update && \ + sh "docker run -it --volume ${sourceDir}:/source python:3.6-slim bash -c \"apt-get update && \ apt-get install -y python3-pip && \ apt-get install -y wget unzip && \ pip3 install tox && \ @@ -19,11 +19,7 @@ node ("docker-light") { echo \"------about to build------\" && \ cd /source && \ tox && \ - echo \"------finish setup------\" && \ - /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ - -Dsonar.sources=/source \ - -Dsonar.host.url=${env.SONAR_HOST_URL} \ - -Dsonar.login=${env.SONAR_AUTH_TOKEN}\"" + echo \"------finish setup------\"" } } } catch (e) { From 81927fa9ee44a09db291dbc9d9f8321b8d21aed0 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 25 Jan 2023 19:53:58 -0400 Subject: [PATCH 155/247] RCB-616: smaller build. --- CI.Jenkinsfile | 7 +------ tox.ini | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index ac5f4d0..2b0ef0b 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -13,13 +13,8 @@ node ("docker-light") { apt-get install -y python3-pip && \ apt-get install -y wget unzip && \ pip3 install tox && \ - cd /root/ && \ - wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ - unzip sonar-scanner-cli-4.8.0.2856-linux.zip && \ - echo \"------about to build------\" && \ cd /source && \ - tox && \ - echo \"------finish setup------\"" + tox\"" } } } catch (e) { diff --git a/tox.ini b/tox.ini index 23301ee..3f4f612 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ [tox] skipsdist = True -envlist = py2, py3 +envlist = py3 [testenv] commands = From 33e2845e21ca39f76acf60efbf2bc0fc373f6492 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 25 Jan 2023 19:55:34 -0400 Subject: [PATCH 156/247] RCB-616: minimal script --- CI.Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 2b0ef0b..d8267c4 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -9,10 +9,11 @@ node ("docker-light") { } stage("Build & Test") { withSonarQubeEnv { - sh "docker run -it --volume ${sourceDir}:/source python:3.6-slim bash -c \"apt-get update && \ - apt-get install -y python3-pip && \ - apt-get install -y wget unzip && \ - pip3 install tox && \ + sh "docker run \ + --pull always \ + --rm --volume ${sourceDir}:/source \ + python:3.6-slim \ + bash -c \"pip3 install tox && \ cd /source && \ tox\"" } From 2485ccba75f6b03633e46602b06bd305023a0a4b Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 25 Jan 2023 20:06:32 -0400 Subject: [PATCH 157/247] RCB-616: working script --- CI.Jenkinsfile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index d8267c4..d687db3 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -13,9 +13,18 @@ node ("docker-light") { --pull always \ --rm --volume ${sourceDir}:/source \ python:3.6-slim \ - bash -c \"pip3 install tox && \ + bash -c \"apt-get update && \ + apt-get install -y wget unzip && \ + pip3 install tox && \ + cd /root/ && \ + wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ + unzip sonar-scanner-cli-4.8.0.2856-linux.zip && \ cd /source && \ - tox\"" + tox && \ + /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ + -Dsonar.sources=/source \ + -Dsonar.host.url=${env.SONAR_HOST_URL} \ + -Dsonar.login=${env.SONAR_AUTH_TOKEN}\"" } } } catch (e) { From b93552e14fd5046a634a13e0cfa8ec99210a455a Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Thu, 26 Jan 2023 11:36:01 -0400 Subject: [PATCH 158/247] RCB-616: loop python versions --- CI.Jenkinsfile | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index d687db3..ca34507 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -1,3 +1,26 @@ + + +def versions = [3.11, 3.10, 3.9, 3.8, 3.7] + +def runSonnarForPythonVersion(ver){ + sh "docker run \ + --pull always \ + --rm --volume ${sourceDir}:/source \ + python:${ver}-slim \ + bash -c \"apt-get update && \ + apt-get install -y wget unzip && \ + pip3 install tox && \ + cd /root/ && \ + wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ + unzip sonar-scanner-cli-4.8.0.2856-linux.zip && \ + cd /source && \ + tox && \ + /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ + -Dsonar.sources=/source \ + -Dsonar.host.url=${env.SONAR_HOST_URL} \ + -Dsonar.login=${env.SONAR_AUTH_TOKEN}\"" +} + node ("docker-light") { def sourceDir = pwd() try { @@ -9,22 +32,10 @@ node ("docker-light") { } stage("Build & Test") { withSonarQubeEnv { - sh "docker run \ - --pull always \ - --rm --volume ${sourceDir}:/source \ - python:3.6-slim \ - bash -c \"apt-get update && \ - apt-get install -y wget unzip && \ - pip3 install tox && \ - cd /root/ && \ - wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ - unzip sonar-scanner-cli-4.8.0.2856-linux.zip && \ - cd /source && \ - tox && \ - /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ - -Dsonar.sources=/source \ - -Dsonar.host.url=${env.SONAR_HOST_URL} \ - -Dsonar.login=${env.SONAR_AUTH_TOKEN}\"" + + versions.each { ver -> + runSonnarForPythonVersion(ver) + } } } } catch (e) { From ff078d1d5f331467bb233fb40c7c447ca7e382f5 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Thu, 26 Jan 2023 11:46:56 -0400 Subject: [PATCH 159/247] RCB-616: fix syntax --- CI.Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index ca34507..e4830ef 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -2,7 +2,7 @@ def versions = [3.11, 3.10, 3.9, 3.8, 3.7] -def runSonnarForPythonVersion(ver){ +def runSonnarForPythonVersion(sourceDir, ver){ sh "docker run \ --pull always \ --rm --volume ${sourceDir}:/source \ @@ -34,7 +34,7 @@ node ("docker-light") { withSonarQubeEnv { versions.each { ver -> - runSonnarForPythonVersion(ver) + runSonnarForPythonVersion(sourceDir, ver) } } } From fbf350072c071133596aec96aff2420e88445429 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 27 Jan 2023 11:45:36 -0400 Subject: [PATCH 160/247] RCB-616: adding extra sonnar config --- CI.Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index e4830ef..cb681b5 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -17,6 +17,9 @@ def runSonnarForPythonVersion(sourceDir, ver){ tox && \ /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ -Dsonar.sources=/source \ + -Dsonar.pullrequest.key=${env.CHANGE_ID} \ + -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ + -Dsonar.pullrequest.branch=${env.BRANCH_NAME} \ -Dsonar.host.url=${env.SONAR_HOST_URL} \ -Dsonar.login=${env.SONAR_AUTH_TOKEN}\"" } From 9fffeb9afee86a75791150eac2112839b524a9b1 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Mon, 30 Jan 2023 12:33:57 -0400 Subject: [PATCH 161/247] RCB-616: adding sonar opts --- CI.Jenkinsfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index cb681b5..70ef23c 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -3,6 +3,12 @@ def versions = [3.11, 3.10, 3.9, 3.8, 3.7] def runSonnarForPythonVersion(sourceDir, ver){ + mySonarOpts="-Dsonar.sources=/source -Dsonar.pullrequest.branch=${env.BRANCH_NAME} -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}" + if ("${env.CHANGE_BRANCH}" != "null") { + mySonarOpts="$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" + }else{ + mySonarOpts="$mySonarOpts -Dsonar.pullrequest.branch=${env.BRANCH_NAME}" + } sh "docker run \ --pull always \ --rm --volume ${sourceDir}:/source \ @@ -16,12 +22,7 @@ def runSonnarForPythonVersion(sourceDir, ver){ cd /source && \ tox && \ /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ - -Dsonar.sources=/source \ - -Dsonar.pullrequest.key=${env.CHANGE_ID} \ - -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ - -Dsonar.pullrequest.branch=${env.BRANCH_NAME} \ - -Dsonar.host.url=${env.SONAR_HOST_URL} \ - -Dsonar.login=${env.SONAR_AUTH_TOKEN}\"" + ${mySonarOpts}\"" } node ("docker-light") { From 9426cc00afdaa36ebe3cccb8f4f4d62467c18646 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Mon, 30 Jan 2023 13:48:30 -0400 Subject: [PATCH 162/247] RCB-616: adding pull request key --- CI.Jenkinsfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 70ef23c..d5ac399 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -3,11 +3,9 @@ def versions = [3.11, 3.10, 3.9, 3.8, 3.7] def runSonnarForPythonVersion(sourceDir, ver){ - mySonarOpts="-Dsonar.sources=/source -Dsonar.pullrequest.branch=${env.BRANCH_NAME} -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}" + mySonarOpts="-Dsonar.sources=/source -Dsonar.pullrequest.branch=${env.BRANCH_NAME} -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN} -Dsonar.pullrequest.key=${env.CHANGE_ID}" if ("${env.CHANGE_BRANCH}" != "null") { - mySonarOpts="$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" - }else{ - mySonarOpts="$mySonarOpts -Dsonar.pullrequest.branch=${env.BRANCH_NAME}" + mySonarOpts="$mySonarOpts -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" } sh "docker run \ --pull always \ From de4e3c5dee79f28818b56639ad0f94281eabcd1c Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 31 Jan 2023 12:06:08 -0400 Subject: [PATCH 163/247] CB-616: adding NO-PR --- CI.Jenkinsfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index d5ac399..440ffb3 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -3,7 +3,12 @@ def versions = [3.11, 3.10, 3.9, 3.8, 3.7] def runSonnarForPythonVersion(sourceDir, ver){ - mySonarOpts="-Dsonar.sources=/source -Dsonar.pullrequest.branch=${env.BRANCH_NAME} -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN} -Dsonar.pullrequest.key=${env.CHANGE_ID}" + mySonarOpts="-Dsonar.sources=/source -Dsonar.pullrequest.branch=${env.BRANCH_NAME} -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN} " + if ("${env.CHANGE_ID}" != "null"){ + mySonarOpts = "$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID}" + } else { + mySonarOpts = "$mySonarOpts -Dsonar.pullrequest.key=NO-PR" + } if ("${env.CHANGE_BRANCH}" != "null") { mySonarOpts="$mySonarOpts -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" } From ee73556ec739994fb269b3315c4cc95118302b09 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 31 Jan 2023 12:26:29 -0400 Subject: [PATCH 164/247] RCB-616: moving branch name param --- CI.Jenkinsfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 440ffb3..7d3de48 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -3,12 +3,12 @@ def versions = [3.11, 3.10, 3.9, 3.8, 3.7] def runSonnarForPythonVersion(sourceDir, ver){ - mySonarOpts="-Dsonar.sources=/source -Dsonar.pullrequest.branch=${env.BRANCH_NAME} -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN} " - if ("${env.CHANGE_ID}" != "null"){ - mySonarOpts = "$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID}" + mySonarOpts="-Dsonar.sources=/source -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}" + if("${env.CHANGE_ID}" != "null"){ + mySonarOpts = "$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.branch=${env.BRANCH_NAME}" } else { - mySonarOpts = "$mySonarOpts -Dsonar.pullrequest.key=NO-PR" - } + mySonarOpts = "$mySonarOpts -Dsonar.branch.name=${env.BRANCH_NAME}" + } if ("${env.CHANGE_BRANCH}" != "null") { mySonarOpts="$mySonarOpts -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" } @@ -20,8 +20,8 @@ def runSonnarForPythonVersion(sourceDir, ver){ apt-get install -y wget unzip && \ pip3 install tox && \ cd /root/ && \ - wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip && \ - unzip sonar-scanner-cli-4.8.0.2856-linux.zip && \ + 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 && \ cd /source && \ tox && \ /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ From f742863d5adadcdc5d64a3c217df3c67c3450f06 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Thu, 2 Feb 2023 00:55:35 +0000 Subject: [PATCH 165/247] Version 1.24.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 0846005..59b477c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.20.0' +version = '1.24.0' # The full version, including alpha/beta/rc tags. -release = '1.20.0' +release = '1.24.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 bbeb61e..ae2c643 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.20.0' +__version__ = '1.24.0' diff --git a/rosette/api.py b/rosette/api.py index e729624..3bdede0 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -30,7 +30,7 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' -_BINDING_VERSION = '1.20.0' +_BINDING_VERSION = '1.24.0' _CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' _CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' _CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX) From d9ef6a701216e050beef608afaeb2a57567b8306 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Thu, 2 Feb 2023 15:44:59 -0400 Subject: [PATCH 166/247] RCB-616: reverting categories_url_data --- examples/categories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index b032488..88fbb37 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://www.rosette.com/about/" + categories_url_data = "https://rosette.com/about" url = categories_url_data # Create an API instance api = API(user_key=key, service_url=alt_url) From 57b6ed39a7b6eacf401b8b745150edd920e08f75 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Thu, 2 Feb 2023 16:52:34 -0400 Subject: [PATCH 167/247] RCB-616: conflict fix --- examples/categories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/categories.py b/examples/categories.py index b032488..88fbb37 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://www.rosette.com/about/" + categories_url_data = "https://rosette.com/about" url = categories_url_data # Create an API instance api = API(user_key=key, service_url=alt_url) From df87f734702107d4c62aafd86f8e2facfecb5f9f Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Mon, 6 Feb 2023 10:50:48 -0400 Subject: [PATCH 168/247] RCB-616: updating docker pull images name --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 42eec0f..58a6d77 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,8 +15,8 @@ node ("docker-light") { echo "${env.ALT_URL}" def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}" withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) { - sh "docker pull rosetteapi/docker-python" - sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-python" + sh "docker pull rosette/docker-python" + sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosette/docker-python" } } slack(true) From 0016068eee393f041772377a807ee17a5c365aaa Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 10 Feb 2023 15:20:49 -0400 Subject: [PATCH 169/247] RCB-616: removing VS Code dir --- .gitignore | 3 +++ .vscode/launch.json | 16 ---------------- 2 files changed, 3 insertions(+), 16 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.gitignore b/.gitignore index d08202e..be7f8d9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ ehthumbs.db Thumbs.db +# VS Code +.vscode + # Jetbrains **/.idea/* !**/.idea/runConfigurations/ diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 2b2502c..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "justMyCode": false - } - ] -} \ No newline at end of file From 747f14c52a5f926e283a0f411627e561076d80d1 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 10 Feb 2023 15:38:36 -0400 Subject: [PATCH 170/247] RCB-616: adding TODO comment. --- CI.Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 7d3de48..526663b 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -1,5 +1,6 @@ +// TODO: find a way to skip the Sonar scan for all this version, but one (maybe the latest?). def versions = [3.11, 3.10, 3.9, 3.8, 3.7] def runSonnarForPythonVersion(sourceDir, ver){ From f56e007765f6576d34f55583e7c18f1f983fd00f Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 10 Feb 2023 15:54:15 -0400 Subject: [PATCH 171/247] RCB-616: moved TODO comment --- CI.Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 526663b..660a300 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -1,6 +1,5 @@ -// TODO: find a way to skip the Sonar scan for all this version, but one (maybe the latest?). def versions = [3.11, 3.10, 3.9, 3.8, 3.7] def runSonnarForPythonVersion(sourceDir, ver){ @@ -13,6 +12,8 @@ def runSonnarForPythonVersion(sourceDir, ver){ if ("${env.CHANGE_BRANCH}" != "null") { mySonarOpts="$mySonarOpts -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" } + + // TODO: find a way to skip the Sonar scan for all those version, but one (maybe the latest?). sh "docker run \ --pull always \ --rm --volume ${sourceDir}:/source \ From 2340b7c0d02236a072ba69b0bee64381e3d766f7 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 10 Feb 2023 16:03:23 -0400 Subject: [PATCH 172/247] RCB-616: updated supported python versions --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index b581082..b266ac2 100755 --- a/setup.py +++ b/setup.py @@ -49,13 +49,11 @@ def read(*filenames, **kwargs): 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', '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', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) From f6514610270985f7bc90bfdec1aba8f23118bfb4 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 10 Feb 2023 19:21:38 -0400 Subject: [PATCH 173/247] RCB-616: removing all genre references. --- rosette/api.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index e729624..88bf653 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -153,14 +153,12 @@ class DocumentParameters(_DocumentParamSetBase): def __init__(self): """Create a L{DocumentParameters} object.""" _DocumentParamSetBase.__init__( - self, ("content", "contentUri", "genre", "language", "profileId")) + self, ("content", "contentUri", "language", "profileId")) self.file_name = "" self.use_multipart = False def validate(self): """Internal. Do not use.""" - if self["genre"] is not None: - warnings.warn("genre is deprecated and will be removed in the next release.") if self["content"] is None: if self["contentUri"] is None: raise RosetteException( From fed6935a72b684f45b1d62a123001a09ef824c6c Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 31 Mar 2023 16:37:43 -0400 Subject: [PATCH 174/247] WS-2705: updating dockerhub ref --- DEVELOPER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 43d2168..54afffa 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -47,7 +47,7 @@ To test changes you have made to the binding, you can use a pre-configured Docke git clone git@github.com:rosette-api/python.git cd python # Modify the binding... -docker run -e API_KEY=$API_KEY -v $(pwd):/source rosetteapi/docker-python +docker run -e API_KEY=$API_KEY -v $(pwd):/source rosette/docker-python ``` Optional parameters for the `docker run` execution are: From 63ca14a9297253156ba18887d0e2eed2040f6eca Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Fri, 31 Mar 2023 16:48:08 -0400 Subject: [PATCH 175/247] WS-2705: updating docker compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3cc15a6..1ca7e96 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ application: - image: rosetteapi/docker-python + image: rosette/docker-python environment: - API_KEY=$API_KEY - HTTP_PROXY=http://squid:3128 From f8bba262e63899ba339f54ed45d808bdc9cfcf51 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 5 Apr 2023 09:23:55 -0400 Subject: [PATCH 176/247] RCB-619: using str instead of boolean --- rosette/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 6e925a2..b35701c 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -494,7 +494,7 @@ def call(self, parameters): _my_loads(rdata, response_headers), status) else: if self.debug: - headers[_CUSTOM_HEADER_PREFIX + 'Devel'] = True + headers[_CUSTOM_HEADER_PREFIX + 'Devel'] = 'true' self.logger.info('operate: ' + url) headers['Accept'] = _APPLICATION_JSON headers['Accept-Encoding'] = "gzip" From 02899c0289d563614211da546a358d050dca3fbd Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 8 May 2023 17:11:16 -0500 Subject: [PATCH 177/247] RCB-620: Name and Address match parameter overrides. --- examples/address_similarity.py | 1 + examples/name_similarity.py | 2 + rosette/api.py | 34 ++++++++++++---- tests/test_rosette_api.py | 71 +++++++++++++++++++++++++++++++++- 4 files changed, 99 insertions(+), 9 deletions(-) diff --git a/examples/address_similarity.py b/examples/address_similarity.py index a245636..f69e4e1 100644 --- a/examples/address_similarity.py +++ b/examples/address_similarity.py @@ -18,6 +18,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): params = AddressSimilarityParameters() params["address1"] = {"houseNumber": "1600", "road": "Pennsylvania Ave NW", "city": "Washington", "state": "DC", "postCode": "20500"} params["address2"] = "160 Pennsilvana Avenue, Washington, D.C., 20500" + #params["parameters"] = {"houseNumberAddressFieldWeight": "0.9"} try: return api.address_similarity(params) diff --git a/examples/name_similarity.py b/examples/name_similarity.py index 1e81ba8..d700789 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -20,6 +20,8 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): params = NameSimilarityParameters() params["name1"] = {"text": matched_name_data1, "language": "eng", "entityType": "PERSON"} params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} + #params["parameters"] = {"conflictScore": "0.9", "deletionScore": "0.2"} + try: return api.name_similarity(params) except RosetteException as exception: diff --git a/rosette/api.py b/rosette/api.py index b35701c..030702f 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -250,7 +250,10 @@ def validate(self): class AddressSimilarityParameters(_DocumentParamSetBase): """Parameter object for C{address-similarity} endpoint. - All are required. + + C{address1} and C{address2} are required. + + `parameters` is optional. C{address1} The address to be matched, a C{address} object or address string. @@ -258,11 +261,17 @@ class AddressSimilarityParameters(_DocumentParamSetBase): The C{address} object contains these optional fields: city, island, district, stateDistrict, state, countryRegion, country, worldRegion, postCode, poBox + + `parameters` is a dictionary listing any parameter overrides to include. For example, `postCodeAddressFieldWeight`. + Setting `parameters` is not cumulative. Define all overrides at once. If defined multiple times, only the + final declaration is used. + + See `examples/address_similarity.py` """ def __init__(self): self.use_multipart = False - _DocumentParamSetBase.__init__(self, ("address1", "address2")) + _DocumentParamSetBase.__init__(self, ("address1", "address2", "parameters")) def validate(self): """Internal. Do not use.""" @@ -276,7 +285,10 @@ def validate(self): class NameSimilarityParameters(_DocumentParamSetBase): """Parameter object for C{name-similarity} endpoint. - All are required. + + C{name1} and C{name2} are required. + + `parameters` is optional. C{name1} The name to be matched, a C{name} object. @@ -284,18 +296,24 @@ class NameSimilarityParameters(_DocumentParamSetBase): The C{name} object contains these fields: - C{text} Text of the name, required. + C{text} Text of the name, required. + + C{language} Language of the name in ISO639 three-letter code, optional. + + C{script} The ISO15924 code of the name, optional. - C{language} Language of the name in ISO639 three-letter code, optional. + C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional. - C{script} The ISO15924 code of the name, optional. + `parameters` is a dictionary listing any parameter overrides to include. For example, `deletionScore`. + Setting `parameters` is not cumulative. Define all overrides at once. If defined multiple times, only the + final declaration is used. - C{entityType} The entity type, can be "PERSON", "LOCATION" or "ORGANIZATION", optional. + See `examples/name_similarity.py` """ def __init__(self): self.use_multipart = False - _DocumentParamSetBase.__init__(self, ("name1", "name2")) + _DocumentParamSetBase.__init__(self, ("name1", "name2", "parameters")) def validate(self): """Internal. Do not use.""" diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 0770bec..dd193b0 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -427,6 +427,48 @@ def test_the_name_translation_endpoint(api, json_response): # Test the name similarity endpoint +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_multiple_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", "deletionScore": "0.5"} + + result = api.name_similarity(params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() + + def test_the_name_similarity_endpoint(api, json_response): """Test the name similarity endpoint""" httpretty.enable() @@ -449,10 +491,11 @@ def test_the_name_similarity_endpoint(api, json_response): httpretty.disable() httpretty.reset() + # Test the name deduplication endpoint -def test_name_deduplicatation_parameters(api, json_response): +def test_name_deduplication_parameters(api, json_response): """Test the Name Deduplication Parameters""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", @@ -612,6 +655,32 @@ def test_for_address_similarity_required_parameters(api, json_response): httpretty.reset() +def test_for_address_similarity_optional_parameters(api, json_response): + """Test address 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/address-similarity", + body=json_response, status=200, content_type="application/json") + + params = AddressSimilarityParameters() + + params["address1"] = {"houseNumber": "1600", + "road": "Pennsylvania Ave NW", + "city": "Washington", + "state": "DC", + "postCode": "20500"} + + params["address2"] = {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"} + + params["parameters"] = {"houseNumberAddressFieldWeight": "0.9"} + + result = api.address_similarity(params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() + + # Test for required Name Similarity parameters From 106832d0d9673c6bfed3a89078ad76b184f80fd7 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 9 May 2023 12:19:55 -0500 Subject: [PATCH 178/247] RCB-620: Update source and test directories for Sonar reporting. --- sonar-project.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sonar-project.properties b/sonar-project.properties index fb71b92..a81bdc1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,6 @@ sonar.projectKey=rosette-api-python-binding sonar.sources=rosette sonar.python.coverage.reportPaths=coverage.xml +sonar.sources=rosette +sonar.tests=tests #sonar.branch.name=RCB-596-pool-size From 8d150cd56cc757c037c7e9fa0aaef6a1bd37e6eb Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 9 May 2023 12:46:25 -0500 Subject: [PATCH 179/247] RCB-620: More Sonar filtering. Try to run the scan just once. --- CI.Jenkinsfile | 18 ++++++++++++------ sonar-project.properties | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 660a300..b7a1e51 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -13,7 +13,17 @@ def runSonnarForPythonVersion(sourceDir, ver){ mySonarOpts="$mySonarOpts -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}" } - // TODO: find a way to skip the Sonar scan for all those version, but one (maybe the latest?). + // 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 && \ + cd /source && \ + /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner ${mySonarOpts}" + } else { + sonarExec="" + } + sh "docker run \ --pull always \ --rm --volume ${sourceDir}:/source \ @@ -21,13 +31,9 @@ def runSonnarForPythonVersion(sourceDir, ver){ bash -c \"apt-get update && \ apt-get install -y wget unzip && \ pip3 install tox && \ - 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 && \ cd /source && \ tox && \ - /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner \ - ${mySonarOpts}\"" + ${sonarExec}\"" } node ("docker-light") { diff --git a/sonar-project.properties b/sonar-project.properties index a81bdc1..cf62eb3 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,5 +2,5 @@ sonar.projectKey=rosette-api-python-binding sonar.sources=rosette sonar.python.coverage.reportPaths=coverage.xml sonar.sources=rosette -sonar.tests=tests +sonar.tests=tests/*.py #sonar.branch.name=RCB-596-pool-size From f81510731801c7399efedc84f2b8c5dd34b1dc64 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 9 May 2023 13:37:15 -0500 Subject: [PATCH 180/247] RCB-620: Fix CI and only give sonar a directory name. --- CI.Jenkinsfile | 2 +- sonar-project.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index b7a1e51..4328983 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -14,7 +14,7 @@ def runSonnarForPythonVersion(sourceDir, ver){ } // Only run Sonar once. - if($ver == 3.11) { + 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 && \ diff --git a/sonar-project.properties b/sonar-project.properties index cf62eb3..a81bdc1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,5 +2,5 @@ sonar.projectKey=rosette-api-python-binding sonar.sources=rosette sonar.python.coverage.reportPaths=coverage.xml sonar.sources=rosette -sonar.tests=tests/*.py +sonar.tests=tests #sonar.branch.name=RCB-596-pool-size From 28005f24c0bd7ad59a59b36595d841811804de1c Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 9 May 2023 14:22:12 -0500 Subject: [PATCH 181/247] RCB-620: Do not call setup.py. Generate coverage data. Use Sonar recommended relative files setting. --- sonar-project.properties | 2 -- tox.ini | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index a81bdc1..fb71b92 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,6 +1,4 @@ sonar.projectKey=rosette-api-python-binding sonar.sources=rosette sonar.python.coverage.reportPaths=coverage.xml -sonar.sources=rosette -sonar.tests=tests #sonar.branch.name=RCB-596-pool-size diff --git a/tox.ini b/tox.ini index 3f4f612..808daa0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,21 @@ -# Tox (http://tox.testrun.org/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - [tox] -skipsdist = True envlist = py3 +skipsdist = True [testenv] -commands = - {envpython} setup.py install - {envbindir}/py.test deps = pytest pep8 httpretty epydoc requests + coverage + build + +commands = + python -m build + coverage run -m pytest + coverage xml + +[coverage:run] +relative_files = True From 54e5a136e182f7807de86f01ba9a4d69cbfb19e6 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 9 May 2023 14:50:44 -0500 Subject: [PATCH 182/247] RCB-620: Need to have sonarExec default to something. Run Python version tests in the other order. --- CI.Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 4328983..457d077 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -1,6 +1,6 @@ -def versions = [3.11, 3.10, 3.9, 3.8, 3.7] +def versions = [3.7, 3.8, 3.9, 3.10, 3.11] def runSonnarForPythonVersion(sourceDir, ver){ mySonarOpts="-Dsonar.sources=/source -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}" @@ -21,7 +21,7 @@ def runSonnarForPythonVersion(sourceDir, ver){ cd /source && \ /root/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner ${mySonarOpts}" } else { - sonarExec="" + sonarExec="echo Skipping Sonar for this version." } sh "docker run \ From 9697f06dcd52f6dd0df1cbd906491f7642e13d87 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 9 May 2023 15:02:47 -0500 Subject: [PATCH 183/247] RCB-602: Sonar cleanup. --- rosette/api.py | 8 ++++---- sonar-project.properties | 1 + tests/test_rosette_api.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 030702f..744c479 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -113,7 +113,7 @@ def serialize(self, options): """serialize keys with values""" self.validate() values = {} - for (key, val) in self.__params.items(): + for key, val in self.__params.items(): if val is None: continue else: @@ -240,7 +240,7 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for option in ("name", "targetLanguage"): # required + for option in "name", "targetLanguage": # required if self[option] is None: raise RosetteException( "missingParameter", @@ -275,7 +275,7 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for option in ("address1", "address2"): # required + for option in "address1", "address2": # required if self[option] is None: raise RosetteException( "missingParameter", @@ -317,7 +317,7 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for option in ("name1", "name2"): # required + for option in "name1", "name2": # required if self[option] is None: raise RosetteException( "missingParameter", diff --git a/sonar-project.properties b/sonar-project.properties index fb71b92..2bdb883 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,5 @@ sonar.projectKey=rosette-api-python-binding sonar.sources=rosette +sonar.exclusions=**/tests/**,**/docs/**,**/examples/** sonar.python.coverage.reportPaths=coverage.xml #sonar.branch.name=RCB-596-pool-size diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index dd193b0..456a1af 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -589,7 +589,7 @@ def test_for_content_and_contentUri(api, json_response, doc_params): httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/entities", body=json_response, status=200, content_type="application/json") - doc_params['contentUri'] = 'http://google.com' + doc_params['contentUri'] = 'https://example.com' with pytest.raises(RosetteException) as e_rosette: api.entities(doc_params) From 86b295257cf17cadfd750433153597c60c9d980b Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 11 May 2023 13:35:53 -0500 Subject: [PATCH 184/247] RCB-620: Update a placeholder in a docstring. --- rosette/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 744c479..169bfe0 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -212,7 +212,7 @@ class NameTranslationParameters(_DocumentParamSetBase): C{targetLangauge} The language into which the name is to be translated. - C{entityType} The entity type (TBD) of the name. + C{entityType} The entity type of the name. PERSON (default), LOCATION, or ORGANIZATION C{sourceLanguageOfOrigin} The language of origin of the name. From 37c21ef82de49774ec9a6cba0b6d50db1b0b35c9 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 11 May 2023 19:44:10 +0000 Subject: [PATCH 185/247] Version 1.25.1 --- 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 59b477c..06117be 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.24.0' +version = '1.25.1' # The full version, including alpha/beta/rc tags. -release = '1.24.0' +release = '1.25.1' # 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 ae2c643..c583524 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.24.0' +__version__ = '1.25.1' diff --git a/rosette/api.py b/rosette/api.py index 169bfe0..cfe5633 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -30,7 +30,7 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' -_BINDING_VERSION = '1.24.0' +_BINDING_VERSION = '1.25.1' _CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' _CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' _CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX) From a940bdc4bb10b9468211afd43e9cc749f3f08847 Mon Sep 17 00:00:00 2001 From: seth-mg Date: Fri, 23 Jun 2023 12:44:10 -0500 Subject: [PATCH 186/247] 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 187/247] 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 188/247] 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 189/247] 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 190/247] 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 191/247] 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 192/247] 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 193/247] 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 194/247] 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 195/247] 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 196/247] 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 197/247] 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 198/247] 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 199/247] 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 200/247] 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 201/247] 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 202/247] 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 203/247] 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 204/247] 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) From bbfa6bac9ed5cf9cced91f78f0df376987ae7ac8 Mon Sep 17 00:00:00 2001 From: seth-mg Date: Tue, 16 Jan 2024 15:49:41 -0600 Subject: [PATCH 205/247] Update CI.Jenkinsfile Re-permission files for Jenkins cleanup. Not comprehensive but good enough for now. --- CI.Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index f6aaf1e..28697c2 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -34,7 +34,10 @@ def runSonnarForPythonVersion(sourceDir, ver){ pip3 install tox && \ cd /source && \ tox && \ - ${sonarExec}\"" + ${sonarExec} && \ + echo && \ + echo [INFO] Re-permission files for cleanup. && \ + chown -R jenkins:jenkins /source\"" } node ("docker-light") { From 5bccc8c63dd0458e56e6ac1461fb83690ef5257e Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 5 Apr 2024 17:12:37 +0200 Subject: [PATCH 206/247] WS-3151: fix description --- examples/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/events.py b/examples/events.py index 7e5147a..828dd45 100644 --- a/examples/events.py +++ b/examples/events.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get entities from a piece of text. +Example code to call Rosette API to get events from a piece of text. """ import argparse From 0c93c5b2c7c3f4c0decdc0e1a6d17468538d086c Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 5 Apr 2024 17:14:02 +0200 Subject: [PATCH 207/247] WS-3151: add coref option example --- examples/entities.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/entities.py b/examples/entities.py index e6e2a50..30a2ea5 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -22,6 +22,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): # api.set_option('calculateSalience','true') # api.set_option('linkEntities','false') + # api.set_option('useIndocServer', True) entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country." params = DocumentParameters() From c9c01338f3f233b45acb093e6274d429b1c8b1ef Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 5 Apr 2024 17:15:26 +0200 Subject: [PATCH 208/247] WS-3151: add record similarity top level object and example --- examples/record_similarity.py | 112 ++++++++++++++++++++++++++++++++++ rosette/api.py | 33 +++++++++- 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 examples/record_similarity.py diff --git a/examples/record_similarity.py b/examples/record_similarity.py new file mode 100644 index 0000000..454aacd --- /dev/null +++ b/examples/record_similarity.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +""" +Example code to call Rosette API to get similarity score between a list of records +""" + +import argparse +import json +import os + +from rosette.api import API, RecordSimilarityParameters, 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) + + fields = { + "primaryName": { + "type": "rni_name", + "weight": 0.5 + }, + "dob": { + "type": "rni_date", + "weight": 0.2 + }, + "addr": { + "type": "rni_address", + "weight": 0.5 + }, + "dob2": { + "type": "rni_date", + "weight": 0.1 + } + } + properties = { + "threshold": 0.1, + "includeExplainInfo": False + } + records = { + "left": [ + { + "primaryName": { + "text": "Ethan R", + "entityType": "PERSON", + "language": "eng", + "languageOfOrigin": "eng", + "script": "Latn" + }, + "dob": "1993-04-16", + "addr": "123 Roadlane Ave", + "dob2": { + "date": "1993/04/16" + } + }, + { + "dob": { + "date": "1993-04-16" + }, + "primaryName": { + "text": "Evan R" + } + } + ], + "right": [ + { + "dob": { + "date": "1993-04-16" + }, + "primaryName": { + "text": "Seth R", + "language": "eng" + } + }, + { + "primaryName": "Ivan R", + "dob": { + "date": "1993-04-16" + }, + "addr": { + "address": "123 Roadlane Ave" + }, + "dob2": { + "date": "1993/04/16" + } + } + ] + } + params = RecordSimilarityParameters() + params["fields"] = fields + params["properties"] = properties + params["records"] = records + + #params["parameters"] = {"conflictScore": "0.9", "deletionScore": "0.2"} + + try: + return api.record_similarity(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("key", "http://localhost:8181/rest/v1/") + print(RESULT) diff --git a/rosette/api.py b/rosette/api.py index f3fec57..cb98445 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -344,6 +344,27 @@ def validate(self): "Required Name De-Duplication parameter is missing: names", repr("names")) +class RecordSimilarityParameters(_RequestParametersBase): + """Parameter object for C{record-similarity} endpoint. + Required: + C{records} A list of C{record} objects + C{properties} A C{property} object + C{fields} A dictionary of C{field} objects + """ + + def __init__(self): + self.use_multipart = False + _RequestParametersBase.__init__(self, ("fields", "properties", "records")) + + def validate(self): + """Internal. Do not use.""" + for option in "fields", "properties", "records": # required + if self[option] is None: + raise RosetteException( + "missingParameter", + "Required Name Similarity parameter is missing: " + option, + repr(option)) + class EndpointCaller(object): """L{EndpointCaller} objects are invoked via their instance methods to obtain results @@ -592,7 +613,8 @@ def __init__( 'TOKENS': 'tokens', 'TOPICS': 'topics', 'TRANSLITERATION': 'transliteration', - 'EVENTS': 'events' + 'EVENTS': 'events', + 'RECORD_SIMILARITY': 'record-similarity' } def __del__(self): @@ -966,6 +988,15 @@ def name_deduplication(self, parameters): @return: A python dictionary containing the results of de-duplication""" return EndpointCaller(self, self.endpoints['NAME_DEDUPLICATION']).call(parameters, NameDeduplicationParameters) + def record_similarity(self, parameters): + """ + Create an L{EndpointCaller} to get similarity core between a list of records and call it. + @param parameters: An object specifying the data, + and possible metadata, to be processed by the record matcher. + @type parameters: L{RecordSimilarityParameters} + @return: A python dictionary containing the results of record matching.""" + return EndpointCaller(self, self.endpoints['RECORD_SIMILARITY']).call(parameters, RecordSimilarityParameters) + def text_embedding(self, parameters): """ deprecated Create an L{EndpointCaller} to identify text vectors found in the texts From b1f50fb9f7c14609900b71e02e4346e3b7f4a034 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 8 Apr 2024 11:55:50 +0200 Subject: [PATCH 209/247] WS-3151: unit tests --- examples/record_similarity.py | 4 +-- rosette/api.py | 3 +- tests/test_rosette_api.py | 62 +++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/examples/record_similarity.py b/examples/record_similarity.py index 454aacd..42d59ea 100644 --- a/examples/record_similarity.py +++ b/examples/record_similarity.py @@ -34,8 +34,8 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): } } properties = { - "threshold": 0.1, - "includeExplainInfo": False + "threshold": 0.7, + "includeExplainInfo": True } records = { "left": [ diff --git a/rosette/api.py b/rosette/api.py index cb98445..32e8c99 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -344,6 +344,7 @@ def validate(self): "Required Name De-Duplication parameter is missing: names", repr("names")) + class RecordSimilarityParameters(_RequestParametersBase): """Parameter object for C{record-similarity} endpoint. Required: @@ -362,7 +363,7 @@ def validate(self): if self[option] is None: raise RosetteException( "missingParameter", - "Required Name Similarity parameter is missing: " + option, + "Required Record Similarity parameter is missing: " + option, repr(option)) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index c05ea05..9b75d20 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -29,6 +29,7 @@ NameTranslationParameters, NameSimilarityParameters, NameDeduplicationParameters, + RecordSimilarityParameters, RosetteException) _ISPY3 = sys.version_info[0] == 3 @@ -484,6 +485,10 @@ def test_the_name_requests_with_text(api, json_response): result = api.address_similarity("should fail") assert e_rosette.value.status == 'incompatible' + with pytest.raises(RosetteException) as e_rosette: + result = api.record_similarity("should fail") + assert e_rosette.value.status == 'incompatible' + httpretty.disable() httpretty.reset() @@ -958,4 +963,61 @@ def test_the_events_endpoint(api, json_response, doc_params): result = api.events(doc_params) assert result["name"] == "Rosette" httpretty.disable() + httpretty.reset() + +# Test the record similarity endpoint + + +def test_the_record_similarity_endpoint(api, json_response): + """Test the record similarity endpoint""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/record-similarity", + body=json_response, status=200, content_type="application/json") + + params = RecordSimilarityParameters() + params["fields"] = {} + params["properties"] = {} + params["records"] = [] + result = api.record_similarity(params) + assert result["name"] == "Rosette" + httpretty.disable() + httpretty.reset() + + +# Tests for required record-similarities parameters +def test_for_record_similarity_required_parameters(api, json_response): + """Test record similarity parameters""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/record-similarity", + body=json_response, status=200, content_type="application/json") + + params = RecordSimilarityParameters() + + with pytest.raises(RosetteException) as e_rosette: + api.record_similarity(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Record Similarity parameter is missing: fields' + + params["fields"] = {} + + with pytest.raises(RosetteException) as e_rosette: + api.record_similarity(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Record Similarity parameter is missing: properties' + + params["properties"] = {} + + with pytest.raises(RosetteException) as e_rosette: + api.record_similarity(params) + + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Record Similarity parameter is missing: records' + + params["records"] = [] + + result = api.record_similarity(params) + assert result["name"] == "Rosette" + httpretty.disable() httpretty.reset() \ No newline at end of file From f7c6b75aa4b8729431fadb567561b7908782aa82 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 8 Apr 2024 12:23:09 +0200 Subject: [PATCH 210/247] WS-3151: copyright years and version number --- docs/source/conf.py | 6 +++--- rosette/__init__.py | 2 +- rosette/api.py | 4 ++-- tests/test_rosette_api.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index c95582f..2ec8928 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -47,7 +47,7 @@ # General information about the project. project = '' -copyright = '2022, Basis Technology' +copyright = '2024, Basis Technology' author = 'Basis Technology' # The version info for the project you're documenting, acts as replacement for @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.28.0' +version = '1.29.0' # The full version, including alpha/beta/rc tags. -release = '1.28.0' +release = '1.29.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 72eac6f..8944820 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.28.0' +__version__ = '1.29.0' diff --git a/rosette/api.py b/rosette/api.py index 32e8c99..199e405 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -3,7 +3,7 @@ """ Python client for the Rosette API. -Copyright (c) 2014-2022 Basis Technology Corporation. +Copyright (c) 2014-2024 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' -_BINDING_VERSION = '1.28.0' +_BINDING_VERSION = '1.29.0' _CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' _CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' _CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 9b75d20..88e58a2 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Copyright (c) 2014-2022 Basis Technology Corporation. +Copyright (c) 2014-2024 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From df50abcdde2388d1fd03fc130a641528f146031d Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 8 Apr 2024 14:48:27 +0200 Subject: [PATCH 211/247] WS-3151: change jenkins cleanup to uid guid --- CI.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 28697c2..811c36a 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -37,7 +37,7 @@ def runSonnarForPythonVersion(sourceDir, ver){ ${sonarExec} && \ echo && \ echo [INFO] Re-permission files for cleanup. && \ - chown -R jenkins:jenkins /source\"" + chown -R 9960:9960 /source\"" } node ("docker-light") { From 35bb8bb4db5bf7920ff1dc7c71cba84db2666528 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Thu, 11 Apr 2024 17:09:43 +0200 Subject: [PATCH 212/247] WS-3151: fix description, fix example --- examples/record_similarity.py | 6 ++---- rosette/api.py | 7 ++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/record_similarity.py b/examples/record_similarity.py index 42d59ea..2ae4c1e 100644 --- a/examples/record_similarity.py +++ b/examples/record_similarity.py @@ -91,8 +91,6 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): params["properties"] = properties params["records"] = records - #params["parameters"] = {"conflictScore": "0.9", "deletionScore": "0.2"} - try: return api.record_similarity(params) except RosetteException as exception: @@ -107,6 +105,6 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): default='https://api.rosette.com/rest/v1/') if __name__ == '__main__': - # ARGS = PARSER.parse_args() - RESULT = run("key", "http://localhost:8181/rest/v1/") + ARGS = PARSER.parse_args() + RESULT = run(ARGS.key, ARGS.url) print(RESULT) diff --git a/rosette/api.py b/rosette/api.py index 199e405..39f3467 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -348,9 +348,10 @@ def validate(self): class RecordSimilarityParameters(_RequestParametersBase): """Parameter object for C{record-similarity} endpoint. Required: - C{records} A list of C{record} objects - C{properties} A C{property} object - C{fields} A dictionary of C{field} objects + C{records} The records to be compared; where each left record is compared to the associated right record. + C{properties} Parameters used in the call + C{fields} The definition of the fields used in the comparison. There must be a minimum of 1 field and + can have a maximum of 5 fields. """ def __init__(self): From e62c1c261843ad570d85021ee40488976425fded Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 17 Apr 2024 17:52:47 -0500 Subject: [PATCH 213/247] WS-3151: README/branding updates. Events example string. --- README.md | 18 ++++++------------ examples/events.py | 2 +- setup.py | 4 ++-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index fc7daf3..ceb1212 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,10 @@ - - ---- + +# Rosette by Babel Street [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) -## Rosette API -The Rosette Text Analytics Platform uses natural language processing, statistical modeling, and machine learning to -analyze unstructured and semi-structured text across 364 language-encoding-script combinations, revealing valuable -information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and -comparing the similarity of names, categorizing and adding linguistic tags to text and more. +Rosette uses natural language processing, statistical modeling, and machine learning to analyze unstructured and semi-structured text across hundreds of language-script combinations, revealing valuable information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and comparing the similarity of names, categorizing and adding linguistic tags to text and more. Rosette Server is the on-premises installation of Rosette, with access to Rosette's functions as RESTful web service endpoints. This solves cloud security worries and allows customization (models/indexes) as needed for your business. ## Rosette API Access - Rosette Cloud [Sign Up](https://developer.rosette.com/signup) @@ -25,11 +20,10 @@ in the [examples](https://github.com/rosette-api/python/tree/develop/examples) d #### Documentation & Support - [Binding API](https://rosette-api.github.io/python/) -- [Rosette Platform API](https://developer.rosette.com/features-and-functions) +- [Rosette Platform API](https://docs.babelstreet.com/API/en/index-en.html) - [Binding Release Notes](https://github.com/rosette-api/python/wiki/Release-Notes) -- [Rosette Platform Release Notes](https://support.rosette.com/hc/en-us/articles/360018354971-Release-Notes) -- [Binding/Rosette Platform Compatibility](https://developer.rosette.com/features-and-functions?python#) -- [Support](https://support.rosette.com) +- [Rosette Platform Release Notes](https://babelstreet.my.site.com/support/s/article/Rosette-Cloud-Release-Notes) +- [Support](https://babelstreet.my.site.com/support/s/) - [Binding License: Apache 2.0](https://github.com/rosette-api/python/blob/develop/LICENSE.txt) ## Binding Developer Information diff --git a/examples/events.py b/examples/events.py index 828dd45..832f6e3 100644 --- a/examples/events.py +++ b/examples/events.py @@ -15,7 +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) - events_text_data = "I am looking for flights to Super Bowl 2022 in Inglewood, LA." + events_text_data = "Alice has a flight to Budapest. She has not booked a hotel." params = DocumentParameters() params["content"] = events_text_data diff --git a/setup.py b/setup.py index 551de4f..309ec07 100755 --- a/setup.py +++ b/setup.py @@ -7,8 +7,8 @@ NAME = "rosette_api" DESCRIPTION = "Rosette API Python client SDK" -AUTHOR = "Basis Technology Corp." -AUTHOR_EMAIL = "support@rosette.com" +AUTHOR = "Rosette by Babel Street" +AUTHOR_EMAIL = "helpdesk@babelstreet.com" HOMEPAGE = "https://github.com/rosette-api/python" VERSION = rosette.__version__ From a5121cb388d9e7f97439ed98754a5fba38128cb4 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 19 Apr 2024 11:24:51 -0500 Subject: [PATCH 214/247] WS-3151: Revert example payhload. There is a separate negation example. --- examples/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/events.py b/examples/events.py index 832f6e3..828dd45 100644 --- a/examples/events.py +++ b/examples/events.py @@ -15,7 +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) - events_text_data = "Alice has a flight to Budapest. She has not booked a hotel." + events_text_data = "I am looking for flights to Super Bowl 2022 in Inglewood, LA." params = DocumentParameters() params["content"] = events_text_data From 37de35a3e4de8969c531fa950e2b39f9e9f13e3a Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 19 Apr 2024 11:25:14 -0500 Subject: [PATCH 215/247] WS-3151: Use a supported Python in the examples. --- examples/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/README.md b/examples/README.md index 5928376..e52b2cb 100644 --- a/examples/README.md +++ b/examples/README.md @@ -32,7 +32,7 @@ python ping.py -k $API_KEY ``` git clone git@github.com:rosette-api/python.git cd python/examples -docker run -it -v $(pwd):/source --entrypoint bash python:3.6-slim +docker run -it -v $(pwd):/source --entrypoint bash python:3.12-slim cd /source pip install rosette_api python ping.py -k $API_KEY @@ -42,7 +42,7 @@ python ping.py -k $API_KEY ``` git clone git@github.com:rosette-api/python.git cd python -docker run -it -v $(pwd):/source --entrypoint bash python:3.6-slim +docker run -it -v $(pwd):/source --entrypoint bash python:3.12-slim cd /source python setup.py install cd examples From b579e0a711f461b4ed1b646be30579b4b9d5f2b5 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 19 Apr 2024 11:43:31 -0500 Subject: [PATCH 216/247] WS-3151: change records param in unit test from array to dict. --- tests/test_rosette_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 88e58a2..a0e2b3d 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -977,7 +977,7 @@ def test_the_record_similarity_endpoint(api, json_response): params = RecordSimilarityParameters() params["fields"] = {} params["properties"] = {} - params["records"] = [] + params["records"] = {} result = api.record_similarity(params) assert result["name"] == "Rosette" httpretty.disable() @@ -1015,9 +1015,9 @@ def test_for_record_similarity_required_parameters(api, json_response): assert e_rosette.value.status == 'missingParameter' assert e_rosette.value.message == 'Required Record Similarity parameter is missing: records' - params["records"] = [] + params["records"] = {} result = api.record_similarity(params) assert result["name"] == "Rosette" httpretty.disable() - httpretty.reset() \ No newline at end of file + httpretty.reset() From c04b05b1505b76f35a907fde351881107b26db93 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 28 Jun 2024 15:01:32 +0200 Subject: [PATCH 217/247] WS-3224: fix requests compatibility issue --- rosette/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 39f3467..5bdb038 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -528,7 +528,7 @@ def call(self, parameters, paramtype=None): request = requests.Request( 'POST', url, files=files, headers=headers, params=payload) prepared_request = self.api.session.prepare_request(request) - settings = self.api.session.merge_environment_settings(prepared_request.url, {}, {}, None, {}) + settings = self.api.session.merge_environment_settings(prepared_request.url, {}, {}, None, None) response = self.api.session.send(prepared_request, **settings) rdata = response.content response_headers = {"responseHeaders": dict(response.headers)} @@ -671,7 +671,7 @@ def _make_request(self, operation, url, data, headers): operation, url, data=data, headers=headers, params=payload) prepared_request = self.session.prepare_request(request) # Take into account environment settings, e.g. HTTP_PROXY and HTTPS_PROXY - settings = self.session.merge_environment_settings(prepared_request.url, {}, {}, None, {}) + settings = self.session.merge_environment_settings(prepared_request.url, {}, {}, None, None) try: response = self.session.send(prepared_request, **settings) From bd0a9a19b94c495c7add249805acae260a0bd8ba Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 1 Jul 2024 10:42:46 +0200 Subject: [PATCH 218/247] WS-3224: synchronize validation with java binding --- rosette/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 5bdb038..fe45eb5 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -360,7 +360,7 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for option in "fields", "properties", "records": # required + for option in "records": # required if self[option] is None: raise RosetteException( "missingParameter", From 3a7b86aee28dea70823caa27e6a94c105734d831 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 1 Jul 2024 10:46:01 +0200 Subject: [PATCH 219/247] WS-3224: supdate example --- examples/record_similarity.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/record_similarity.py b/examples/record_similarity.py index 2ae4c1e..f39b548 100644 --- a/examples/record_similarity.py +++ b/examples/record_similarity.py @@ -50,7 +50,8 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): "dob": "1993-04-16", "addr": "123 Roadlane Ave", "dob2": { - "date": "1993/04/16" + "date": "04161993", + "format": "MMddyyyy" } }, { @@ -78,7 +79,8 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): "date": "1993-04-16" }, "addr": { - "address": "123 Roadlane Ave" + "houseNumber": "123", + "road": "Roadlane Ave" }, "dob2": { "date": "1993/04/16" From 31e9afb35d7073db2c8febc823aa5c924f5aa45b Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 1 Jul 2024 11:09:02 +0200 Subject: [PATCH 220/247] WS-3224: remove record-similarity validation tests --- tests/test_rosette_api.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index a0e2b3d..a635025 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -993,22 +993,6 @@ def test_for_record_similarity_required_parameters(api, json_response): params = RecordSimilarityParameters() - with pytest.raises(RosetteException) as e_rosette: - api.record_similarity(params) - - assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Record Similarity parameter is missing: fields' - - params["fields"] = {} - - with pytest.raises(RosetteException) as e_rosette: - api.record_similarity(params) - - assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Record Similarity parameter is missing: properties' - - params["properties"] = {} - with pytest.raises(RosetteException) as e_rosette: api.record_similarity(params) From 7b110e845835f6185bf9bcd641e2ec9f606e54e6 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 1 Jul 2024 11:18:47 +0200 Subject: [PATCH 221/247] WS-3224: fix record-similarity validation --- rosette/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index fe45eb5..182c239 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -360,7 +360,7 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for option in "records": # required + for option in ["records"]: # required if self[option] is None: raise RosetteException( "missingParameter", From de457c7ce36f66fdb5fc841af9577d13e3794cf3 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Wed, 10 Jul 2024 09:35:52 +0000 Subject: [PATCH 222/247] Version 1.30.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 2ec8928..ec6a33a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.29.0' +version = '1.30.0' # The full version, including alpha/beta/rc tags. -release = '1.29.0' +release = '1.30.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 8944820..200c03e 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.29.0' +__version__ = '1.30.0' diff --git a/rosette/api.py b/rosette/api.py index 182c239..6114554 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -30,7 +30,7 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' -_BINDING_VERSION = '1.29.0' +_BINDING_VERSION = '1.30.0' _CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' _CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' _CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX) From 6a6ebdfe38e1963bdbd70cdb0d0433bf648f3a5c Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 24 Oct 2024 16:49:37 -0500 Subject: [PATCH 223/247] WS-3314: Switch to png files. Add a favicon. --- docs/source/conf.py | 3 ++- docs/source/favicon-16x16.png | Bin 0 -> 1423 bytes docs/source/logo-400x113.png | Bin 0 -> 13239 bytes docs/source/rosette-logo.svg | 35 ---------------------------------- 4 files changed, 2 insertions(+), 36 deletions(-) create mode 100644 docs/source/favicon-16x16.png create mode 100644 docs/source/logo-400x113.png delete mode 100644 docs/source/rosette-logo.svg diff --git a/docs/source/conf.py b/docs/source/conf.py index ec6a33a..39446dd 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -95,7 +95,8 @@ # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] -html_logo = 'rosette-logo.svg' +html_logo = 'logo-400x113.png' +html_favicon = 'favicon-16x16.png' # Custom sidebar templates, must be a dictionary that maps document names # to template names. diff --git a/docs/source/favicon-16x16.png b/docs/source/favicon-16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..2750b933b5f2a9c894496d3ca4f5c7ed9ee349dc GIT binary patch literal 1423 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBDAAG{;hE;^%b*2hb1<+n z3NbJPS&Tr)z$nE4G7ZRL@M4sPvx68lplX;H7}_%#SfFa6fHa7y10vuw^8!YMi3^zE zss$D>BiJB)3wv^I0V&P`kH}&M20djEW~^9hU&g?|bSg6>q9nrC$0|8LS1&OoKPgqO zBDVmfi@~PC3dqb&ElE_U$j!+swyLmI0;{kBvO&W7N(x{lCE2!05xxNm&iO^D3TAo+ zdIm~%TnY*bHbp6ERzWUqQ0+jTtx`rwNr9EVetCJhUb(Seeo?xG?WUP)qwZeFo6#1NP{E~&-IMVSR9nfZANAafIw@=Hr>m6Sjh!2!gbC7EdmoAQdG z-U511A0(r1sAr&$ON8HhHpzaZAxfDE&W3`#A|&nX2t%g)%qzy@puiYUT? z5FH2&p?R4lc1BPwXu{~aA`tRO_8^O*>+mniOa%rd*ky)LOOVBo)PwwI6_8nxniJuY znVXtd4DyYknT-m&{c!2iNs|Mk_1$vjXo&0kzyZ` zw7{akv}MO-qYqD~c3k#NJ0Alx$b3&1#}Es_*2#|AE`cJ)pBrwLP!$VK60>7ST%6+? zbjnFFs4U5G(^F;*ZfkFCv!H2ZVq#)#Q%!Do_!^l_7BV{a_4oeD?`8KF|9SoWT;=mS z)%SNkzbC##NitcgK>DCV!zwR9|I<}mAF`k9kL_{fI_8oi@+`^m{n2xrPZWAG)$eo9 zzrcLkfJya5Q~8DP{R>Xa3EIKY&%-!%7fX=fsRF^H{2$&wMxS4ulHr)-oTJs zaPEL6OHho)_ydvNrL!Q)s z$$EZ!ZY$O0Pnf(iCYq}~*;qc|Xt=BVf{*|84$PR+w^i~@T(syP@2npEwQ_PvqYy&weXoKCxk&aJInvRVwGrgTe~DWM4fRoBIh literal 0 HcmV?d00001 diff --git a/docs/source/logo-400x113.png b/docs/source/logo-400x113.png new file mode 100644 index 0000000000000000000000000000000000000000..b411943a005e194bd5694ea8bdb379c5b40efe44 GIT binary patch literal 13239 zcmdU$g+Mkx&Bwpb}nXXCVCR_F?kM=(T`yRg)G2 zRE`txz3zlr=*U_sDgx+VWgq|!3JU=9N9FYmfFcCI{gnX#IVht4%4$%w|LQ;k01z+$ z_Fo;n*Yc0Z_-FIq5+)Doe?8_w|3@1tArIz1GQjzdoeDsi`L#fFlF@Yq0GO%%e4xAv zg*{$f>4G(M+;kKb_{|*cnN7?cO)Z$c?4ABt0R+AHUqyQhHxqI%dpieLelHN^Uk(0O z`A;=xTA{&IX5#aGb^PK5;-}!po_UBznX;9zvi!dAWCaDHz$4; z7Ee!4W={@gM;9v=HaQJ0siV6ah?4S8p#Q%9X{Q_5@_!>axc=L%*ABA$`G$p!nU&?gzF$oR|J3p;yMQfT zBmeO)#3uMx^Z%;*H;y37pWy#TWB%#s-`dx%3Ly!y{5NevNCbu(2mk<^m8^uQh8NV4 zKXQ_RX8N}Ga;aRQAtL&xQdnSqsYpTnM|e^DHrQ0Ec&?zXk6?GeUX7|%-=4#wLu!W} zPAVsdt^R({mKrIje#O3E(wc`G?S~;TtcD!nBGOwrF{os@cet{p^vN14zN8oazPYX^ z6}}Uon=GHz(no=>zT-dR15cigI$i=_9>Dmfuu!5R7#Ohs?-p@Xu;p8{RUb9~X=gB; zNEd9Zir1+@3^_Rv2ptkcu7V9Ea5>fKZL56Cto*N5zbN@(1q<5MyMo13Q4QvTgM|gx zrajBbIaLPVC;D%%R)36IQkS{gy;7iR>(A#H&);JDFr77eC+Vf};+5UBf1iRpB z)MB~RC{^%Hc)oG399wbXDG_Wner0fzOl>u$l>N25$%TW4?#-Vp=5=D~v_OaTm>HAL z*P0x>SD1LH0qYU@E6181;S&+@LN9zZxVu9A_C@JW)`OFyyX1&_#4^~Lpf;u&^LN;n zYIC_1%?eI@r70v-u%17)@;17v8NhxYuE_l8^4g*jS6HnK0AiTf9Qb7aF3IA(Fel27 zYyVtVa$A%&9)%GBY05>ELX z;JQuqI(K4wxA_d-vcJ^SmKA+5e6`po2`=6INM`tH0bi4Oi@=uTiUAE=XYw!axJ7lKVu3rYwM zttrAG?ejD4vR_?p`#QDqFcD$#ji3jnr_cJ!Cw8H2e#RfHs4V!Mn~&0gbl8xTkEnty zL!sWu6!q_d^(Zl4^YmNH_$w^10k)~4>_O@WPbIsbD=|v02N&u#5397pFO>Ojzyb{- z`Y;5721G^J3$h$XcQsQaAWFa_g;Ydk zK+q;~gs7)G2$q_1XSH+}+43eplo316>EI;-uA$0Zuo3dT?OlZZQsl77G6uOn2DuHd zt!M$J>EFD}AVbT)6>;-)zQYm9^SQ$*UHyH@qlFKwS*GJE$Q$A>pRP+j8gIHtp^TDIm zYupGnT%q-zSKQ=BJK_P6fUh4?y#5T>*~qSQqy#705zY+U=1d+QqTUs6E~rir^zk#W zEksi|^>#c*S2g4Nb&RMU3XxjmIN?Stx6Xml5fNQUI%n^fivL%I+1PO47!H_ zZiXM#W4!~e#}eAo2D$`?qN6u9-@4USj=aRmf*$BnR&-8{@|plFG4GF9J+r>Tk<+~W z#|sy5CKZ5a9FD_R8Ygh}1ZF*j_uDyLiNVz#w4@+Iku|xwQTQ52%lX@tqAsNHp=+OM z!Zrl2?>$=o-)Ws32n(Dk1Z)ID_E8wojJ~>7#-Mma8TW>3FE?weg(cuE3degudQ|vQ z4L7|jt9Va5D@EUB{him#FoRoh$icx85j`ALv^+f^a{MXTF=&^ zA5e`H5ys&#pQZxKShH2VOOjJKk6mM=D{8aMGSlP*GLj2f$LbhE(OWfpg@<4CkMP>` zw=*imnqM2~Mv);ch0s#1#Zt*+ZtuWyMC3bfBK4bI13hc1!5msbbMBM!>YUGL#;U1K z3Njb)yxNXU#2Qizwjy40N253~v#E+6c4%(*cJM|QQw8{TZRkq`(!14w^^;~{+d`#Z zhvi;7E!Ao3_zz`Q!7|0)Y;pMKkq-uO4GW(hq@|?d;Co_FI6r6^7}Nx_9_-sM_E!YHF7m}<_HvEKz4q{5?q`f_#!~cA`thA1Mo&tnp`c7z zUs}R_`c2YXzftDBwCsG@kj?vvLOw<=Owrt&UwNT@X`kD%JIl;`Fvton{4V-D6pmVJ zz%Gry{UltQ(hRZseUrrq|4v#*`fpOnV*I(wl`Jmj%XMVlG+LYx`V;e_L@;9n>gw?D zJE6|$NnXMsS8vD3g~TTok|24F7KS$L)^Xlk#WgWDGoF2HZ5#s+w7v(`ojGZZy|Wfl;O^ zt`%Cf{WMBw<0e6FL8bRCLd(8a;)PEl5*l78ke%C0eNq^XU=T;!)HRt6TU>y>`CDWu zU(_BD>pW8Lz=mqV7=Fu3=s~E!#Uji-XR*DgDR_LMi*s+B zY%VxNm8{&6b1^<({#&KRPwteZ3wp3AE@tXn#PVJQ!(og+3oM$_%5_<)fQ=sYmSUs( zH44StAZYDnJ8|j|ZPJqRws-`A1+%DDfA=f<3Z`hX^t>3Qv)yXo;5^ehU8zBex7P1{ z{5b=UfmVgzG?k>OaF*!=l?{Qt5p@#_-(I{OP-!PV4fig7y3V!paS*20VwhGI?e#*A z2v#|{^t5=^IKk$TCqCxAnyJ{T>hy{1JbMGlE=oS`!W~24A@3BgYiHbl)C~^VaZh4o;>?ry$f)}e?MbPp>cU_XM~Lx(I} z$i#TQ!gS<- zy*g{n%qBov1#OOD97IV)YL`S;cmr%@XOiAoknFh7vdhc&_&b6!De$P_(w@1Ft?_AE zQX~(dwR}N~=jkUm?c{@n$ik1-XfxUV8%20Od*Yyx63 z5Ks;f_BcNmhi}^kz=De3-<+Jp@AFLsDw>H^00l805^AJ>$0M#AurxEK{R|WPIOK;z zIR6%H_0bKZ@yjE0X*Wy=q#OSY5#|$H+$nk$vL!ykp34H}D9s&s8c_}4S3AC_K7M#k ze1c$HJ|^dMJ7C4maV!o&J0h6pyk|e6`PSI)$jS^a_d?)((!icR0;0J=T6W~7tkNE* zKb&i2niyM`mBcM%2hd z@arAp(t6#khbF@Xc}v>w)g#C43+yqj_`patk<2;rYMO`EenB5LEn zE(mR+WGVTyF{zap@Olx?E|bC;vC8)Q;a|k%j}_ss`4o5hzPcxQrkn*IuSoSG>b~Ld zO#=hEs&rotr~d>0pj)P9c3BGoDhchN>vcSc>=>+`mz1ErKl!+{M3dHGe& z6qz-7_jZqt3_MaLINgq7{d1?&NVLP)ccOa=m4lH@@rRx{zvju4sYw(>Il|k# z-;$+uX0j6TE_hwc_w%i>)|LMSPm_E0UF=X|wt&eSB*=7i;Ym3WryskJBm|EwB4AfN z`V>Dt7#sY9<#{8y_=zQLPduZJG@?idhH){dUsWSk{&kTi#32w>&cPNT9)z-W@EDr# zRC@A@InDYkpK02B~ar*^i^lDur0o)6WS0KgAWk zSSTr!S0Y=W-DBGkNun9Y$GoYUj=SXJ8F_x32?+I$<)q!}#n34)+WJJ*W*Bo>51YbZ z5R^dYRYBC&^s~sFkA6|r+PA*UM&(x;HurnMk(bn=j!@z@P0mty9U%nw8BqP+1Ywas zx?YcL%0Yqjae4ri+KHZ3Ucg#}Ts_GO*0mntIs|na#6KjLSuzEr=YXJH4l;@D(lG(c z+P>pX#Vr`>82Eqc)xjWlEil5OV!?uu4II5Xyy4d2z|OJfO5?lCQ81sl%&=c;K{*S+ zJkl^Aj3|cb{%P!ENVY2ybQvtt7-l}J9nq_j^-yh3@B;Vag60=Vsw*qd$OOmi-T2XV z4XD-jNdyO`64=~@H%jzF=0X68q1VgWk1Pzr-{9i~e@zi;CZu4t#7&gpjz+jRrY~WP zf;Nr5Qd(%Vqgk=Y&zE-vXlKyRzB*{~5UKbaF(PD-O^g!id5D6VPZNkLgcLxK;?9~l zu`&V$eZH&A_BB#DrnxGrzl(KH7Jk8 zw5ba-TFxlgs{JkF6|>cv-ypK9o+e&f@+x&x;|qqSD6MKL7N`ulZ7`iVV!`GMyQX4{ zso3~*)B8leG}oQqDd?V)Ggg=!d7pF@T2G`dq(U!AW>s&V&{kMAbAVDGkz%8ej?BbQ zw7fdS(6z&HX97t$l>h{p_Z+7nbm#}qn)?H14F}vxPF1>9_g2YP=GC9dO!J8?gybQqrCYd3QU8d+E6jxd(h=vlE0OdA#!7_4U)Y0UV^~$-)cbID1R6R%Uw5 zW}8OhKdW|FSF#h?rX%^@B!57F-R=014VH~Gd6y1XLqM9tCgAIWu}W^`pw0P^ep2ci z$k|(NG{%q0NO2vk_jw5#7Kd{^m3M&cSXEh6Z9f$_u zua0Z;=??x`x=K6XKII!>@(Bet@xHQ*>=d*H8huM=>Eq%S==(I_#2Zq?PIrq-9 z`re1yD)P#=9m_uvS?#KVzF%=DTRZ+t z`-leIlU_&H#_WxWMI}ZombJPotwP5MV-`1N4Vw1inDh!995{}TkGK4$szCpwg00?h zt`__T>Eq}5{dWB_o#jen&{_49i0V00Y43uzgJmdL(xhCk)8f(qau3UfV&KC zmFn-X)#H8EGO?g9^hn$cT6D}MWsWd8q76OmB^719gfSi@_0a4(9!XieE+efFg9Wk>uf($~f>!hj_HJ60*Iz&bj{E&;Bq&r>M z6Frg7j&2BH-w}f0&RWX~>K^4Si7bjgD>ZNS<_d&^po8`m8|h85IB-(Li?wY*JM(4x*Y0uV>G%mJirUy3 zp!f(Qzz1LEovyU@t>iP)Aysb;uXuFPvMxvG^#i^rGyx-(B}Uk&#d-;q#X2m$I)g&inA; zFA5?fho8(AARjlM_}qY_OtNQ<62H;P8HZ8w1XkIbP3%qPy{`$N?(7XVNOTaoiTzqb zQMnLR@dKY*`UPHd^3qp;-&Z)gxgH)%W51R&pFguXZQQQ^K51}3+5@B&9iV&L`XrbG zC$oYlC)-oanloa>CmKgD(>O+ROW#71qdy$&zB#<%%~%aN&66$lzs!HEvo5h}hnZnk z8O_K{nGxeYaTNLfTaLJ4t&67<=7GgnCRVWzib|jXG=B=EAk}3=M)-c3R})%3ko;3S z!S)C50&$AK`%KhNvEGDe-|_@d-YFBJhCTBQe2|oMP%^ZzyCV%L-zJS4%tG=&DFg0y^%P) zY5KaFC2LofwJW&`16~kuKPK%0LeCS8WT-!C$;34{;>a*0>dd*kQ%_zrX#b4t>Ws2= z98X-sKXmRxP>TOMEo;NCeweYmy@cxoFOf#Tgw9+3Sgp@CoOK|nHgwoRn(u+WyT&mKGG4f8-!+f2 zSID{($pTR)J`gbaJX@DUeLF|`E~W4}UfDeE=^YgcPnlxWSbz1Nvr#C*21sCKj zOj%0TOPfRpqC?Y>^8}@H83F}awFC@_>pP7!N_{d#=I9(X_<}DoT(FRxPJren zHbfes&UnAH_Y>=x20E`*6ZV)Hem#-uK)J#!iXL`jiMc-M1C)A!l6sM|WZp@vC-e4WzLz%*rN5Cg7sPXAC%V zZ0E{U>cpaPQTLOPHLOreiQ@Yci9tt!o?@K6lX0i+PMG3K=0#3?FBL9$+&5QU=0W~VycgZWiK>OJ7KKSVnrmw~9TG-1{Ii$Wb*o=~!pjicDzTk>|{Rdz7k4G&n9`f2tuC zaSZRpOZ}r}YqCk-hGJt-+XPfF$`0R|-Uecff`>__?LqW&! zmFwH3BCHS$?JCe-Y_=#&d=#>1DG@85?bBQZ$?%|u(j(rvrK|W`?TOozD;oM(w=FqV zi708Z$DX%FYw=Ln+n7@Qy>I5iZ35k@-t@X1_>`%`uImOweZ_KZrc&-gMkXbNFUqy# z8mzXg%O27%2~}BV%oW|_+L9`$adgMHL!|!bCrk1KPiM z={i4?*CcJ4*Yj!fyW?Lqo169yF9_O?fI^J(G44r^=MA+eIgQTg;D4qfPK-gWS$2qW zw(}r%#qWI+?tVzzrMguz$?kQ#X*ahLhJ8%yg(g8`c(W+Lef$83_@Ip7x=kEfiY#|9 zRUS3!mm=DxMQyxojHoYU*Tl`aT@~7U)T*83Vv4bMO)Om;;72@RoQMP0J6atz)wAK+ zZSx@JldxyZH$NwlJV#6yl_dmiX@UjnwD%ecnd#-h-1W+?3;n$AmKu z63)Vt#iBe-V~gpaN;uS%8+PGHnOv}?Q$trPWhJHlLIR3pgyP3wptdgmB-OI z$6As;;@SFr3l2bKDfYeIH(y=A7}ShgOzFQRcViOu5NKCVJDL!#rF?4W`;*plXx$P76Dj`*Pe;1$Y;`F zTh)3+b~TDP3VXiYE?nRKEbjHe(I0*lgJ|Ll-L`S?jmt~Xgewn5>o@JXq&2(u<@Dn% z$|DLA#+8lH2io#21M@A67U~VHPzKtSNH}pJFfP{6CdyHy(xmqa57=CQGa2zCE4A67s}z$>r>ZzMB>jr&vj>rkV}-Uj>s*x zK2cQW(GkXPY1G@Whdwgh0@P9-Pb6XF=bCH-%24YjA&&~ZX925h7LR33d*x-+2(vBL zPDqfA5DG!G3xxw)Bvux8xNR(_OMy$yB`+<>PAsh_m0ht&h07b^>BgEHmMN=S6n@?l z(We*6{olE%S!dkH6AS30({wju4;%xhT(qm}8c7Qxx+(8VuKMp8H42U<_ce=|_Y!O* zz2_r~d-!S{G;j6HqhFuNgcuHObhPEbC_T#C>a<{KCDnh~IWlr@VT)Tqkm_~tC{*RK z*mbXT`lW)mz+P+KVld~hd z1dyc&L)A$wYw}c$#r3i(OF_0N!^&)$6A`T9f&-pWj_Blo*A(N7Gr$|+^mHl1Wwmzt3} z8VXOXf;7^ePjvkBCn0(MG-3g05S!<3XTiZ_#kiCywqQj~1I0%XjhNZPG`Y6|<6X#* zKJZ7|EN9ps&Hedl5##NTm2OZyqjd>P8s#xH)EnKAqROZn`x0KehRAyO%~_>&y0+$H+jGQe@wyH|IM3{=)v|@p_43`WOno zD0Ldk;_|f5MR|I36X^io-Dr8qftWu2wrh#fE;tw#oHiK zKG&spUvN%T(@-VA_BUM$sa9SA4ZvJH;{6KGmWD-2Q!F|+?<(LN2FhkNTCu{BpOcl9 zv{joX*kuDx|5`v{%aYNm6Q9u5nZQp&MAN4vvvVyDRxlVF{h6peT=N|z?A!-u!dad* zg;?SZP8JKrNDf-MQGxA*W?`}S8_P-x#Li(V(%nqPYN@u2vq^Cbib1g9>Qi|g5>``v zA?kSqMo^~U(bpSTBFJcFI2@4DK53`I^r;;;9FL1Dr>?x0{Wbl1;j4b!d^elmg z@ka_S2QeYCq)2Cb27V078Akq8>Nr;&xC~=ze2s6cVV7&Jm}Bb$K6+o zRs;Jce^o?Yv9Eg~RkuO4@56)C;l^Z55Q$h7AD|zjmz#I zv(L}EMmR%Ju5fzDS`_c0%V-QjXl%NRw(rWn-9oWBrJG(81R_^^sg!r<3$JQ0U)3#ALyIh97x8h@|+T3tH($O5!RND4T+A%i#%DH~%2}*)tT0dd! zyWp0Xj_gbeCDo+TI}nXCA$s~r8!J|bfO6uSv(s+p^Njh6EiQ3Vm=kaT2pd3Ka>-?0 zHPtq_5W&Zd-{EX`&>i1_|>$-6MDsV(P>`<4-_e8e*8X&^iw z>=ICf^ppVH5^Zg=LOVIy!8pRL$Obub8tkYobdqeEBKvej1(Tb#hsgz8}!#79|fidkf{SloGpi z{S38uTwK#|D(L0VQzPJ*OYFTT8)gDxIq{!hezQL>R3Ei_j$W;KB{_@g*6Wm68CqaB zTI`-N9FAa5rsA9@e}O(piJr%#s6jwpk{91~h^V_u`}t@Q;!Z3_fM$pd3b~C%SXmww z^?T$5O8Wjzi5!OZmRl~_ev@1I{m7uhQ%o-qx|A$s+T{l!cfn6?kKEQ9lfgsOh)ym$ zLi(MKgyZ=Fnr>$=q!wbIq1fH<0H{xKfo$LE`yc~I3CgAj2QQ4Hs3PIg8GMKjf!$x$ zh~m0UH*e5lR@T@@$Xa2;+rK!rGe&!B1xcV#G3W3$sjYv!XF%<}X^BAI3xh7sat=G* zaP2$`bGt2I9`JxX~PMUVq)aM>oh4@2H6hyC| zWFRS`qoR@ohSD4f+xRqHxWN0$~sDZib zHLg2SQG8SHYz&NaMch@qee+p*%;tMkTT;X*6mGD%1hJBQfx%ZpQbOI&AJhh5wtGHo zOna%VgsObh62qC^;NV8p+@y}BFRFgj01L^Ev@`l^T5C6;T@-9GS{a&@c=shn2H-27 zGOpW*k8F`*7mZ{y@zR=G*LH#P!w|r=%mb$R1r^WoS{(i_yZ+B#?&IcBE zFBAPr%3zg%VrmiXSEz>dcpeh_Ju9wyLC!T_Ulc8%W55Y<8|U%|f7XlQ9saQ;=9O?a zS-lvc`36h}B>3ITDvT_Jt)Po;Rj91J&&ep+@}+EWkHdhW&t(VSq4xECv&DQqw&Fi4g9c&Ip^ApkB|0$BbQst3jSu2ZkH>fXRk z=rE9}@6$|gC-E9G^>pnzJ^~F{4n~PQ zR7k()m`!T^4$s#P-SA(`Psr4>&ikAL-}QwTu&Xb@3HblOf6}n~@m))(|_ zy0;;NvDG!Sp^~EH8bZD)`41Tv`G?qQK!DlZUs+!o>q*9NmDJC6?{}@COzjI1y3rf$ zHkJiz&sRnyV)k|u$Cl4zz=UB*yxMA^L%W)NK~4@N=FF2#-yaX@$$sN%^k9@zJB{cy z(C;YxTwd&gRrifTaE6V9SJ_<-ljWC5qwpQp9~{-VfvUP4I;@S)JG;~*D->JWv8Vf2 zMSFQbPTmFiiBx$ye-Jj;3sSvUcYfGlE7SWqZ;tc>?>ufiEjVaK?-+6is`a;OPXacB ztwMa9d{Ae9alA%N>U&?p` z-}R{tcUyKLZkG`r?ke>}%FvyW(q{QGdzd`WtX{6H+Wc&(%TC(3b^4#|s3RwqEy;Cnr z-@)do+fa&w!S40Fw)PQ33m+6Udp0XNV{#Ho+|qW6#v;eCvxJxKPi+YYN68ssAX971 zj0NN@sZ}Sw`G<^T`-6?vmi~wrdU0)*-%stj!0_^dHxpVUosT#p!KQKzsEz5m{rc0* zxNt`K^p_1Y672S;nh_W3p^F#6LwuHViys5H<20ENy# z#zFuEZ$LNtO2q4tf&^te_0nqA!S#vhKcKfN zFlhot;!bzN!(T4Q*yp#Pl8ZRv<|*#Bv;vVU>B7yipNr`lGZOl}dM4@_4%MHIzjEa; z!CN9h*09xzTiM-9D6rD-88WLk+0iso2q$WK5Ra@AHhQjgJga|>4LbB-Fknb+E68Ib zcZ6gYgOtfD&Y0!?JPM6>)v&m!2 zIpaenoU`ccL>izQ$a{;NL-1O3^Z7`>3u8|NSQ|3>-$pwOa)ej(%f XQl0p2$hGayzgJ`>l_V;~j6?nhr(^z6 literal 0 HcmV?d00001 diff --git a/docs/source/rosette-logo.svg b/docs/source/rosette-logo.svg deleted file mode 100644 index 4c69ed4..0000000 --- a/docs/source/rosette-logo.svg +++ /dev/null @@ -1,35 +0,0 @@ - - - - - -rosette2 - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From ce6e29cf239ebacdc8fd31199c0fcdaf395f4f7a Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 25 Oct 2024 12:55:10 +0200 Subject: [PATCH 224/247] WS-3314: documentation rebranding --- docs/source/conf.py | 4 ++-- docs/source/index.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 39446dd..5b56fd1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -47,8 +47,8 @@ # General information about the project. project = '' -copyright = '2024, Basis Technology' -author = 'Basis Technology' +copyright = '2024, Babel Street' +author = 'Babel Street' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/docs/source/index.rst b/docs/source/index.rst index 40ebcf1..1eac0ca 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -6,7 +6,7 @@ Python Binding ========================================== -This is the API documentation for the Rosette API Python Binding. For examples and usage, please refer to our `API Guide `_. +This is the API documentation for the Babel Street Analytics API Python Binding. For examples and usage, please refer to our `API Guide `_. .. toctree:: :maxdepth: 2 From 1bcdea585a74422135c9bf78eeafa75a6598cfe9 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 25 Oct 2024 13:48:35 +0200 Subject: [PATCH 225/247] WS-3314: update examples --- examples/README.md | 12 ++++++------ examples/address_similarity.py | 8 ++++---- examples/categories.py | 12 ++++++------ examples/entities.py | 12 ++++++------ examples/events.py | 8 ++++---- examples/events_negation.py | 8 ++++---- examples/info.py | 8 ++++---- examples/language.py | 8 ++++---- examples/language_multilingual.py | 8 ++++---- examples/morphology_complete.py | 12 ++++++------ examples/morphology_compound-components.py | 12 ++++++------ examples/morphology_han-readings.py | 12 ++++++------ examples/morphology_lemmas.py | 12 ++++++------ examples/morphology_parts-of-speech.py | 12 ++++++------ examples/name_deduplication.py | 8 ++++---- examples/name_similarity.py | 8 ++++---- examples/name_translation.py | 8 ++++---- examples/ping.py | 8 ++++---- examples/record_similarity.py | 8 ++++---- examples/relationships.py | 8 ++++---- examples/semantic_vectors.py | 12 ++++++------ examples/sentences.py | 8 ++++---- examples/sentiment.py | 12 ++++++------ examples/similar_terms.py | 12 ++++++------ examples/syntax_dependencies.py | 8 ++++---- examples/tokens.py | 12 ++++++------ examples/topics.py | 12 ++++++------ examples/transliteration.py | 12 ++++++------ 28 files changed, 140 insertions(+), 140 deletions(-) diff --git a/examples/README.md b/examples/README.md index e52b2cb..74b23a9 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,18 +1,18 @@ ## Endpoint Examples -Each example file demonstrates one of the capabilities of the Rosette Platform. +Each example file demonstrates one of the capabilities of the Babel Street Analytics Platform. Here are some methods for running the examples. Each example will also accept an optional `--url` parameter for overriding the default URL. -A note on prerequisites. Rosette API only supports TLS 1.2 so ensure your toolchain also supports it. +A note on prerequisites. Analytics API only supports TLS 1.2 so ensure your toolchain also supports it. #### Virtualenv/Latest Release ``` git clone git@github.com:rosette-api/python.git cd python/examples -virtualenv rosette_venv -source rosette_venv/bin/activate +virtualenv analytics_venv +source analytics_venv/bin/activate pip install rosette_api python ping.py -k $API_KEY ``` @@ -21,8 +21,8 @@ python ping.py -k $API_KEY ``` git clone git@github.com:rosette-api/python.git cd python -virtualenv rosette_venv -source rosette_venv/bin/activate +virtualenv analytics_venv +source analytics_venv/bin/activate python setup.py install cd examples python ping.py -k $API_KEY diff --git a/examples/address_similarity.py b/examples/address_similarity.py index f69e4e1..2175817 100644 --- a/examples/address_similarity.py +++ b/examples/address_similarity.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get match score (similarity) of two addresses. +Example code to call Analytics API to get match score (similarity) of two addresses. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, AddressSimilarityParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -29,9 +29,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/categories.py b/examples/categories.py index 1c3e122..6f09c75 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get the category of a document (at a given URL). +Example code to call Analytics API to get the category of a document (at a given URL). """ import argparse @@ -12,7 +12,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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 @@ -20,8 +20,8 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): # 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#categorization + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#categorization # api.set_option('singleLabel', 'true') # api.set_option('scoreThreshold',- 0.20) @@ -38,9 +38,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/entities.py b/examples/entities.py index 30a2ea5..beba9de 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get entities from a piece of text. +Example code to call Analytics API to get entities from a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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 + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#entity-extraction-and-linking # api.set_option('calculateSalience','true') # api.set_option('linkEntities','false') @@ -36,9 +36,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/events.py b/examples/events.py index 828dd45..79ffc3e 100644 --- a/examples/events.py +++ b/examples/events.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get events from a piece of text. +Example code to call Analytics API to get events from a piece of text. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -27,9 +27,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/events_negation.py b/examples/events_negation.py index 880420f..becc731 100644 --- a/examples/events_negation.py +++ b/examples/events_negation.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get events, based on a set negation option, from a piece of text. +Example code to call Analytics API to get events, based on a set negation option, from a piece of text. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -31,9 +31,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/info.py b/examples/info.py index 9684088..8fba621 100644 --- a/examples/info.py +++ b/examples/info.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get information such as version and build +Example code to call Analytics API to get information such as version and build """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -24,9 +24,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/language.py b/examples/language.py index fbfc936..e4fa87a 100644 --- a/examples/language.py +++ b/examples/language.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to determine the language of a piece of text. +Example code to call Analytics API to determine the language of a piece of text. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -28,9 +28,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/language_multilingual.py b/examples/language_multilingual.py index c442b76..36bd8e6 100644 --- a/examples/language_multilingual.py +++ b/examples/language_multilingual.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to determine the language of a piece of text. +Example code to call Analytics API to determine the language of a piece of text. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -30,9 +30,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index b1c0880..10b1004 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get the complete morphological analysis of a piece of text. +Example code to call Analytics API to get the complete morphological analysis of a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#morphological-analysis-introduction + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#morphological-analysis-introduction # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only @@ -34,9 +34,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index 3332e71..5bacddb 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get de-compounded words from a piece of text. +Example code to call Analytics API to get de-compounded words from a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#morphological-analysis-introduction + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#morphological-analysis-introduction # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only @@ -34,9 +34,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index b140969..f5c12f6 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get Chinese readings of words in a piece of text. +Example code to call Analytics API to get Chinese readings of words in a piece of text. """ import argparse @@ -10,14 +10,14 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#morphological-analysis-introduction + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#morphological-analysis-introduction # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only @@ -33,9 +33,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index 20921cb..dc7bb8d 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get lemmas for words in a piece of text. +Example code to call Analytics API to get lemmas for words in a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#morphological-analysis-introduction + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#morphological-analysis-introduction # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only @@ -34,9 +34,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index 48e3a07..f020ca2 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get part-of-speech tags for words in a piece of text. +Example code to call Analytics API to get part-of-speech tags for words in a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#morphological-analysis-introduction + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#morphological-analysis-introduction # api.set_option('modelType','perceptron') # Valid for Chinese and Japanese only @@ -34,9 +34,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/name_deduplication.py b/examples/name_deduplication.py index 3c56fa9..7c69e20 100644 --- a/examples/name_deduplication.py +++ b/examples/name_deduplication.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to deduplicate a list of names. +Example code to call Analytics API to deduplicate a list of names. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, NameDeduplicationParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -29,9 +29,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/name_similarity.py b/examples/name_similarity.py index d700789..b8a51ec 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get match score (similarity) of two names. +Example code to call Analytics API to get match score (similarity) of two names. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, NameSimilarityParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -31,9 +31,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/name_translation.py b/examples/name_translation.py index fd9a753..455fc50 100644 --- a/examples/name_translation.py +++ b/examples/name_translation.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to translate a name from one language to another. +Example code to call Analytics API to translate a name from one language to another. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, NameTranslationParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -30,9 +30,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/ping.py b/examples/ping.py index 89d0925..f908367 100644 --- a/examples/ping.py +++ b/examples/ping.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to send Rosette API a ping to check its reachability. +Example code to send Analytics API a ping to check its reachability. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -24,9 +24,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/record_similarity.py b/examples/record_similarity.py index f39b548..0ef1ea7 100644 --- a/examples/record_similarity.py +++ b/examples/record_similarity.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get similarity score between a list of records +Example code to call Analytics API to get similarity score between a list of records """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, RecordSimilarityParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -102,9 +102,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/relationships.py b/examples/relationships.py index a04651c..490a527 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get entities's relationships from a piece of text. +Example code to call Analytics API to get entities's relationships from a piece of text. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -26,9 +26,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/semantic_vectors.py b/examples/semantic_vectors.py index c67e326..ef99e5b 100644 --- a/examples/semantic_vectors.py +++ b/examples/semantic_vectors.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get text vectors from a piece of text. +Example code to call Analytics API to get text vectors from a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#semantic-vectors + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#semantic-vectors # api.set_option('perToken', 'true') @@ -34,9 +34,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/sentences.py b/examples/sentences.py index 747db2e..f0c3e12 100644 --- a/examples/sentences.py +++ b/examples/sentences.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get sentences in a piece of text. +Example code to call Analytics API to get sentences in a piece of text. """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key=key, service_url=alt_url) @@ -28,9 +28,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/sentiment.py b/examples/sentiment.py index dd5b52e..1a292d8 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get the sentiment of a local file. +Example code to call Analytics API to get the sentiment of a local file. """ import argparse @@ -12,7 +12,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ # Create default file to read from temp_file = tempfile.NamedTemporaryFile(suffix=".html") @@ -25,8 +25,8 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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#sentiment-analysis + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#sentiment-analysis # api.set_option('modelType','dnn') #Valid for English only @@ -49,9 +49,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/similar_terms.py b/examples/similar_terms.py index 88f2940..753e397 100644 --- a/examples/similar_terms.py +++ b/examples/similar_terms.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get similar terms for an input. +Example code to call Analytics API to get similar terms for an input. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#similar-terms + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#similar-terms api.set_option("resultLanguages", ['spa', 'deu', 'jpn']) @@ -34,9 +34,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index 38a86b0..e5e99a0 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get the syntactic dependencies of a document (at a given URL). +Example code to call Analytics API to get the syntactic dependencies of a document (at a given URL). """ import argparse @@ -10,7 +10,7 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): """ Run the example """ syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday." params = DocumentParameters() @@ -26,9 +26,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/tokens.py b/examples/tokens.py index a7f47a6..e98601c 100644 --- a/examples/tokens.py +++ b/examples/tokens.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get the tokens (words) in a piece of text. +Example code to call Analytics API to get the tokens (words) in a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#tokenization + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#tokenization # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only @@ -34,9 +34,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/topics.py b/examples/topics.py index 55fa627..e33a745 100644 --- a/examples/topics.py +++ b/examples/topics.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to get the topics (key phrases and concepts) in a piece of text. +Example code to call Analytics API to get the topics (key phrases and concepts) in a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#topic-extraction + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#topic-extraction # api.set_option('keyphraseSalienceThreshold','.5') # api.set_option('conceptSalienceThreshold','.1') @@ -35,9 +35,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() diff --git a/examples/transliteration.py b/examples/transliteration.py index be9aa82..bc7c5da 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Example code to call Rosette API to transliterate a piece of text. +Example code to call Analytics API to transliterate a piece of text. """ import argparse @@ -10,15 +10,15 @@ from rosette.api import API, DocumentParameters, RosetteException -def run(key, alt_url='https://api.rosette.com/rest/v1/'): +def run(key, alt_url='https://analytics.babelstreet.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#transliteration + # and other available options, see Analytics Features & Functions + # https://developer.babelstreet.com/features-and-functions#transliteration # To transliterate from native Arabic script to Arabizi add: # api.set_option('reversed','True') @@ -36,9 +36,9 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): 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('-k', '--key', help='Analytics API Key', required=True) PARSER.add_argument('-u', '--url', help="Alternative API URL", - default='https://api.rosette.com/rest/v1/') + default='https://analytics.babelstreet.com/rest/v1/') if __name__ == '__main__': ARGS = PARSER.parse_args() From 740a61c62c7032fba5db2b09a3537c57bcdc6e00 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 25 Oct 2024 14:05:25 +0200 Subject: [PATCH 226/247] WS-3314: update url, key header and documentation comments --- rosette/__init__.py | 2 +- rosette/api.py | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index 200c03e..880e295 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -1,5 +1,5 @@ """ -Python client for the Rosette API. +Python client for the Babel Street Analytics API. Copyright (c) 2014-2022 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/rosette/api.py b/rosette/api.py index 6114554..b6fa7af 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -Python client for the Rosette API. +Python client for the Babel Street Analytics API. Copyright (c) 2014-2024 Basis Technology Corporation. @@ -68,7 +68,7 @@ def _my_loads(obj, response_headers): class RosetteException(Exception): - """Exception thrown by all Rosette API operations for errors local and remote. + """Exception thrown by all Analytics API operations for errors local and remote. TBD. Right now, the only valid operation is conversion to __str__. """ @@ -96,13 +96,13 @@ def __init__(self, repertoire): def __setitem__(self, key, val): if key not in self.__params: raise RosetteException( - "badKey", "Unknown Rosette parameter key", repr(key)) + "badKey", "Unknown Analytics parameter key", repr(key)) self.__params[key] = val def __getitem__(self, key): if key not in self.__params: raise RosetteException( - "badKey", "Unknown Rosette parameter key", repr(key)) + "badKey", "Unknown Analytics parameter key", repr(key)) return self.__params[key] def validate(self): @@ -370,9 +370,9 @@ def validate(self): class EndpointCaller(object): """L{EndpointCaller} objects are invoked via their instance methods to obtain results - from the Rosette server described by the L{API} object from which they + from the Analytics server described by the L{API} object from which they are created. Each L{EndpointCaller} object communicates with a specific endpoint - of the Rosette server, specified at its creation. Use the specific + of the Analytics server, specified at its creation. Use the specific instance methods of the L{API} object to create L{EndpointCaller} objects bound to corresponding endpoints. @@ -382,7 +382,7 @@ class EndpointCaller(object): The results of all operations are returned as python dictionaries, whose keys and values correspond exactly to those of the corresponding - JSON return value described in the Rosette web service documentation. + JSON return value described in the Analytics web service documentation. """ def __init__(self, api, suburl): @@ -413,7 +413,7 @@ def __finish_result(self, response, ename): complaint_url = ename + " " + self.suburl raise RosetteException(code, complaint_url + - " : failed to communicate with Rosette", msg) + " : failed to communicate with Analytics", msg) def __set_headers(self): headers = {'Accept': _APPLICATION_JSON, @@ -435,7 +435,7 @@ def __set_headers(self): headers[_CUSTOM_HEADER_PREFIX + 'Devel'] = 'true' if self.user_key is not None: - headers[_CUSTOM_HEADER_PREFIX + "Key"] = self.user_key + headers["X-BabelStreetAPI-Key"] = self.user_key return headers @@ -473,7 +473,7 @@ def call(self, parameters, paramtype=None): In all cases, the result is returned as a python dictionary conforming to the JSON object described in the endpoint's entry - in the Rosette web service documentation. + in the Analytics web service documentation. @param parameters: An object specifying the data, and possible metadata, to be processed by the endpoint. See the @@ -548,22 +548,22 @@ def call(self, parameters, paramtype=None): class API(object): """ - Rosette Python Client Binding API; representation of a Rosette server. + Analytics Python Client Binding API; representation of an Analytics server. Call instance methods upon this object to obtain L{EndpointCaller} objects - which can communicate with particular Rosette server endpoints. + which can communicate with particular Analytics server endpoints. """ def __init__( self, user_key=None, - service_url='https://api.rosette.com/rest/v1/', + service_url='https://analytics.babelstreet.com/rest/v1/', retries=5, refresh_duration=0.5, debug=False): """ Create an L{API} object. @param user_key: (Optional; required for servers requiring authentication.) An authentication string to be sent as user_key with all requests. The - default Rosette server requires authentication to the server. + default Analytics server requires authentication to the server. """ # logging.basicConfig(filename="binding.log", filemode="w", level=logging.DEBUG) self.user_key = user_key @@ -703,7 +703,7 @@ def _make_request(self, operation, url, data, headers): except requests.exceptions.RequestException as exception: raise RosetteException( exception, - "Unable to establish connection to the Rosette API server", + "Unable to establish connection to the Analytics API server", url) raise RosetteException(code, message, url) From ea8bbc34bdb66e11ba3f6cffa534fe140b80384b Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 25 Oct 2024 14:37:14 +0200 Subject: [PATCH 227/247] WS-3314: update tests --- tests/test_rosette_api.py | 146 +++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index a635025..8316b97 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -155,7 +155,7 @@ def test_user_agent(api): def test_ping(api, json_response): """Test ping""" httpretty.enable() - httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/ping", + httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/ping", body=json_response, status=200, content_type="application/json") result = api.ping() @@ -169,7 +169,7 @@ def test_ping(api, json_response): def test_info(api, json_response): """Test info""" httpretty.enable() - httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") result = api.info() @@ -184,7 +184,7 @@ def test_info(api, json_response): def test_for_409(api, json_409): """Test for 409 handling""" httpretty.enable() - httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/info", body=json_409, status=409, content_type="application/json") with pytest.raises(RosetteException) as e_rosette: @@ -200,7 +200,7 @@ def test_for_409(api, json_409): def test_the_max_pool_size(json_response, doc_params): """Test max pool size""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/language", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", body=json_response, status=200, content_type="application/json", adding_headers={ 'x-rosetteapi-concurrency': 5 @@ -221,7 +221,7 @@ def test_the_max_pool_size(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/language", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", body=json_response, status=200, content_type="application/json") result = api.language(doc_params) @@ -240,7 +240,7 @@ def test_the_language_endpoint(api, json_response, doc_params, doc_map): 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/sentences", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentences", body=json_response, status=200, content_type="application/json") result = api.sentences(doc_params) @@ -261,7 +261,7 @@ def test_the_sentences_endpoint(api, json_response, doc_params, doc_map): 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/tokens", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/tokens", body=json_response, status=200, content_type="application/json") result = api.tokens(doc_params) @@ -275,9 +275,9 @@ def test_the_tokens_endpoint(api, json_response, doc_params): def test_the_morphology_complete_endpoint(api, json_response, doc_params): """Test the morphology complete endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/morphology/complete", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/complete", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params) @@ -291,9 +291,9 @@ def test_the_morphology_complete_endpoint(api, json_response, doc_params): def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): """Test the morphology lemmas endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/morphology/lemmas", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/lemmas", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'lemmas') @@ -307,9 +307,9 @@ def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): def test_the_morphology_parts_of_speech_endpoint(api, json_response, doc_params): """Test the morphology parts-of-speech endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/morphology/parts-of-speech", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/parts-of-speech", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'parts-of-speech') @@ -323,9 +323,9 @@ def test_the_morphology_parts_of_speech_endpoint(api, json_response, doc_params) def test_the_morphology_compound_components_endpoint(api, json_response, doc_params): """Test the morphology compound-components endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/morphology/compound-components", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/compound-components", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'compound-components') @@ -339,9 +339,9 @@ def test_the_morphology_compound_components_endpoint(api, json_response, doc_par def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): """Test the morphology han-reading endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/morphology/han-readings", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/han-readings", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'han-readings') @@ -355,9 +355,9 @@ def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): def test_the_entities_endpoint(api, json_response, doc_params): """Test the entities endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/entities", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", body=json_response, status=200, content_type="application/json") result = api.entities(doc_params) @@ -371,9 +371,9 @@ def test_the_entities_endpoint(api, json_response, doc_params): def test_the_categories_endpoint(api, json_response, doc_params): """Test the categories endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/categories", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/categories", body=json_response, status=200, content_type="application/json") result = api.categories(doc_params) @@ -387,9 +387,9 @@ def test_the_categories_endpoint(api, json_response, doc_params): def test_the_sentiment_endpoint(api, json_response, doc_params): """Test the sentiment endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/sentiment", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentiment", body=json_response, status=200, content_type="application/json") result = api.sentiment(doc_params) @@ -403,9 +403,9 @@ def test_the_sentiment_endpoint(api, json_response, doc_params): def test_the_multipart_operation(api, json_response, doc_params, tmpdir): """Test multipart""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/sentiment", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentiment", body=json_response, status=200, content_type="application/json") tmp_file = tmpdir.mkdir("sub").join("testfile.txt") @@ -420,9 +420,9 @@ def test_the_multipart_operation(api, json_response, doc_params, tmpdir): 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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentences", body=json_response, status=200, content_type="application/json") params = NameTranslationParameters() @@ -445,9 +445,9 @@ def test_incompatible_type(api, json_response): def test_the_name_translation_endpoint(api, json_response): """Test the name translation endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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-translation", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", body=json_response, status=200, content_type="application/json") params = NameTranslationParameters() @@ -465,9 +465,9 @@ def test_the_name_translation_endpoint(api, json_response): 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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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") @@ -496,9 +496,9 @@ def test_the_name_requests_with_text(api, json_response): 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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") matched_name_data1 = "John Mike Smith" @@ -517,9 +517,9 @@ def test_the_name_similarity_single_parameters(api, json_response): def test_the_name_similarity_multiple_parameters(api, json_response): """Test the name similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") matched_name_data1 = "John Mike Smith" @@ -538,9 +538,9 @@ def test_the_name_similarity_multiple_parameters(api, json_response): def test_the_name_similarity_endpoint(api, json_response): """Test the name similarity endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") matched_name_data1 = "Michael Jackson" @@ -564,9 +564,9 @@ def test_the_name_similarity_endpoint(api, json_response): def test_name_deduplication_parameters(api, json_response): """Test the Name Deduplication Parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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-deduplication", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-deduplication", body=json_response, status=200, content_type="application/json") params = NameDeduplicationParameters() @@ -589,9 +589,9 @@ def test_name_deduplication_parameters(api, json_response): def test_the_name_deduplication_endpoint(api, json_response): """Test the name deduplication endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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-deduplication", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-deduplication", body=json_response, status=200, content_type="application/json") dedup_list = ["John Smith", "Johnathon Smith", "Fred Jones"] @@ -611,9 +611,9 @@ def test_the_name_deduplication_endpoint(api, json_response): def test_the_relationships_endpoint(api, json_response): """Test the relationships endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/relationships", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/relationships", body=json_response, status=200, content_type="application/json") params = DocumentParameters() @@ -631,9 +631,9 @@ def test_for_404(api, json_response): """Test for 404 handling""" httpretty.enable() body = json.dumps({'message': 'not found'}) - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/info", body=body, status=404, content_type="application/json") with pytest.raises(RosetteException) as e_rosette: @@ -650,9 +650,9 @@ def test_for_404(api, json_response): def test_for_content_and_contentUri(api, json_response, doc_params): """Test for content and contentUri in DocumentParameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/entities", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", body=json_response, status=200, content_type="application/json") doc_params['contentUri'] = 'https://example.com' @@ -670,9 +670,9 @@ def test_for_content_and_contentUri(api, json_response, doc_params): def test_for_no_content_or_contentUri(api, json_response, doc_params): """Test for missing content and contentUri in DocumentParameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/entities", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", body=json_response, status=200, content_type="application/json") doc_params['content'] = None @@ -688,9 +688,9 @@ def test_for_no_content_or_contentUri(api, json_response, doc_params): def test_for_address_similarity_required_parameters(api, json_response): """Test address similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/address-similarity", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/address-similarity", body=json_response, status=200, content_type="application/json") params = AddressSimilarityParameters() @@ -724,9 +724,9 @@ def test_for_address_similarity_required_parameters(api, json_response): def test_for_address_similarity_optional_parameters(api, json_response): """Test address similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/address-similarity", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/address-similarity", body=json_response, status=200, content_type="application/json") params = AddressSimilarityParameters() @@ -753,9 +753,9 @@ def test_for_address_similarity_optional_parameters(api, json_response): def test_for_name_similarity_required_parameters(api, json_response): """Test name similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") matched_name_data1 = "Michael Jackson" @@ -791,9 +791,9 @@ def test_for_name_similarity_required_parameters(api, json_response): def test_for_name_translation_required_parameters(api, json_response): """Test name translation parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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-translation", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", body=json_response, status=200, content_type="application/json") params = NameTranslationParameters() @@ -826,7 +826,7 @@ def test_for_name_translation_required_parameters(api, json_response): def test_the_semantic_vectors_endpoint(api, json_response, doc_params): """Test semantic vectors endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/semantics/vector", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/semantics/vector", body=json_response, status=200, content_type="application/json") result = api.semantic_vectors(doc_params) @@ -838,7 +838,7 @@ def test_the_semantic_vectors_endpoint(api, json_response, doc_params): def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): """Test syntax dependencies endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/syntax/dependencies", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/syntax/dependencies", body=json_response, status=200, content_type="application/json") result = api.syntax_dependencies(doc_params) @@ -852,9 +852,9 @@ def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): def test_the_transliteration_endpoint(api, json_response): """Test the transliteration endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/transliteration", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/transliteration", body=json_response, status=200, content_type="application/json") params = DocumentParameters() @@ -870,9 +870,9 @@ def test_the_transliteration_endpoint(api, json_response): def test_the_topics_endpoint(api, json_response, doc_params): """Test the topics endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", body=json_response, status=200, content_type="application/json") - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/topics", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/topics", body=json_response, status=200, content_type="application/json") result = api.topics(doc_params) @@ -886,7 +886,7 @@ def test_the_topics_endpoint(api, json_response, doc_params): def test_the_similar_terms_endpoint(api, json_response, doc_params): """Test the similar terms endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/semantics/similar", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/semantics/similar", body=json_response, status=200, content_type="application/json") api.set_option("resultLanguages", ["spa", "jpn", "deu"]) @@ -901,7 +901,7 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): # TEXT_EMBEDDING calls SEMANTIC_VECTORS httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/semantics/vector", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/semantics/vector", body=json_response, status=200, content_type="application/json") result = api.text_embedding(doc_params) @@ -911,9 +911,9 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): # MATCHED_NAME calls NAME_SIMILARITY httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") name_similarity_params = NameSimilarityParameters() @@ -932,9 +932,9 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): # TRANSLATED_NAME calls NAME_TRANSLATION httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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-translation", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", body=json_response, status=200, content_type="application/json") name_translation_params = NameTranslationParameters() @@ -955,9 +955,9 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): 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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.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", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/events", body=json_response, status=200, content_type="application/json") result = api.events(doc_params) @@ -971,7 +971,7 @@ def test_the_events_endpoint(api, json_response, doc_params): def test_the_record_similarity_endpoint(api, json_response): """Test the record similarity endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/record-similarity", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/record-similarity", body=json_response, status=200, content_type="application/json") params = RecordSimilarityParameters() @@ -988,7 +988,7 @@ def test_the_record_similarity_endpoint(api, json_response): def test_for_record_similarity_required_parameters(api, json_response): """Test record similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/record-similarity", + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/record-similarity", body=json_response, status=200, content_type="application/json") params = RecordSimilarityParameters() From 69b8291986fa16de95841a95d3b18dcaf53274a2 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 25 Oct 2024 14:49:21 +0200 Subject: [PATCH 228/247] WS-3314: update readme and package description --- README.md | 34 ++++++++++++++++++++++++++-------- setup.py | 4 ++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ceb1212..2ce08ef 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,31 @@ - -# Rosette by Babel Street + + + + + Babel Street Logo + + + +# Analytics by Babel Street [![PyPI version](https://badge.fury.io/py/rosette-api.svg)](https://badge.fury.io/py/rosette-api) [![Python Versions](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions)](https://img.shields.io/pypi/pyversions/rosette-api.svg?color=dark%20green&label=Python%20Versions) -Rosette uses natural language processing, statistical modeling, and machine learning to analyze unstructured and semi-structured text across hundreds of language-script combinations, revealing valuable information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and comparing the similarity of names, categorizing and adding linguistic tags to text and more. Rosette Server is the on-premises installation of Rosette, with access to Rosette's functions as RESTful web service endpoints. This solves cloud security worries and allows customization (models/indexes) as needed for your business. +Our product is a full text processing pipeline from data preparation to extracting the most relevant information and +analysis utilizing precise, focused AI that has built-in human understanding. Text Analytics provides foundational +linguistic analysis for identifying languages and relating words. The result is enriched and normalized text for +high-speed search and processing without translation. + +Text Analytics extracts events and entities — people, organizations, and places — from unstructured text and adds the +structure of associating those entities into events that deliver only the necessary information for near real-time +decision making. Accompanying tools shorten the process of training AI models to recognize domain-specific events. + +The product delivers a multitude of ways to sharpen and expand search results. Semantic similarity expands search +beyond keywords to words with the same meaning, even in other languages. Sentiment analysis and topic extraction help +filter results to what’s relevant. -## Rosette API Access -- Rosette Cloud [Sign Up](https://developer.rosette.com/signup) +## Analytics API Access +- Analytics Cloud [Sign Up](https://developer.babelstreet.com/signup) ## Quick Start @@ -15,14 +33,14 @@ Rosette uses natural language processing, statistical modeling, and machine lear `pip install rosette_api` #### Examples -View small example programs for each Rosette endpoint +View small example programs for each Analytics endpoint in the [examples](https://github.com/rosette-api/python/tree/develop/examples) directory. #### Documentation & Support - [Binding API](https://rosette-api.github.io/python/) -- [Rosette Platform API](https://docs.babelstreet.com/API/en/index-en.html) +- [Analytics Platform API](https://docs.babelstreet.com/API/en/index-en.html) - [Binding Release Notes](https://github.com/rosette-api/python/wiki/Release-Notes) -- [Rosette Platform Release Notes](https://babelstreet.my.site.com/support/s/article/Rosette-Cloud-Release-Notes) +- [Analytics Platform Release Notes](https://docs.babelstreet.com/Release/en/rosette-cloud.html) - [Support](https://babelstreet.my.site.com/support/s/) - [Binding License: Apache 2.0](https://github.com/rosette-api/python/blob/develop/LICENSE.txt) diff --git a/setup.py b/setup.py index 309ec07..78cb2b2 100755 --- a/setup.py +++ b/setup.py @@ -6,8 +6,8 @@ import rosette NAME = "rosette_api" -DESCRIPTION = "Rosette API Python client SDK" -AUTHOR = "Rosette by Babel Street" +DESCRIPTION = "Babel Street Analytics API Python client SDK" +AUTHOR = "Analytics by Babel Street" AUTHOR_EMAIL = "helpdesk@babelstreet.com" HOMEPAGE = "https://github.com/rosette-api/python" VERSION = rosette.__version__ From a48864d056398d5ad36c9c7ba7a43f99316930ab Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 28 Oct 2024 12:11:08 +0100 Subject: [PATCH 229/247] WS-3314: copyright year --- rosette/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosette/__init__.py b/rosette/__init__.py index 880e295..a1108fd 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -1,6 +1,6 @@ """ Python client for the Babel Street Analytics API. -Copyright (c) 2014-2022 Basis Technology Corporation. +Copyright (c) 2014-2024 Basis Technology Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at From 7c5f72cf150426db6967658e95aa954445e2d59b Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Tue, 29 Oct 2024 16:35:15 +0100 Subject: [PATCH 230/247] WS-3314: update example runner --- examples/run_all.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/run_all.sh b/examples/run_all.sh index 3f18bd7..d29f729 100644 --- a/examples/run_all.sh +++ b/examples/run_all.sh @@ -1,5 +1,11 @@ #!/bin/bash + +OPTS="" +if [ -n "$2" ]; then + OPTS="-u $2" +fi + for f in *.py do - python $f --key $1 + python $f --key $1 "$OPTS" done From 44f9b4815277f01531416d5bbcfb573f0ab3e1f5 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Tue, 29 Oct 2024 17:19:24 +0100 Subject: [PATCH 231/247] WS-3314: update example runner usage info --- examples/run_all.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/run_all.sh b/examples/run_all.sh index d29f729..738516f 100644 --- a/examples/run_all.sh +++ b/examples/run_all.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ $# -eq 0 ]; then + echo "Usage: $0 API_KEY [ALT_URL]" 1>&2 + exit 1 +fi OPTS="" if [ -n "$2" ]; then OPTS="-u $2" From db7e3a1adb8616d82e30356de68dbf2b9ea511e6 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 4 Nov 2024 11:38:37 +0100 Subject: [PATCH 232/247] WS-3314: fix example runner --- examples/run_all.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/run_all.sh b/examples/run_all.sh index 738516f..ab797c9 100644 --- a/examples/run_all.sh +++ b/examples/run_all.sh @@ -4,12 +4,12 @@ if [ $# -eq 0 ]; then echo "Usage: $0 API_KEY [ALT_URL]" 1>&2 exit 1 fi -OPTS="" -if [ -n "$2" ]; then - OPTS="-u $2" -fi for f in *.py do - python $f --key $1 "$OPTS" + if [ -n "$2" ]; then + python $f --key $1 --url $2 + else + python $f --key $1 + fi done From b8742d0d1ab320fe9e64d80bd57e24c028a3c904 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 4 Nov 2024 14:18:12 +0100 Subject: [PATCH 233/247] WS-3314: update more headers --- rosette/api.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index b6fa7af..d999380 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -31,9 +31,12 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' _BINDING_VERSION = '1.30.0' -_CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' -_CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' -_CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX) +# TODO Remove legacies in future release +_LEGACY_CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' +_CONCURRENCY_HEADER = 'x-babelstreetapi-concurrency' +_LEGACY_CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-' +_CUSTOM_HEADER_PREFIX = "X-BabelStreetAPI-" +_CUSTOM_HEADER_PATTERN = re.compile('^(:?' + _CUSTOM_HEADER_PREFIX + '|' + _LEGACY_CUSTOM_HEADER_PREFIX + ')') _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) _ISPY3 = sys.version_info[0] == 3 @@ -413,12 +416,15 @@ def __finish_result(self, response, ename): complaint_url = ename + " " + self.suburl raise RosetteException(code, complaint_url + - " : failed to communicate with Analytics", msg) + " : failed to communicate with Babel Street Analytics API", msg) def __set_headers(self): headers = {'Accept': _APPLICATION_JSON, _CUSTOM_HEADER_PREFIX + 'Binding': _BINDING_LANGUAGE, - _CUSTOM_HEADER_PREFIX + 'Binding-Version': _BINDING_VERSION} + _CUSTOM_HEADER_PREFIX + 'Binding-Version': _BINDING_VERSION, + #TODO Remove in future release + _LEGACY_CUSTOM_HEADER_PREFIX + 'Binding': _BINDING_LANGUAGE, + _LEGACY_CUSTOM_HEADER_PREFIX + 'Binding-Version': _BINDING_VERSION} custom_headers = self.api.get_custom_headers() if custom_headers is not None: @@ -427,12 +433,13 @@ def __set_headers(self): headers[key] = custom_headers[key] else: raise RosetteException("badHeader", - "Custom header name must begin with \"" + _CUSTOM_HEADER_PREFIX + "\"", + "Custom header name must begin with \"" + _CUSTOM_HEADER_PREFIX + "\" or \"" + + _LEGACY_CUSTOM_HEADER_PREFIX + "\"", key) self.api.clear_custom_headers() if self.debug: - headers[_CUSTOM_HEADER_PREFIX + 'Devel'] = 'true' + headers[_LEGACY_CUSTOM_HEADER_PREFIX + 'Devel'] = 'true' if self.user_key is not None: headers["X-BabelStreetAPI-Key"] = self.user_key @@ -537,7 +544,7 @@ def call(self, parameters, paramtype=None): _my_loads(rdata, response_headers), status) else: if self.debug: - headers[_CUSTOM_HEADER_PREFIX + 'Devel'] = 'true' + headers[_LEGACY_CUSTOM_HEADER_PREFIX + 'Devel'] = 'true' self.logger.info('operate: ' + url) headers['Accept'] = _APPLICATION_JSON headers['Accept-Encoding'] = "gzip" @@ -584,7 +591,7 @@ def __init__( self.url_parameters = {} self.max_pool_size = 1 self.session = requests.Session() - self.user_agent_string = 'RosetteAPIPython/' + _BINDING_VERSION + '/' + platform.python_version() + self.user_agent_string = 'Babel-Street-Analytics-API-Python/' + _BINDING_VERSION + '/' + platform.python_version() self.morphology_output = { 'LEMMAS': 'lemmas', @@ -646,8 +653,12 @@ def set_pool_size(self, new_pool_size): self.session.mount('http://', adapter) # NOSONAR def __adjust_concurrency(self, dict_headers): - if _CONCURRENCY_HEADER in dict_headers and dict_headers[_CONCURRENCY_HEADER] != self.max_pool_size: - self.set_pool_size(dict_headers[_CONCURRENCY_HEADER]) + if _CONCURRENCY_HEADER in dict_headers: + if dict_headers[_CONCURRENCY_HEADER] != self.max_pool_size: + self.set_pool_size(dict_headers[_CONCURRENCY_HEADER]) + elif _LEGACY_CONCURRENCY_HEADER in dict_headers: + if dict_headers[_LEGACY_CONCURRENCY_HEADER] != self.max_pool_size: + self.set_pool_size(dict_headers[_LEGACY_CONCURRENCY_HEADER]) def _make_request(self, operation, url, data, headers): """ From 22b945fc3579522d39e2dbf6413bcf0a90267b91 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 4 Nov 2024 14:23:59 +0100 Subject: [PATCH 234/247] WS-3314: update tests with additional headers and remove mocking of the info endpoint --- tests/test_rosette_api.py | 179 +++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 101 deletions(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 8316b97..81de474 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -38,7 +38,7 @@ @pytest.fixture def json_response(): """ fixture to return info body""" - body = json.dumps({'name': 'Rosette', 'versionChecked': True}) + body = json.dumps({'name': 'Babel Street Analytics', 'versionChecked': True}) return body @@ -120,7 +120,7 @@ def test_url_parameter_clear_single(api): def test_custom_header_props(api): """Test custom header get/set/clear""" - key = 'X-RosetteAPI-Test' + key = 'X-BabelStreetAPI-Test' value = 'foo' api.set_custom_headers(key, value) assert value == api.get_custom_headers()[key] @@ -145,7 +145,7 @@ def test_invalid_header(api): def test_user_agent(api): """ Test user agent """ - value = "RosetteAPIPython/" + api.get_binding_version() + "/" + platform.python_version() + value = "Babel-Street-Analytics-API-Python/" + api.get_binding_version() + "/" + platform.python_version() assert value == api.get_user_agent_string() # Test that pinging the API is working properly @@ -159,7 +159,7 @@ def test_ping(api, json_response): body=json_response, status=200, content_type="application/json") result = api.ping() - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -173,7 +173,7 @@ def test_info(api, json_response): body=json_response, status=200, content_type="application/json") result = api.info() - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -197,7 +197,7 @@ def test_for_409(api, json_409): # Test the max_pool_size -def test_the_max_pool_size(json_response, doc_params): +def test_the_max_pool_size_rosette(json_response, doc_params): """Test max pool size""" httpretty.enable() httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", @@ -208,13 +208,50 @@ def test_the_max_pool_size(json_response, doc_params): api = API('bogus_key') assert api.get_pool_size() == 1 result = api.language(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" assert api.get_pool_size() == 5 api.set_pool_size(11) assert api.get_pool_size() == 11 httpretty.disable() httpretty.reset() +def test_the_max_pool_size_babelstreet(json_response, doc_params): + """Test max pool size""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", + body=json_response, status=200, content_type="application/json", + adding_headers={ + 'x-babelstreetapi-concurrency': 5 + }) + api = API('bogus_key') + assert api.get_pool_size() == 1 + result = api.language(doc_params) + assert result["name"] == "Babel Street Analytics" + assert api.get_pool_size() == 5 + api.set_pool_size(11) + assert api.get_pool_size() == 11 + httpretty.disable() + httpretty.reset() + +def test_the_max_pool_size_bot(json_response, doc_params): + """Test max pool size""" + httpretty.enable() + httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", + body=json_response, status=200, content_type="application/json", + adding_headers={ + 'x-rosetteapi-concurrency': 5, + 'x-babelstreetapi-concurrency': 8 + }) + api = API('bogus_key') + assert api.get_pool_size() == 1 + result = api.language(doc_params) + assert result["name"] == "Babel Street Analytics" + assert api.get_pool_size() == 8 + api.set_pool_size(11) + assert api.get_pool_size() == 11 + httpretty.disable() + httpretty.reset() + # Test the language endpoint @@ -225,7 +262,7 @@ def test_the_language_endpoint(api, json_response, doc_params, doc_map): body=json_response, status=200, content_type="application/json") result = api.language(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" with pytest.raises(RosetteException) as e_rosette: result = api.language(doc_map) @@ -244,7 +281,7 @@ def test_the_sentences_endpoint(api, json_response, doc_params, doc_map): body=json_response, status=200, content_type="application/json") result = api.sentences(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" with pytest.raises(RosetteException) as e_rosette: result = api.sentences(doc_map) @@ -265,7 +302,7 @@ def test_the_tokens_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.tokens(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -275,13 +312,11 @@ def test_the_tokens_endpoint(api, json_response, doc_params): def test_the_morphology_complete_endpoint(api, json_response, doc_params): """Test the morphology complete endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/complete", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -291,13 +326,11 @@ def test_the_morphology_complete_endpoint(api, json_response, doc_params): def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): """Test the morphology lemmas endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/lemmas", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'lemmas') - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -307,13 +340,11 @@ def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): def test_the_morphology_parts_of_speech_endpoint(api, json_response, doc_params): """Test the morphology parts-of-speech endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/parts-of-speech", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'parts-of-speech') - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -323,13 +354,11 @@ def test_the_morphology_parts_of_speech_endpoint(api, json_response, doc_params) def test_the_morphology_compound_components_endpoint(api, json_response, doc_params): """Test the morphology compound-components endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/compound-components", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'compound-components') - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -339,13 +368,11 @@ def test_the_morphology_compound_components_endpoint(api, json_response, doc_par def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): """Test the morphology han-reading endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/han-readings", body=json_response, status=200, content_type="application/json") result = api.morphology(doc_params, 'han-readings') - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -355,13 +382,11 @@ def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): def test_the_entities_endpoint(api, json_response, doc_params): """Test the entities endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", body=json_response, status=200, content_type="application/json") result = api.entities(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -371,13 +396,11 @@ def test_the_entities_endpoint(api, json_response, doc_params): def test_the_categories_endpoint(api, json_response, doc_params): """Test the categories endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/categories", body=json_response, status=200, content_type="application/json") result = api.categories(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -387,13 +410,11 @@ def test_the_categories_endpoint(api, json_response, doc_params): def test_the_sentiment_endpoint(api, json_response, doc_params): """Test the sentiment endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentiment", body=json_response, status=200, content_type="application/json") result = api.sentiment(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -403,8 +424,6 @@ def test_the_sentiment_endpoint(api, json_response, doc_params): def test_the_multipart_operation(api, json_response, doc_params, tmpdir): """Test multipart""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentiment", body=json_response, status=200, content_type="application/json") @@ -412,7 +431,7 @@ def test_the_multipart_operation(api, json_response, doc_params, tmpdir): tmp_file.write(json_response) doc_params.load_document_file = tmp_file result = api.sentiment(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -420,8 +439,6 @@ def test_the_multipart_operation(api, json_response, doc_params, tmpdir): def test_incompatible_type(api, json_response): """Test the name translation endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentences", body=json_response, status=200, content_type="application/json") @@ -445,8 +462,6 @@ def test_incompatible_type(api, json_response): def test_the_name_translation_endpoint(api, json_response): """Test the name translation endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", body=json_response, status=200, content_type="application/json") @@ -456,7 +471,7 @@ def test_the_name_translation_endpoint(api, json_response): params["targetLanguage"] = "eng" params["targetScript"] = "Latn" result = api.name_translation(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -465,8 +480,6 @@ def test_the_name_translation_endpoint(api, json_response): def test_the_name_requests_with_text(api, json_response): """Test the name similarity with text""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") with pytest.raises(RosetteException) as e_rosette: @@ -496,8 +509,6 @@ def test_the_name_requests_with_text(api, json_response): def test_the_name_similarity_single_parameters(api, json_response): """Test the name similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") @@ -509,7 +520,7 @@ def test_the_name_similarity_single_parameters(api, json_response): params["parameters"] = {"conflictScore": "0.9"} result = api.name_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -517,8 +528,6 @@ def test_the_name_similarity_single_parameters(api, json_response): def test_the_name_similarity_multiple_parameters(api, json_response): """Test the name similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") @@ -530,7 +539,7 @@ def test_the_name_similarity_multiple_parameters(api, json_response): params["parameters"] = {"conflictScore": "0.9", "deletionScore": "0.5"} result = api.name_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -538,8 +547,6 @@ def test_the_name_similarity_multiple_parameters(api, json_response): def test_the_name_similarity_endpoint(api, json_response): """Test the name similarity endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") @@ -553,7 +560,7 @@ def test_the_name_similarity_endpoint(api, json_response): params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} result = api.name_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -564,8 +571,6 @@ def test_the_name_similarity_endpoint(api, json_response): def test_name_deduplication_parameters(api, json_response): """Test the Name Deduplication Parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-deduplication", body=json_response, status=200, content_type="application/json") @@ -580,7 +585,7 @@ def test_name_deduplication_parameters(api, json_response): params["names"] = ["John Smith", "Johnathon Smith", "Fred Jones"] result = api.name_deduplication(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -589,8 +594,6 @@ def test_name_deduplication_parameters(api, json_response): def test_the_name_deduplication_endpoint(api, json_response): """Test the name deduplication endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-deduplication", body=json_response, status=200, content_type="application/json") @@ -601,7 +604,7 @@ def test_the_name_deduplication_endpoint(api, json_response): params["threshold"] = threshold result = api.name_deduplication(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -611,8 +614,6 @@ def test_the_name_deduplication_endpoint(api, json_response): def test_the_relationships_endpoint(api, json_response): """Test the relationships endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/relationships", body=json_response, status=200, content_type="application/json") @@ -620,7 +621,7 @@ def test_the_relationships_endpoint(api, json_response): params["content"] = "some text data" api.set_option('accuracyMode', 'PRECISION') result = api.relationships(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -631,8 +632,6 @@ def test_for_404(api, json_response): """Test for 404 handling""" httpretty.enable() body = json.dumps({'message': 'not found'}) - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/info", body=body, status=404, content_type="application/json") @@ -650,8 +649,6 @@ def test_for_404(api, json_response): def test_for_content_and_contentUri(api, json_response, doc_params): """Test for content and contentUri in DocumentParameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", body=json_response, status=200, content_type="application/json") @@ -670,8 +667,6 @@ def test_for_content_and_contentUri(api, json_response, doc_params): def test_for_no_content_or_contentUri(api, json_response, doc_params): """Test for missing content and contentUri in DocumentParameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", body=json_response, status=200, content_type="application/json") @@ -688,8 +683,6 @@ def test_for_no_content_or_contentUri(api, json_response, doc_params): def test_for_address_similarity_required_parameters(api, json_response): """Test address similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/address-similarity", body=json_response, status=200, content_type="application/json") @@ -716,7 +709,7 @@ def test_for_address_similarity_required_parameters(api, json_response): params["address2"] = {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"} result = api.address_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -724,8 +717,6 @@ def test_for_address_similarity_required_parameters(api, json_response): def test_for_address_similarity_optional_parameters(api, json_response): """Test address similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/address-similarity", body=json_response, status=200, content_type="application/json") @@ -742,7 +733,7 @@ def test_for_address_similarity_optional_parameters(api, json_response): params["parameters"] = {"houseNumberAddressFieldWeight": "0.9"} result = api.address_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -753,8 +744,6 @@ def test_for_address_similarity_optional_parameters(api, json_response): def test_for_name_similarity_required_parameters(api, json_response): """Test name similarity parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") @@ -781,7 +770,7 @@ def test_for_name_similarity_required_parameters(api, json_response): params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} result = api.name_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -791,8 +780,6 @@ def test_for_name_similarity_required_parameters(api, json_response): def test_for_name_translation_required_parameters(api, json_response): """Test name translation parameters""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", body=json_response, status=200, content_type="application/json") @@ -817,7 +804,7 @@ def test_for_name_translation_required_parameters(api, json_response): params["targetLanguage"] = "eng" result = api.name_translation(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -830,7 +817,7 @@ def test_the_semantic_vectors_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.semantic_vectors(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -842,7 +829,7 @@ def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.syntax_dependencies(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -852,15 +839,13 @@ def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): def test_the_transliteration_endpoint(api, json_response): """Test the transliteration endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/transliteration", body=json_response, status=200, content_type="application/json") params = DocumentParameters() params["content"] = "Some test content" result = api.transliteration(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -870,13 +855,11 @@ def test_the_transliteration_endpoint(api, json_response): def test_the_topics_endpoint(api, json_response, doc_params): """Test the topics endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/topics", body=json_response, status=200, content_type="application/json") result = api.topics(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -891,7 +874,7 @@ def test_the_similar_terms_endpoint(api, json_response, doc_params): api.set_option("resultLanguages", ["spa", "jpn", "deu"]) result = api.similar_terms(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -905,14 +888,12 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): body=json_response, status=200, content_type="application/json") result = api.text_embedding(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() # MATCHED_NAME calls NAME_SIMILARITY httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", body=json_response, status=200, content_type="application/json") @@ -926,14 +907,12 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): name_similarity_params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"} result = api.matched_name(name_similarity_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() # TRANSLATED_NAME calls NAME_TRANSLATION httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", body=json_response, status=200, content_type="application/json") @@ -944,7 +923,7 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): name_translation_params["targetLanguage"] = "eng" result = api.translated_name(name_translation_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -955,13 +934,11 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): def test_the_events_endpoint(api, json_response, doc_params): """Test the events endpoint""" httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/events", body=json_response, status=200, content_type="application/json") result = api.events(doc_params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -979,7 +956,7 @@ def test_the_record_similarity_endpoint(api, json_response): params["properties"] = {} params["records"] = {} result = api.record_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() @@ -1002,6 +979,6 @@ def test_for_record_similarity_required_parameters(api, json_response): params["records"] = {} result = api.record_similarity(params) - assert result["name"] == "Rosette" + assert result["name"] == "Babel Street Analytics" httpretty.disable() httpretty.reset() From 6f818d42a9d71ee6076cd65a28010338973d7e17 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 5 Nov 2024 18:22:39 -0600 Subject: [PATCH 235/247] WS-3314: Few small tweaks. --- docs/source/index.rst | 2 +- examples/README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 1eac0ca..9436fde 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -6,7 +6,7 @@ Python Binding ========================================== -This is the API documentation for the Babel Street Analytics API Python Binding. For examples and usage, please refer to our `API Guide `_. +This is the API documentation for the Babel Street Analytics API Python Binding. For examples and usage, please refer to our `API Guide `_. .. toctree:: :maxdepth: 2 diff --git a/examples/README.md b/examples/README.md index 74b23a9..80a19b0 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,7 +11,7 @@ A note on prerequisites. Analytics API only supports TLS 1.2 so ensure your too ``` git clone git@github.com:rosette-api/python.git cd python/examples -virtualenv analytics_venv +python -m venv analytics_venv source analytics_venv/bin/activate pip install rosette_api python ping.py -k $API_KEY @@ -21,7 +21,7 @@ python ping.py -k $API_KEY ``` git clone git@github.com:rosette-api/python.git cd python -virtualenv analytics_venv +python -m venv analytics_venv source analytics_venv/bin/activate python setup.py install cd examples From 1eaf585c1a0f35c847155aeed21cf0bab585b97f Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 11 Nov 2024 13:52:12 +0100 Subject: [PATCH 236/247] no-jira: add fields as required parameter --- rosette/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index d999380..179683a 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -363,7 +363,7 @@ def __init__(self): def validate(self): """Internal. Do not use.""" - for option in ["records"]: # required + for option in ["records","fields"]: # required if self[option] is None: raise RosetteException( "missingParameter", From 170b46fb0cecba45957091903bbf861dd9a2e95f Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 11 Nov 2024 13:53:40 +0100 Subject: [PATCH 237/247] no-jira: add test case for fields being required --- tests/test_rosette_api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 81de474..8429719 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -978,6 +978,11 @@ def test_for_record_similarity_required_parameters(api, json_response): params["records"] = {} + assert e_rosette.value.status == 'missingParameter' + assert e_rosette.value.message == 'Required Record Similarity parameter is missing: fields' + + params["fields"] = {} + result = api.record_similarity(params) assert result["name"] == "Babel Street Analytics" httpretty.disable() From b176a9859a5a096dabfb00bf99ad51e58d970443 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 15 Nov 2024 13:38:23 -0600 Subject: [PATCH 238/247] NO-JIRA: Call again to generate new status message. --- tests/test_rosette_api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index 8429719..f8252f2 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -978,6 +978,9 @@ def test_for_record_similarity_required_parameters(api, json_response): params["records"] = {} + with pytest.raises(RosetteException) as e_rosette: + api.record_similarity(params) + assert e_rosette.value.status == 'missingParameter' assert e_rosette.value.message == 'Required Record Similarity parameter is missing: fields' From 37df247d3f9c387a6997f225f14b24c79224f492 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 15 Nov 2024 13:58:27 -0600 Subject: [PATCH 239/247] NO-JIRA: Add Python 3.13 to tests. Drop 3.8. --- CI.Jenkinsfile | 11 ++++++----- docs/README.md | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 811c36a..f855b8b 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -1,6 +1,6 @@ -def versions = [3.8, 3.9, 3.10, 3.11, 3.12] +def versions = [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,12 +15,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.12) { + sonarScannerFilename="sonar-scanner-6.2.1.4610-linux-x64" + 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 && \ + wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/${sonarScannerFilename}.zip && \ + unzip -q ${sonarScannerFilename}.zip && \ cd /source && \ - /root/sonar-scanner-4.8.1.3023-linux/bin/sonar-scanner ${mySonarOpts}" + /root/${sonarScannerFilename}/bin/sonar-scanner ${mySonarOpts}" } else { sonarExec="echo Skipping Sonar for this version." } diff --git a/docs/README.md b/docs/README.md index 2ca7a5b..b9f2584 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,9 +8,9 @@ Files in the source directory are generally static and should not need to be upd This will overwrite the *.rst files, which may then require some editing to provide the desired look. Edits to date: 1. index.rst: Changed the `Welcome ...` title to `Python Binding` -1. index.rst: Added minor summary, "This is the API documentation for the Rosette API Python Binding. For examples and usage, please refer to our `API Guide `_." +1. index.rst: Added minor summary, "This is the API documentation for the Babel Street Analytics API Python Binding. For examples and usage, please refer to our `API Guide `_." 1. conf.py: removed blank line at end of file -1. conf.py: added rosette logo +1. conf.py: added Babel Street logo 1. conf.py: blank project (let logo handle it) 1. conf.py: added version (auto updated by publish) 1. conf.py: added author From 6a846d9cf90fc2d96926c860d5c5ba50d1ad5ba9 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 15 Nov 2024 18:00:30 -0600 Subject: [PATCH 240/247] NO-JIRA: Replace httpretty with pook. Some test parameterization. --- tests/test_rosette_api.py | 744 ++++++++++++-------------------------- tests/tox.ini | 2 +- tox.ini | 2 +- 3 files changed, 232 insertions(+), 516 deletions(-) diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index f8252f2..ca8085c 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -21,7 +21,7 @@ import json import sys import platform -import httpretty +import pook import pytest from rosette.api import (AddressSimilarityParameters, API, @@ -35,10 +35,15 @@ _ISPY3 = sys.version_info[0] == 3 +def get_base_url(): + return "https://analytics.babelstreet.com/rest/" + + @pytest.fixture def json_response(): """ fixture to return info body""" - body = json.dumps({'name': 'Babel Street Analytics', 'versionChecked': True}) + body = json.dumps({'name': 'Babel Street Analytics', + 'versionChecked': True}) return body @@ -66,20 +71,13 @@ 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. -# Use the old enable/disable to avoid this. - -# Test the option set/get/clear - - def test_option_get_set_clear(api): """Tests the get/set/clear methods""" api.set_option('test', 'foo') @@ -115,8 +113,6 @@ def test_url_parameter_clear_single(api): api.set_url_parameter('test', None) assert api.get_url_parameter('test') is None -# Test the custom header set/get/clear - def test_custom_header_props(api): """Test custom header get/set/clear""" @@ -128,8 +124,6 @@ def test_custom_header_props(api): api.clear_custom_headers() assert len(api.get_custom_headers()) == 0 -# Test for invalid header name - def test_invalid_header(api): """Test for invalid header""" @@ -145,66 +139,53 @@ def test_invalid_header(api): def test_user_agent(api): """ Test user agent """ - value = "Babel-Street-Analytics-API-Python/" + api.get_binding_version() + "/" + platform.python_version() + value = ("Babel-Street-Analytics-API-Python/" + + api.get_binding_version() + "/" + platform.python_version()) assert value == api.get_user_agent_string() -# Test that pinging the API is working properly -# @httpretty.activate - -def test_ping(api, json_response): - """Test ping""" - httpretty.enable() - httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/ping", - body=json_response, status=200, content_type="application/json") +@pook.on +def test_ping_pook(api, json_response): + pook.get(url=get_base_url() + "v1/ping", + response_json=json_response, + reply=200) result = api.ping() assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test that getting the info about the API is being called correctly +@pook.on def test_info(api, json_response): - """Test info""" - httpretty.enable() - httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/info", - body=json_response, status=200, content_type="application/json") + pook.get(url=get_base_url() + "v1/info", + response_json=json_response, + reply=200) result = api.info() assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -# Test for 409 +@pook.on def test_for_409(api, json_409): - """Test for 409 handling""" - httpretty.enable() - httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/info", - body=json_409, status=409, content_type="application/json") + pook.get(url=get_base_url() + "v1/info", + response_json=json_409, + reply=409) with pytest.raises(RosetteException) as e_rosette: result = api.info() assert e_rosette.value.status == 'incompatibleClientVersion' - httpretty.disable() - httpretty.reset() -# Test the max_pool_size +@pook.on +@pytest.mark.parametrize("header_key", + ['x-rosetteapi-concurrency', + 'x-babelstreetapi-concurrency']) +def test_the_max_pool_size_header(json_response, doc_params, header_key): + pook.post(url=get_base_url() + "v1/language", + response_json=json_response, + reply=200, + response_headers={header_key: 5}) -def test_the_max_pool_size_rosette(json_response, doc_params): - """Test max pool size""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", - body=json_response, status=200, content_type="application/json", - adding_headers={ - 'x-rosetteapi-concurrency': 5 - }) api = API('bogus_key') assert api.get_pool_size() == 1 result = api.language(doc_params) @@ -212,36 +193,16 @@ def test_the_max_pool_size_rosette(json_response, doc_params): assert api.get_pool_size() == 5 api.set_pool_size(11) assert api.get_pool_size() == 11 - httpretty.disable() - httpretty.reset() - -def test_the_max_pool_size_babelstreet(json_response, doc_params): - """Test max pool size""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", - body=json_response, status=200, content_type="application/json", - adding_headers={ - 'x-babelstreetapi-concurrency': 5 - }) - api = API('bogus_key') - assert api.get_pool_size() == 1 - result = api.language(doc_params) - assert result["name"] == "Babel Street Analytics" - assert api.get_pool_size() == 5 - api.set_pool_size(11) - assert api.get_pool_size() == 11 - httpretty.disable() - httpretty.reset() - -def test_the_max_pool_size_bot(json_response, doc_params): - """Test max pool size""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", - body=json_response, status=200, content_type="application/json", - adding_headers={ - 'x-rosetteapi-concurrency': 5, - 'x-babelstreetapi-concurrency': 8 - }) + + +@pook.on +def test_the_max_pool_size_both(json_response, doc_params): + pook.post(url=get_base_url() + "v1/language", + response_json=json_response, + reply=200, + response_headers={'x-rosetteapi-concurrency': 5, + 'x-babelstreetapi-concurrency': 8}) + api = API('bogus_key') assert api.get_pool_size() == 1 result = api.language(doc_params) @@ -249,198 +210,106 @@ def test_the_max_pool_size_bot(json_response, doc_params): assert api.get_pool_size() == 8 api.set_pool_size(11) assert api.get_pool_size() == 11 - httpretty.disable() - httpretty.reset() -# Test the language endpoint - -def test_the_language_endpoint(api, json_response, doc_params, doc_map): - """Test language endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/language", - body=json_response, status=200, content_type="application/json") - - result = api.language(doc_params) - assert result["name"] == "Babel Street Analytics" +@pook.on +def test_a_doc_endpoint_fails_on_map(api, json_response, doc_map): + pook.post(url=get_base_url() + "v1/language", + response_json=json_response, + reply=200) 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, doc_map): - """Test the sentences endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentences", - body=json_response, status=200, content_type="application/json") - - result = api.sentences(doc_params) - assert result["name"] == "Babel Street Analytics" - - with pytest.raises(RosetteException) as e_rosette: - result = api.sentences(doc_map) - - assert e_rosette.value.status == 'incompatible' - - - httpretty.disable() - httpretty.reset() - -# Test the tokens endpoint - - -def test_the_tokens_endpoint(api, json_response, doc_params): - """Test the tokens endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/tokens", - body=json_response, status=200, content_type="application/json") - - result = api.tokens(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the morphology complete endpoint - - -def test_the_morphology_complete_endpoint(api, json_response, doc_params): - """Test the morphology complete endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/complete", - body=json_response, status=200, content_type="application/json") - - result = api.morphology(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the morphology lemmas endpoint - - -def test_the_morphology_lemmas_endpoint(api, json_response, doc_params): - """Test the morphology lemmas endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/lemmas", - body=json_response, status=200, content_type="application/json") - - result = api.morphology(doc_params, 'lemmas') - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the morphology parts-of-speech endpoint - - -def test_the_morphology_parts_of_speech_endpoint(api, json_response, doc_params): - """Test the morphology parts-of-speech endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/parts-of-speech", - body=json_response, status=200, content_type="application/json") - - result = api.morphology(doc_params, 'parts-of-speech') - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the morphology compound-components endpoint - - -def test_the_morphology_compound_components_endpoint(api, json_response, doc_params): - """Test the morphology compound-components endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/compound-components", - body=json_response, status=200, content_type="application/json") - - result = api.morphology(doc_params, 'compound-components') - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the morphology han-readings endpoint - - -def test_the_morphology_han_readings_endpoint(api, json_response, doc_params): - """Test the morphology han-reading endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/morphology/han-readings", - body=json_response, status=200, content_type="application/json") - - result = api.morphology(doc_params, 'han-readings') - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the entities endpoint - - -def test_the_entities_endpoint(api, json_response, doc_params): - """Test the entities endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", - body=json_response, status=200, content_type="application/json") - - result = api.entities(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the categories endpoint - - -def test_the_categories_endpoint(api, json_response, doc_params): - """Test the categories endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/categories", - body=json_response, status=200, content_type="application/json") - - result = api.categories(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the sentiment endpoint - - -def test_the_sentiment_endpoint(api, json_response, doc_params): - """Test the sentiment endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentiment", - body=json_response, status=200, content_type="application/json") - - result = api.sentiment(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the multipart operation - +@pook.on +@pytest.mark.parametrize("endpoint", + ['categories', + 'entities', + 'events', + 'language', + 'morphology/complete', + 'morphology/compound-components', + 'morphology/han-readings', + 'morphology/lemmas', + 'morphology/parts-of-speech', + 'relationships', + 'semantics/similar', + 'semantics/vector', + 'sentences', + 'sentiment', + 'syntax/dependencies', + 'tokens', + 'topics', + 'transliteration']) +def test_document_endpoints(api, json_response, doc_params, endpoint): + pook.post(url=get_base_url() + "v1/" + endpoint, + response_json=json_response, + reply=200) + + # TODO: Convert to match-case when minimum supported version is 3.10 + if endpoint == "categories": + result = api.categories(doc_params) + elif endpoint == "entities": + result = api.entities(doc_params) + elif endpoint == "events": + result = api.events(doc_params) + elif endpoint == "language": + result = api.language(doc_params) + elif endpoint == "morphology/complete": + result = api.morphology(doc_params) + elif endpoint == "morphology/compound-components": + result = api.morphology(doc_params, "compound-components") + elif endpoint == "morphology/han-readings": + result = api.morphology(doc_params, "han-readings") + elif endpoint == "morphology/lemmas": + result = api.morphology(doc_params, "lemmas") + elif endpoint == "morphology/parts-of-speech": + result = api.morphology(doc_params, "parts-of-speech") + elif endpoint == "relationships": + api.set_option('accuracyMode', 'PRECISION') + result = api.relationships(doc_params) + elif endpoint == "semantics/similar": + result = api.similar_terms(doc_params) + elif endpoint == "semantics/vector": + result = api.semantic_vectors(doc_params) + elif endpoint == "sentences": + result = api.sentences(doc_params) + elif endpoint == "sentiment": + result = api.sentiment(doc_params) + elif endpoint == "syntax/dependencies": + result = api.syntax_dependencies(doc_params) + elif endpoint == "tokens": + result = api.tokens(doc_params) + elif endpoint == "topics": + result = api.topics(doc_params) + elif endpoint == "transliteration": + result = api.transliteration(doc_params) + else: + raise Exception("Unknown endpoint.") + + assert result["name"] == "Babel Street Analytics" + + +@pook.on def test_the_multipart_operation(api, json_response, doc_params, tmpdir): - """Test multipart""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentiment", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/sentiment", + response_json=json_response, + reply=200) tmp_file = tmpdir.mkdir("sub").join("testfile.txt") tmp_file.write(json_response) doc_params.load_document_file = tmp_file result = api.sentiment(doc_params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() +@pook.on def test_incompatible_type(api, json_response): - """Test the name translation endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/sentences", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/sentences", + response_json=json_response, + reply=200) params = NameTranslationParameters() params["name"] = "some data to translate" @@ -452,18 +321,12 @@ def test_incompatible_type(api, json_response): with pytest.raises(RosetteException) as e_rosette: api.sentences(params) - httpretty.disable() - httpretty.reset() - - -# Test the name translation endpoint - +@pook.on def test_the_name_translation_endpoint(api, json_response): - """Test the name translation endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-translation", + response_json=json_response, + reply=200) params = NameTranslationParameters() params["name"] = "some data to translate" @@ -472,16 +335,14 @@ def test_the_name_translation_endpoint(api, json_response): params["targetScript"] = "Latn" result = api.name_translation(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() -# Test the name similarity endpoint +@pook.on def test_the_name_requests_with_text(api, json_response): - """Test the name similarity with text""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-similarity", + response_json=json_response, + reply=200) + with pytest.raises(RosetteException) as e_rosette: result = api.name_similarity("should fail") assert e_rosette.value.status == 'incompatible' @@ -502,15 +363,12 @@ def test_the_name_requests_with_text(api, json_response): result = api.record_similarity("should fail") assert e_rosette.value.status == 'incompatible' - httpretty.disable() - httpretty.reset() - +@pook.on def test_the_name_similarity_single_parameters(api, json_response): - """Test the name similarity parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-similarity", + response_json=json_response, + reply=200) matched_name_data1 = "John Mike Smith" matched_name_data2 = "John Joe Smith" @@ -521,15 +379,13 @@ def test_the_name_similarity_single_parameters(api, json_response): result = api.name_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() +@pook.on def test_the_name_similarity_multiple_parameters(api, json_response): - """Test the name similarity parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-similarity", + response_json=json_response, + reply=200) matched_name_data1 = "John Mike Smith" matched_name_data2 = "John Joe Smith" @@ -540,15 +396,13 @@ def test_the_name_similarity_multiple_parameters(api, json_response): result = api.name_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() +@pook.on def test_the_name_similarity_endpoint(api, json_response): - """Test the name similarity endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-similarity", + response_json=json_response, + reply=200) matched_name_data1 = "Michael Jackson" matched_name_data2 = "迈克尔·杰克逊" @@ -561,18 +415,13 @@ def test_the_name_similarity_endpoint(api, json_response): result = api.name_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -# Test the name deduplication endpoint +@pook.on def test_name_deduplication_parameters(api, json_response): - """Test the Name Deduplication Parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-deduplication", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-deduplication", + response_json=json_response, + reply=200) params = NameDeduplicationParameters() @@ -580,22 +429,20 @@ def test_name_deduplication_parameters(api, json_response): api.name_deduplication(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name De-Duplication parameter is missing: names' + assert (e_rosette.value.message == + 'Required Name De-Duplication parameter is missing: names') params["names"] = ["John Smith", "Johnathon Smith", "Fred Jones"] result = api.name_deduplication(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - +@pook.on def test_the_name_deduplication_endpoint(api, json_response): - """Test the name deduplication endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-deduplication", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-deduplication", + response_json=json_response, + reply=200) dedup_list = ["John Smith", "Johnathon Smith", "Fred Jones"] threshold = 0.75 @@ -605,86 +452,56 @@ def test_the_name_deduplication_endpoint(api, json_response): result = api.name_deduplication(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the relationships endpoint -def test_the_relationships_endpoint(api, json_response): - """Test the relationships endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/relationships", - body=json_response, status=200, content_type="application/json") - - params = DocumentParameters() - params["content"] = "some text data" - api.set_option('accuracyMode', 'PRECISION') - result = api.relationships(params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test for non 200 - - -def test_for_404(api, json_response): - """Test for 404 handling""" - httpretty.enable() - body = json.dumps({'message': 'not found'}) - httpretty.register_uri(httpretty.GET, "https://analytics.babelstreet.com/rest/v1/info", - body=body, status=404, content_type="application/json") +@pook.on +def test_for_404(api): + pook.get(url=get_base_url() + "v1/info", + response_json={'message': 'not found'}, + reply=404) with pytest.raises(RosetteException) as e_rosette: api.info() assert e_rosette.value.status == 404 assert e_rosette.value.message == 'not found' - httpretty.disable() - httpretty.reset() -# Test for content and contentUri - -def test_for_content_and_contentUri(api, json_response, doc_params): - """Test for content and contentUri in DocumentParameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", - body=json_response, status=200, content_type="application/json") +@pook.on +def test_both_content_and_content_uri(api, json_response, doc_params): + pook.post(url=get_base_url() + "v1/entities", + response_json=json_response, + reply=200) doc_params['contentUri'] = 'https://example.com' with pytest.raises(RosetteException) as e_rosette: api.entities(doc_params) assert e_rosette.value.status == 'badArgument' - assert e_rosette.value.message == 'Cannot supply both Content and ContentUri' - httpretty.disable() - httpretty.reset() - -# Test for content and contentUri + assert (e_rosette.value.message == + 'Cannot supply both Content and ContentUri') -def test_for_no_content_or_contentUri(api, json_response, doc_params): - """Test for missing content and contentUri in DocumentParameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/entities", - body=json_response, status=200, content_type="application/json") +@pook.on +def test_for_no_content_or_content_uri(api, json_response, doc_params): + pook.post(url=get_base_url() + "v1/entities", + response_json=json_response, + reply=200) doc_params['content'] = None with pytest.raises(RosetteException) as e_rosette: api.entities(doc_params) assert e_rosette.value.status == 'badArgument' - assert e_rosette.value.message == 'Must supply one of Content or ContentUri' - httpretty.disable() - httpretty.reset() + assert (e_rosette.value.message == + 'Must supply one of Content or ContentUri') +@pook.on def test_for_address_similarity_required_parameters(api, json_response): - """Test address similarity parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/address-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/address-similarity", + response_json=json_response, + reply=200) params = AddressSimilarityParameters() @@ -692,7 +509,8 @@ def test_for_address_similarity_required_parameters(api, json_response): api.address_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Address Similarity parameter is missing: address1' + assert (e_rosette.value.message == + 'Required Address Similarity parameter is missing: address1') params["address1"] = {"houseNumber": "1600", "road": "Pennsylvania Ave NW", @@ -704,21 +522,21 @@ def test_for_address_similarity_required_parameters(api, json_response): api.address_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Address Similarity parameter is missing: address2' + assert (e_rosette.value.message == + 'Required Address Similarity parameter is missing: address2') - params["address2"] = {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"} + params["address2"] =\ + {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"} result = api.address_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() +@pook.on def test_for_address_similarity_optional_parameters(api, json_response): - """Test address similarity parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/address-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/address-similarity", + response_json=json_response, + reply=200) params = AddressSimilarityParameters() @@ -728,24 +546,20 @@ def test_for_address_similarity_optional_parameters(api, json_response): "state": "DC", "postCode": "20500"} - params["address2"] = {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"} + params["address2"] =\ + {"text": "160 Pennsilvana Avenue, Washington, D.C., 20500"} params["parameters"] = {"houseNumberAddressFieldWeight": "0.9"} result = api.address_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -# Test for required Name Similarity parameters +@pook.on def test_for_name_similarity_required_parameters(api, json_response): - """Test name similarity parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-similarity", + response_json=json_response, + reply=200) matched_name_data1 = "Michael Jackson" matched_name_data2 = "迈克尔·杰克逊" @@ -755,7 +569,8 @@ def test_for_name_similarity_required_parameters(api, json_response): api.name_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Similarity parameter is missing: name1' + assert (e_rosette.value.message == + 'Required Name Similarity parameter is missing: name1') params["name1"] = { "text": matched_name_data1, @@ -765,23 +580,20 @@ def test_for_name_similarity_required_parameters(api, json_response): api.name_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Similarity parameter is missing: name2' + assert (e_rosette.value.message == + 'Required Name Similarity parameter is missing: name2') params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"} result = api.name_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test for required Name Translation parameters +@pook.on def test_for_name_translation_required_parameters(api, json_response): - """Test name translation parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-translation", + response_json=json_response, + reply=200) params = NameTranslationParameters() params["entityType"] = "PERSON" @@ -791,7 +603,8 @@ def test_for_name_translation_required_parameters(api, json_response): api.name_translation(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Translation parameter is missing: name' + assert (e_rosette.value.message == + 'Required Name Translation parameter is missing: name') params["name"] = "some data to translate" @@ -799,103 +612,29 @@ def test_for_name_translation_required_parameters(api, json_response): api.name_translation(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Name Translation parameter is missing: targetLanguage' + assert (e_rosette.value.message == + 'Required Name Translation parameter is missing: targetLanguage') params["targetLanguage"] = "eng" result = api.name_translation(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -def test_the_semantic_vectors_endpoint(api, json_response, doc_params): - """Test semantic vectors endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/semantics/vector", - body=json_response, status=200, content_type="application/json") - - result = api.semantic_vectors(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -def test_the_syntax_dependencies_endpoint(api, json_response, doc_params): - """Test syntax dependencies endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/syntax/dependencies", - body=json_response, status=200, content_type="application/json") - - result = api.syntax_dependencies(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -# Test the transliteration endpoint - -def test_the_transliteration_endpoint(api, json_response): - """Test the transliteration endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/transliteration", - body=json_response, status=200, content_type="application/json") - - params = DocumentParameters() - params["content"] = "Some test content" - result = api.transliteration(params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -# Test the topics endpoint - -def test_the_topics_endpoint(api, json_response, doc_params): - """Test the topics endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/topics", - body=json_response, status=200, content_type="application/json") - - result = api.topics(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - - -# Test the similar-terms endpoint - -def test_the_similar_terms_endpoint(api, json_response, doc_params): - """Test the similar terms endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/semantics/similar", - body=json_response, status=200, content_type="application/json") - - api.set_option("resultLanguages", ["spa", "jpn", "deu"]) - result = api.similar_terms(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - +@pook.on def test_the_deprecated_endpoints(api, json_response, doc_params): - """There are three deprecated endpoints. Exercise them until they are deleted.""" - # TEXT_EMBEDDING calls SEMANTIC_VECTORS - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/semantics/vector", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/semantics/vector", + response_json=json_response, + reply=200) result = api.text_embedding(doc_params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() # MATCHED_NAME calls NAME_SIMILARITY - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-similarity", + response_json=json_response, + reply=200) name_similarity_params = NameSimilarityParameters() @@ -904,17 +643,16 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): "language": "eng", "entityType": "PERSON"} - name_similarity_params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"} + name_similarity_params["name2"] =\ + {"text": "迈克尔·杰克逊", "entityType": "PERSON"} result = api.matched_name(name_similarity_params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() # TRANSLATED_NAME calls NAME_TRANSLATION - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/name-translation", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/name-translation", + response_json=json_response, + reply=200) name_translation_params = NameTranslationParameters() name_translation_params["entityType"] = "PERSON" @@ -925,31 +663,12 @@ def test_the_deprecated_endpoints(api, json_response, doc_params): result = api.translated_name(name_translation_params) assert result["name"] == "Babel Street Analytics" - 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://analytics.babelstreet.com/rest/v1/events", - body=json_response, status=200, content_type="application/json") - - result = api.events(doc_params) - assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() - -# Test the record similarity endpoint - +@pook.on def test_the_record_similarity_endpoint(api, json_response): - """Test the record similarity endpoint""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/record-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/record-similarity", + response_json=json_response, + reply=200) params = RecordSimilarityParameters() params["fields"] = {} @@ -957,16 +676,13 @@ def test_the_record_similarity_endpoint(api, json_response): params["records"] = {} result = api.record_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() -# Tests for required record-similarities parameters +@pook.on def test_for_record_similarity_required_parameters(api, json_response): - """Test record similarity parameters""" - httpretty.enable() - httpretty.register_uri(httpretty.POST, "https://analytics.babelstreet.com/rest/v1/record-similarity", - body=json_response, status=200, content_type="application/json") + pook.post(url=get_base_url() + "v1/record-similarity", + response_json=json_response, + reply=200) params = RecordSimilarityParameters() @@ -974,7 +690,8 @@ def test_for_record_similarity_required_parameters(api, json_response): api.record_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Record Similarity parameter is missing: records' + assert (e_rosette.value.message == + 'Required Record Similarity parameter is missing: records') params["records"] = {} @@ -982,11 +699,10 @@ def test_for_record_similarity_required_parameters(api, json_response): api.record_similarity(params) assert e_rosette.value.status == 'missingParameter' - assert e_rosette.value.message == 'Required Record Similarity parameter is missing: fields' + assert (e_rosette.value.message == + 'Required Record Similarity parameter is missing: fields') params["fields"] = {} result = api.record_similarity(params) assert result["name"] == "Babel Street Analytics" - httpretty.disable() - httpretty.reset() diff --git a/tests/tox.ini b/tests/tox.ini index bdf6e7d..ed9b966 100644 --- a/tests/tox.ini +++ b/tests/tox.ini @@ -7,6 +7,6 @@ commands = pytest -s deps = pytest - httpretty + pook epydoc requests diff --git a/tox.ini b/tox.ini index 808daa0..7f53adf 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ skipsdist = True deps = pytest pep8 - httpretty + pook epydoc requests coverage From 2c4bf420f7ebfe708d4fc77b17348f7a7a5988f7 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 15 Nov 2024 18:30:14 -0600 Subject: [PATCH 241/247] NO-JIRA: Fix Sonar CLI updates. --- CI.Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index f855b8b..8704189 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -15,13 +15,13 @@ def runSonnarForPythonVersion(sourceDir, ver){ // Only run Sonar once. // Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/ - sonarScannerFilename="sonar-scanner-6.2.1.4610-linux-x64" + sonarScannerVersion="6.2.1.4610-linux-x64" if(ver == 3.13) { sonarExec="cd /root/ && \ - wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/${sonarScannerFilename}.zip && \ - unzip -q ${sonarScannerFilename}.zip && \ + wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${sonarScannerVersion}.zip && \ + unzip -q sonar-scanner-cli-${sonarScannerVersion}.zip && \ cd /source && \ - /root/${sonarScannerFilename}/bin/sonar-scanner ${mySonarOpts}" + /root/sonar-scanner-${sonarScannerVersion}/bin/sonar-scanner ${mySonarOpts}" } else { sonarExec="echo Skipping Sonar for this version." } From 0dcee40cb2a30403462b0935abd1abbda319f25f Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Fri, 15 Nov 2024 18:41:23 -0600 Subject: [PATCH 242/247] NO-JIRA: package metadata --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 78cb2b2..1bcd653 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ NAME = "rosette_api" DESCRIPTION = "Babel Street Analytics API Python client SDK" AUTHOR = "Analytics by Babel Street" -AUTHOR_EMAIL = "helpdesk@babelstreet.com" +AUTHOR_EMAIL = "analyticssupport@babelstreet.com" HOMEPAGE = "https://github.com/rosette-api/python" VERSION = rosette.__version__ @@ -49,11 +49,11 @@ def read(*filenames, **kwargs): 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python', - '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 e80d481919458da6bccb1e5dac26da59c646b09b Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 18 Nov 2024 19:54:54 +0000 Subject: [PATCH 243/247] Version 1.31.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 5b56fd1..2114fa5 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '1.30.0' +version = '1.31.0' # The full version, including alpha/beta/rc tags. -release = '1.30.0' +release = '1.31.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 a1108fd..5c89253 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -12,4 +12,4 @@ limitations under the License. """ -__version__ = '1.30.0' +__version__ = '1.31.0' diff --git a/rosette/api.py b/rosette/api.py index 179683a..734b4d4 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -30,7 +30,7 @@ _APPLICATION_JSON = 'application/json' _BINDING_LANGUAGE = 'python' -_BINDING_VERSION = '1.30.0' +_BINDING_VERSION = '1.31.0' # TODO Remove legacies in future release _LEGACY_CONCURRENCY_HEADER = 'x-rosetteapi-concurrency' _CONCURRENCY_HEADER = 'x-babelstreetapi-concurrency' From e32db6392003b60c0efad5dd238479681c019ab3 Mon Sep 17 00:00:00 2001 From: seth-mg Date: Fri, 22 Nov 2024 11:45:59 -0600 Subject: [PATCH 244/247] Add default image --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ce08ef..bc34f47 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ - Babel Street Logo + Babel Street Logo From 36fdb337990ad3003426ab9b9230418c37cad3e8 Mon Sep 17 00:00:00 2001 From: Kenny Chen Date: Thu, 12 Dec 2024 17:10:27 -0500 Subject: [PATCH 245/247] NOJIRA: Remove warning filter * This overrode user's warning filters. * This was (arguably) erroneously added to warn users of deprecations. However, DeprecationWarnings are intentionally ignored by default in Python. --- rosette/api.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index 734b4d4..9dadf15 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -24,7 +24,6 @@ import sys import os import re -import warnings import requests import platform @@ -46,8 +45,6 @@ else: _GZIP_SIGNATURE = str(_GZIP_BYTEARRAY) -warnings.simplefilter('always') - class _ReturnObject(object): From ab360fd9de9c175c9d8c89b06adddcac570c0a87 Mon Sep 17 00:00:00 2001 From: Jacob McIntosh Date: Tue, 11 Mar 2025 12:56:26 -0600 Subject: [PATCH 246/247] github url string updates --- DEVELOPER.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 54afffa..dfa4aa0 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -58,7 +58,7 @@ Optional parameters for the `docker run` execution are: - For testing a single example file instead of all the example files. To alter the behavior of the pre-configured Docker environment, you can see the Dockerfile source and entry-point -script [here](https://git.basistech.net/raas/rapid-development-tools/tree/master/binding-dockerfiles). +script [here](https://github.com/RosetteTextAnalytics/rapid-development-tools/tree/master/binding-dockerfiles). ### Documentation Generation The existing README for documentation generation is [here](docs/README.md). @@ -68,7 +68,7 @@ The next time the API documentation is touched, please refresh the README and mi There's an old [Docker README](examples/docker) in the examples directory that might be a candidate for removal. ### Building A Release -See the [instructions](https://git.basistech.net/raas/rapid-development-tools/tree/master/publish) +See the [instructions](https://github.com/RosetteTextAnalytics/rapid-development-tools/tree/master/publish) ### TODOs - Inconsistent references with `rosette_api` and `rosette-api` From 005888457d1d8b978cc52fb9e482ac0a872a71ec Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 12 Dec 2025 15:21:33 +0100 Subject: [PATCH 247/247] WS_3698: update record-similarity example with new field types --- examples/record_similarity.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/examples/record_similarity.py b/examples/record_similarity.py index 0ef1ea7..a2c1fe2 100644 --- a/examples/record_similarity.py +++ b/examples/record_similarity.py @@ -31,6 +31,18 @@ def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): "dob2": { "type": "rni_date", "weight": 0.1 + }, + "jobTitle": { + "type": "rni_string", + "weight": 0.2 + }, + "age": { + "type": "rni_number", + "weight": 0.4 + }, + "isRetired": { + "type": "rni_boolean", + "weight": 0.05 } } properties = { @@ -52,7 +64,8 @@ def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): "dob2": { "date": "04161993", "format": "MMddyyyy" - } + }, + "jobTitle": "software engineer" }, { "dob": { @@ -60,7 +73,9 @@ def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): }, "primaryName": { "text": "Evan R" - } + }, + "age": 47, + "isRetired": False } ], "right": [ @@ -71,7 +86,9 @@ def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): "primaryName": { "text": "Seth R", "language": "eng" - } + }, + "jobTitle": "manager", + "isRetired": True }, { "primaryName": "Ivan R", @@ -84,7 +101,9 @@ def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'): }, "dob2": { "date": "1993/04/16" - } + }, + "age": 72, + "isRetired": True } ] }