test_occorrenzario.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # %%
  2. import sqlite3
  3. # %%
  4. def getCursor(path="../db/test1.db"):
  5. con = sqlite3.connect("file:"+path+"?mode=ro", uri=True)
  6. cur = con.cursor()
  7. return cur
  8. def closeConn(cur):
  9. cur.connection.close()
  10. def doQuery(cur, queryText):
  11. queryReponse = cur.execute(queryText)
  12. results = queryReponse.fetchall()
  13. return results
  14. # %%
  15. cur1 = getCursor()
  16. # %%
  17. res1 = doQuery(cur1, "select cod, spec, norm from form where norm='gatto'")
  18. print(res1)
  19. # %%
  20. listOcc = ["occ00001", "occ00002", "occ00003"]
  21. res2 = []
  22. for table in listOcc:
  23. res2 = res2 + doQuery(cur1, "select ntx, pitxt from " + table + " where cod=" + str(res1[0][0]))
  24. print(res2)
  25. # %%
  26. with open("../db/itxt/p07", 'r', encoding="utf-32-le") as f:
  27. f.seek(4*int(res2[0][1]), 0)
  28. char = f.read(20)
  29. print(char)
  30. # %%
  31. # Experimentally: 'Gatto' (exact spelling) is in 'p07'
  32. with open("../db/itxt/p07", 'r', encoding="utf-32-le") as file:
  33. pyppa = file.read()
  34. print( pyppa[int(res2[0][1])-20:int(res2[0][1])+20] )
  35. print()
  36. print( pyppa[int(res2[1][1])-20:int(res2[1][1])+20] )
  37. # %%