12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import csv
- import codecs
- import pandas as pd
- import re
- import os
- import io
- import tokenize
- merged_data = open('mergeOVI.csv', 'w')
- csvwriter = csv.writer(merged_data)
- params = ['sigla', 'n_lemma', 'lemma', 'n_iperlemma', 'iperlemma', 'pos', 'commento', 'merce', 'link_tlio']
- csvwriter.writerow(params)
- def get_link_ovi (lemma):
- link_file = open('/Users/leonardocanova/Library/CloudStorage/OneDrive-UniversityofPisa(1)/Documenti/Progetti università/OVI/Programmazione/OVI_lemmi_clean.csv')
- reader = csv.DictReader(link_file)
- for row in reader:
- sLemma = row['sLemma']
- if (sLemma == lemma):
- return (row['FileHTM'])
- merge_file = open('/Users/leonardocanova/Library/CloudStorage/OneDrive-UniversityofPisa(1)/Documenti/Progetti università/OVI/Programmazione/data_lemmi.csv')
- reader = csv.DictReader(merge_file)
- for row in reader:
- line = []
- sigla = row['sigla']
- n_lemma = row['n_lemma']
- lemma = row['lemma']
- n_iperlemma = row['n_iperlemma']
- iperlemma = row['iperlemma']
- pos = row['pos']
- commento = row['commento']
- merce = row['merce']
- link_ovi = get_link_ovi(lemma)
- line.append (sigla)
- line.append (n_lemma)
- line.append (lemma)
- line.append (n_iperlemma)
- line.append (iperlemma)
- line.append (pos)
- line.append (commento)
- line.append (merce)
- if link_ovi is not None:
- line.append(link_ovi)
- else:
- line.append("")
- csvwriter.writerow(line)
- #print (line)
- merged_data.close()
|