def get_children_and_child_in_laws(children, parent): # basically, we are finding child-in-law of parent node child_in_laws = copy.copy(children) if config.debug: print "children in law of parent " + parent.name + " are: " for child in children: grandchildren = child.create_children_list() for grandchild in grandchildren: for curr_key in grandchild.parents.keys(): for child_in_law in grandchild.parents[curr_key]: if ( child_in_law not in children and child_in_law != parent and child_in_law not in parent.create_ancestors_list() ): # todo: child_in_law.dummy_label = child.dummy_label child_in_laws.insert(child_in_laws.index(child) + 1, child_in_law) if config.debug: print "child in law added: ", child_in_law.name + "/" + ( "" if child_in_law.dummy_label is None else child_in_law.dummy_label ) child_in_laws = my_util.unique_list(child_in_laws) # #that means, some child in laws are found # new_child_in_laws = list(set(child_in_laws)-set(children)) # if new_child_in_laws: # #todo: this is not optimal # return get_children_and_child_in_laws(child_in_laws, parent) # else: # return child_in_laws return child_in_laws
def get_children_and_child_in_laws(children, parent): #basically, we are finding child-in-law of parent node child_in_laws = copy.copy(children) if config.debug: print 'children in law of parent ' + parent.name + ' are: ' for child in children: grandchildren = child.create_children_list() for grandchild in grandchildren: for curr_key in grandchild.parents.keys(): for child_in_law in grandchild.parents[curr_key]: if child_in_law not in children and child_in_law != parent and child_in_law not in parent.create_ancestors_list( ): #todo: child_in_law.dummy_label = child.dummy_label child_in_laws.insert( child_in_laws.index(child) + 1, child_in_law) if config.debug: print 'child in law added: ', child_in_law.name + '/' + ( '' if child_in_law.dummy_label is None else child_in_law.dummy_label) child_in_laws = my_util.unique_list(child_in_laws) # #that means, some child in laws are found # new_child_in_laws = list(set(child_in_laws)-set(children)) # if new_child_in_laws: # #todo: this is not optimal # return get_children_and_child_in_laws(child_in_laws, parent) # else: # return child_in_laws return child_in_laws
def get_descendants(root_node, descendants=None): if descendants is None: descendants = [root_node] children = root_node.create_children_list() children_ = list(set(children) - set(descendants)) descendants += children_ for child in children_: descendants = get_descendants(child, descendants) descendants = my_util.unique_list(descendants) if descendants[0] != root_node: descendants.remove(root_node) descendants.insert(0, root_node) return descendants
def create_parent_list(self): if self.__parent_list is None: parents_list = [] for parent_key in self.parents.keys(): parent = self.parents[parent_key] if isinstance(parent, list): #list of nodes for curr_parent in parent: # curr_parent_idx = parent.index(curr_parent) # curr_parent = copy.copy(curr_parent) curr_parent.dummy_label_inv = parent_key # parent[curr_parent_idx] = curr_parent parents_list += parent else: # parent = copy.copy(parent) #todo: verify effects of this change parents_list.append(parent) #assuming just a single node self.__parent_list = my_util.unique_list(parents_list) return self.__parent_list
def create_parent_list(self): if self.__parent_list is None: parents_list = [] for parent_key in self.parents.keys(): parent = self.parents[parent_key] if isinstance(parent, list): # list of nodes for curr_parent in parent: # curr_parent_idx = parent.index(curr_parent) # curr_parent = copy.copy(curr_parent) curr_parent.dummy_label_inv = parent_key # parent[curr_parent_idx] = curr_parent parents_list += parent else: # parent = copy.copy(parent) #todo: verify effects of this change parents_list.append(parent) # assuming just a single node self.__parent_list = my_util.unique_list(parents_list) return self.__parent_list
def create_children_list(self): if self.__children_list is None: children_list = [] for child_key in self.children.keys(): child = self.children[child_key] if isinstance(child, list): #list of nodes for curr_child in child: # curr_child_idx = child.index(curr_child) # curr_child = copy.copy(curr_child) #todo: verify effects of this change curr_child.dummy_label = child_key # child[curr_child_idx] = curr_child children_list += child else: # child = copy.copy(child) #todo: verify effects of this change child.dummy_label = child_key children_list.append(child) #assuming just a single node self.__children_list = my_util.unique_list(children_list) return self.__children_list
def create_children_list(self): if self.__children_list is None: children_list = [] for child_key in self.children.keys(): child = self.children[child_key] if isinstance(child, list): # list of nodes for curr_child in child: # curr_child_idx = child.index(curr_child) # curr_child = copy.copy(curr_child) #todo: verify effects of this change curr_child.dummy_label = child_key # child[curr_child_idx] = curr_child children_list += child else: # child = copy.copy(child) #todo: verify effects of this change child.dummy_label = child_key children_list.append(child) # assuming just a single node self.__children_list = my_util.unique_list(children_list) return self.__children_list
def get_descendants_undirected(root_node, descendants=None): if root_node is None: raise AssertionError if descendants is None: descendants = [root_node] children = root_node.create_undirected_children_list() children_ = list(set(children) - set(descendants)) descendants += children_ for child in children_: if child is None: raise AssertionError descendants = get_descendants_undirected(child, descendants) descendants = my_util.unique_list(descendants) if descendants[0] != root_node: descendants.remove(root_node) descendants.insert(0, root_node) if descendants is None: raise AssertionError return descendants
def create_undirected_children_list(self): #unique function should not be required return my_util.unique_list(self.create_parent_list() + self.create_children_list())
def create_undirected_children_list(self): # unique function should not be required return my_util.unique_list(self.create_parent_list() + self.create_children_list())
) if is_training_match: training_match = match else: pos_matches.append(match) elif match_id in neg_match_ids: neg_matches.append(match) pos_matches.insert(0, training_match) try: training_match.match_tokens # Training match found except AttributeError: print('Training match not found') continue annotate_match_token_depths(matches) add_has_valence_extension_to_matches(matches) docs = util.unique_list(docs, key=lambda doc: doc.text) # Log initial metrics initial_fitness = pattern_fitness(role_pattern, matches, pos_matches, neg_matches) # Refinement if 'up' in role_pattern.token_labels or 'down' in role_pattern.token_labels: feature_dicts = [{ 'DEP': 'dep_', 'TAG': 'tag_', '_': { 'valence': 'valence' } }] else: feature_dicts = [ {