class Manager: """ Actual object to manage everything """ # reference to the entire data storage __cache = None # reference to object managing articles access and storage __articles = None # reference to the object doing the analysis __analyzer = None def __init__(self, config): """ Prepare the entire system's objects config - the configuration object from the click library """ yaml_config = yaml.load(config.obj["config"]) config.obj["config"].close() self.__cache = Cache(db_file=config.obj["database"]) self.__articles = Articles(key=yaml_config["api_key"], cache=self.__cache) self.__analyzer = Analyzer() def perform_search(self, phrase, training_size=1000): """ Perform the actual search either to cache or ny times phrase - the phrase to search by training_size - the amount of articles to use and fetch returns the list of found articles """ return self.__articles.perform_search(phrase, training_size) def analyze_results(self, article_list): """ Perform the regression analysis on the results and print them out to the command line """ print("Using %i articles" % (len(article_list),)) self.__analyzer.process_data(article_list) def predict_result(self, date): """ Make a prediction on a date date - a datetime to make a prediction on return a tuple of the type of article created from the analyzer """ return self.__analyzer.predict(date)
def analyze(self, filePath): """ Analyze a file. @param filePath Path to the file. """ print("Analyzing book located at: %s" % filePath) try: with codecs.open(filePath, 'r', 'utf8') as book: book_contents = book.read() except: raise BookAnalyzerException("Error: Unable to read book.") analyzer = Analyzer() analyzer.process_data(book_contents) analyzer.report_results()