1
2
3
4 """
5 @author: Eleftherios Avramidis
6 """
7
8 from copy import deepcopy
9 import sys
10 import logging as log
11
13 """
14 A simple (shallow) sentence object, which wraps both a sentence and its attributes
15 """
16
17
18 - def __init__(self, string="", attributes={}):
19 """
20 Initializes a simple (shallow) sentence object, which wraps both a sentence and its attributes
21 @param string: the string that the simple sentence will consist of
22 @type string: string
23 @param attributes: a dictionary of arguments that describe properties of the simple sentence
24 @type attributes: {String key, String value}
25
26 """
27
28
29 self.string = string.replace("\t", " ")
30
31 self.attributes = deepcopy (attributes)
32
33
34
35
36
37
38
39
42
44 """
45 Get the string of this simple sentence
46 @return: the text contained in the simple sentence
47 @rtype: String
48 """
49 return self.string
50
52 """
53 Get the attributes of this sentence
54 @return: a dictionary of attributes that describe properties of the sentence
55 @rtype: dict
56 """
57 return self.attributes
58
61
64
66 try:
67 return self.attributes[key]
68 except:
69 if sub:
70 return sub
71 else:
72 log.debug("Could not find attribute {}\n".format(key))
73 raise AttributeError
74
77
81
84
86 for name in self.attributes.keys():
87 if name not in attribute_names:
88 del(self.attributes[name])
89
90
92 return self.string + ": " + str(self.attributes)
93
95 """
96 Add the attributes to the object SimpleSentence(). In place
97 @param attr: attributes of a simple sentence
98 @type attr: dict
99 """
100
101 incoming_attributes = ss.get_attributes()
102 for incoming_attribute in incoming_attributes:
103 if incoming_attribute in attribute_replacements:
104 new_key = attribute_replacements[incoming_attribute]
105 new_value = incoming_attributes[incoming_attribute]
106 incoming_attributes[new_key] = new_value
107 del(incoming_attributes[incoming_attribute])
108
109 self.attributes.update(incoming_attributes)
110 self.string = ss.string
111