|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Example code to call Rosette API to get entities from a piece of text. |
| 4 | +""" |
| 5 | + |
| 6 | +import argparse |
| 7 | +import json |
| 8 | +import os |
| 9 | + |
| 10 | +from rosette.api import API, DocumentParameters, RosetteException |
| 11 | + |
| 12 | + |
| 13 | +def run(key, alt_url='https://api.rosette.com/rest/v1/'): |
| 14 | + """ Run the example """ |
| 15 | + # Create an API instance |
| 16 | + api = API(user_key=key, service_url=alt_url) |
| 17 | + |
| 18 | + events_text_data = "I am looking for flights to Super Bowl 2022 in Inglewood, LA." |
| 19 | + params = DocumentParameters() |
| 20 | + params["content"] = events_text_data |
| 21 | + |
| 22 | + try: |
| 23 | + return api.events(params) |
| 24 | + except RosetteException as exception: |
| 25 | + print(exception) |
| 26 | + |
| 27 | +PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 28 | + description='Calls the ' + |
| 29 | + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') |
| 30 | +PARSER.add_argument('-k', '--key', help='Rosette API Key', required=True) |
| 31 | +PARSER.add_argument('-u', '--url', help="Alternative API URL", |
| 32 | + default='https://api.rosette.com/rest/v1/') |
| 33 | + |
| 34 | +if __name__ == '__main__': |
| 35 | + ARGS = PARSER.parse_args() |
| 36 | + RESULT = run(ARGS.key, ARGS.url) |
| 37 | + print(RESULT) |
0 commit comments