|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Example code to call Rosette API to get events, based on a set negation option, 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 | + # Double negative, meaning that the event should be skipped with "IGNORE" or "ONLY_NEGATIVE" |
| 19 | + # and recognized under "BOTH" or "ONLY_POSITIVE" |
| 20 | + events_text_data = "Sam didn't not take a flight to Boston." |
| 21 | + params = DocumentParameters() |
| 22 | + params["content"] = events_text_data |
| 23 | + api.set_option('negation', 'ONLY_POSITIVE') |
| 24 | + |
| 25 | + |
| 26 | + try: |
| 27 | + return api.events(params) |
| 28 | + except RosetteException as exception: |
| 29 | + print(exception) |
| 30 | + |
| 31 | +PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 32 | + description='Calls the ' + |
| 33 | + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint') |
| 34 | +PARSER.add_argument('-k', '--key', help='Rosette API Key', required=True) |
| 35 | +PARSER.add_argument('-u', '--url', help="Alternative API URL", |
| 36 | + default='https://api.rosette.com/rest/v1/') |
| 37 | + |
| 38 | +if __name__ == '__main__': |
| 39 | + ARGS = PARSER.parse_args() |
| 40 | + RESULT = run(ARGS.key, ARGS.url) |
| 41 | + print(RESULT) |
0 commit comments