-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_lemmatize_predictions.py
41 lines (30 loc) · 1.08 KB
/
08_lemmatize_predictions.py
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
37
38
39
40
41
# Lemmatize *inputfile* with predicted answers using MorphoDita and save the results to the *outputfile*.
# Lemmatize model can be extracted from http://hdl.handle.net/11234/1-1836
import json
import sys
import requests
import xml.etree.ElementTree as ET
import time
import lemmatizer
inputfile = 'predictions_czu84.json'
outputfile = 'predictions_czu84_lemmatized.json'
# load input json file
def load_file(file):
with open(file, "r", encoding='utf-8') as read_file:
data = json.load(read_file)
print('--DATA SUCCESSFULLY LOADED--', file=sys.stderr)
return data
# save data to json file
def save_file(data, filename):
with open(filename, 'w', encoding='utf-8') as f:
json.dump(data, f,ensure_ascii=False)
print('--DATA SUCCESSFULLY SAVED--', file=sys.stderr)
def main():
data = load_file(inputfile)
for (k, v) in data.items():
lemmalist = lemmatizer.lemmatize(v)
data[k] = lemmalist
print('--LEMMATIZATION FINISHED--', file=sys.stderr)
save_file(data, outputfile)
if __name__ == "__main__":
main()