def delete_dataStopword(self): id = request.form['id'] instance_Model = Models( 'DELETE FROM tbl_stopword WHERE id_stopword = %s') instance_Model.query_sql(id) flash('Berhasil menghapus data.', 'success') return None
def add_dataLabeling(self): id = request.form['id'] value = request.form['value'] data_ubah = (value, id) instance_Model = Models('UPDATE tbl_tweet_clean SET sentiment_type=%s WHERE id=%s') instance_Model.query_sql(data_ubah) return 'Berhasil Melabeli Data!'
def add_dataStopword(self): stopword = request.form['stopword'].strip() instance_Model = Models( 'INSERT INTO tbl_stopword(stopword) VALUES (%s)') instance_Model.query_sql(stopword.lower()) flash('Berhasil menambahkan data.', 'success') return None
def delete_dataPositiveWord(self): id = request.form['id'] instance_Model = Models( 'DELETE FROM tbl_lexicon_positive WHERE id_positive = %s') instance_Model.query_sql(id) flash('Berhasil menghapus data.', 'success') return None
def add_dataPositiveWord(self): kata_positif = request.form['kata_positif'].strip() instance_Model = Models( 'INSERT INTO tbl_lexicon_positive(positive_word) VALUES (%s)') instance_Model.query_sql(kata_positif.lower()) flash('Berhasil menambahkan data.', 'success') return None
def update_dataStopword(self): id = request.form['id'] stopword = request.form['stopword'].strip() data_ubah = (stopword.lower(), id ) # Membuat tupple dari form data masukan instance_Model = Models( 'UPDATE tbl_stopword SET stopword=%s WHERE id_stopword = %s') instance_Model.query_sql(data_ubah) flash('Berhasil mengubah data.', 'success') return None
def add_dataSlangword(self): slangword = request.form['slangword'].strip() kata_asli = request.form['kata_asli'].strip() data_tambah = (slangword.lower(), kata_asli.lower() ) # Membuat tupple dari form data masukan instance_Model = Models( 'INSERT INTO tbl_slangword(slangword, kata_asli) VALUES (%s,%s)') instance_Model.query_sql(data_tambah) flash('Berhasil menambahkan data.', 'success') return None
def update_dataPositiveWord(self): id = request.form['id'] kata_positif = request.form['kata_positif'].strip() data_ubah = (kata_positif.lower(), id ) # Membuat tupple dari form data masukan instance_Model = Models( 'UPDATE tbl_lexicon_positive SET positive_word=%s WHERE id_positive = %s' ) instance_Model.query_sql(data_ubah) flash('Berhasil mengubah data.', 'success') return None
def delete_dataModelling(self): id = request.form['id'] instance_Model = Models('DELETE FROM tbl_model WHERE model_name = %s') instance_Model.query_sql(id) if os.path.exists('application/static/model_data/' + id): os.remove('application/static/model_data/' + id) flash( 'Berhasil menghapus data. File (.json) model latih berhasil dihapus!', 'success') else: flash('File (.json) model latih gagal dihapus!', 'error') print("\nFile tidak ditemukan!\n")
def register(self): username = request.form['username'].strip() kata_sandi = request.form['kata_sandi'].strip() fullname = request.form['fullname'].strip() # cek record (ada?) instance_Model = Models( 'SELECT password, fullname FROM tbl_users WHERE username = %s') user = instance_Model.select_row(username) # record TIDAK ditemukan if user == None: data_tambah = (username, 'textmining_' + str(kata_sandi) + '_sentimentanalysis', fullname) # simpan data user instance_Model = Models( 'INSERT INTO tbl_users(username, password, fullname) VALUES (%s, %s, %s)' ) instance_Model.query_sql(data_tambah) flash('Berhasil mendaftar, silakan masuk.', 'success') return True flash('Username telah terdaftar.', 'error') return False
def create_dataModeling(self): sample_positive = request.form['sample_positive'] sample_negative = request.form['sample_negative'] jumlah_sample = int(sample_positive) + int(sample_negative) # if sample_positive == sample_negative == sample_netral: if sample_positive == sample_negative: list_data = [ ] # wadah untuk menyimpan data yang diperoleh dari database # Select data positif dari tbl_tweet_training sebanyak n record (berdasarkan variabel sample) instance_Model = Models( "SELECT clean_text, sentiment_type FROM tbl_tweet_training WHERE clean_text IS NOT NULL AND sentiment_type = 'positif' ORDER BY RAND() LIMIT " + sample_positive) list_data.append(instance_Model.select()) # Select data negatif dari tbl_tweet_training sebanyak n record (berdasarkan variabel sample) instance_Model = Models( "SELECT clean_text, sentiment_type FROM tbl_tweet_training WHERE clean_text IS NOT NULL AND sentiment_type = 'negatif' ORDER BY RAND() LIMIT " + sample_negative) list_data.append(instance_Model.select()) teks_list = [ ] # wadah untuk tweet (clean_text) yang akan dijadikan sebagai model latih label_list = [ ] # wadah untuk sentimen (sentiment_type) yang akan dijadikan sebagai model latih # set data untuk teks_list dan label_list menggunakan data yang telah diambil dari database # for index_luar in range(3): for index_luar in range(2): for index_dalam in range(len(list_data[index_luar])): clean_text = list_data[index_luar][index_dalam][ 'clean_text'] sentiment_type = list_data[index_luar][index_dalam][ 'sentiment_type'] teks_list.append(clean_text) label_list.append(sentiment_type) # akses ke kelas Vectorizer instance_Vectorizer = Vectorizer(teks_list, label_list) # membuat vektor angka data_dict = instance_Vectorizer.create_vectorList() model_name = 'sentiment_model(' + datetime.today().strftime( '%d-%m-%Y %H%M%S') + ').json' # model_name = 'sentiment_model('+ datetime.today().strftime('%d-%m-%Y') +').json' # Menyimpan model kedalam bentuk .json agar dapat digunakan kembali (untuk proses Evaluasi & Prediksi) with open('application/static/model_data/' + model_name, 'w') as outfile: json.dump(data_dict, outfile, indent=4) # Membuat tuple untuk simpan data data_simpan = (model_name, jumlah_sample, sample_positive, sample_negative) # Insert model ke dalam database instance_Model = Models( 'REPLACE INTO tbl_model(model_name, sentiment_count, sentiment_positive, sentiment_negative) VALUES (%s, %s, %s, %s)' ) # Menjadikan tuple sebagai argumen untuk method query_sql instance_Model.query_sql(data_simpan) return { 'model_name': model_name, 'sentiment_count': jumlah_sample, 'sentiment_positive': sample_positive, 'sentiment_negative': sample_negative, 'data_dict': data_dict } return {'error': 'Gagal Membuat Model Latih'}