Realizations.py
2.16 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
54
#! /usr/bin/python
# -*- coding: utf-8 -*-
class ArgumentRealization:
def __init__(self, argument, position, phrases):
self._argument = argument
self._position = position
self._phrases = phrases
@classmethod
def fromTree(cls, tree, arguments, all_phrases):
argument = arguments[tree._children[0]._children[0]._attrs['sameAs'][1:]]
phrases = []
for subtree in tree._children[1]._children[0]._children:
phrases.append(all_phrases[subtree._attrs['sameAs'][1:]])
position = phrases[0]._position
return cls(argument, position, phrases)
def prolog(self):
return self._position.toUnicode(None, self._phrases) + '/' + unicode(self._argument._semantic_role)
def __unicode__(self):
return self._position.toUnicode(None, self._phrases) + "(" + unicode(self._argument._semantic_role) + ")"
class FrameRealization:
def __init__(self, frame, schema, argument_realizations):
self._frame = frame
self._schema = schema
self._argument_realizations = argument_realizations
@classmethod
def fromTree(cls, tree, arguments, phrases):
argument_realizations = []
for subtree in tree._children[0]._children[0]._children:
argument_realizations.append(ArgumentRealization.fromTree(subtree, arguments, phrases))
frame = argument_realizations[0]._argument._frame
schema = argument_realizations[0]._phrases[0]._position._schema
return cls(frame, schema, argument_realizations)
def prolog(self, meaning):
fake = []
if self._schema.hasInherentSie():
fake += ['[sie]/lemma']
return 'realization(' + unicode(meaning).lower() + ',[' + ','.join(fake + [argument_realization.prolog() for argument_realization in self._argument_realizations]) + ']).'
def __unicode__(self):
fake = []
if self._schema.hasInherentSie():
fake += ['[sie](Lemma)']
return unicode(self._schema._id) + '\t' + self._frame.getSignature() + '\t [' + ','.join(fake + [unicode(argument_realization) for argument_realization in self._argument_realizations]) + ']'