test_sottocorpora.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. # %%
  2. import sqlite3
  3. import pandas as pd
  4. import dtale
  5. import unicodedata
  6. from simple_query_test_pandas import ricercaforme, ricercalemmi, ricercaformelemmi, ricercalemmiforme, interpreter
  7. from test_occorrenzario_pandas import findtexts, findcontexts, findbib, contestimultipli, get_tables_occ
  8. #funzione di definizione sottocorpus
  9. def definiscisottocorpus (path, table, conditions=None):
  10. conn = sqlite3.connect(f"file:{path}/bibliografia/BiblioTLIO.db?mode=ro", uri=True)
  11. c = conn.cursor()
  12. query = "SELECT sigla FROM {} WHERE 1".format(table)
  13. if conditions:
  14. for key, value in conditions.items():
  15. if isinstance(value, list):
  16. query += " AND {} = '{}'".format(key, "' OR '".join([str(v) for v in value]))
  17. print(query)
  18. else:
  19. query += " AND {}='{}'".format(key, value)
  20. c.execute(query)
  21. results = c.fetchall()
  22. conn.close()
  23. sottocorpus = [result[0] for result in results]
  24. return sottocorpus
  25. # %%
  26. path = "/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db"
  27. siglas = definiscisottocorpus(path,"datibib", {"IQ": "TS", "[Titolo Abbreviato]": ["Albertano volg., 1275 (fior.)", "Simintendi, a. 1333 (prat.)"]})
  28. print(siglas)
  29. # %%