def do_stats(self, line): self._register_config() action, extra = self._parse_line(line) import shakespeare.stats stats = shakespeare.stats.Stats() if action == 'init': self._init_index() for text in self._index: # exclude folios as many odd spellings if text.name.endswith('_f'): continue self._print('Adding: %s' % text.name) stats.statsify(text, text.get_text()) elif action == 'addtext': import shakespeare.model as model text = model.Material.byName(extra) stats.statsify(text, text.get_text()) elif action == 'show': textstats = stats.text_stats(extra) for s in textstats: print s.word, s.freq else: print 'Unrecognized action: %s' % action self.help_stats() return 1
def text(self, id=None): text_name = id text = model.Material.by_name(text_name) # no id or no text by that id if not text: return self.text_index() stats = shakespeare.stats.Stats() c.text = text c.stats = stats.text_stats(text) # 40 seems limit for google data = [(s.word, s.freq) for s in c.stats[:40]] try: c.img_url = self.vertical_bar_chart(data) except: # TODO: log error message c.img_url = '' return render('stats/text.html')
def text(self, id=None): text_name = id text = model.Material.by_name(text_name) # no id or no text by that id if not text: return self.text_index() stats = shakespeare.stats.Stats() c.text = text c.stats = stats.text_stats(text) # 40 seems limit for google data = [ (s.word, s.freq) for s in c.stats[:40] ] try: c.img_url = self.vertical_bar_chart(data) except: # TODO: log error message c.img_url = '' return render('stats/text.html')