1 """
2 Parser for the clink layer in KAF/NAF
3 """
4 from lxml import etree
5
7 """
8 This class encapsulates a clink object in KAF/NAF
9 """
11 """
12 Constructor of the object
13 @type node: xml Element or None (to create and empty one)
14 @param node: this is the node of the element.
15 If it is None it will create a new object
16 """
17 if node is None:
18 self.node = etree.Element('clink')
19 else:
20 self.node = node
21
29
31 """
32 Returns the node of the element
33 @rtype: xml Element
34 @return: the node of the element
35 """
36 return self.node
37
39 """
40 Returns the token identifier
41 @rtype: string
42 @return: the token identifier
43 """
44 return self.node.get('id')
45
46
48 """
49 Returns the from attribute of the clink
50 @rtype: string
51 @return: the from attribute
52 """
53 return self.node.get('from')
54
56 """
57 Returns the to attribute of the clink
58 @rtype: string
59 @return: the to attribute
60 """
61 return self.node.get('to')
62
64 """
65 Set the identifier for the token
66 @type this_id: string
67 @param this_id: the identifier
68 """
69 return self.node.set('id',this_id)
70
72 """
73 Sets the from attribute
74 @type f: string
75 @param f: the from attribute
76 """
77 self.node.set('from',f)
78
80 """
81 Sets the to attribute
82 @type t: string
83 @param t: the to attribute
84 """
85 self.node.set('to',t)
86
95
97 return dump(self.node)
98
100 """
101 This class encapsulates the clink layer in KAF/NAF
102 """
104 """
105 Constructor of the object
106 @type node: xml Element or None (to create and empty one)
107 @param node: this is the node of the element.
108 If it is None it will create a new object
109 """
110 if node is None:
111 self.node = etree.Element('causalRelations')
112 else:
113 self.node = node
114
116 """
117 Returns the node of the element
118 @rtype: xml Element
119 @return: the node of the element
120 """
121 return self.node
122
125
128
130 return dump(self.node)
131
132
134 for node_clink in self.node.findall('clink'):
135 yield node_clink
136
138 """
139 Iterator that returns all the causalRelations in the layer
140 @rtype: L{Cclink}
141 @return: list of causalRelations (iterator)
142 """
143 for node in self.__get_node_causalRelations():
144 yield Cclink(node)
145
147 """
148 Adds a clink object to the layer
149 @type my_clink: L{Cclink}
150 @param my_clink: the clink object to be added
151 """
152 self.node.append(my_clink.get_node())
153
155 """
156 Removes the clink for the given clink identifier
157 @type clink_id: string
158 @param clink_id: the clink identifier to be removed
159 """
160 for clink in self.get_clinks():
161 if clink.get_id() == clink_id:
162 self.node.remove(clink.get_node())
163 break
164