associate_OVI_URL_TLIO.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import csv
  2. import codecs
  3. import pandas as pd
  4. import re
  5. import os
  6. import io
  7. import tokenize
  8. merged_data = open('mergeOVI.csv', 'w')
  9. csvwriter = csv.writer(merged_data)
  10. params = ['sigla', 'n_lemma', 'lemma', 'n_iperlemma', 'iperlemma', 'pos', 'commento', 'merce', 'link_tlio']
  11. csvwriter.writerow(params)
  12. def get_link_ovi (lemma):
  13. link_file = open('/Users/leonardocanova/Library/CloudStorage/OneDrive-UniversityofPisa(1)/Documenti/Progetti università/OVI/Programmazione/OVI_lemmi_clean.csv')
  14. reader = csv.DictReader(link_file)
  15. for row in reader:
  16. sLemma = row['sLemma']
  17. if (sLemma == lemma):
  18. return (row['FileHTM'])
  19. merge_file = open('/Users/leonardocanova/Library/CloudStorage/OneDrive-UniversityofPisa(1)/Documenti/Progetti università/OVI/Programmazione/data_lemmi.csv')
  20. reader = csv.DictReader(merge_file)
  21. for row in reader:
  22. line = []
  23. sigla = row['sigla']
  24. n_lemma = row['n_lemma']
  25. lemma = row['lemma']
  26. n_iperlemma = row['n_iperlemma']
  27. iperlemma = row['iperlemma']
  28. pos = row['pos']
  29. commento = row['commento']
  30. merce = row['merce']
  31. link_ovi = get_link_ovi(lemma)
  32. line.append (sigla)
  33. line.append (n_lemma)
  34. line.append (lemma)
  35. line.append (n_iperlemma)
  36. line.append (iperlemma)
  37. line.append (pos)
  38. line.append (commento)
  39. line.append (merce)
  40. if link_ovi is not None:
  41. line.append(link_ovi)
  42. else:
  43. line.append("")
  44. csvwriter.writerow(line)
  45. #print (line)
  46. merged_data.close()