File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments