-
Notifications
You must be signed in to change notification settings - Fork 2
/
categoriza.py
56 lines (44 loc) · 1.42 KB
/
categoriza.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import dados
import rake
'''
import categoriza
claims = categoriza.categoriza_claims()
claims
claims['keywords']
set().union(claims['keywords'])
set().union(*claims['keywords'])
unicas = set().union(*claims['keywords'])
[u[0] for u in unicas]
unicas = set([u[0] for u in set().union(*claims['keywords'])])
unicas
with open('stoplists/all.txt', 'w') as tudo:
for item in unicas:
tudo.write('{}\n'.format(item))
'''
def categoriza_claims(categ, claims):
for claim in claims:
categoriza_claim(categ, claim)
return claims
def categoriza_claim(categ, claim):
if 'x20150701145318' in claim['uri']:
import pdb; pdb.set_trace()
if 'x20160216105543' in claim['uri']:
import pdb; pdb.set_trace()
if 'x20160219112156' in claim['uri']:
import pdb; pdb.set_trace()
texto = '{} - {}'.format(claim['title'], claim['description'])
claim['keywords'] = categ.run(texto)
return claim
def keywords_para_arquivo(arquivo, dados):
with open(arquivo, 'w') as output:
output.writelines(
('{0[uri]} - {0[keywords]}\n'.format(item) for item in dados))
def main(stoplist='stoplists/ouvidoria.txt'):
categ = rake.Rake(stoplist)
claims = dados.prepara_dados()
claims = categoriza_claims(categ, claims)
keywords_para_arquivo('/tmp/teste.txt', claims)
for claim in claims:
print(claim['uri'], claim['keywords'])
if __name__ == '__main__':
main()