1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import re
- import csv
- import os
- lemmi = []
- basepath_lemmi = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/lemmi'
- for entry in os.listdir(basepath_lemmi):
- if os.path.isfile(os.path.join(basepath_lemmi, entry)):
- ll = entry.split('.')[1].lstrip().split(' ')[0]
- if ll != '':
- lemmi.append([ll, entry])
- iperlem_data = open('iperlem_Data.csv', 'w')
- csvwriter = csv.writer(iperlem_data)
- params = ["sigla", "file", "num", "iperlemma", "commento", "livello"]
- csvwriter.writerow(params)
- def write_lines(lines, sig, file):
- for line in lines:
- row = [sig, file]
- lem = re.split('\|', line)
- for l in lem:
- if "IPERLEMMA" in l:
- ll = l.replace("IPERLEMMA", " ")
- else:
- ll = l
- m = ll.rstrip()
- n = m.lstrip()
- row.append(n)
- csvwriter.writerow(row)
- for x in range(len(lemmi)):
- sigla = lemmi[x][0]
- file_name = lemmi[x][1]
- f = open('/Users/alessiaspadi/Documents/RESTORE/temp_ovi/lemmi/' + file_name, "r", encoding='latin-1')
- lines = f.readlines()
- clean_lines = []
- for line in lines:
- if "IPERLEMMA" in line:
- clean_lines.append(line)
- write_lines(clean_lines, sigla, file_name)
- f.close()
- iperlem_data.close()
|