Beispiel #1
0
def classify_news():
    s = get_session(engine)
    model = NaiveBayesClassifier()
    train_set = s.query(News).filter(News.label != None).all()
    model.fit(
        [clean(news.title).lower() for news in train_set],
        [news.label for news in train_set],
    )
    test = s.query(News).filter(News.label == None).all()
    cell = list(map(lambda x: model.predict(x.title), test))
    return template(
        "color_template",
        rows=list(map(lambda x: (x[1], colors[cell[x[0]]]), enumerate(test))),
    )
Beispiel #2
0
def update_news():
    s = get_session(engine)
    get_new_news(s)
    redirect("/news")
Beispiel #3
0
def news_list():
    s = get_session(engine)
    rows = s.query(News).filter(News.label == None).all()
    return template("news_template", rows=rows)
Beispiel #4
0
def add_label():
    s = get_session(engine)
    id = request.query["id"]
    label = request.query["label"]
    change_label(s, id, label)
    redirect("/news")
Beispiel #5
0
def session(engine):
    session = database.get_session(engine)
    db_set_up(engine)
    yield session
    db_tear_down(session)