Skip to content

Commit

Permalink
Fixed incorrect behavior in text_opnion_collection filling process. A…
Browse files Browse the repository at this point in the history
…ll text_opinions were linked as a single
  • Loading branch information
nicolay-r committed Apr 11, 2020
1 parent 5316fe6 commit a0c60b2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion common/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions contrib/experiments/single/embedding/opinions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions source/ruattitudes/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 2 additions & 9 deletions source/rusentrel/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit a0c60b2

Please sign in to comment.