Skip to content

Commit

Permalink
#216 refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolay-r committed Dec 10, 2021
1 parent 294b380 commit cb1b76e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 22 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

class FramesCollection(object):
class FrameConnotationProvider(object):

def try_get_frame_sentiment_polarity(self, frame_id):
raise NotImplementedError()
2 changes: 1 addition & 1 deletion arekit/common/experiment/api/ctx_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def StringEntityFormatter(self):
raise NotImplementedError()

@property
def FramesCollection(self):
def FramesConnotationProvider(self):
raise NotImplementedError()

@property
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions arekit/contrib/experiment_rusentrel/connotations/provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from arekit.common.connotations.provider import FrameConnotationProvider
from arekit.contrib.source.rusentiframes.collection import RuSentiFramesCollection


class RuSentiFramesConnotationProvider(FrameConnotationProvider):

def __init__(self, collection):
assert(isinstance(collection, RuSentiFramesCollection))
self.__collection = collection

def try_get_frame_sentiment_polarity(self, frame_id):
return self.__collection.try_get_frame_polarity(frame_id=frame_id,
role_src='a0',
role_dest='a1')
2 changes: 1 addition & 1 deletion arekit/contrib/networks/core/input/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __create_samples_repo(exp_data, term_embedding_pairs, entity_to_group_func):
term_embedding_pairs=term_embedding_pairs,
exp_data=exp_data,
entity_to_group_func=entity_to_group_func),
frames_collection=exp_data.FramesCollection,
frames_connotation_provider=exp_data.FramesConnotationProvider,
frame_role_label_scaler=exp_data.FrameRolesLabelScaler,
entity_to_group_func=entity_to_group_func,
pos_terms_mapper=PosTermsMapper(exp_data.PosTagger))
Expand Down
6 changes: 3 additions & 3 deletions arekit/contrib/networks/core/input/providers/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NetworkSampleRowProvider(BaseSampleRowProvider):
def __init__(self,
label_provider,
text_provider,
frames_collection,
frames_connotation_provider,
entity_to_group_func,
frame_role_label_scaler,
pos_terms_mapper):
Expand All @@ -27,7 +27,7 @@ def __init__(self,
text_provider=text_provider)

self.__entity_to_group_func = entity_to_group_func
self.__frames_collection = frames_collection
self.__frames_connotation_provider = frames_connotation_provider
self.__frame_role_label_scaler = frame_role_label_scaler
self.__pos_terms_mapper = pos_terms_mapper

Expand All @@ -54,7 +54,7 @@ def _fill_row_core(self, row, linked_wrap, index_in_linked, etalon_label,
uint_frame_roles = list(
map(lambda variant: FrameRoleFeatures.extract_uint_frame_variant_sentiment_role(
text_frame_variant=variant,
frames_collection=self.__frames_collection,
frames_connotation_provider=self.__frames_collection,
three_label_scaler=self.__frame_role_label_scaler),
[terms[frame_ind] for frame_ind in uint_frame_inds]))

Expand Down
12 changes: 6 additions & 6 deletions arekit/contrib/networks/features/term_frame_roles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from arekit.common.frames.collection import FramesCollection
from arekit.common.frames.polarity import FramePolarity
from arekit.common.connotations.descriptor import FrameConnotationDescriptor
from arekit.common.connotations.provider import FrameConnotationProvider
from arekit.common.labels.scaler import BaseLabelScaler
from arekit.common.text_frame_variant import TextFrameVariant
from arekit.contrib.networks.features.utils import create_filled_array
Expand All @@ -23,18 +23,18 @@ def to_input(frame_inds, frame_sent_roles, size, filler):
return vector

@staticmethod
def extract_uint_frame_variant_sentiment_role(text_frame_variant, frames_collection, three_label_scaler):
def extract_uint_frame_variant_sentiment_role(text_frame_variant, frames_connotation_provider, three_label_scaler):
assert(isinstance(text_frame_variant, TextFrameVariant))
assert(isinstance(frames_collection, FramesCollection))
assert(isinstance(frames_connotation_provider, FrameConnotationProvider))
assert(isinstance(three_label_scaler, BaseLabelScaler))

frame_id = text_frame_variant.Variant.FrameID
polarity = frames_collection.try_get_frame_sentiment_polarity(frame_id)
polarity = frames_connotation_provider.try_get_frame_sentiment_polarity(frame_id)

if polarity is None:
return three_label_scaler.label_to_uint(label=three_label_scaler.get_no_label_instance())

assert(isinstance(polarity, FramePolarity))
assert(isinstance(polarity, FrameConnotationDescriptor))

if text_frame_variant.IsInverted:
inv_label = three_label_scaler.invert_label(polarity.Label)
Expand Down
8 changes: 1 addition & 7 deletions arekit/contrib/source/rusentiframes/collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json

from arekit.common.frames.collection import FramesCollection
from arekit.common.labels.str_fmt import StringLabelsFormatter
from arekit.contrib.source.rusentiframes.effect import FrameEffect
from arekit.contrib.source.rusentiframes.io_utils import RuSentiFramesIOUtils
Expand All @@ -12,7 +11,7 @@
from arekit.contrib.source.rusentiframes.state import FrameState


class RuSentiFramesCollection(FramesCollection):
class RuSentiFramesCollection(object):

__frames_key = "frames"
__polarity_key = "polarity"
Expand Down Expand Up @@ -55,11 +54,6 @@ def __from_json(cls, input_file, labels_fmt, effect_labels_fmt):

# region public 'try get' methods

def try_get_frame_sentiment_polarity(self, frame_id):
return self.try_get_frame_polarity(frame_id=frame_id,
role_src='a0',
role_dest='a1')

def try_get_frame_polarity(self, frame_id, role_src, role_dest):
assert(isinstance(role_src, str))
assert(isinstance(role_dest, str))
Expand Down
4 changes: 2 additions & 2 deletions arekit/contrib/source/rusentiframes/polarity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from arekit.common.frames.polarity import FramePolarity
from arekit.common.connotations.descriptor import FrameConnotationDescriptor
from arekit.common.labels.base import Label


class RuSentiFramesFramePolarity(FramePolarity):
class RuSentiFramesFramePolarity(FrameConnotationDescriptor):
"""
Polarity description between source (Agent) towards dest (Theme)
The latter are related to roles of frame polarity.
Expand Down

0 comments on commit cb1b76e

Please sign in to comment.