More renumbering
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
Style #31
|
||||
==============================
|
||||
|
||||
Constraints:
|
||||
|
||||
- The application is divided into three components: the model, the
|
||||
view and the controller. The model represents the application's
|
||||
data; the view represents a specific rendition of the data; the
|
||||
controller provides for input/output, for populating/updating the
|
||||
model and for invoking the right view.
|
||||
|
||||
Possible names:
|
||||
|
||||
- Trinity
|
||||
- Model/View/Controller
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, re, operator, collections
|
||||
|
||||
#
|
||||
# Model
|
||||
#
|
||||
class WordFrequenciesModel:
|
||||
""" Models the data. In this case, we're only interested
|
||||
in words and their frequencies as an end result """
|
||||
freqs = {}
|
||||
def __init__(self, path_to_file):
|
||||
stopwords = set(open('../stop_words.txt').read().split(','))
|
||||
words = re.findall('[a-z]{2,}', open(path_to_file).read().lower())
|
||||
self.freqs = collections.Counter(w for w in words if w not in stopwords)
|
||||
|
||||
|
||||
#
|
||||
# View
|
||||
#
|
||||
class WordFrequenciesView:
|
||||
def __init__(self, model):
|
||||
self._model = model
|
||||
|
||||
def render(self):
|
||||
sorted_freqs = sorted(self._model.freqs.iteritems(), key=operator.itemgetter(1), reverse=True)
|
||||
for (w, c) in sorted_freqs[:25]:
|
||||
print w, '-', c
|
||||
|
||||
#
|
||||
# Controller
|
||||
#
|
||||
class WordFrequencyController:
|
||||
def __init__(self, model, view):
|
||||
self._model = model
|
||||
self._view = view
|
||||
view.render()
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
m = WordFrequenciesModel(sys.argv[1])
|
||||
v = WordFrequenciesView(m)
|
||||
c = WordFrequencyController(m, v)
|
||||
Reference in New Issue
Block a user