|
@@ -16,7 +16,52 @@ class cooccorrenze(basicQueries):
|
|
|
|
|
|
|
|
|
|
|
|
- def ricerca_cooccorrenze (self, listaricerche, intervallo, periodo, ordinate):
|
|
|
+ def ricerca_cooccorrenze(self, listaricerche, intervallo, periodo, ordinate):
|
|
|
+ listatesti = pd.DataFrame()
|
|
|
+ cod = 1
|
|
|
+ if listaricerche[0][1] == 0:
|
|
|
+ ricerca = self.sendBasicQuery(listaricerche[0][0], 'forma', listaricerche[0][2], listaricerche[0][3], pandas=True)
|
|
|
+ listatesti = self.findtexts(0, ricerca)
|
|
|
+ elif listaricerche[0][1] == 1:
|
|
|
+ ricerca = self.sendBasicQuery(listaricerche[0][0], 'lemma', listaricerche[0][2], listaricerche[0][3], pandas=True)
|
|
|
+ listatesti = self.findtexts(1, ricerca)
|
|
|
+ elif listaricerche[0][1] == 2:
|
|
|
+ ricerca = self.sendBasicQuery(listaricerche[0][0], 'lemma', listaricerche[0][2], listaricerche[0][3], pandas=True)
|
|
|
+ listatesti = self.findtexts(2, ricerca)
|
|
|
+
|
|
|
+ if listatesti.empty:
|
|
|
+ return []
|
|
|
+
|
|
|
+ for ricerca, tipo, espansa, raddoppiata in listaricerche[1:]:
|
|
|
+ if tipo == 0:
|
|
|
+ search = self.sendBasicQuery(ricerca, 'forma', espansa, raddoppiata, pandas=True)
|
|
|
+ elif tipo == 1:
|
|
|
+ search = self.sendBasicQuery(ricerca, 'lemma', espansa, raddoppiata, pandas=True)
|
|
|
+ elif tipo == 2:
|
|
|
+ search = self.sendBasicQuery(ricerca, 'lemma', espansa, raddoppiata, pandas=True)
|
|
|
+
|
|
|
+ textlist = self.findtexts(tipo, search)
|
|
|
+
|
|
|
+ listatesti = listatesti.merge(textlist, on='ntx', suffixes=('', f'_{cod}'))
|
|
|
+ cond1 = listatesti['numperiod'] == listatesti[f'numperiod_{cod}'] if periodo == 1 else True
|
|
|
+ cond2 = ((listatesti['mappa'] - listatesti[f'mappa_{cod}']) != 0) & ((listatesti['mappa'] - listatesti[f'mappa_{cod}']).abs() <= intervallo) if ordinate == 0 else ((listatesti[f'mappa_{cod}'] - listatesti['mappa']) > 0) & ((listatesti[f'mappa_{cod}'] - listatesti['mappa']).abs() <= intervallo)
|
|
|
+ cod += 1
|
|
|
+ listatesti = listatesti[cond1 & cond2]
|
|
|
+
|
|
|
+ if listatesti.empty:
|
|
|
+ return []
|
|
|
+ else:
|
|
|
+ contexts = self.findcontexts(listatesti)
|
|
|
+ bibliocontexts = self.findbib(contexts)
|
|
|
+ clean = bibliocontexts.drop_duplicates(subset="contesto")
|
|
|
+ highlights = self.highlight(clean)
|
|
|
+
|
|
|
+ return highlights.to_dict(orient='records')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ '''def ricerca_cooccorrenze (self, listaricerche, intervallo, periodo, ordinate):
|
|
|
listatesti = pd.DataFrame()
|
|
|
cod = 1
|
|
|
if listaricerche[0][1] == 0:
|
|
@@ -70,17 +115,18 @@ class cooccorrenze(basicQueries):
|
|
|
ntx1 = row1['ntx']
|
|
|
mappa1 = row1['mappa']
|
|
|
nperiodo1 = row1['numperiod']
|
|
|
-
|
|
|
if ordinate == 0:
|
|
|
test = (textlist['ntx'].astype(int) == ntx1) & (textlist['mappa'].astype(int) > mappa1-intervallo) & (textlist['mappa'].astype(int) < mappa1+intervallo) & (textlist['mappa'].astype(int) != mappa1)
|
|
|
else:
|
|
|
test = (textlist['ntx'].astype(int) == ntx1) & (textlist['mappa'].astype(int) > mappa1-intervallo)
|
|
|
if periodo == 1:
|
|
|
test = test & (textlist['numperiod'] == nperiodo1)
|
|
|
-
|
|
|
df_temp = textlist[test]
|
|
|
- cod_cols = [] + df_temp['cod'].tolist()
|
|
|
+ df_temp[f'cod{cod}'] = df_temp['cod']
|
|
|
+ cod_cols.append(f'cod{cod}')
|
|
|
df_new = pd.concat([df_new, df_temp])
|
|
|
+ cod += 1
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -89,7 +135,6 @@ class cooccorrenze(basicQueries):
|
|
|
|
|
|
listatesti = df_new
|
|
|
|
|
|
- cod += 1
|
|
|
|
|
|
if listatesti.empty:
|
|
|
return []
|
|
@@ -99,5 +144,5 @@ class cooccorrenze(basicQueries):
|
|
|
clean = bibliocontexts.drop_duplicates(subset="contesto")
|
|
|
highlights = self.highlight (clean)
|
|
|
return highlights.to_dict(orient='records')
|
|
|
-
|
|
|
+
|
|
|
|