Semantics.py
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/python
# -*- coding: utf-8 -*-
from importer.Frame import Frame
from importer.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, meanings):
for frame in self._frames:
frame.store(entry, meanings)
for realization in self._realizations:
realization.store(entry)
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])