-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_first_prediction.py
More file actions
36 lines (31 loc) · 1.23 KB
/
extract_first_prediction.py
File metadata and controls
36 lines (31 loc) · 1.23 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
#!/usr/bin/python3
import time
import math
import sys
import pdb
import requests
import urllib
from collections import OrderedDict
import argparse
import config_utils as cf
import pdb
def extract(input_file,output_file):
wfp = open(output_file,"w")
with open(input_file) as fp:
for line in fp:
line = line.rstrip("\n")
arr = line.split()
if (len(arr) > 1):
p_field = arr[1].split("/")[0].split("[")[0]
print(arr[0],p_field)
wfp.write(arr[0] + " " + p_field + "\n")
else:
print(line)
wfp.write("\n")
wfp.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Conversion utility to extract only the first type in prediction from a columnar format file and output the resultant columnar file ',formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-input', action="store", dest="input",default="ner_output.txt",help='Input file for batch run option')
parser.add_argument('-output', action="store", dest="output",default="test.tsv",help='Input file for batch run option')
results = parser.parse_args()
extract(results.input,results.output)