Skip to content

Commit 9d1c191

Browse files
author
Chris Park
committed
Merge branch 'develop'
2 parents f725954 + a4a2644 commit 9d1c191

File tree

10 files changed

+96
-263
lines changed

10 files changed

+96
-263
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ The samples use the following procedure:
8282

8383
See [examples](examples) for more request samples.
8484

85+
## Docker ##
86+
A Docker image for running the examples against the compiled source library is available on Docker Hub.
87+
88+
Command: `docker run -e API_KEY=api-key -v "<binding root directory>:/source" rosetteapi/docker-python`
89+
90+
Additional environment settings:
91+
`-e ALT_URL=<alternative URL>`
92+
`-e FILENAME=<single filename>`
93+
8594
API Documentation
8695
-----------------
8796

docker/Dockerfile

Lines changed: 0 additions & 54 deletions
This file was deleted.

docker/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

docker/run_python.sh

Lines changed: 0 additions & 115 deletions
This file was deleted.

docker/tox.ini

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/relationships.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
1515
# Create an API instance
1616
api = API(user_key=key, service_url=altUrl)
17-
relationships_text_data = "The Ghostbusters movie was filmed in Boston."
17+
relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist."
1818
params = DocumentParameters()
1919
params["content"] = relationships_text_data
2020
api.setOption('accuracyMode', 'PRECISION')

examples/syntax_dependencies.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Example code to call Rosette API to get the syntactic dependencies of a document (at a given URL).
5+
"""
6+
7+
import argparse
8+
import json
9+
import os
10+
11+
from rosette.api import API, DocumentParameters
12+
13+
14+
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
15+
syntax_dependencies_data = "Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday."
16+
params = DocumentParameters()
17+
params["content"] = syntax_dependencies_data
18+
params["genre"] = "social-media"
19+
# Create an API instance
20+
api = API(user_key=key, service_url=altUrl)
21+
return api.syntax_dependencies(params)
22+
23+
24+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
25+
parser.add_argument('-k', '--key', help='Rosette API Key', required=True)
26+
parser.add_argument('-u', '--url', help="Alternative API URL", default='https://api.rosette.com/rest/v1/')
27+
28+
if __name__ == '__main__':
29+
args = parser.parse_args()
30+
result = run(args.key, args.url)
31+
print(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8"))

rosette/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
limitations under the License.
1717
"""
1818

19-
__version__ = '1.3.0'
19+
__version__ = '1.4.0'

rosette/api.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import re
2929
import warnings
3030

31-
_BINDING_VERSION = '1.3.0'
31+
_BINDING_VERSION = '1.4.0'
3232
_GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08])
3333

3434
_IsPy3 = sys.version_info[0] == 3
@@ -522,7 +522,6 @@ def __init__(
522522
if (refresh_duration < 0):
523523
refresh_duration = 0
524524

525-
self.num_retries = retries
526525
self.connection_refresh_duration = refresh_duration
527526
self.options = {}
528527
self.customHeaders = {}
@@ -538,8 +537,6 @@ def _set_pool_size(self):
538537

539538
def _make_request(self, op, url, data, headers):
540539
"""
541-
Handles the actual request, retrying if a 429 is encountered
542-
543540
@param op: POST or GET
544541
@param url: endpoing URL
545542
@param data: request data
@@ -556,43 +553,39 @@ def _make_request(self, op, url, data, headers):
556553
session = requests.Session()
557554
prepared_request = session.prepare_request(request)
558555

559-
for i in range(self.num_retries + 1):
560-
try:
561-
response = session.send(prepared_request)
562-
status = response.status_code
563-
rdata = response.content
564-
dict_headers = dict(response.headers)
565-
response_headers = {"responseHeaders": dict_headers}
566-
if 'x-rosetteapi-concurrency' in dict_headers:
567-
if dict_headers['x-rosetteapi-concurrency'] != self.maxPoolSize:
568-
self.maxPoolSize = dict_headers['x-rosetteapi-concurrency']
569-
self._set_pool_size()
570-
571-
if status == 200:
572-
return rdata, status, response_headers
573-
if status == 429:
574-
code = status
575-
message = "{0} ({1})".format(rdata, i)
576-
time.sleep(self.connection_refresh_duration)
577-
continue
578-
if rdata is not None:
579-
try:
580-
the_json = _my_loads(rdata, response_headers)
581-
if 'message' in the_json:
582-
message = the_json['message']
583-
if "code" in the_json:
584-
code = the_json['code']
585-
else:
586-
code = status
587-
raise RosetteException(code, message, url)
588-
589-
except:
590-
raise
591-
except requests.exceptions.RequestException as e:
592-
raise RosetteException(
593-
e.message,
594-
"Unable to establish connection to the Rosette API server",
595-
url)
556+
try:
557+
response = session.send(prepared_request)
558+
status = response.status_code
559+
rdata = response.content
560+
dict_headers = dict(response.headers)
561+
response_headers = {"responseHeaders": dict_headers}
562+
if 'x-rosetteapi-concurrency' in dict_headers:
563+
if dict_headers['x-rosetteapi-concurrency'] != self.maxPoolSize:
564+
self.maxPoolSize = dict_headers['x-rosetteapi-concurrency']
565+
self._set_pool_size()
566+
567+
if status == 200:
568+
return rdata, status, response_headers
569+
if rdata is not None:
570+
try:
571+
the_json = _my_loads(rdata, response_headers)
572+
if 'message' in the_json:
573+
message = the_json['message']
574+
if "code" in the_json:
575+
code = the_json['code']
576+
else:
577+
code = status
578+
if not message:
579+
message = rdata
580+
raise RosetteException(code, message, url)
581+
582+
except:
583+
raise
584+
except requests.exceptions.RequestException as e:
585+
raise RosetteException(
586+
e.message,
587+
"Unable to establish connection to the Rosette API server",
588+
url)
596589

597590
raise RosetteException(code, message, url)
598591

@@ -841,3 +834,11 @@ def text_embedding(self, parameters):
841834
@type parameters: L{DocumentParameters} or L{str}
842835
@return: A python dictionary containing the results of text embedding."""
843836
return EndpointCaller(self, "text-embedding").call(parameters)
837+
838+
def syntax_dependencies(self, parameters):
839+
"""
840+
Create an L{EndpointCaller} to identify the syntactic dependencies in the texts
841+
to which it is applied and call it.
842+
@type parameters: L{DocumentParameters} or L{str}
843+
@return: A python dictionary containing the results of syntactic dependencies identification"""
844+
return EndpointCaller(self, "syntax/dependencies").call(parameters)

0 commit comments

Comments
 (0)