Skip to content

Commit 8d84d6b

Browse files
authored
Merge pull request #109 from rosette-api/TEJ-2055-event-negation
TEJ-2055: added test file for event negation
2 parents 8d293b1 + d4f0770 commit 8d84d6b

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

examples/events_negation.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)