def _make_document_from_response (response) : soup = parse_html(response.text) string = ''.join(flattened((tag.find_all(text=True, recursive=True) for tag in soup.find_all('p')), basecase=lambda tags : isinstance(tags, str))) return Document(string, word_count=len(list(split(string))), title='wikipedia', url=response.url, created_on=datetime.now())
def plot( iterable, key=lambda item: item, sample_size=1, depth=1, colors=_plot_colors, basecase=_plot_basecase, _show=True ): """ This function can be used for plotting an iterable graphically. If matplotlib isn't installed, this will only throw a warning, and no GUI will be launched.. """ try: pyplot except NameError: warnings.warn("matplotlib must be installed in order to see the plot graphic.", Warning) else: for i, iterable in enumerate(flattened(iterable, basecase)): xs, ys = zip( *( (i, math.avg(key(item) for item in sample)) for i, sample in enumerate(iterate.chunked(iterable, sample_size, trail=True)) ) ) pyplot.plot(xs, ys, linewidth=1.0, color=colors[i % len(colors)]) if _show: pyplot.show()