Skip to content

Commit 8a510bb

Browse files
author
Ervin Papp
committed
RCB-601 new: events example
1 parent a940bdc commit 8a510bb

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

examples/events.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
# Set selected API options.
19+
# For more information on the functionality of these
20+
# and other available options, see Rosette Features & Functions
21+
# https://developer.rosette.com/features-and-functions#entity-extraction-and-linking
22+
23+
# api.set_option('calculateSalience','true')
24+
# api.set_option('linkEntities','false')
25+
26+
events_text_data = "James wanted to test this awesome document."
27+
params = DocumentParameters()
28+
params["content"] = events_text_data
29+
30+
try:
31+
return api.events(params)
32+
except RosetteException as exception:
33+
print(exception)
34+
35+
PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
36+
description='Calls the ' +
37+
os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
38+
PARSER.add_argument('-k', '--key', help='Rosette API Key', required=True)
39+
PARSER.add_argument('-u', '--url', help="Alternative API URL",
40+
default='https://api.rosette.com/rest/v1/')
41+
42+
if __name__ == '__main__':
43+
ARGS = PARSER.parse_args()
44+
RESULT = run(ARGS.key, ARGS.url)
45+
print(RESULT)

0 commit comments

Comments
 (0)