def buttonPushed(): data = None word_thresh=0.01 objects = [] verb_forms = {} spec_post = False with_preps = True print "success" newhognew(file1) svminput.svminputfn() svmfile.svmfilefn() #classi() #print file1 #txt.insert(END, file1) data = yaml.load(file('C:/meenuneenu/project/libsvm-3.17/python/detail.txt', 'r')) pickle.dump(data, open("C:/meenuneenu/project/libsvm-3.17/python/pickled_files/data.pk", "wb")) learn_obj = learn(objects, word_thresh) gen_obj = Generator(learn_obj, data, spec_post, with_preps) final_sentence=gen_obj.run() for post_id in sorted(final_sentence): print "***", post_id for s_num in final_sentence[post_id]: for sentence in final_sentence[post_id][s_num]: #print sentence + '.'+ '\n' txt.insert(END, sentence) txt.insert(END, '.\n') deletefiles()
def get_detections(self, data={}): label = "" if data == {}: data = self.data for a in data: last_label = label try: label = self.learn_obj.label_hash[a['label']] except KeyError: label = a['label'] except: txt.insert(END, 'No sentence') deletefiles() id_n = str(a['id']) post_id = a['post_id'] # Generating for just a single image. if self.spec_post and post_id != self.spec_post: continue try: self.label_id_hash[post_id][id_n] = label except KeyError: self.label_id_hash[post_id] = {id_n:label} try: if a['preps'] == {}: self.prep_detections[post_id] = {} for id_set in a['preps']: ids = id_set.split(",") id1 = ids[0].strip("'") id2 = ids[1].strip("'") try: self.prep_detections[post_id][(id1, id2)] = a['preps'][id_set] except KeyError: self.prep_detections[post_id] = {(id1, id2): a['preps'][id_set]} except KeyError: pass try: self.mod_detections[post_id][id_n] = {} except KeyError: self.mod_detections[post_id] = {id_n:{}} try: for mod in a['attrs']: self.mod_detections[post_id][id_n][mod] = a['attrs'][mod] except KeyError: self.mod_detections[post_id][id_n] = {}