Last active
August 1, 2018 06:48
-
-
Save AlexDel/fca9c3457eba50d6050847430c0bb6b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import re | |
f = open('./fear1.txt', 'r', encoding='utf-8') | |
tablitsa = [row for row in csv.reader(f, delimiter=',')] | |
def CountFearFeatures_time(text): | |
features_time = [] | |
words = text.lower().split() | |
if len(words) == 0: | |
return 0 | |
for word in words: | |
if re.match ('^минут.*$', word): | |
features_time.append(word) | |
elif re.match ('^секунд.*$', word): | |
features_time.append(word) | |
elif re.match ('^момент.*$', word): | |
features_time.append(word) | |
elif re.match ('^час.*$', word): | |
features_time.append(word) | |
elif re.match ('^дн.+$', word): | |
features_time.append(word) | |
elif re.match ('^ден.+$', word): | |
features_time.append(word) | |
return len(features_time)/len(words) | |
print(CountFearFeatures_time(tablitsa[0][4])) | |
def CountFearFeatures_time_total(file_emotion): | |
summa = 0 | |
for row in file_emotion: | |
summa += CountFearFeatures_time(row[4]) | |
return summa/len(file_emotion) | |
print(CountFearFeatures_time_total(tablitsa)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment