Semantics.py 1.54 KB
#! /usr/bin/python
# -*- coding: utf-8 -*-

from Frame import Frame
from Realizations import FrameRealization


class Semantics:

    def __init__(self, base, pos, frames, realizations):
        self._frames = frames
        self._base = base
        self._pos = pos
        self._realizations = realizations

    @classmethod
    def fromTree(cls, base, pos, frames_tree, all_frames, meanings, syntax, realizations_tree):
        arguments = {}
        
        frames = []
        for frame_subtree in frames_tree._children[0]._children[0]._children:
            frame = Frame.fromTree(base, pos, frame_subtree)
            if frame._base is None:
                frame = all_frames[frame._id]
            frames.append(frame)
            arguments.update(frame._arguments)

        realizations = [FrameRealization.fromTree(subtree, arguments, syntax._phrases) for subtree in realizations_tree._children[0]._children[0]._children]
        
        return cls(base, pos, frames, realizations)

    def store(self, entry):
        pass
    
    def getPhraseIds(self):
        return self._phrases

    def preferencesToUnicode(self):
        return '\n'.join([unicode(frame) for frame in self._frames])

    def realizationsToUnicode(self):
        return '\n'.join([unicode(realization) for realization in self._realizations])

    def prolog(self, meanings):
        return '\n\n'.join([frame.prolog(meanings, self._realizations) for frame in self._frames])
    
    def __unicode__(self):
        return '\n'.join([unicode(frame) for frame in self._frames])