-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREACHProcess.py
More file actions
31 lines (27 loc) · 1.2 KB
/
REACHProcess.py
File metadata and controls
31 lines (27 loc) · 1.2 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
# import HTTP requests module
import requests
# import JSON utils to
import json
# REACH web-service processing
class REACHProcessor:
# construct REACH web-service processor for specific URL
def __init__(self, reach_url="http://agathon.sista.arizona.edu:8080/odinweb/api/text"):
self.ws_url = reach_url
def process_REACH(self, pmid, abstract):
# send post request to REACH web-service
reach_response = requests.post(self.ws_url, data={'text': abstract, 'output': 'fries'})
# enforce UTF-8 encoding
reach_response.encoding = 'UTF-8'
# process statistics
self.statistics(reach_response.content)
# return REACH data
return str(reach_response.text)
# process REACH file to get some statistics
def statistics(self, reach_data):
# load data as json object
stats = json.loads(reach_data)
# Get statistics according to fries-data-representation-spec-3 format
print ("Number of events: {0:d}\nNumber of entities: {1:d}\nNumber of sentences: {2:d}\n" \
.format(len(stats['events']['frames']),
len(stats['entities']['frames']),
len(stats['sentences']['frames'])))