Skip to content

Commit ca542d5

Browse files
authored
Added the Python script.
Initial upload.
1 parent 1c971a0 commit ca542d5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

metamap_fetch.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import subprocess
2+
import tempfile
3+
4+
def metamap_fetch(sentences, mm_location):
5+
6+
if sentences is not None:
7+
in_file = tempfile.NamedTemporaryFile(mode="wb", delete=False)
8+
for sentence in sentences:
9+
in_file.write(b'%r\n' % sentence)
10+
else:
11+
print("No input defined.")
12+
13+
in_file.flush()
14+
15+
out_file = tempfile.NamedTemporaryFile(mode="r", delete=False)
16+
17+
command = [mm_location]
18+
19+
command.append("-f") #number the mappings
20+
command.append("-s") #short semantic types
21+
command.append("--negex") #negex
22+
command.append("--silent") #hide header information
23+
command.append("-G") #show sources
24+
command.append("-c") #show candidates
25+
26+
'''
27+
add other options here in the format as below
28+
command.append("")
29+
'''
30+
31+
command.append(in_file.name)
32+
command.append(out_file.name)
33+
34+
run_metamap = subprocess.Popen(command, stdout=subprocess.PIPE)
35+
36+
while run_metamap.poll() is None:
37+
stdout = str(run_metamap.stdout.readline())
38+
if 'ERROR' in stdout:
39+
run_metamap.terminate()
40+
error = stdout.rstrip()
41+
output = str(out_file.read())
42+
return output

0 commit comments

Comments
 (0)