Skip to content

Commit 4b21fb6

Browse files
authored
Add files via upload
1 parent 2367c8c commit 4b21fb6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

package.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json, requests
2+
3+
4+
class OpenIE5:
5+
6+
def __init__(self, server_url):
7+
if server_url[-1] == '/':
8+
server_url = server_url[:-1]
9+
self.server_url = server_url
10+
self.extract_context = '/getExtraction'
11+
12+
def extract(self, text, properties=None):
13+
assert isinstance(text, str)
14+
if properties is None:
15+
properties = {}
16+
else:
17+
assert isinstance(properties, dict)
18+
19+
try:
20+
requests.get(self.server_url)
21+
except requests.exceptions.ConnectionError:
22+
raise Exception('Check whether you have started the OpenIE5 server')
23+
24+
data = text.encode('utf-8')
25+
26+
r = requests.post(
27+
self.server_url + self.extract_context, params={
28+
'properties': str(properties)
29+
}, data=data, headers={'Connection': 'close'})
30+
31+
return json.loads(r.text)

0 commit comments

Comments
 (0)