Skip to content

Frames Annotation

Nicolay Rusnachenko edited this page Feb 22, 2023 · 6 revisions

Core component of the AREkit-0.22.1 framework is a FrameVariant. The Variant suffix here denotes a one potential form of entry which stands behind the particular frame identifier.

This entry contains list of terms (terms) and its identifier (frame_id):

NOTE Using lower() method for lowercasing is the missed refactoring of the AREkit=0.22.1 which is expected to be considered within the next releases. Issue #403

class FrameVariant(object):
    def __init__(self, text, frame_id):
        assert(isinstance(text, str))
        assert(isinstance(frame_id, str))
        self.__terms = text.lower().split()
        self.__frame_id = frame_id

Class that provides implementation of gathering frame variants into collection is called FrameVariantsCollection.

class FrameVariantsCollection(object):
    def __init__(self):
        self.__variants = {}
        self.__frames_list = []

    def fill_from_iterable(self, variants_with_id, ...):
        # .. implementations out of this post.
        pass

RuSentiFrames -- Frame Variants Provider

RuSentiFrames Represents a lexicon which describes sentiments and connotations conveyed with a predicate in a verbal or nominal form. Checkout the related paper for greater details. AREkit supports this frames collection out-of-the-box.

First, it is necessary to declare labels. We consider the following types: Positive, Negative.

class Positive(Label):
    pass

class Negative(Label):
    pass

Next step, we declare frames collection:

frames_collection = RuSentiFramesCollection.read_collection(
    version=RuSentiFramesVersions.V20,
    labels_fmt=RuSentiFramesLabelsFormatter(
        pos_label_type=Positive, neg_label_type=Negative),
    effect_labels_fmt=RuSentiFramesEffectLabelsFormatter(
        pos_label_type=Positive, neg_label_type=Negative))

Then, variant collection might be initialized as follows:

frame_variant_collection = FrameVariantsCollection()
frame_variant_collection.fill_from_iterable(
    variants_with_id=frames_collection.iter_frame_id_and_variants(),
    overwrite_existed_variant=True,
    raise_error_on_existed_variant=False)

Frame variant collection might be adopted in text parsing. Checkout AREkit Tutorial: Compose your text-processing pipeline! for a greater details.

Connotation Provider

In such cases when the only information required from frames is their connections between roles (Agent, Theme), the related connotation provider finds its application. Connotation provider could be presented in a form of the class or interface with a single method that provides such connotation-related information by a given frame_id. Snippet below illustrates an AREkit-0.22.1 implementation of the base FrameConnotationProvider.

class FrameConnotationProvider(object):
    def try_provide(self, frame_id):
        raise NotImplementedError()

Here is an example of the connotation provider based on the RuSentiFrames collection:

class RuSentiFramesConnotationProvider(FrameConnotationProvider):
    def __init__(self, collection):
        self.__collection = collection
    def try_provide(self, frame_id):
        return self.__collection.try_get_frame_polarity(
            frame_id, role_src='a0', role_dest='a1')

frames_connotation_provider = RuSentiFramesConnotationProvider(frames_collection)

Connotation provider might be adopted in samples preparation for neural networks. Checkout AREkit Tutorial: Sample Mass-Media Text Opinions for Neural Network for a greater details.