def update_network(self, link_list): """ :param link_list: a list of tuples. Each tuple contains a name of an article and the name of the referred article. Method updates this wikinetwork with the new details from link_list """ for couple in link_list: if couple[0] not in self.__collection.keys() \ and couple[1] not in self.__collection.keys(): article_A = Article(couple[0]) article_B = Article(couple[1]) article_A.add_neighbor(article_B) self.__collection[couple[0]] = article_A self.__collection[couple[1]] = article_B elif couple[0] in self.__collection.keys() \ and couple[1] not in self.__collection.keys(): article = Article(couple[1]) self.__collection[couple[0]].add_neighbor(article) self.__collection[couple[1]] = article elif couple[0] in self.__collection.keys() \ and couple[1] in self.__collection.keys(): self.__collection[couple[0]].add_neighbor( self.__collection[couple[1]]) else: article = Article(couple[0]) article.add_neighbor(self.__collection[couple[1]]) self.__collection[couple[0]] = article
def update_network(self, link_list): for pair in link_list: article_title = pair[WikiNetwork.ARTICLE_TITLE_IDX] if article_title not in self.__titles_to_articles: article = Article(article_title) self.__titles_to_articles[article_title] = article neighbor_title = pair[WikiNetwork.ARTICLE_NEIGHBOR_IDX] if neighbor_title not in self.__titles_to_articles: neighbor_article = Article(neighbor_title) self.__titles_to_articles[neighbor_title] = neighbor_article article = self.__titles_to_articles[article_title] neighbor_article = self.__titles_to_articles[neighbor_title] if neighbor_article not in article: article.add_neighbor(neighbor_article)