-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcFeatures.py
27 lines (24 loc) · 1.07 KB
/
calcFeatures.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
import numpy as np
from features import base, commonWords, punctuation, sentLength, diversity
FEATURES = [commonWords.CommonWords, punctuation.Punctuation, sentLength.SentenceLength, diversity.Diversity]
class FeatureCalculator():
def __init__(self, text, textName="", args=[[]] * len(FEATURES), features=FEATURES, debug=True):
self.text = text
self.textName = textName
self.args = args
#Features to calculate
self.feats = features
self.debug = debug
#Results of calculations
self.results = [[]] * len(self.feats)
def calcFeatures(self):
if self.debug:
print "FeatureCalculator started on " + self.textName + " with " + str(len(self.feats)) + " features"
featIndex = 0
for f in self.feats:
feat = self.feats[featIndex](self.text, self.textName, self.args[featIndex], self.debug)
self.results[featIndex] = feat.calc()
featIndex+=1
if self.debug:
print "FeatureCalculator finished on " + self.textName
return self.results