|
4 | 4 | Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text. |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import argparse |
7 | 8 | import json |
| 9 | +import os |
8 | 10 |
|
9 | 11 | from rosette.api import API, DocumentParameters |
10 | 12 |
|
11 | 13 |
|
12 | | -def run(key): |
| 14 | +def run(key, altUrl='https://api.rosette.com/rest/v1/'): |
13 | 15 | # Create an API instance |
14 | | - api = API(user_key=key) |
| 16 | + api = API(user_key=key, service_url=altUrl) |
15 | 17 |
|
16 | 18 | params = DocumentParameters() |
17 | | - params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people." |
18 | | - result = api.entities(params, True) # entity linking is turned on |
| 19 | + params["content"] = u"Last month director Paul Feig announced the movie will have an all-star female cast including Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon." |
| 20 | + return api.entities(params, True) # entity linking is turned on |
19 | 21 |
|
20 | | - print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) |
21 | | - return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") |
| 22 | + |
| 23 | +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') |
| 24 | +parser.add_argument('-k', '--key', help='Rosette API Key', required=True) |
| 25 | +parser.add_argument('-u', '--url', help="Alternative API URL", default='https://api.rosette.com/rest/v1/') |
| 26 | + |
| 27 | +if __name__ == '__main__': |
| 28 | + args = parser.parse_args() |
| 29 | + result = run(args.key, args.url) |
| 30 | + print(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) |
0 commit comments