Jelajahi Sumber

esempi notebook e fixes

Leonardo Canova 1 tahun lalu
induk
melakukan
8888eb2a86

+ 5 - 8
flask_be/engine/test/test_contesti_singoli.py

@@ -58,7 +58,7 @@ def singlecontexts(textlist, index, parole, periodi, brani, listOcc, path):
                 context ['pfin'] = queryresponse["pfin"].max() 
     context['contesto'] = contexts
     context['formattazione'] = formats
-    return pd.DataFrame(context).T.set_index('index')
+    return pd.DataFrame(context).T.reset_index()
 
 
 #%% funzione di ricerca dei brani associati. Ha in input singlecontexts.
@@ -127,7 +127,6 @@ def singlefindbib(contexts, path):
     contexts['Rig_completo'] = rif2
     contexts.pag = contexts.pag.astype(int)
     chrono = contexts.sort_values(by=['Anno iniziale', 'Rif_organico', 'pag'])   
-    print(chrono)
     if 'nota' in chrono.columns and 'testo associato' in chrono.columns:
         cols = ['links','Titolo Abbreviato', 'Rif_organico', 'tipostanza', 'stanza', 'verso', 'pag', 'riga', 'IQ', 'lemma', 'cat_gr', 'disambiguatore', 'contesto', 'nota', 'testo associato']
     elif 'nota' in chrono.columns:
@@ -136,12 +135,11 @@ def singlefindbib(contexts, path):
         cols = ['links','Titolo Abbreviato', 'Rif_organico', 'tipostanza', 'stanza', 'verso', 'pag', 'riga', 'IQ', 'lemma', 'cat_gr', 'disambiguatore', 'contesto', 'testo associato']
     else:
         cols = ['links','Titolo Abbreviato', 'Rif_organico', 'tipostanza', 'stanza', 'verso', 'pag', 'riga', 'IQ', 'lemma', 'cat_gr', 'disambiguatore', 'contesto']
-    print(cols)
     clean_df = chrono[cols].reset_index()
     return clean_df
 
 # %%
-parola = "filius"
+parola = "amistade"
 path = "/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db"
 # tipo di ricerca (0 per forme, 1 per lemmi, 2 per lemmi con opzione "mostra occorrenze non lemmatizzate")
 type= 0
@@ -149,10 +147,9 @@ listOcc = ["occ00001", "occ00002", "occ00003"]
 search=ricercaforme(interpreter(parola), path, 0, 0)
 textlist=findtexts(type, search, listOcc, path)
 contexts = findcontexts(textlist, 30, 0, listOcc, path)
-context = singlecontexts(contexts, 0, 30, 0, 0, listOcc, path)
+bibliocontexts = findbib(contexts, path)
+context = singlecontexts(contexts, 28, 30, 0, 0, listOcc, path)
 links = findlinks(context, path)
 bibliocontext = singlefindbib(links, path)
 dtale.show(bibliocontext)
-# %%
-#print(context)
-# %%
+# %%

+ 497 - 0
flask_be/engine/test/test_contesti_singoli_notebook.ipynb

@@ -0,0 +1,497 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import sqlite3\n",
+    "import pandas as pd\n",
+    "import dtale\n",
+    "import unicodedata\n",
+    "from simple_query_test_pandas import ricercaforme\n",
+    "from simple_query_test_pandas import ricercalemmi\n",
+    "from simple_query_test_pandas import ricercaformelemmi \n",
+    "from simple_query_test_pandas import ricercalemmiforme\n",
+    "from simple_query_test_pandas import inizialeraddoppiata\n",
+    "from simple_query_test_pandas import interpreter\n",
+    "from test_occorrenzario_pandas import findtexts\n",
+    "from test_occorrenzario_pandas import findcontexts\n",
+    "from test_occorrenzario_pandas import findbib\n",
+    "from test_cooccorrenze import ricerca_cooccorrenze\n",
+    "from test_contesti_singoli import findbib, findcontexts, findlinks, findtexts, singlecontexts, singlefindbib\n",
+    "import warnings\n",
+    "warnings.filterwarnings('ignore')"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "<h2>Ricerca di contesti singoli</h2>"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca per forme di: filius (primo contesto utile)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "![](img/coocco1.png)\n",
+    "\n",
+    "![](img/coocco1.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/6\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x1741e9150>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 4,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "parola = \"filius\"\n",
+    "path = \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\"\n",
+    "# tipo di ricerca (0 per forme, 1 per lemmi, 2 per lemmi con opzione \"mostra occorrenze non lemmatizzate\")\n",
+    "type= 0\n",
+    "listOcc = [\"occ00001\", \"occ00002\", \"occ00003\"]\n",
+    "search=ricercaforme(interpreter(parola), path, 0, 0)\n",
+    "textlist=findtexts(type, search, listOcc, path)\n",
+    "contexts = findcontexts(textlist, 30, 0, listOcc, path)\n",
+    "context = singlecontexts(contexts, 0, 30, 0, 0, listOcc, path)\n",
+    "links = findlinks(context, path)\n",
+    "bibliocontext = singlefindbib(links, path)\n",
+    "dtale.show(bibliocontext)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca per forme di: tarda (primo contesto utile)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "![](img/coocco2.png)\n",
+    "\n",
+    "![](img/coocco2.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/7\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x1741ebd90>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 5,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "parola = \"tarda\"\n",
+    "path = \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\"\n",
+    "# tipo di ricerca (0 per forme, 1 per lemmi, 2 per lemmi con opzione \"mostra occorrenze non lemmatizzate\")\n",
+    "type= 0\n",
+    "listOcc = [\"occ00001\", \"occ00002\", \"occ00003\"]\n",
+    "search=ricercaforme(interpreter(parola), path, 0, 0)\n",
+    "textlist=findtexts(type, search, listOcc, path)\n",
+    "contexts = findcontexts(textlist, 30, 0, listOcc, path)\n",
+    "context = singlecontexts(contexts, 0, 30, 0, 0, listOcc, path)\n",
+    "links = findlinks(context, path)\n",
+    "bibliocontext = singlefindbib(links, path)\n",
+    "dtale.show(bibliocontext)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca per forme di: amistade (contesto n. 29)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/5\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x161845180>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 3,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "parola = \"amistade\"\n",
+    "path = \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\"\n",
+    "# tipo di ricerca (0 per forme, 1 per lemmi, 2 per lemmi con opzione \"mostra occorrenze non lemmatizzate\")\n",
+    "type= 0\n",
+    "listOcc = [\"occ00001\", \"occ00002\", \"occ00003\"]\n",
+    "search=ricercaforme(interpreter(parola), path, 0, 0)\n",
+    "textlist=findtexts(type, search, listOcc, path)\n",
+    "contexts = findcontexts(textlist, 30, 0, listOcc, path)\n",
+    "context = singlecontexts(contexts, 28, 30, 0, 0, listOcc, path)\n",
+    "links = findlinks(context, path)\n",
+    "bibliocontext = singlefindbib(links, path)\n",
+    "dtale.show(bibliocontext)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca per forme di: orgoglia"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "![](img/coocco3.0.png)![](img/coocco3.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/7\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x16188f970>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 5,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "parola = \"orgoglia\"\n",
+    "path = \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\"\n",
+    "# tipo di ricerca (0 per forme, 1 per lemmi, 2 per lemmi con opzione \"mostra occorrenze non lemmatizzate\")\n",
+    "type= 0\n",
+    "listOcc = [\"occ00001\", \"occ00002\", \"occ00003\"]\n",
+    "search=ricercaforme(interpreter(parola), path, 0, 0)\n",
+    "textlist=findtexts(type, search, listOcc, path)\n",
+    "contexts = findcontexts(textlist, 30, 0, listOcc, path)\n",
+    "context = singlecontexts(contexts, 0, 30, 0, 0, listOcc, path)\n",
+    "links = findlinks(context, path)\n",
+    "bibliocontext = singlefindbib(links, path)\n",
+    "dtale.show(bibliocontext)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca per forme di: intradetta"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/8\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x1618686a0>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 6,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "parola = \"intradetta\"\n",
+    "path = \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\"\n",
+    "# tipo di ricerca (0 per forme, 1 per lemmi, 2 per lemmi con opzione \"mostra occorrenze non lemmatizzate\")\n",
+    "type= 0\n",
+    "listOcc = [\"occ00001\", \"occ00002\", \"occ00003\"]\n",
+    "search=ricercaforme(interpreter(parola), path, 0, 0)\n",
+    "textlist=findtexts(type, search, listOcc, path)\n",
+    "contexts = findcontexts(textlist, 30, 0, listOcc, path)\n",
+    "context = singlecontexts(contexts, 0, 30, 0, 0, listOcc, path)\n",
+    "links = findlinks(context, path)\n",
+    "bibliocontext = singlefindbib(links, path)\n",
+    "dtale.show(bibliocontext)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "\n",
+    "ricerca per forme di: pennace"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/9\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x16186a500>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 7,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "parola = \"pennace\"\n",
+    "path = \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\"\n",
+    "# tipo di ricerca (0 per forme, 1 per lemmi, 2 per lemmi con opzione \"mostra occorrenze non lemmatizzate\")\n",
+    "type= 0\n",
+    "listOcc = [\"occ00001\", \"occ00002\", \"occ00003\"]\n",
+    "search=ricercaforme(interpreter(parola), path, 0, 0)\n",
+    "textlist=findtexts(type, search, listOcc, path)\n",
+    "contexts = findcontexts(textlist, 30, 0, listOcc, path)\n",
+    "context = singlecontexts(contexts, 0, 30, 0, 0, listOcc, path)\n",
+    "links = findlinks(context, path)\n",
+    "bibliocontext = singlefindbib(links, path)\n",
+    "dtale.show(bibliocontext)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: “Ldovere Lavere” (per L vedi l’esempio che Lquesto anche se non ho mai capito a cosa serva, secondo me è funzionale solo la ricerca con G)\n",
+    "\n",
+    "![](img/coocco6.0.png)\n",
+    "\n",
+    "![](img/coocco6.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "ricerca = [[\"dovere\", \"1\", 0, 0], [\"avere\", \"1\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "ricerca = [[\"dovere\", \"1\", 0, 0], [\"avere\", \"1\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: \"Gdovere Gavere\"\n",
+    "\n",
+    "![](img/coocco7.0.png)\n",
+    "\n",
+    "![](img/coocco7.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "ricerca = [[\"dovere\", \"2\", 0, 0], [\"avere\", \"2\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.10.4"
+  },
+  "vscode": {
+   "interpreter": {
+    "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 1 - 1
flask_be/engine/test/test_cooccorrenze.py

@@ -129,7 +129,7 @@ def ricerca_cooccorrenze (listaricerche, intervallo, periodo, ordinate, path):
         return clean
 
 # %%
-ricerca = [["agg.", "3"], ["avere", "1", 0, 0]]
+ricerca = [["cavaliere", "0", 0, 0], ["corte", "0", 0, 0]]
 cooccorrenze = ricerca_cooccorrenze(ricerca, 10, 1, 1, "/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db")
 dtale.show(cooccorrenze)
 

+ 546 - 0
flask_be/engine/test/test_cooccorrenze_notebook.ipynb

@@ -0,0 +1,546 @@
+{
+ "cells": [
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "<h2>Funzionamento della funzione ricerca co-occorrenze</h2>\n",
+    "\n",
+    "La funzione ricerca_cooccorrenze() prende tre argomenti:\n",
+    "\n",
+    "1. listaricerche: una lista di liste, dove ogni sottolista rappresenta una ricerca e ha quattro elementi: una stringa che rappresenta la parola da cercare, una stringa che indica se cercare per lemma (\"L\") o forma (\"F\"), un intero che rappresenta se la ricerca deve includere forme espanso (\"1\") o meno (\"0\"), un intero che rappresenta se la ricerca deve includere forme raddoppiate (\"1\") o meno (\"0\")\n",
+    "2. intervallo: un intero che rappresenta il numero massimo di parole tra le parole cercate\n",
+    "3. periodo: un intero che rappresenta il numero di parole massimo per ogni contesto restituito\n",
+    "\n",
+    "La funzione inizia creando una lista di stringhe listOcc con tre elementi. Questo serve a indicare quali occorrenze dei risultati di ricerca saranno prese in considerazione successivamente.\n",
+    "\n",
+    "Inoltre, la funzione crea una variabile charOffsetConst impostata a 100. Questa variabile viene utilizzata successivamente nella funzione findcontexts() per determinare il numero di caratteri da considerare come contesto per ogni parola trovata.\n",
+    "\n",
+    "Inizialmente, viene creato un DataFrame vuoto listatesti dove verranno salvati i risultati delle ricerche.\n",
+    "\n",
+    "Successivamente, la funzione esegue la ricerca per il primo elemento nella lista listaricerche. Se il tipo di ricerca è \"L\", viene utilizzata la funzione ricercalemmi() per cercare i lemmi corrispondenti alla parola, altrimenti viene utilizzata la funzione ricercaforme() per cercare le forme corrispondenti alla parola. I risultati della ricerca vengono salvati nel DataFrame listatesti utilizzando la funzione findtexts().\n",
+    "\n",
+    "Se invece il tipo di ricerca è \"F\", viene eseguita una ricerca di forma e il risultato viene salvato in textlist. Successivamente, viene creato un nuovo DataFrame df_new vuoto e vengono eseguite due iterazioni for attraverso listatesti e textlist per cercare le parole con un intervallo specifico (indicato da intervallo) tra di loro. Se la parola corrente in listatesti e quella corrente in textlist si trovano nella stessa frase (ntx corrispondente) e la loro differenza di posizione (mappa) rientra nell'intervallo specificato, la riga corrente in listatesti viene aggiunta a df_new. Infine, listatesti viene aggiornato con df_new e la funzione stampa il DataFrame risultante.\n",
+    "\n",
+    "La funzione continua eseguendo le stesse operazioni per ogni elemento successivo in listaricerche. Alla fine, la funzione utilizza la funzione findcontexts() per cercare i contesti di ogni parola trovata. La funzione restituisce una lista di contesti di lunghezza massima periodo.\n",
+    "\n",
+    "Infine, nel codice di esempio viene definita una lista di ricerca ricerca e la funzione"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import sqlite3\n",
+    "import pandas as pd\n",
+    "import dtale\n",
+    "import unicodedata\n",
+    "from simple_query_test_pandas import ricercaforme\n",
+    "from simple_query_test_pandas import ricercalemmi\n",
+    "from simple_query_test_pandas import ricercaformelemmi \n",
+    "from simple_query_test_pandas import ricercalemmiforme\n",
+    "from simple_query_test_pandas import inizialeraddoppiata\n",
+    "from simple_query_test_pandas import interpreter\n",
+    "from test_occorrenzario_pandas import findtexts\n",
+    "from test_occorrenzario_pandas import findcontexts\n",
+    "from test_occorrenzario_pandas import findbib\n",
+    "from test_cooccorrenze import ricerca_cooccorrenze\n",
+    "import warnings\n",
+    "warnings.simplefilter(action='ignore', category=FutureWarning)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "<h2>Ricerca di cooccorrenze</h2>"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: cavaliere corte"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "![](img/coocco1.png)\n",
+    "\n",
+    "![](img/coocco1.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/4\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x151f380a0>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 10,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"cavaliere\", \"0\", 0, 0], [\"corte\", \"0\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 10, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: don* gent*"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "![](img/coocco2.png)\n",
+    "\n",
+    "![](img/coocco2.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/5\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x15690f010>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 12,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"don*\", \"0\", 0, 0], [\"gent*\", \"0\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 10, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: don* gent* (entro 3 parole di testo)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "![](img/coocco2.0.png)\n",
+    "\n",
+    "![](img/coocco2.2.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/6\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x15690e770>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 13,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"don*\", \"0\", 0, 0], [\"gent*\", \"0\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 3, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: \" * <u,o>m? sav *\" (nota usa di “”)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "![](img/coocco3.0.png)![](img/coocco3.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/8\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x1569b5ed0>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 15,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"*<u,o>m?\", \"0\", 0, 0], [\"sav*\", \"0\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: \"de* av?re\"\n",
+    "\n",
+    "![](img/coocco4.0.png)\n",
+    "\n",
+    "![](img/coocco4.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/9\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x1569b52a0>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 16,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"de*\", \"0\", 0, 0], [\"av?re\", \"0\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di “Gsavio Guomo” (per G vedi l’esempio casa Grestare => attenzione perché per questa ricerca occorre avere un corpus contenente i soli filgat del corpus di prova)\n",
+    "\n",
+    "![](img/coocco5.0.png)\n",
+    "\n",
+    "![](img/coocco5.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 17,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/10\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x1569f5e70>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 17,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"savio\", \"2\", 0, 0], [\"uomo\", \"2\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: “Ldovere Lavere” (per L vedi l’esempio che Lquesto anche se non ho mai capito a cosa serva, secondo me è funzionale solo la ricerca con G)\n",
+    "\n",
+    "![](img/coocco6.0.png)\n",
+    "\n",
+    "![](img/coocco6.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 19,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/12\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x156a1f010>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 19,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"dovere\", \"1\", 0, 0], [\"avere\", \"1\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "ricerca = [[\"dovere\", \"1\", 0, 0], [\"avere\", \"1\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  },
+  {
+   "attachments": {},
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "ricerca di: \"Gdovere Gavere\"\n",
+    "\n",
+    "![](img/coocco7.0.png)\n",
+    "\n",
+    "![](img/coocco7.1.png)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 20,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "        <iframe\n",
+       "            width=\"100%\"\n",
+       "            height=\"475\"\n",
+       "            src=\"http://MacBook-Air-di-Leonardo-2.local:40000/dtale/iframe/13\"\n",
+       "            frameborder=\"0\"\n",
+       "            allowfullscreen\n",
+       "            \n",
+       "        ></iframe>\n",
+       "        "
+      ],
+      "text/plain": [
+       "<IPython.lib.display.IFrame at 0x1569efee0>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": []
+     },
+     "execution_count": 20,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "ricerca = [[\"dovere\", \"2\", 0, 0], [\"avere\", \"2\", 0, 0]]\n",
+    "cooccorrenze = ricerca_cooccorrenze(ricerca, 1, 1, 0, \"/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db\")\n",
+    "dtale.show(cooccorrenze)"
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.10.4"
+  },
+  "vscode": {
+   "interpreter": {
+    "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 4 - 4
flask_be/engine/test/test_occorrenzario_pandas.py

@@ -89,12 +89,12 @@ def findbib(contexts, path):
 
 # %%
 path = "/Users/leonardocanova/Library/CloudStorage/OneDrive-ConsiglioNazionaledelleRicerche/TIGRO/Ricerche/db/first_db"
-entry = "prep."
-type= 1
+entry = "amistade"
+type= 0
 numeroparole = 30
 listOcc = ["occ00001", "occ00002", "occ00003"]
-#search=ricercaforme(interpreter(entry), path, 0, 0)
-search= ricercacatgr(entry, path)
+search=ricercaforme(interpreter(entry), path, 0, 0)
+#search= ricercacatgr(entry, path)
 textlist=findtexts(type, search, listOcc, path)
 contexts = findcontexts(textlist, numeroparole, 0, listOcc, path)
 bibliocontexts = findbib(contexts,path)