-
Notifications
You must be signed in to change notification settings - Fork 1
/
Frequency.py
56 lines (46 loc) · 1.51 KB
/
Frequency.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
# -*- coding: utf-8 -*-
import string
import nltk
import re
import csv
import datetime
from nltk.corpus import stopwords
from nltk import pos_tag, word_tokenize
from collections import Counter
dTrading = 'C:/Users/vitor/Documents/GetDataset/TradingView/'
now = datetime.datetime.now()
today = now.strftime("%Y-%m-%d")
def RemoveStopWords(instancia):
instancia = instancia.lower()
stopwords = set(nltk.corpus.stopwords.words('portuguese'))
palavras = [i for i in instancia.split() if not i in stopwords]
return (" ".join(palavras))
def preProcess(frase):
# Conversao para minusculos
frase = frase.lower()
# Remoção de numeros
frase = re.sub('[-10-9]','', frase)
# Remoçao de pontuação
frase = re.sub(r'[-./?!,":;()\']','',frase)
# Remoção de stopwords
texto = RemoveStopWords(frase)
return texto
def readFile(ativo):
with open(dTrading + today + ativo + '.csv') as csvFile:
readCSV = csv.reader(csvFile, delimiter=';')
words = []
for row in readCSV:
if len(row) != 0 and 'Neutro' in row[1]:
texto = preProcess(row[0])
words.append(texto)
countWord(words)
def countWord(texts):
freq = {}
for row in texts:
print(row)
count = freq.get(row, 0)
freq[row] = count + 1
freq_list = freq.keys()
for words in freq_list:
print(words + ' - ' + str(freq[words]))
readFile('/polaritySentiLexPre_ciel3')