From a0c60b2963a84b3e5877d7fbee87086ca3e7abf5 Mon Sep 17 00:00:00 2001 From: Nicolay Rusnachenko Date: Sat, 11 Apr 2020 14:33:29 +0300 Subject: [PATCH] Fixed incorrect behavior in text_opnion_collection filling process. All text_opinions were linked as a single --- common/news.py | 2 +- contrib/experiments/single/embedding/opinions.py | 7 ++++--- source/ruattitudes/news.py | 5 ++--- source/rusentrel/news.py | 11 ++--------- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/common/news.py b/common/news.py index 2a9636a2..8e37fe7e 100644 --- a/common/news.py +++ b/common/news.py @@ -4,7 +4,7 @@ class News(object): def __init__(self): pass - def iter_text_opinions(self, opinions): + def iter_linked_text_opinions(self, opinions): """ opinions: iterable Opinion is an iterable opinions that should be used to find a related text_opinion entries. diff --git a/contrib/experiments/single/embedding/opinions.py b/contrib/experiments/single/embedding/opinions.py index a1f2b848..dc7c62b7 100644 --- a/contrib/experiments/single/embedding/opinions.py +++ b/contrib/experiments/single/embedding/opinions.py @@ -90,8 +90,9 @@ def extract_text_opinions(experiment_io, data_type=data_type) for opinions in opinions_it: - text_opinions.try_add_linked_text_opinions( - linked_text_opinions=news.iter_text_opinions(opinions=opinions), - check_opinion_correctness=lambda text_opinion: __check_text_opinion(text_opinion, config.TermsPerContext)) + for linked_text_opinions in news.iter_linked_text_opinions(opinions=opinions): + text_opinions.try_add_linked_text_opinions( + linked_text_opinions=linked_text_opinions, + check_opinion_correctness=lambda text_opinion: __check_text_opinion(text_opinion, config.TermsPerContext)) return text_opinions diff --git a/source/ruattitudes/news.py b/source/ruattitudes/news.py index 5b3f464c..c77ef65c 100644 --- a/source/ruattitudes/news.py +++ b/source/ruattitudes/news.py @@ -65,13 +65,12 @@ def iter_sentences(self): # region base News - def iter_text_opinions(self, opinions): + def iter_linked_text_opinions(self, opinions): """ Note: Complexity is O(N^2) """ for opinion in opinions: - for text_opinion in self.__iter_all_text_opinions_in_sentences(opinion=opinion): - yield text_opinion + yield list(self.__iter_all_text_opinions_in_sentences(opinion=opinion)) # region Private methods diff --git a/source/rusentrel/news.py b/source/rusentrel/news.py index 4802f0f9..fa8564c3 100644 --- a/source/rusentrel/news.py +++ b/source/rusentrel/news.py @@ -151,20 +151,13 @@ def iter_sentences(self): # region base News - def iter_text_opinions(self, opinions): + def iter_linked_text_opinions(self, opinions): assert(isinstance(opinions, OpinionCollection)) for entries in self.__iter_rusentrel_text_opinion_entries(opinions=opinions): - assert(isinstance(entries, RuSentRelTextOpinionCollection)) - for text_opinion in RuSentRelNews.__iter_text_opinions(entries=entries): - yield text_opinion + yield [self.__entry_to_text_opinion(entry) for entry in entries] # region private methods - @staticmethod - def __iter_text_opinions(entries): - for entry in entries: - yield RuSentRelNews.__entry_to_text_opinion(entry=entry) - @staticmethod def __entry_to_text_opinion(entry): """