forked from glerm/CatatauScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exclamatal2.py
51 lines (37 loc) · 1011 Bytes
/
exclamatal2.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import codecs
import nltk
from nltk.corpus import stopwords
from pyuca import Collator
c = Collator("corpustxt/allkeys.txt")
arq="corpustxt/exclama.txt"
fileObj = codecs.open( arq, "r", "utf-8" )
catatau = fileObj.read() # Returns a Unicode string from the UTF-8 bytes in the file
# separa em linhas
stok = nltk.data.load('tokenizers/punkt/portuguese.pickle')
catalinhas=stok.tokenize(catatau)
# filtra repetições
a = set(catalinhas)
frases=list(a)
# usando o padrao de ordenamento do collate pyuca para considerar acentos
frases=sorted(frases, key=c.sort_key)
#frases.reverse()
# termina em interrogação.
txt=""
conta=0
for c in frases:
c.replace(' ','\n')
m = re.match("^.*\!$", c, re.MULTILINE)
if m:
#print(c)
txt=txt+c+" \n\n"
conta=conta+1
txt=txt+"\n total de linhas= "+str(conta)
frases.reverse()
print frases
############# grava arquivo
file = codecs.open("Exclamatau.txt", "w", "utf-8")
file.write(txt)
file.close()