forked from rosette-api/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelationships.py
More file actions
37 lines (30 loc) · 1.84 KB
/
relationships.py
File metadata and controls
37 lines (30 loc) · 1.84 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
# -*- coding: utf-8 -*-
"""
Example code to call Rosette API to get entities's relationships from a piece of text.
"""
from __future__ import print_function
import argparse
import json
import os
from rosette.api import API, DocumentParameters, RosetteException
def run(key, alt_url='https://api.rosette.com/rest/v1/'):
""" Run the example """
# Create an API instance
api = API(user_key=key, service_url=alt_url)
relationships_text_data = "FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai."
params = DocumentParameters()
params["content"] = relationships_text_data
try:
return api.relationships(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='Rosette API Key', required=True)
PARSER.add_argument('-u', '--url', help="Alternative API URL",
default='https://api.rosette.com/rest/v1/')
if __name__ == '__main__':
ARGS = PARSER.parse_args()
RESULT = run(ARGS.key, ARGS.url)
print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8"))