Exemplo n.º 1
0
 def update_question_voca(self, answer_num, user, project, thread_yn):
     if thread_yn == 'Y':
         self.clear_updating_message(user, project)
     res = qna.search_question(answer_num, user, project)
     fragment = qna.search_question_fragment(answer_num, user, project)
     res += fragment
     all_voca = db_voca.search_voca_by_voca_nm('')
     conn = update.get_connection()
     for i in range(len(res)):
         if thread_yn == 'Y':
             if self.stop_yn == True:
                 self.end_updating_message(user, project, i + 1, len(res))
                 break
             self.make_updating_message(user, project, i + 1, len(res))
         answer_num = res[i]['answer_num']
         question_srno = res[i]['question_srno']
         question_voca = voca_util.get_voca_from_question(
             res[i]['question'], all_voca)
         if len(question_voca) == 0:
             continue
         if res[i]['fragment_yn'] == 'N':
             qna.update_all_question_voca(conn, user, project,
                                          ";".join(question_voca),
                                          answer_num, question_srno)
         else:
             qna.update_all_question_voca_in_fragment(
                 conn, user, project, ";".join(question_voca), answer_num,
                 question_srno)
     update.end_connection(conn)
     if thread_yn == 'Y':
         if self.stop_yn == False:
             self.end_updating_message(user, project, len(res), len(res))
Exemplo n.º 2
0
 def generate_all_fragment(self, user, project):
     self.clear_generating_all_fragment_message(user, project)
     sent = []
     ans = []
     all_sentences = []
     all_answers = []
     res = qna.search_question('', user, project)
     for r in res:
         ans.append(r['answer_num'])
         sent.append(r['question'])
     all_voca_sentences, all_voca_answers = self.make_only_one_voca_sentence(
         sent, ans)
     all_sentences += all_voca_sentences
     all_answers += all_voca_answers
     for i in range(len(sent)):
         word_arr = sent[i].split(" ")
         answer = ans[i]
         for i in range(len(word_arr) - 1):
             if i == 0:
                 continue
             s = ""
             for j in range(i + 1):
                 s += word_arr[j] + " "
             s = s.strip()
             if s not in all_sentences:
                 all_sentences.append(s)
                 all_answers.append(answer)
             else:
                 for i in range(len(all_sentences)):
                     if all_sentences[i] == s:
                         aa = all_answers[i].split(";")
                         if answer not in aa:
                             all_answers[i] += ";" + answer
                             break
     db_generator.delete_all_question_fragment(user, project)
     all_voca = db_voca.search_voca_by_voca_nm('')
     conn = update.get_connection()
     for i in range(len(all_sentences)):
         if self.stop_yn == True:
             self.end_generating_all_fragment_message(
                 user, project, i + 1, len(all_sentences))
             break
         self.make_generating_all_fragment_message(user, project, i + 1,
                                                   len(all_sentences))
         question_srno = db_generator.insert_question_fragment(
             conn, all_answers[i], all_sentences[i], '', user, project)
         question_voca = voca_util.get_voca_from_question(
             all_sentences[i], all_voca)
         qna.update_all_question_voca_in_fragment(conn, user, project,
                                                  ";".join(question_voca),
                                                  all_answers[i],
                                                  question_srno)
     conn = update.end_connection(conn)
     if self.stop_yn == False:
         self.end_generating_all_fragment_message(user, project,
                                                  len(all_sentences),
                                                  len(all_sentences))
Exemplo n.º 3
0
 def make_only_one_voca_sentence(self, sent, ans):
     all_voca_sentences, all_voca_answers = [], []
     all_voca = db_voca.search_voca_by_voca_nm('')
     for voca in all_voca:
         voca_nm = voca.get('voca_nm')
         if len(voca_nm) < 2:
             continue
         answer_num = []
         for i in range(len(sent)):
             if voca_nm in sent[i]:
                 if ans[i] not in answer_num:
                     answer_num.append(ans[i])
         if len(answer_num) > 0:
             all_voca_sentences.append(voca_nm)
             all_voca_answers.append(";".join(answer_num))
     return all_voca_sentences, all_voca_answers
Exemplo n.º 4
0
def chat_bot(request):
    global answer_num_and_rpsn_question, enc_vocab, rev_dec_vocab, language, buckets, all_voca
    req_dict = eval(request.data.decode('utf8'))
    user = req_dict['user']
    project = req_dict['project']
    language = db_training_config.get_project_language(user, project)
    enc_vocab, rev_dec_vocab = run.init_chatbot(user, project)
    answer_dict = training_file_manager.get_answer_and_answer_num(
        user, project)
    all_voca = db_voca.search_voca_by_voca_nm('')
    answer_num_and_rpsn_question = db_chat.get_all_answer_num_and_rpsn_question(
        user, project)
    answer_dict_arr.append({
        "user": user,
        "project": project,
        "answer_dict": answer_dict
    })
    buckets = db_training_config.get_bucket(user, project).split(",")

    return ''
Exemplo n.º 5
0
def submit_question(request):
    req_dict = eval(request.data.decode('utf8'))
    all_voca = db_voca.search_voca_by_voca_nm('')
    for i in range(len(req_dict)):
        user = req_dict[i]['user']
        project = req_dict[i]['project']
        answer_num = req_dict[i]['answer_num']
        question = req_dict[i]['question']
        question_tag = req_dict[i]['question_tag']
        question_srno = qna.insert_question(answer_num, question, question_tag,
                                            user, project)
        question_voca = voca_util.get_voca_from_question(question, all_voca)
        if len(question_voca) == 0:
            continue
        conn = update.get_connection()
        qna.update_all_question_voca(conn, user, project,
                                     ";".join(question_voca), answer_num,
                                     question_srno)
        update.end_connection(conn)

    return jsonify('')
Exemplo n.º 6
0
def search_voca(request):
    req_dict = eval(request.data.decode('utf8'))
    voca_nm = req_dict['voca_nm']
    res = db_voca.search_voca_by_voca_nm(voca_nm)
    
    return jsonify(results = res)
Exemplo n.º 7
0
def update_voca_synonym():
    all_voca = db_voca.search_voca_by_voca_nm('')
    for voca in all_voca:
        voca_nm = voca['voca_nm']
        voca_synonym = synonym_util.get_synonym_nm_list_by_voca_nm(voca_nm)
        db_voca.update_voca_synonym(voca_synonym, voca_nm)
Exemplo n.º 8
0
def reload_voca():
    global all_voca
    all_voca = db_voca.search_voca_by_voca_nm('')