Skip to content

Commit 015cae2

Browse files
authored
Merge pull request #56 from kbailey-basistech/RCB-473_Syntax-Dependencies
Rcb 473 syntax dependencies
2 parents 3401114 + 16362f8 commit 015cae2

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

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 = "Sony Pictures is planning to shoot a good portion of the new \"Ghostbusters\" in Boston as well."
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/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,11 @@ def text_embedding(self, parameters):
841841
@type parameters: L{DocumentParameters} or L{str}
842842
@return: A python dictionary containing the results of text embedding."""
843843
return EndpointCaller(self, "text-embedding").call(parameters)
844+
845+
def syntax_dependencies(self, parameters):
846+
"""
847+
Create an L{EndpointCaller} to identify the syntactic dependencies in the texts
848+
to which it is applied and call it.
849+
@type parameters: L{DocumentParameters} or L{str}
850+
@return: A python dictionary containing the results of syntactic dependencies identification"""
851+
return EndpointCaller(self, "syntax/dependencies").call(parameters)

tests/test_rosette_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,14 @@ def test_the_text_embedded_endpoint(api, json_response, doc_params):
590590
assert result["name"] == "Rosette API"
591591
httpretty.disable()
592592
httpretty.reset()
593+
594+
595+
def test_the_syntax_dependencies_endpoint(api, json_response, doc_params):
596+
httpretty.enable()
597+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/syntax/dependencies",
598+
body=json_response, status=200, content_type="application/json")
599+
600+
result = api.syntax_dependencies(doc_params)
601+
assert result["name"] == "Rosette API"
602+
httpretty.disable()
603+
httpretty.reset()

0 commit comments

Comments
 (0)