forked from glerm/CatatauScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MachadoRimas.py
59 lines (36 loc) · 1.03 KB
/
MachadoRimas.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
import codecs
import nltk
from nltk.corpus import stopwords
from pyuca import Collator
c = Collator("corpustxt/allkeys.txt")
#importar corpus da biblia do rei james
M=nltk.corpus.machado.words()
#convertendo tudo pra minuscula
M=[x.lower() for x in M]
#convertendo para vetor para filtrar repetições
M=set(M)
# retornando para tipo lista - LEXICO DA BIBLIA EM FORMATO LISTA
M=list(M)
# usando o padrao de ordenamento do collate pyuca para considerar acentos - ORDENANDO
M=sorted(M, key=c.sort_key)
# convertendo pra lista e ordenando (considerando acentos)
M=list(M)
M=sorted(M, key=c.sort_key)
# formatando separado por espaços e vírgulas
M.reverse() #inverter pois a iteração é reversa
TXT=""
count=0
for w in M:
m = re.match("^.*"+sys.argv[1]+"$", w, re.MULTILINE)
if m:
TXT=w+", "+TXT
count=count+1
print w + " - "+str(count)
############# grava arquivo
#file = codecs.open("MACHADORIMAS.txt", "w", "utf-8")
#file.write(TXT)
#file.close()