diff --git a/.gitignore b/.gitignore
index f2480a7..be7f8d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,9 @@
ehthumbs.db
Thumbs.db
+# VS Code
+.vscode
+
# Jetbrains
**/.idea/*
!**/.idea/runConfigurations/
@@ -59,6 +62,7 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
+.scannerwork/
# Translations
*.mo
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
-
diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile
new file mode 100644
index 0000000..8704189
--- /dev/null
+++ b/CI.Jenkinsfile
@@ -0,0 +1,65 @@
+
+
+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}"
+ if("${env.CHANGE_ID}" != "null"){
+ mySonarOpts = "$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.branch=${env.BRANCH_NAME}"
+ } else {
+ 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}"
+ }
+
+ // Only run Sonar once.
+ // Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/
+ sonarScannerVersion="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-${sonarScannerVersion}.zip && \
+ unzip -q sonar-scanner-cli-${sonarScannerVersion}.zip && \
+ cd /source && \
+ /root/sonar-scanner-${sonarScannerVersion}/bin/sonar-scanner ${mySonarOpts}"
+ } else {
+ sonarExec="echo Skipping Sonar for this version."
+ }
+
+ 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 /source && \
+ tox && \
+ ${sonarExec} && \
+ echo && \
+ echo [INFO] Re-permission files for cleanup. && \
+ chown -R 9960:9960 /source\""
+}
+
+node ("docker-light") {
+ def sourceDir = pwd()
+ try {
+ stage("Clean up") {
+ step([$class: 'WsCleanup'])
+ }
+ stage("Checkout Code") {
+ checkout scm
+ }
+ stage("Build & Test") {
+ withSonarQubeEnv {
+
+ versions.each { ver ->
+ runSonnarForPythonVersion(sourceDir, ver)
+ }
+ }
+ }
+ } catch (e) {
+ currentBuild.result = "FAILED"
+ throw e
+ }
+}
diff --git a/DEVELOPER.md b/DEVELOPER.md
index 43d2168..dfa4aa0 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:
@@ -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`
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)
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)
+}
diff --git a/README.md b/README.md
index a15f1e3..bc34f47 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,31 @@
-
+
+
+
+
+
+
+
----
+# Analytics by Babel Street
-[](https://travis-ci.org/rosette-api/python)
[](https://badge.fury.io/py/rosette-api)
[](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.
+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.
-## Rosette API Access
-- Rosette Cloud [Sign Up](https://developer.rosette.com/signup)
-- Rosette Enterprise [Evaluation](https://www.rosette.com/product-eval/)
+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.
+
+## Analytics API Access
+- Analytics Cloud [Sign Up](https://developer.babelstreet.com/signup)
## Quick Start
@@ -22,16 +33,15 @@ comparing the similarity of names, categorizing and adding linguistic tags to te
`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://developer.rosette.com/features-and-functions)
+- [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://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)
+- [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)
## Binding Developer Information
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
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
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 0846005..2114fa5 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -47,17 +47,17 @@
# General information about the project.
project = ''
-copyright = '2022, 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
# built documents.
#
# The short X.Y version.
-version = '1.20.0'
+version = '1.31.0'
# The full version, including alpha/beta/rc tags.
-release = '1.20.0'
+release = '1.31.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@@ -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 0000000..2750b93
Binary files /dev/null and b/docs/source/favicon-16x16.png differ
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 40ebcf1..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 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
diff --git a/docs/source/logo-400x113.png b/docs/source/logo-400x113.png
new file mode 100644
index 0000000..b411943
Binary files /dev/null and b/docs/source/logo-400x113.png differ
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 @@
-
-
-
-
\ No newline at end of file
diff --git a/examples/README.md b/examples/README.md
index 5928376..80a19b0 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
+python -m venv 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
+python -m venv analytics_venv
+source analytics_venv/bin/activate
python setup.py install
cd examples
python ping.py -k $API_KEY
@@ -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
diff --git a/examples/address_similarity.py b/examples/address_similarity.py
index 9ffe3a6..2175817 100644
--- a/examples/address_similarity.py
+++ b/examples/address_similarity.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -19,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)
@@ -29,11 +29,11 @@ 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()
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..6f09c75 100644
--- a/examples/categories.py
+++ b/examples/categories.py
@@ -1,9 +1,8 @@
# -*- 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).
"""
-from __future__ import print_function
import argparse
import json
@@ -13,25 +12,23 @@
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_url_data = "https://www.rosette.com/about/"
- 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)
# 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)
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:
@@ -41,11 +38,11 @@ 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()
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..beba9de 100644
--- a/examples/entities.py
+++ b/examples/entities.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,23 +10,24 @@
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')
+ # 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()
params["content"] = entities_text_data
- params["genre"] = "social-media"
+
try:
return api.entities(params)
except RosetteException as exception:
@@ -36,11 +36,11 @@ 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()
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/events.py b/examples/events.py
new file mode 100644
index 0000000..79ffc3e
--- /dev/null
+++ b/examples/events.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+"""
+Example code to call Analytics API to get events from a piece of text.
+"""
+
+import argparse
+import json
+import os
+
+from rosette.api import API, DocumentParameters, RosetteException
+
+
+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)
+
+ events_text_data = "I am looking for flights to Super Bowl 2022 in Inglewood, LA."
+ 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='Analytics API Key', required=True)
+PARSER.add_argument('-u', '--url', help="Alternative API URL",
+ default='https://analytics.babelstreet.com/rest/v1/')
+
+if __name__ == '__main__':
+ ARGS = PARSER.parse_args()
+ RESULT = run(ARGS.key, ARGS.url)
+ print(RESULT)
diff --git a/examples/events_negation.py b/examples/events_negation.py
new file mode 100644
index 0000000..becc731
--- /dev/null
+++ b/examples/events_negation.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+"""
+Example code to call Analytics 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://analytics.babelstreet.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='Analytics API Key', required=True)
+PARSER.add_argument('-u', '--url', help="Alternative API URL",
+ default='https://analytics.babelstreet.com/rest/v1/')
+
+if __name__ == '__main__':
+ ARGS = PARSER.parse_args()
+ RESULT = run(ARGS.key, ARGS.url)
+ print(RESULT)
diff --git a/examples/info.py b/examples/info.py
index ab7159f..8fba621 100644
--- a/examples/info.py
+++ b/examples/info.py
@@ -1,8 +1,7 @@
# -*- 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
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -25,11 +24,11 @@ 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()
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..e4fa87a 100644
--- a/examples/language.py
+++ b/examples/language.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -29,11 +28,11 @@ 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()
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..36bd8e6 100644
--- a/examples/language_multilingual.py
+++ b/examples/language_multilingual.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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,11 +30,11 @@ 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()
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..10b1004 100644
--- a/examples/morphology_complete.py
+++ b/examples/morphology_complete.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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
@@ -35,11 +34,11 @@ 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()
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..5bacddb 100644
--- a/examples/morphology_compound-components.py
+++ b/examples/morphology_compound-components.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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
@@ -35,11 +34,11 @@ 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()
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..f5c12f6 100644
--- a/examples/morphology_han-readings.py
+++ b/examples/morphology_han-readings.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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
@@ -34,11 +33,11 @@ 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()
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..dc7bb8d 100644
--- a/examples/morphology_lemmas.py
+++ b/examples/morphology_lemmas.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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
@@ -35,11 +34,11 @@ 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()
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..f020ca2 100644
--- a/examples/morphology_parts-of-speech.py
+++ b/examples/morphology_parts-of-speech.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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
@@ -35,11 +34,11 @@ 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()
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..7c69e20 100644
--- a/examples/name_deduplication.py
+++ b/examples/name_deduplication.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -30,11 +29,11 @@ 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()
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..b8a51ec 100644
--- a/examples/name_similarity.py
+++ b/examples/name_similarity.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -21,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:
@@ -30,11 +31,11 @@ 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()
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_translation.py b/examples/name_translation.py
index 7f7372d..455fc50 100644
--- a/examples/name_translation.py
+++ b/examples/name_translation.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -31,11 +30,11 @@ 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()
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..f908367 100644
--- a/examples/ping.py
+++ b/examples/ping.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -25,11 +24,11 @@ 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()
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/record_similarity.py b/examples/record_similarity.py
new file mode 100644
index 0000000..a2c1fe2
--- /dev/null
+++ b/examples/record_similarity.py
@@ -0,0 +1,131 @@
+# -*- coding: utf-8 -*-
+"""
+Example code to call Analytics 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://analytics.babelstreet.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
+ },
+ "jobTitle": {
+ "type": "rni_string",
+ "weight": 0.2
+ },
+ "age": {
+ "type": "rni_number",
+ "weight": 0.4
+ },
+ "isRetired": {
+ "type": "rni_boolean",
+ "weight": 0.05
+ }
+ }
+ properties = {
+ "threshold": 0.7,
+ "includeExplainInfo": True
+ }
+ records = {
+ "left": [
+ {
+ "primaryName": {
+ "text": "Ethan R",
+ "entityType": "PERSON",
+ "language": "eng",
+ "languageOfOrigin": "eng",
+ "script": "Latn"
+ },
+ "dob": "1993-04-16",
+ "addr": "123 Roadlane Ave",
+ "dob2": {
+ "date": "04161993",
+ "format": "MMddyyyy"
+ },
+ "jobTitle": "software engineer"
+ },
+ {
+ "dob": {
+ "date": "1993-04-16"
+ },
+ "primaryName": {
+ "text": "Evan R"
+ },
+ "age": 47,
+ "isRetired": False
+ }
+ ],
+ "right": [
+ {
+ "dob": {
+ "date": "1993-04-16"
+ },
+ "primaryName": {
+ "text": "Seth R",
+ "language": "eng"
+ },
+ "jobTitle": "manager",
+ "isRetired": True
+ },
+ {
+ "primaryName": "Ivan R",
+ "dob": {
+ "date": "1993-04-16"
+ },
+ "addr": {
+ "houseNumber": "123",
+ "road": "Roadlane Ave"
+ },
+ "dob2": {
+ "date": "1993/04/16"
+ },
+ "age": 72,
+ "isRetired": True
+ }
+ ]
+ }
+ params = RecordSimilarityParameters()
+ params["fields"] = fields
+ params["properties"] = properties
+ params["records"] = records
+
+ 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='Analytics API Key', required=True)
+PARSER.add_argument('-u', '--url', help="Alternative API URL",
+ default='https://analytics.babelstreet.com/rest/v1/')
+
+if __name__ == '__main__':
+ ARGS = PARSER.parse_args()
+ RESULT = run(ARGS.key, ARGS.url)
+ print(RESULT)
diff --git a/examples/relationships.py b/examples/relationships.py
index c59861d..490a527 100644
--- a/examples/relationships.py
+++ b/examples/relationships.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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,11 +26,11 @@ 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()
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/run_all.sh b/examples/run_all.sh
index 3f18bd7..ab797c9 100644
--- a/examples/run_all.sh
+++ b/examples/run_all.sh
@@ -1,5 +1,15 @@
#!/bin/bash
+
+if [ $# -eq 0 ]; then
+ echo "Usage: $0 API_KEY [ALT_URL]" 1>&2
+ exit 1
+fi
+
for f in *.py
do
+ if [ -n "$2" ]; then
+ python $f --key $1 --url $2
+ else
python $f --key $1
+ fi
done
diff --git a/examples/semantic_vectors.py b/examples/semantic_vectors.py
index 066d920..ef99e5b 100644
--- a/examples/semantic_vectors.py
+++ b/examples/semantic_vectors.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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')
@@ -35,12 +34,11 @@ 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()
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..f0c3e12 100644
--- a/examples/sentences.py
+++ b/examples/sentences.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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)
@@ -29,11 +28,11 @@ 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()
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..1a292d8 100644
--- a/examples/sentiment.py
+++ b/examples/sentiment.py
@@ -1,9 +1,8 @@
#!/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.
"""
-from __future__ import print_function
import argparse
import json
@@ -13,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")
@@ -26,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
@@ -50,12 +49,11 @@ 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()
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..753e397 100644
--- a/examples/similar_terms.py
+++ b/examples/similar_terms.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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'])
@@ -35,12 +34,11 @@ 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()
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..e5e99a0 100644
--- a/examples/syntax_dependencies.py
+++ b/examples/syntax_dependencies.py
@@ -1,8 +1,7 @@
# -*- 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).
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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()
@@ -27,12 +26,11 @@ 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()
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..e98601c 100644
--- a/examples/tokens.py
+++ b/examples/tokens.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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
@@ -35,11 +34,11 @@ 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()
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..e33a745 100644
--- a/examples/topics.py
+++ b/examples/topics.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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')
@@ -36,11 +35,11 @@ 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()
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..bc7c5da 100644
--- a/examples/transliteration.py
+++ b/examples/transliteration.py
@@ -1,8 +1,7 @@
# -*- 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.
"""
-from __future__ import print_function
import argparse
import json
@@ -11,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')
@@ -37,12 +36,11 @@ 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()
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/rosette/__init__.py b/rosette/__init__.py
index bbeb61e..5c89253 100644
--- a/rosette/__init__.py
+++ b/rosette/__init__.py
@@ -1,6 +1,6 @@
"""
-Python client for the Rosette API.
-Copyright (c) 2014-2022 Basis Technology Corporation.
+Python client for the Babel Street Analytics API.
+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
@@ -12,4 +12,4 @@
limitations under the License.
"""
-__version__ = '1.20.0'
+__version__ = '1.31.0'
diff --git a/rosette/api.py b/rosette/api.py
index a85a49f..9dadf15 100644
--- a/rosette/api.py
+++ b/rosette/api.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python
"""
-Python client for the Rosette API.
+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.
@@ -24,16 +24,18 @@
import sys
import os
import re
-import warnings
import requests
import platform
_APPLICATION_JSON = 'application/json'
_BINDING_LANGUAGE = 'python'
-_BINDING_VERSION = '1.20.0'
-_CONCURRENCY_HEADER = 'x-rosetteapi-concurrency'
-_CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-'
-_CUSTOM_HEADER_PATTERN = re.compile('^' + _CUSTOM_HEADER_PREFIX)
+_BINDING_VERSION = '1.31.0'
+# 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
@@ -43,8 +45,6 @@
else:
_GZIP_SIGNATURE = str(_GZIP_BYTEARRAY)
-warnings.simplefilter('always')
-
class _ReturnObject(object):
@@ -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__.
"""
@@ -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 = {}
@@ -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):
@@ -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:
@@ -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,8 +152,8 @@ class DocumentParameters(_DocumentParamSetBase):
def __init__(self):
"""Create a L{DocumentParameters} object."""
- _DocumentParamSetBase.__init__(
- self, ("content", "contentUri", "language", "genre", "profileId"))
+ _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}).
@@ -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.
@@ -227,7 +227,7 @@ class NameTranslationParameters(_DocumentParamSetBase):
def __init__(self):
self.use_multipart = False
- _DocumentParamSetBase.__init__(
+ _RequestParametersBase.__init__(
self,
("name",
"targetLanguage",
@@ -236,12 +236,11 @@ def __init__(self):
"sourceLanguageOfUse",
"sourceScript",
"targetScript",
- "targetScheme",
- "genre"))
+ "targetScheme"))
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",
@@ -249,9 +248,12 @@ def validate(self):
repr(option))
-class AddressSimilarityParameters(_DocumentParamSetBase):
+class AddressSimilarityParameters(_RequestParametersBase):
"""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.
@@ -259,15 +261,21 @@ 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"))
+ _RequestParametersBase.__init__(self, ("address1", "address2", "parameters"))
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",
@@ -275,9 +283,12 @@ def validate(self):
repr(option))
-class NameSimilarityParameters(_DocumentParamSetBase):
+class NameSimilarityParameters(_RequestParametersBase):
"""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.
@@ -285,22 +296,28 @@ 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"))
+ _RequestParametersBase.__init__(self, ("name1", "name2", "parameters"))
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",
@@ -308,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
@@ -317,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."""
@@ -328,11 +345,34 @@ def validate(self):
repr("names"))
+class RecordSimilarityParameters(_RequestParametersBase):
+ """Parameter object for C{record-similarity} endpoint.
+ Required:
+ 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):
+ self.use_multipart = False
+ _RequestParametersBase.__init__(self, ("fields", "properties", "records"))
+
+ def validate(self):
+ """Internal. Do not use."""
+ for option in ["records","fields"]: # required
+ if self[option] is None:
+ raise RosetteException(
+ "missingParameter",
+ "Required Record Similarity parameter is missing: " + option,
+ repr(option))
+
+
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.
@@ -342,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):
@@ -373,12 +413,15 @@ 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 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:
@@ -387,15 +430,16 @@ 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[_CUSTOM_HEADER_PREFIX + "Key"] = self.user_key
+ headers["X-BabelStreetAPI-Key"] = self.user_key
return headers
@@ -421,7 +465,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
@@ -433,29 +477,31 @@ def call(self, parameters):
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
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.suburl)
- 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 paramtype and not isinstance(parameters, DocumentParameters):
+ raise RosetteException(
+ "incompatible",
+ "The parameters must be string or DocumentParameters",
+ self.suburl)
self.use_multipart = parameters.use_multipart
url = self.service_url + self.suburl
@@ -486,7 +532,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, {}, {}, 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)}
@@ -495,7 +541,7 @@ def call(self, parameters):
_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"
@@ -506,22 +552,22 @@ def call(self, parameters):
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
@@ -542,7 +588,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',
@@ -572,7 +618,9 @@ def __init__(
'TEXT_EMBEDDING': 'semantics/vector',
'TOKENS': 'tokens',
'TOPICS': 'topics',
- 'TRANSLITERATION': 'transliteration'
+ 'TRANSLITERATION': 'transliteration',
+ 'EVENTS': 'events',
+ 'RECORD_SIMILARITY': 'record-similarity'
}
def __del__(self):
@@ -602,8 +650,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):
"""
@@ -627,7 +679,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)
@@ -659,7 +711,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)
@@ -897,7 +949,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):
"""
@@ -907,7 +959,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
@@ -926,7 +978,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
@@ -944,7 +996,16 @@ 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 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
@@ -993,3 +1054,13 @@ 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):
+ """
+ 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)
diff --git a/setup.py b/setup.py
index 017af14..1bcd653 100755
--- a/setup.py
+++ b/setup.py
@@ -6,9 +6,9 @@
import rosette
NAME = "rosette_api"
-DESCRIPTION = "Rosette API Python client SDK"
-AUTHOR = "Basis Technology Corp."
-AUTHOR_EMAIL = "support@rosette.com"
+DESCRIPTION = "Babel Street Analytics API Python client SDK"
+AUTHOR = "Analytics by Babel Street"
+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 :: 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',
+ 'Programming Language :: Python :: 3.12',
+ 'Programming Language :: Python :: 3.13',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)
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 0770bec..ca8085c 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.
@@ -21,7 +21,7 @@
import json
import sys
import platform
-import httpretty
+import pook
import pytest
from rosette.api import (AddressSimilarityParameters,
API,
@@ -29,15 +29,21 @@
NameTranslationParameters,
NameSimilarityParameters,
NameDeduplicationParameters,
+ RecordSimilarityParameters,
RosetteException)
_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': 'Rosette', 'versionChecked': True})
+ body = json.dumps({'name': 'Babel Street Analytics',
+ 'versionChecked': True})
return body
@@ -65,12 +71,11 @@ def doc_params():
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.
-# Test the option set/get/clear
+@pytest.fixture
+def doc_map():
+ """ fixture for a simple map of doc request """
+ return {'content': 'Simple test string'}
def test_option_get_set_clear(api):
@@ -108,12 +113,10 @@ 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"""
- key = 'X-RosetteAPI-Test'
+ key = 'X-BabelStreetAPI-Test'
value = 'foo'
api.set_custom_headers(key, value)
assert value == api.get_custom_headers()[key]
@@ -121,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"""
@@ -138,302 +139,270 @@ 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
-# @httpretty.activate
-
-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")
+@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"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
-
-# Test that getting the info about the API is being called correctly
+ assert result["name"] == "Babel Street Analytics"
+@pook.on
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")
+ pook.get(url=get_base_url() + "v1/info",
+ response_json=json_response,
+ reply=200)
result = api.info()
- assert result["name"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
-
-
-# Test for 409
+ assert result["name"] == "Babel Street Analytics"
+@pook.on
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")
+ 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(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",
- adding_headers={
- 'x-rosetteapi-concurrency': 5
- })
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()
-
-# Test the language endpoint
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/language",
- body=json_response, status=200, content_type="application/json")
+@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)
- assert result["name"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
-
-# Test the sentences endpoint
-
-
-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")
- 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"
- 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://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")
-
- result = api.tokens(doc_params)
- assert result["name"] == "Rosette"
- 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://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/morphology/complete",
- body=json_response, status=200, content_type="application/json")
-
- result = api.morphology(doc_params)
- assert result["name"] == "Rosette"
- 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://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/morphology/lemmas",
- body=json_response, status=200, content_type="application/json")
-
- result = api.morphology(doc_params, 'lemmas')
- assert result["name"] == "Rosette"
- 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://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/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"
- httpretty.disable()
- httpretty.reset()
-
-# Test the morphology compound-components endpoint
-
+ assert result["name"] == "Babel Street Analytics"
+ assert api.get_pool_size() == 8
+ api.set_pool_size(11)
+ assert api.get_pool_size() == 11
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.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"
- httpretty.disable()
- httpretty.reset()
+@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)
-# Test the morphology han-readings endpoint
+ with pytest.raises(RosetteException) as e_rosette:
+ result = api.language(doc_map)
+ assert e_rosette.value.status == 'incompatible'
+
+
+@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):
+ 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"
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.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"
- httpretty.disable()
- httpretty.reset()
+@pook.on
+def test_incompatible_type(api, json_response):
+ pook.post(url=get_base_url() + "v1/sentences",
+ response_json=json_response,
+ reply=200)
-# Test the entities endpoint
+ 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)
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/entities",
- body=json_response, status=200, content_type="application/json")
- result = api.entities(doc_params)
- assert result["name"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
+@pook.on
+def test_the_name_translation_endpoint(api, json_response):
+ pook.post(url=get_base_url() + "v1/name-translation",
+ response_json=json_response,
+ reply=200)
-# Test the categories endpoint
+ params = NameTranslationParameters()
+ params["name"] = "some data to translate"
+ params["entityType"] = "PERSON"
+ params["targetLanguage"] = "eng"
+ params["targetScript"] = "Latn"
+ result = api.name_translation(params)
+ assert result["name"] == "Babel Street Analytics"
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/categories",
- body=json_response, status=200, content_type="application/json")
+@pook.on
+def test_the_name_requests_with_text(api, json_response):
+ pook.post(url=get_base_url() + "v1/name-similarity",
+ response_json=json_response,
+ reply=200)
- result = api.categories(doc_params)
- assert result["name"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
+ with pytest.raises(RosetteException) as e_rosette:
+ result = api.name_similarity("should fail")
+ assert e_rosette.value.status == 'incompatible'
-# Test the sentiment endpoint
+ 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'
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/sentiment",
- body=json_response, status=200, content_type="application/json")
+ with pytest.raises(RosetteException) as e_rosette:
+ result = api.address_similarity("should fail")
+ assert e_rosette.value.status == 'incompatible'
- result = api.sentiment(doc_params)
- assert result["name"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
+ with pytest.raises(RosetteException) as e_rosette:
+ result = api.record_similarity("should fail")
+ assert e_rosette.value.status == 'incompatible'
-# Test the multipart operation
+@pook.on
+def test_the_name_similarity_single_parameters(api, json_response):
+ pook.post(url=get_base_url() + "v1/name-similarity",
+ response_json=json_response,
+ reply=200)
-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")
+ 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"}
- 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"
- httpretty.disable()
- httpretty.reset()
+ result = api.name_similarity(params)
+ assert result["name"] == "Babel Street Analytics"
-# Test the name translation endpoint
+@pook.on
+def test_the_name_similarity_multiple_parameters(api, json_response):
+ pook.post(url=get_base_url() + "v1/name-similarity",
+ response_json=json_response,
+ reply=200)
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-translation",
- 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"
- result = api.name_translation(params)
- assert result["name"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
+ 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"}
-# Test the name similarity endpoint
+ result = api.name_similarity(params)
+ assert result["name"] == "Babel Street Analytics"
+@pook.on
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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.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 = "迈克尔·杰克逊"
@@ -445,20 +414,14 @@ 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"
- httpretty.disable()
- httpretty.reset()
+ assert result["name"] == "Babel Street Analytics"
-# Test the name deduplication endpoint
-
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-deduplication",
- body=json_response, status=200, content_type="application/json")
+@pook.on
+def test_name_deduplication_parameters(api, json_response):
+ pook.post(url=get_base_url() + "v1/name-deduplication",
+ response_json=json_response,
+ reply=200)
params = NameDeduplicationParameters()
@@ -466,24 +429,20 @@ def test_name_deduplicatation_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"] == "Rosette"
-
- httpretty.disable()
- httpretty.reset()
+ assert result["name"] == "Babel Street Analytics"
+@pook.on
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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.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
@@ -492,97 +451,57 @@ def test_the_name_deduplication_endpoint(api, json_response):
params["threshold"] = threshold
result = api.name_deduplication(params)
- assert result["name"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
-
-# Test the relationships endpoint
+ assert result["name"] == "Babel Street Analytics"
-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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.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"] == "Rosette"
- 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.POST, "https://api.rosette.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",
- 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://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",
- 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'] = 'http://google.com'
+ 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()
+ assert (e_rosette.value.message ==
+ 'Cannot supply both Content and ContentUri')
-# Test for 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://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",
- 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://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")
+ pook.post(url=get_base_url() + "v1/address-similarity",
+ response_json=json_response,
+ reply=200)
params = AddressSimilarityParameters()
@@ -590,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",
@@ -602,26 +522,44 @@ 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"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
+ assert result["name"] == "Babel Street Analytics"
+
+@pook.on
+def test_for_address_similarity_optional_parameters(api, json_response):
+ pook.post(url=get_base_url() + "v1/address-similarity",
+ response_json=json_response,
+ reply=200)
-# Test for required Name Similarity parameters
+ 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"] == "Babel Street Analytics"
+
+
+@pook.on
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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.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 = "迈克尔·杰克逊"
@@ -631,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,
@@ -641,25 +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"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
-
-# Test for required Name Translation parameters
+ assert result["name"] == "Babel Street Analytics"
+@pook.on
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")
- httpretty.register_uri(httpretty.POST, "https://api.rosette.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"
@@ -669,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"
@@ -677,109 +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"] == "Rosette"
-
- 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://api.rosette.com/rest/v1/semantics/vector",
- body=json_response, status=200, content_type="application/json")
-
- result = api.semantic_vectors(doc_params)
- assert result["name"] == "Rosette"
- 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://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"
- 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://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 = DocumentParameters()
- params["content"] = "Some test content"
- result = api.transliteration(params)
- assert result["name"] == "Rosette"
- 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"
- 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"
- httpretty.disable()
- httpretty.reset()
+ assert result["name"] == "Babel Street Analytics"
+@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://api.rosette.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"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
+ assert result["name"] == "Babel Street Analytics"
# 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")
+ pook.post(url=get_base_url() + "v1/name-similarity",
+ response_json=json_response,
+ reply=200)
name_similarity_params = NameSimilarityParameters()
@@ -788,19 +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"] == "Rosette"
- httpretty.disable()
- httpretty.reset()
+ assert result["name"] == "Babel Street Analytics"
# 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")
+ pook.post(url=get_base_url() + "v1/name-translation",
+ response_json=json_response,
+ reply=200)
name_translation_params = NameTranslationParameters()
name_translation_params["entityType"] = "PERSON"
@@ -809,7 +661,48 @@ 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"
+
+
+@pook.on
+def test_the_record_similarity_endpoint(api, json_response):
+ pook.post(url=get_base_url() + "v1/record-similarity",
+ response_json=json_response,
+ reply=200)
+
+ params = RecordSimilarityParameters()
+ params["fields"] = {}
+ params["properties"] = {}
+ params["records"] = {}
+ result = api.record_similarity(params)
+ assert result["name"] == "Babel Street Analytics"
+
+
+@pook.on
+def test_for_record_similarity_required_parameters(api, json_response):
+ pook.post(url=get_base_url() + "v1/record-similarity",
+ response_json=json_response,
+ reply=200)
+
+ 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: records')
+
+ 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')
+
+ params["fields"] = {}
- httpretty.disable()
- httpretty.reset()
+ result = api.record_similarity(params)
+ assert result["name"] == "Babel Street Analytics"
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 23301ee..7f53adf 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]
+envlist = py3
skipsdist = True
-envlist = py2, py3
[testenv]
-commands =
- {envpython} setup.py install
- {envbindir}/py.test
deps =
pytest
pep8
- httpretty
+ pook
epydoc
requests
+ coverage
+ build
+
+commands =
+ python -m build
+ coverage run -m pytest
+ coverage xml
+
+[coverage:run]
+relative_files = True