-
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.
Refactoring Output opinion provider (related to #198)
- Loading branch information
Showing
4 changed files
with
65 additions
and
65 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 |
---|---|---|
@@ -1,65 +1,22 @@ | ||
from arekit.common.experiment.input.views.opinions import BaseOpinionStorageView | ||
from arekit.common.experiment.output.utils import fill_opinion_collection | ||
from arekit.common.experiment.output.views.base import BaseOutputView | ||
from arekit.common.model.labeling.modes import LabelCalculationMode | ||
from arekit.common.model.labeling.single import SingleLabelsHelper | ||
from arekit.common.labels.scaler import BaseLabelScaler | ||
from arekit.common.opinions.base import Opinion | ||
|
||
|
||
class OutputToOpinionCollectionsConverter(object): | ||
|
||
# TODO. To output_view. Provide opinions_iter for collection organization only! | ||
@staticmethod | ||
def iter_opinion_collections(opinions_view, | ||
# TODO. Remove | ||
labels_scaler, | ||
keep_doc_id_func, | ||
# TODO. Collection??? | ||
create_opinion_collection_func, | ||
# TODO. Remove | ||
label_calculation_mode, | ||
# TODO. Remove | ||
supported_labels, | ||
output_formatter): | ||
assert(callable(keep_doc_id_func)) | ||
# TODO. Only for collection filling (remove) | ||
assert(isinstance(labels_scaler, BaseLabelScaler)) | ||
def iter_opinion_collections(output_view, opinions_view, keep_doc_id_func, to_collection_func): | ||
assert(isinstance(output_view, BaseOutputView)) | ||
assert(isinstance(opinions_view, BaseOpinionStorageView)) | ||
# TODO. Collection??? | ||
assert(callable(create_opinion_collection_func)) | ||
# TODO. Only for collection filling (remove) | ||
assert(isinstance(label_calculation_mode, LabelCalculationMode)) | ||
# TODO. Only for collection filling (remove) | ||
assert(isinstance(supported_labels, set) or supported_labels is None) | ||
assert(isinstance(output_formatter, BaseOutputView)) | ||
|
||
labels_helper = SingleLabelsHelper(labels_scaler) | ||
assert(callable(keep_doc_id_func)) | ||
assert(callable(to_collection_func)) | ||
|
||
for news_id in output_formatter.iter_news_ids(): | ||
for news_id in output_view.iter_news_ids(): | ||
|
||
if not keep_doc_id_func(news_id): | ||
continue | ||
|
||
# TODO. Collection??? | ||
collection = create_opinion_collection_func() | ||
|
||
linked_iter = output_formatter.iter_linked_opinions(news_id=news_id, | ||
linked_data_iter = output_view.iter_linked_opinions(news_id=news_id, | ||
opinions_view=opinions_view) | ||
|
||
fill_opinion_collection( | ||
collection=collection, | ||
linked_data_iter=linked_iter, | ||
labels_helper=labels_helper, | ||
to_opinion_func=OutputToOpinionCollectionsConverter.__to_label, | ||
label_calc_mode=label_calculation_mode, | ||
supported_labels=supported_labels) | ||
|
||
yield news_id, collection | ||
|
||
@staticmethod | ||
def __to_label(item, label): | ||
assert(isinstance(item, Opinion)) | ||
return Opinion(source_value=item.SourceValue, | ||
target_value=item.TargetValue, | ||
sentiment=label) | ||
yield news_id, to_collection_func(linked_data_iter) |
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
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
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