3 # -*- encoding: utf-8 -*-
5 import sys
, string
, codecs
, xml
, re
, Ft
;
6 from Ft
.Xml
.XPath
import Evaluate
;
8 sys
.stdout
= codecs
.getwriter('utf-8')(sys
.stdout
);
9 sys
.stderr
= codecs
.getwriter('utf-8')(sys
.stderr
);
12 # This class implements the HTML interface for the
13 # forms. If you want to change how they look, make
21 def display(self
, post_data
): #{
23 if post_data
['committing'] == 'yes': #{
24 left_entrada
= self
.show_entrada(post_data
, 'left');
25 bidix_entrada
= self
.show_entrada(post_data
, 'bidix');
26 right_entrada
= self
.show_entrada(post_data
, 'right');
29 print left_entrada
.replace('<', '<').replace('>', '>');
31 print bidix_entrada
.replace('<', '<').replace('>', '>');
33 print right_entrada
.replace('<', '<').replace('>', '>');
36 selected_pair
= post_data
['selected_pair'];
37 pairs
= post_data
['pairs'];
38 post_data
['left_dictionary'].commit(left_entrada
);
39 post_data
['bidix_dictionary'].commit(bidix_entrada
);
40 post_data
['right_dictionary'].commit(right_entrada
);
42 # pairs[selected_pair].commit(left_entrada, bidix_entrada, right_entrada);
44 print '<a href="http://xixona.dlsi.ua.es:8080/">again!</a>';
49 print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
51 print ' <title>Apertium dictionary management</title>';
52 print ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> ';
53 print ' <link rel="stylesheet" type="text/css" href="/static/styles/default.css"/>';
54 print ' <script src="/static/js/boxover.js"></script> ';
57 print '<form action="add" method="POST" name="dixform">';
58 print '<a href="http://xixona.dlsi.ua.es:8080/">home</a>';
59 print '<div id="language_bar">';
63 print ' <div width="100%"> <!-- Header -->';
64 print ' Language pair: <select name="selected_pair" onChange="dixform.submit();">';
65 for pair
in post_data
['pairs'].keys(): #{
66 if pair
== post_data
['selected_pair']: #{
67 print ' <option value="' + pair
+ '" selected>' + pair
+ '</option>';
69 print ' <option value="' + pair
+ '">' + pair
+ '</option>';
73 print ' Part-of-speech: <select name="selected_tag" onChange="dixform.submit();">';
74 for tag
in post_data
['tags'].keys(): #{
75 if tag
== post_data
['selected_tag']: #{
76 print ' <option value="' + tag
+ '" selected>' + tag
+ '</option>';
78 print ' <option value="' + tag
+ '">' + tag
+ '</option>';
86 print ' <div id="left"> <!-- Left -->';
88 print ' Lemma:<sup><span class="tooltip" title="header=[Lemma] body=[Type in the lemma, or citation form of the word you wish to add.]">?</span></sup>';
89 print ' <input type="text" name="left_lemma" value="' + post_data
['left_lemma'] + '">';
92 print ' Paradigm:<sup><span class="tooltip" title="header=[Paradigm] body=[Paradigms define how a word inflects, select the one that fits the lemma you added.]">?</span></sup>';
93 print ' <select name="left_paradigm">';
94 for left_p
in post_data
['left_paradigms']: #{
95 if post_data
['left_display_mode'] == 'list' and left_p
not in post_data
['left_glosses']: #{
98 if left_p
== post_data
['left_paradigm']: #{
99 if left_p
in post_data
['left_glosses']: #{
100 print ' <option value="' + left_p
+ '" selected>' + post_data
['left_glosses'][left_p
] + '</option>';
102 print ' <option value="' + left_p
+ '" selected>' + left_p
+ '</option>';
104 if left_p
in post_data
['left_glosses']: #{
105 print ' <option value="' + left_p
+ '">' + post_data
['left_glosses'][left_p
] + '</option>';
107 print ' <option value="' + left_p
+ '">' + left_p
+ '</option>';
114 self
.show_preview(post_data
, 'left');
116 left_entrada
= self
.show_entrada(post_data
, 'left');
118 print left_entrada
.replace('<', '<').replace('>', '>');
123 print ' <!-- Bidix side -->';
124 print ' <div id="centre">';
125 if post_data
['restriction'] != 'LR' and post_data
['restriction'] != 'RL': #{
126 print ' <input type="radio" name="restriction" value="none" checked>←→<br />';
128 print ' <input type="radio" name="restriction" value="none">←→<br />';
131 if post_data
['restriction'] == 'LR': #{
132 print ' <input type="radio" name="restriction" value="LR" checked>→→<br />';
134 print ' <input type="radio" name="restriction" value="LR">→→<br />';
137 if post_data
['restriction'] == 'RL': #{
138 print ' <input type="radio" name="restriction" value="RL" checked>←←<br />';
140 print ' <input type="radio" name="restriction" value="RL">←←<br />';
143 print ' <input type="submit" name="clear_box" value="Clear">';
144 print ' <input type="submit" name="preview_box" value="Preview">';
145 print ' <input type="submit" name="commit_box" value="Commit">';
148 bidix_entrada
= self
.show_entrada(post_data
, 'bidix');
150 print bidix_entrada
.replace('<', '<').replace('>', '>');
155 print ' <div id="right"> <!-- Right -->';
157 print ' Lemma:<sup><span class="tooltip" title="header=[Lemma] body=[Type in the lemma, or citation form of the word you wish to add.]">?</span></sup>';
158 print ' <input type="text" name="right_lemma" value="' + post_data
['right_lemma'] + '">';
161 print ' Paradigm:<sup><span class="tooltip" title="header=[Paradigm] body=[Paradigms define how a word inflects, select the one that fits the lemma you added.]">?</span></sup>';
162 print ' <select name="right_paradigm">';
163 for right_p
in post_data
['right_paradigms']: #{
164 if post_data
['right_display_mode'] == 'list' and right_p
not in post_data
['right_glosses']: #{
167 if right_p
== post_data
['right_paradigm']: #{
168 if right_p
in post_data
['right_glosses']: #{
169 print ' <option value="' + right_p
+ '" selected>' + post_data
['right_glosses'][right_p
] + '</option>';
171 print ' <option value="' + right_p
+ '" selected>' + right_p
+ '</option>';
173 if right_p
in post_data
['right_glosses']: #{
174 print ' <option value="' + right_p
+ '">' + post_data
['right_glosses'][right_p
] + '</option>';
176 print ' <option value="' + right_p
+ '">' + right_p
+ '</option>';
183 self
.show_preview(post_data
, 'right');
185 right_entrada
= self
.show_entrada(post_data
, 'right');
187 print right_entrada
.replace('<', '<').replace('>', '>');
197 def show_preview(self
, post_data
, _side
): #
198 print >> sys
.stderr
, 'right paradigm: ' , post_data
['right_paradigm'];
199 p
= _side
+ '_paradigm';
200 if post_data
['previewing'] == 'on': #{
201 paradigm
= post_data
[_side
+ '_dictionary'].get_paradigm(post_data
[p
], post_data
['selected_tag']);
202 if type(paradigm
) == type(None): #{
205 if type(paradigm
.get_stems()) != type(None): #{
206 for s
in post_data
[_side
+ '_paradigms'][paradigm
.name
].get_stems(): #{
207 shows
= post_data
[_side
+ '_dictionary'].get_tag_by_tag(post_data
['selected_tag']).get_list();
209 if len(shows
) > 0: #{
210 for show
in post_data
[_side
+ '_dictionary'].get_tag_by_tag(post_data
['selected_tag']).get_list(): #{
212 print self
.incondicional(post_data
[_side
+ '_lemma'], paradigm
.name
) + s
[0] + '<br />';
213 print '<span id="symbol_list">' + s
[1] + '</span>';
219 print self
.incondicional(post_data
[_side
+ '_lemma'], post_data
[_side
+ '_paradigm']) + s
[0] + '<br />';
220 print '<span id="symbol_list">' + s
[1] + '</span>';
230 def show_entrada(self
, post_data
, _side
): #{
231 if post_data
['previewing'] == 'on': #{
232 if _side
== 'bidix': #{
233 dictionary
= post_data
[_side
+ '_dictionary'];
235 if type(dictionary
) != None: #{
236 _lemma1
= post_data
['left_lemma'];
237 _lemma2
= post_data
['right_lemma'];
238 _tag
= post_data
['selected_tag'];
240 _restriction
= post_data
['restriction'];
243 entrada
= dictionary
.generate_bidix_entrada(_lemma1
, _lemma2
, _tag
, _restriction
, _comment
, _author
);
249 if _side
== 'right' or _side
== 'left' and post_data
[_side
+ '_paradigm']: #{
250 dictionary
= post_data
[_side
+ '_dictionary'];
251 paradigm
= post_data
[_side
+ '_dictionary'].get_paradigm(post_data
[_side
+ '_paradigm'], post_data
['selected_tag']);
253 if type(paradigm
) != type(None): #{
254 _lemma
= post_data
[_side
+ '_lemma'];
255 _restriction
= post_data
['restriction'];
256 _paradigm
= paradigm
.name
;
260 entrada
= dictionary
.generate_monodix_entrada(_lemma
, _paradigm
, _restriction
, _comment
, _author
);
269 def incondicional(self
, _lemma
, _paradigm
): #{
270 if _paradigm
.count('/') < 1: #{
274 paradigm
= _paradigm
.decode('utf-8');
275 bar_pos
= paradigm
.find('/');
276 und_pos
= paradigm
.find('_');
277 chr_str
= (und_pos
- bar_pos
) - 1;
278 l
= _lemma
.decode('utf-8');
279 r
= l
[0:(len(l
) - chr_str
)];
281 return r
.encode('utf-8');