-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathentities.py
More file actions
46 lines (36 loc) · 2.11 KB
/
entities.py
File metadata and controls
46 lines (36 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""
Example code to call Analytics API to get entities from a piece of text.
"""
import argparse
import json
import os
from rosette.api import API, DocumentParameters, RosetteException
def run(key, alt_url='https://analytics.babelstreet.com/rest/v1/'):
""" Run the example """
# Create an API instance
api = API(user_key=key, service_url=alt_url)
# Set selected API options.
# For more information on the functionality of these
# and other available options, see Analytics Features & Functions
# https://developer.babelstreet.com/features-and-functions#entity-extraction-and-linking
# api.set_option('calculateSalience','true')
# api.set_option('linkEntities','false')
# api.set_option('useIndocServer', True)
entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country."
params = DocumentParameters()
params["content"] = entities_text_data
try:
return api.entities(params)
except RosetteException as exception:
print(exception)
PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Calls the ' +
os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
PARSER.add_argument('-k', '--key', help='Analytics API Key', required=True)
PARSER.add_argument('-u', '--url', help="Alternative API URL",
default='https://analytics.babelstreet.com/rest/v1/')
if __name__ == '__main__':
ARGS = PARSER.parse_args()
RESULT = run(ARGS.key, ARGS.url)
print(RESULT)