Advertisement
Guest User

Untitled

a guest
Jun 13th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import psycopg2
  2. from collections import Counter
  3.  
  4. # Database Globals
  5. HOST =
  6. PORT =
  7. DB =
  8. USER =
  9. PWD =
  10.  
  11. if __name__ == '__main__':
  12.  
  13.  
  14. conn_string = 'host={} port={} dbname={} user={} password={}'.format(HOST, PORT, DB, USER, PWD)
  15.  
  16. conn = psycopg2.connect(conn_string)
  17. cursor = conn.cursor()
  18.  
  19. # execute our Query
  20.  
  21. cursor.execute("select idtexto from texto where length(texto_completo) > 1 limit 1")
  22. records = cursor.fetchall()
  23. for each in records:
  24. print each[0]
  25. cursor.execute("select * from ocorrencia where idtexto = {}".format(each[0]))
  26. ocorrencias = cursor.fetchall()
  27. #retorna ocorrencia de palavras por texto
  28. for each in ocorrencias:
  29. #print each
  30. #retorna a prob de cada palavra por cada ca
  31. 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])
  32. cursor.execute("select * from ocorrencia where idtexto = {}".format(each[0]))
  33. ocorrencias = cursor.fetchall()
  34. cursor.close()
  35. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement