def get_prediction(): iso = request.args.get('iso', '', type=str) predictions = [] if iso != 'none': string_buffer = request.args.get('text', '') db_file = os.path.abspath( os.path.join(app.static_folder, 'prediction', "{0}.sqlite".format(iso))) config_file = os.path.join(app.static_folder, 'prediction', "{0}.ini".format(iso)) config = configparser.ConfigParser() config.read(config_file) dbconnection = None if config.get("Database", "class") == 'PostgresDatabaseConnector': config.set("Database", "database", iso) # if iso in dbconnections: # dbconnection = dbconnections[iso] else: config.set("Database", "database", db_file) callback = DemoCallback(string_buffer) prsgio = pressagio.Pressagio(callback, config, dbconnection) predictions = prsgio.predict() prsgio.close_database() return predictions
def get_prediction(): iso = request.args.get("iso", "", type=str) predictions = [] if iso != "none": string_buffer = request.args.get("text", "") config_file_base = current_app.config["PREDICTION_INI"] if "{0}" in config_file_base: config_file_base = config_file_base.format(iso) config_file = os.path.join(fapi.root_path, "static", "prediction", config_file_base) config = configparser.ConfigParser() config.read(config_file) dbconnection = None if config.get("Database", "class") == "PostgresDatabaseConnector": config.set("Database", "database", iso) else: db_file = os.path.abspath( os.path.join(fapi.root_path, "static", "prediction", "{0}.sqlite".format(iso))) config.set("Database", "database", db_file) callback = DemoCallback(string_buffer) prsgio = pressagio.Pressagio(callback, config, dbconnection) predictions = prsgio.predict() prsgio.close_database() return predictions
def get_predictions(string): callback = CallbackClass(string) predictions = pressagio.Pressagio(callback, _CONFIG_PARSER).predict() if string.rstrip().split()[-1][0].isupper() and string[-1] != ' ': # capital letters are handled here predictions = [p[0].upper() + p[1:] for p in predictions] if string in predictions: predictions.remove(string) return predictions
def get_predictions(string): """ Get prediction for the given string. :param string: some string. :return: list of predictions, as strings. """ callback = __CallbackClass(string) predictions = pressagio.Pressagio(callback, _CONFIG_PARSER).predict() if string.rstrip().split()[-1][0].isupper() and string[-1] != ' ': # capital letters are handled here predictions = [p[0].upper() + p[1:] for p in predictions] if string in predictions: predictions.remove(string) return predictions
def SetPredictors(self): txt = " " + self.entryVariable.get() callback = DemoCallback(txt) prsgio = pressagio.Pressagio(callback, self.config) predictions = prsgio.predict() try: self.p1Text.set(predictions[0]) except KeyError: self.p1Text.set("") try: self.p2Text.set(predictions[1]) except KeyError: self.p2Text.set("") try: self.p3Text.set(predictions[2]) except KeyError: self.p3Text.set("")
return '' config_file = "prediction_profile.ini" # set configuration to use config = configparser.ConfigParser() config.read(config_file) print('Enter string: \n') while True: # test loop string = input() if string == '': # ending break callback = CallbackClass(string) prsgio = pressagio.Pressagio(callback, config) predictions = prsgio.predict() if string[ -1] != ' ': # if the string ends with a unfinished word predict it's ending n = len(string.split()[-1]) string = string[:-n - 1] # format the string to display predictions if len(string) != 0: for i in predictions: print(string + ' ' + i) else: for i in predictions: print(i) #if the string ends with a space predict the