Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- from collections import Counter
- # Database Globals
- HOST =
- PORT =
- DB =
- USER =
- PWD =
- if __name__ == '__main__':
- conn_string = 'host={} port={} dbname={} user={} password={}'.format(HOST, PORT, DB, USER, PWD)
- conn = psycopg2.connect(conn_string)
- cursor = conn.cursor()
- # execute our Query
- cursor.execute("select idtexto from texto where length(texto_completo) > 1 limit 1")
- records = cursor.fetchall()
- for each in records:
- print each[0]
- cursor.execute("select * from ocorrencia where idtexto = {}".format(each[0]))
- ocorrencias = cursor.fetchall()
- #retorna ocorrencia de palavras por texto
- for each in ocorrencias:
- #print each
- #retorna a prob de cada palavra por cada ca
- sql = "select (sum(numero_ocorrencias)) as ocorrencia,c.descricao categoria from ocorrencia o inner join texto t on t.idtexto = o.idtexto inner join texto_categoria tc on tc.idtexto = t.idtexto inner join categoria c on c.id_categoria = tc.id_categoria where o.id_palavra = '{}' group by c.id_categoria order by ocorrencia desc;".format(each[0])
- cursor.execute("select * from ocorrencia where idtexto = {}".format(each[0]))
- ocorrencias = cursor.fetchall()
- cursor.close()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement