def gen_wordvector_matrices_fr_source_destination_nodes(self): print 'generating word vector matrices for parent child nodes ...' assert self.edgelabel_nodes_map is not None and self.edgelabel_nodes_map source_vec_matrix_map = {} destination_vec_matrix_map = {} for curr_edge_label in self.edgelabel_nodes_map: nodes_pair_list = self.edgelabel_nodes_map[curr_edge_label] source_vectors_list = [] destination_vectors_list = [] for curr_nodes_pair in nodes_pair_list: source = curr_nodes_pair[0] source_vec = wv.get_wordvector(source) source = None destination = curr_nodes_pair[1] destination_vec = wv.get_wordvector(destination) destination = None # if source_vec is None or destination_vec is None: continue # source_vectors_list.append(source_vec) destination_vectors_list.append(destination_vec) assert len(source_vectors_list) == len(destination_vectors_list) if source_vectors_list and destination_vectors_list: source_vec_matrix_map[curr_edge_label] = np.array(source_vectors_list) destination_vec_matrix_map[curr_edge_label] = np.array(destination_vectors_list) assert source_vec_matrix_map and destination_vec_matrix_map self.source_vec_matrix_map = source_vec_matrix_map self.destination_vec_matrix_map = destination_vec_matrix_map
def gen_wordvector_matrices_fr_common_parent_nodes_pair(self): print 'generating word vector matrices for common parent nodes pair ...' assert self.common_parent_edgelabel_nodes_pair is not None \ and self.common_parent_edgelabel_nodes_pair child_i_vec_matrix_map = {} child_j_vec_matrix_map = {} for curr_edge_label_pair in self.common_parent_edgelabel_nodes_pair: if curr_edge_label_pair[0] not in self.source_vec_matrix_map: assert curr_edge_label_pair[0] not in self.destination_vec_matrix_map continue elif curr_edge_label_pair[1] not in self.source_vec_matrix_map: assert curr_edge_label_pair[1] not in self.destination_vec_matrix_map continue # nodes_pair_list = self.common_parent_edgelabel_nodes_pair[curr_edge_label_pair] child_i_vectors_list = [] child_j_vectors_list = [] for curr_nodes_pair in nodes_pair_list: child_i = curr_nodes_pair[0] child_i_vec = wv.get_wordvector(child_i) child_i = None # child_j = curr_nodes_pair[1] child_j_vec = wv.get_wordvector(child_j) child_j = None # if child_i_vec is None or child_j_vec is None: continue # child_i_vectors_list.append(child_i_vec) child_j_vectors_list.append(child_j_vec) assert len(child_i_vectors_list) == len(child_j_vectors_list) if child_i_vectors_list and child_j_vectors_list: if self.is_filter and len(child_i_vectors_list) < self.min_num_common_parent_instances: continue child_i_vec_matrix_map[curr_edge_label_pair] = np.array(child_i_vectors_list) child_j_vec_matrix_map[curr_edge_label_pair] = np.array(child_j_vectors_list) assert child_i_vec_matrix_map and child_j_vec_matrix_map self.child_i_vec_matrix_map = child_i_vec_matrix_map self.child_j_vec_matrix_map = child_j_vec_matrix_map