forked from glerm/CatatauScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catacorpus.py
62 lines (37 loc) · 1.21 KB
/
catacorpus.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
57
58
59
60
61
62
#!/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/catatau_semlinebreaks.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)
#limpa palavras conectivas
def cleanupDoc(s):
stopset = set(stopwords.words('portuguese'))
tokens = nltk.word_tokenize(s)
cleanup = " ".join(filter(lambda word: word not in stopset, s.split()))
return cleanup
tokens = nltk.word_tokenize(catatau)
catacorpus=nltk.Text(nltk.word_tokenize(catatau))
# ordenar
#tokens.sort()
a = set(tokens)
glossario=list(a)
# usando o padrao de ordenamento do collate pyuca para considerar acentos
glossario=sorted(glossario, key=c.sort_key)
glossario.reverse()
a=""
for w in glossario:
a=w+", "+a
print catacorpus.dispersion_plot(["nada", "tudo", "monstro", "Occam","mundo","perdido","fim"])
############# grava arquivo
#file = codecs.open("Alfatatau.txt", "w", "utf-8")
#file.write(a)
#file.close()