12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import pandas as pd
- from .basic_queries import basicQueries
- from .utilities.format import formatAllContexts
- class cooccorrenze(basicQueries):
-
- def __init__(self, dataConfig):
- super().__init__(dataConfig)
-
-
-
-
-
- def ricerca_cooccorrenze(self, listaricerche, intervallo, periodo, ordinate):
- occurrences = []
- for ricerca, tipo, espansa, raddoppiata in listaricerche:
- if tipo==0:
- res1 = self.sendBasicQuery(ricerca, 'forma', espansa, raddoppiata, pandas=True)
- if res1.empty:
- return []
- occurrences.append({'codList': list(res1['cod']), 'querySubtype': 0})
- elif tipo==1:
- res1 = self.sendBasicQuery(ricerca, 'lemma', espansa, raddoppiata, pandas=True)
- if res1.empty:
- return []
- occurrences.append({'codList': list(res1['cod']), 'querySubtype': 1})
- elif tipo==2:
- res1 = self.sendBasicQuery(ricerca, 'lemma', espansa, raddoppiata, pandas=True)
- if res1.empty:
- return []
- codList = list(res1['cod'])
- subQueryData = {'queryType': 'pfl', 'codList': codList}
- subdf = self.queryHandler.query(subQueryData, pandas=True)
- formCodList = list(subdf['codForma'])
- occurrences.append({'codList': codList, 'formCodList': formCodList, 'querySubtype': 2})
- if len(occurrences)==0:
- return []
- queryData = {'queryType': 'co-occurrences', 'occurrences': occurrences, 'intervallo': intervallo, 'periodo': periodo, 'ordinate': ordinate}
- queryResponses = [self.queryHandler.query(dict(queryData, table=table), pandas=True) for table in self.listOcc]
- listatesti = pd.concat(queryResponses)
- if listatesti.empty:
- return []
- else:
- contexts = self.findcontexts(listatesti)
- bibliocontexts = self.findbib(contexts)
- clean = bibliocontexts.drop_duplicates(subset="contesto")
- highlights = formatAllContexts(clean)
- return highlights.to_dict(orient='records')
|