class ProcessTweets(): def __init__(self): self.tools = Utilities() #Calling methods to clean text def cleanTweet(self, tweet): tweet_to_clean = tweet tweetNoURL = self.tools.removeUrlsAndLabeling(tweet_to_clean) tweetNoPuncNoStopWords = self.tools.removePuncStopWords(tweetNoURL) return (tweetNoPuncNoStopWords) #Calling method to transfrom the text def VectorizeTweet(self, tweet): tweet_to_vector = tweet tweetToVectorize = self.tools.transformToVector(tweet_to_vector) return (tweetToVectorize) #Calling method to predict class def predictResult(self, tweet): tweet_to_predict = tweet prediction = self.tools.modelPrediction(tweet_to_predict) return (prediction) #Calling method to predict prediction accuracy def predictWithProba(self, tweet): tweet_to_predict = tweet predictionProba = self.tools.modelPredictionWithProba(tweet_to_predict) return (predictionProba)
def delete(self, id): category = Category.get_by_id(id) if category is None: flash(gettext("The category was not found"), "error") return redirect(url_for("CategoriesView:index")) if not category.can_edit(): abort(401) try: if not Category.transfer_posts(category): return util.redirect_json_or_html( url_for("CategoriesView:index"), "category", gettext("Sorry, the last category can not be removed") ) name = category.name Category.delete(category.id) flash(gettext('The category "%(name)s" was removed', name=name)) except: return util.redirect_json_or_html( url_for("CategoriesView:index"), "category", gettext("Error while removing the category") ) return util.redirect_json_or_html(url_for("CategoriesView:index"), "category")
def put(self, id): category = Category.get_by_id(id) if category is None: flash(gettext("The category was not found"), "error") return redirect(url_for("CategoriesView:index")) if not category.can_edit(): abort(401) if request.method in ["POST", "PUT"]: form = CategoryForm() if form.validate_on_submit(): try: form.populate_obj(category) category.save() flash(gettext("Category was succesfully saved")) return util.redirect_json_or_html(url_for("CategoriesView:index"), "category") except: return util.redirect_json_or_html( url_for("CategoriesView:index"), "category", gettext("Error while updating the category") ) else: if request.is_xhr: return util.redirect_json_or_html( url_for("CategoriesView:index"), "category", gettext("Invalid submission, please check the message below"), ) else: flash(gettext("Invalid submission, please check the message below"), "error") else: form = NewCategoryForm(category) return render_template( "admin/categories/edit.html", title=gettext("Edit Category: %(name)s", name=category.name), form=form, category=category, )
def post(self): form = CategoryForm() if request.method == "POST": if form.validate_on_submit(): try: category = Category.create() form.populate_obj(category) category.save() flash(gettext("Category succesfully created")) return util.redirect_json_or_html(url_for("CategoriesView:index"), "category") except: flash(gettext("Error while creating the category"), "error") else: flash(gettext("Invalid submission, please check the message below"), "error") return render_template("admin/categories/add.html", title=gettext("Create Category"), form=form)
def __init__(self): self.tools = Utilities()