Skip to content

Instantly share code, notes, and snippets.

@AlexDel
Last active August 1, 2018 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDel/fca9c3457eba50d6050847430c0bb6b1 to your computer and use it in GitHub Desktop.
Save AlexDel/fca9c3457eba50d6050847430c0bb6b1 to your computer and use it in GitHub Desktop.
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