#!/usr/bin/etc python import galbackend_online import sys import socket import time import pickle from collections import Counter #socket = None #sys.path.append("~/nltk_data") #target = galbackend.GalInterface() #print(target) #gt = galbackend.Thread(target=galbackend.GalInterface) galbackend_online.InitLogging() galbackend_online.InitResource('v3') oov_state = 1 name_entity_state = 1 anaphra_state = 1 short_answer_state = 1 previous_history = {} word2vec_ranking_state = 0 tfidf_state = 1 #while(1): #galbackend.LaunchQueryDebug('can you say that again') #connection.send('ready') f = open('user_input_v2_revise.txt', 'w') with open('user_input_v2.pkl') as ff: user_input = pickle.load(ff) turn_number = 1 trigger = [] for turn in user_input:
def get_alternative_responses(): rs_preprocess.accumulate_responses() galbackend_online.InitLogging() galbackend_online.InitResource('v3') oov_state =1 name_entity_state =1 anaphra_state =1 short_answer_state=1 previous_history ={} word2vec_ranking_state =1 tfidf_state =1 user_list =[] theme = {} strategyDict = { 'continue' : (True, 0), 'switch' : (False, 0), 'end' : (False, 1), 'init' : (False, 2), 'joke' : (False, 3), 'more' : (False, 4), } conversations = [] logRoot = '/home/ubuntu/zhou/Backend/rating_log/' with open(logRoot + 'conversation_list.pickle', 'rb') as f: conversations = pickle.load(f) badResponses = [] for item in conversations: for response in item: if response['Appropriateness'] < 3: badResponses.append(response) testResponses = [] for response in badResponses: for k in strategyDict.keys(): if not k in response['Strategy']: try: theme, strategy, altered_response, previous_history, word2vec = galbackend_online.get_response( response['You'], "0", {"0" : response['PrevResp']}, {"0" : response['Theme']}, oov_state, name_entity_state, short_answer_state, anaphra_state, word2vec_ranking_state, tfidf_state, strategyDict[k]) alteredDict = {} for y in response.keys(): alteredDict[y] = response[y] alteredDict['TickTock'] = altered_response alteredDict['Strategy'] = [k] alteredDict['PrevResp'] = list(response['PrevResp']) response['PrevResp'] = response['PrevResp'][:-2] testResponses.append(alteredDict) except: pass tmpickle = open('test_responses.pickle', 'wb') pickle.dump(testResponses, tmpickle, pickle.HIGHEST_PROTOCOL) tmpickle.close() return testResponses