-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class BaseLinkedTextOpinionsInstancesProvider(object): | ||
|
||
def iter_instances(self, linked_wrap): | ||
raise NotImplementedError() | ||
|
||
@staticmethod | ||
def provide_label(linked_wrap): | ||
return linked_wrap.First.Sentiment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from arekit.common.data.input.providers.instances.base import BaseLinkedTextOpinionsInstancesProvider | ||
from arekit.common.linked.text_opinions.wrapper import LinkedTextOpinionsWrapper | ||
from arekit.common.text_opinions.base import TextOpinion | ||
|
||
|
||
class MultipleLinkedTextOpinionsInstancesProvider(BaseLinkedTextOpinionsInstancesProvider): | ||
|
||
def __init__(self, supported_labels): | ||
assert(isinstance(supported_labels, list)) | ||
self.__supported_labels = supported_labels | ||
|
||
def iter_instances(self, linked_wrap): | ||
""" Enumerate all opinions as if it would be with the different label types. | ||
""" | ||
for label in self.__supported_labels: | ||
yield self.__modify_first_and_copy_linked_wrap(linked_wrap, label) | ||
|
||
@staticmethod | ||
def __modify_first_and_copy_linked_wrap(linked_wrap, label): | ||
assert (isinstance(linked_wrap, LinkedTextOpinionsWrapper)) | ||
|
||
linked_text_opinions = [opinion for opinion in linked_wrap] | ||
text_opinion_copy = TextOpinion.create_copy(other=linked_text_opinions[0]) | ||
text_opinion_copy.set_label(label=label) | ||
linked_text_opinions[0] = text_opinion_copy | ||
|
||
return LinkedTextOpinionsWrapper(linked_text_opinions=linked_text_opinions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from arekit.common.data.input.providers.instances.base import BaseLinkedTextOpinionsInstancesProvider | ||
|
||
|
||
class SingleLinkedTextOpinionsInstancesProvider(BaseLinkedTextOpinionsInstancesProvider): | ||
|
||
def iter_instances(self, wrapper): | ||
yield wrapper | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters