Skip to content

Commit

Permalink
#212 Partial, updated API method names.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolay-r committed Oct 20, 2021
1 parent d52ea35 commit ebb3d15
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 30 deletions.
16 changes: 8 additions & 8 deletions arekit/common/experiment/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self, exp_data, experiment_io, opin_ops, doc_ops, name, extra_name_

self.__experiment_data = exp_data
self.__experiment_io = experiment_io
self.__opin_operations = opin_ops
self.__doc_operations = doc_ops
self.__opin_ops = opin_ops
self.__doc_ops = doc_ops

# Suffix allows to provide additional experiment setups
# In a form of a string, which might be behind the original
Expand Down Expand Up @@ -55,11 +55,11 @@ def ExperimentIO(self):

@property
def OpinionOperations(self):
return self.__opin_operations
return self.__opin_ops

@property
def DocumentOperations(self):
return self.__doc_operations
return self.__doc_ops

# endregion

Expand Down Expand Up @@ -96,16 +96,16 @@ def evaluate(self, data_type, epoch_index):

# Extracting all docs to cmp and those that is related to data_type.
# TODO. 212. Pass tag ("compare")
cmp_doc_ids_iter = self.__doc_operations.iter_doc_ids_to_compare()
doc_ids_iter = self.__doc_operations.iter_doc_ids(data_type=data_type)
cmp_doc_ids_iter = self.__doc_ops.iter_doc_ids_to_compare()
doc_ids_iter = self.__doc_ops.iter_doc_ids(data_type=data_type)
cmp_doc_ids_set = set(cmp_doc_ids_iter)

# Compose cmp pairs iterator.
cmp_pairs_iter = OpinionCollectionsToCompareUtils.iter_comparable_collections(
doc_ids=[doc_id for doc_id in doc_ids_iter if doc_id in cmp_doc_ids_set],
read_etalon_collection_func=lambda doc_id: self.__opin_operations.read_etalon_opinion_collection(
read_etalon_collection_func=lambda doc_id: self.__opin_ops.get_etalon_opinion_collection(
doc_id=doc_id),
read_result_collection_func=lambda doc_id: self.__opin_operations.read_result_opinion_collection(
read_result_collection_func=lambda doc_id: self.__opin_ops.get_result_opinion_collection(
data_type=data_type,
doc_id=doc_id,
epoch_index=epoch_index))
Expand Down
2 changes: 1 addition & 1 deletion arekit/common/experiment/api/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_samples_writer_target(self, data_type):
def create_opinions_writer_target(self, data_type):
raise NotImplementedError()

def create_result_opinion_collection_target(self, data_type, doc_id, epoch_index):
def create_result_opinion_collection_target(self, doc_id, data_type, epoch_index):
raise NotImplementedError()

def _create_annotated_collection_target(self, doc_id, data_type, check_existance):
Expand Down
8 changes: 2 additions & 6 deletions arekit/common/experiment/api/ops_opin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ def iter_opinions_for_extraction(self, doc_id, data_type):

# region evaluation

# TODO. #211. Move into DataIO.
# TODO. Use get_opinion_collection
def read_etalon_opinion_collection(self, doc_id):
def get_etalon_opinion_collection(self, doc_id):
raise NotImplementedError()

# TODO. #211. Move into DataIO.
# TODO. Use get_opinion_collection
def read_result_opinion_collection(self, data_type, doc_id, epoch_index):
def get_result_opinion_collection(self, doc_id, data_type, epoch_index):
raise NotImplementedError()

# endregion
Expand Down
2 changes: 1 addition & 1 deletion arekit/contrib/bert/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_samples_writer(self):
def create_opinions_writer(self):
return TsvWriter(write_header=False)

def create_result_opinion_collection_target(self, data_type, doc_id, epoch_index):
def create_result_opinion_collection_target(self, doc_id, data_type, epoch_index):
""" Utilized for results evaluation.
"""
assert(isinstance(epoch_index, int))
Expand Down
2 changes: 1 addition & 1 deletion arekit/contrib/experiment_rusentrel/annot/three_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _annot_collection_core(self, parsed_news, data_type, doc_ops, opin_ops):
assert(isinstance(opin_ops, OpinionOperations))

news = doc_ops.get_doc(doc_id=parsed_news.RelatedNewsID)
opinions = opin_ops.read_etalon_opinion_collection(doc_id=parsed_news.RelatedNewsID)
opinions = opin_ops.get_etalon_opinion_collection(doc_id=parsed_news.RelatedNewsID)

annotated_opins_it = self.__annot_algo.iter_opinions(
parsed_news=parsed_news,
Expand Down
2 changes: 1 addition & 1 deletion arekit/contrib/experiment_rusentrel/annot/two_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _annot_collection_core(self, parsed_news, data_type, doc_ops, opin_ops):
# into neutral one with the replaced sentiment values.
# as we treat such opinions as neutral one since only NeutralLabels
# could be casted into correct string.
for opinion in opin_ops.read_etalon_opinion_collection(doc_id):
for opinion in opin_ops.get_etalon_opinion_collection(doc_id):
neut_collection.add_opinion(Opinion(source_value=opinion.SourceValue,
target_value=opinion.TargetValue,
sentiment=ExperimentNeutralLabel()))
Expand Down
2 changes: 1 addition & 1 deletion arekit/contrib/experiment_rusentrel/exp_ds/opinions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def iter_opinions_for_extraction(self, doc_id, data_type):
for opinion in collection:
yield opinion

def read_etalon_opinion_collection(self, doc_id):
def get_etalon_opinion_collection(self, doc_id):
return self.__get_opinion_list_in_doc(doc_id=doc_id)
12 changes: 6 additions & 6 deletions arekit/contrib/experiment_rusentrel/exp_joined/opinions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ def iter_opinions_for_extraction(self, doc_id, data_type):
return target.iter_opinions_for_extraction(doc_id=doc_id,
data_type=data_type)

def read_etalon_opinion_collection(self, doc_id):
def get_etalon_opinion_collection(self, doc_id):
assert(isinstance(doc_id, int))
target = self.__target(doc_id)
return target.read_etalon_opinion_collection(doc_id)
return target.get_etalon_opinion_collection(doc_id)

def read_result_opinion_collection(self, data_type, doc_id, epoch_index):
def get_result_opinion_collection(self, doc_id, data_type, epoch_index):
target = self.__target(doc_id)
return target.read_result_opinion_collection(data_type=data_type,
doc_id=doc_id,
epoch_index=epoch_index)
return target.get_result_opinion_collection(doc_id=doc_id,
data_type=data_type,
epoch_index=epoch_index)

def create_opinion_collection(self):
return self.__rusentrel_op.create_opinion_collection()
Expand Down
8 changes: 4 additions & 4 deletions arekit/contrib/experiment_rusentrel/exp_sl/opinions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def iter_opinions_for_extraction(self, doc_id, data_type):
collections.append(auto_neutral)

# Providing sentiment opinions.
etalon = self.read_etalon_opinion_collection(doc_id=doc_id)
etalon = self.get_etalon_opinion_collection(doc_id=doc_id)
collections.append(etalon)

elif data_type == DataType.Test:
Expand All @@ -62,7 +62,7 @@ def iter_opinions_for_extraction(self, doc_id, data_type):
for opinion in collection:
yield opinion

def read_etalon_opinion_collection(self, doc_id):
def get_etalon_opinion_collection(self, doc_id):
assert(isinstance(doc_id, int))
opins_iter = RuSentRelOpinionCollection.iter_opinions_from_doc(
doc_id=doc_id,
Expand All @@ -73,16 +73,16 @@ def read_etalon_opinion_collection(self, doc_id):
def create_opinion_collection(self):
return self.__create_collection(None)

def read_result_opinion_collection(self, data_type, doc_id, epoch_index):
def get_result_opinion_collection(self, doc_id, data_type, epoch_index):
""" Since evaluation supported only for neural networks,
we need to guarantee the presence of a function that returns filepath
by using isinstance command.
"""
assert(isinstance(self.__experiment_io, BaseIOUtils))

filepath = self.__experiment_io.create_result_opinion_collection_target(
data_type=data_type,
doc_id=doc_id,
data_type=data_type,
epoch_index=epoch_index)

return self.__custom_read(filepath=filepath,
Expand Down
2 changes: 1 addition & 1 deletion arekit/contrib/networks/core/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_output_model_results_filepath(self, data_type, epoch_index):
template=result_template,
prefix="result")

def create_result_opinion_collection_target(self, data_type, doc_id, epoch_index):
def create_result_opinion_collection_target(self, doc_id, data_type, epoch_index):
assert(isinstance(epoch_index, int))

model_eval_root = self.__get_eval_root_filepath(data_type=data_type, epoch_index=epoch_index)
Expand Down

0 comments on commit ebb3d15

Please sign in to comment.