Package libqutrub ::
Package src ::
Module conjugatedisplay
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from verb_const import *
25 from ar_ctype import *
26 import sys,re,string
27
28
29
30
31 OneTensePronoun={u"أنا":"" ,u"أنت":"" ,u"أنتِ":"" ,u"هو":"" ,u"هي":"" ,u"أنتما":"" ,u"أنتما مؤ":"" ,u"هما":"" ,u"هما مؤ":"" ,u"نحن":"" ,u"أنتم":"" ,u"أنتن":"" ,u"هم":"" ,u"هن":""}
32 TableConjug={TensePast:OneTensePronoun.copy(),
33 TensePassivePast:OneTensePronoun.copy(),
34 TenseFuture:OneTensePronoun.copy(),
35 TensePassiveFuture:OneTensePronoun.copy(),
36 TenseJussiveFuture:OneTensePronoun.copy(),
37 TensePassiveJussiveFuture:OneTensePronoun.copy(),
38 TenseSubjunctiveFuture:OneTensePronoun.copy(),
39 TensePassiveSubjunctiveFuture:OneTensePronoun.copy(),
40 TenseImperative:OneTensePronoun.copy(),
41 TenseConfirmedFuture:OneTensePronoun.copy(),
42 TenseConfirmedImperative:OneTensePronoun.copy()
43 }
44
45
46 TabDisplay={
47 PronounAna:u"1",
48 PronounNahnu:u"2",
49 PronounAnta:u"3",
50 PronounAnti:u"4ِ",
51 PronounAntuma:u"5",
52 PronounAntuma_f:u"6",
53 PronounAntum:u"7",
54 PronounAntunna:u"8",
55 PronounHuwa:u"9",
56 PronounHya:u"10",
57 PronounHuma:u"11",
58 PronounHuma_f:u"12",
59 PronounHum:u"13",
60 PronounHunna:u"14",
61
62
63
64 TensePast:u"20",
65 TenseFuture:u"21",
66 TenseImperative:u"22",
67 TenseConfirmedImperative:u"23",
68 TenseJussiveFuture:u"24",
69 TenseSubjunctiveFuture:u"25",
70 TenseConfirmedFuture:u"26",
71
72
73 TensePassivePast:u"27",
74 TensePassiveFuture:u"28",
75 TensePassiveJussiveFuture:u"29",
76 TensePassiveSubjunctiveFuture:u"30",
77 TensePassiveConfirmedFuture:u"31",
78 }
80 """
81 conjugatedisplay class is used to display verb conjugation in different ways and uses.
82 """
83 tab_conjug={}
84 pronouns={}
85 verb=u""
86 mode='Text'
87 future_form=u""
88 text={}
89 transitive=False;
104
105
106
108 """
109 Set the display mode as:
110 - 'Text':
111 - 'HTML':
112 - 'HTMLColoredDiacritics':
113 - 'DICT':
114 - 'CSV':
115 - 'GUI':
116 - 'TABLE':
117 - 'XML':
118 - 'TeX':
119 - 'ROWS':
120 @param mode: the given mode to display result;
121 @type mode: unicode;
122 """
123 self.mode=mode
125 """
126 Set the transitivity value to True.
127 """
128 self.transitive=True;
130 """
131 Set the bab sarf value to bab
132 @param bab: the given sarf bab.
133 @type bab: integer (1-6)
134 """
135 self.bab=bab
136
146 """
147 Get attributes as text
148 @return: Attributes as text.
149 @rtype: unicode;
150 """
151 return self.text;
152
154 """
155 Add a new attribut to display, like the transitivity the root and the future form.
156 @param title: the title of the attribute to display.
157 @type title: unicode;
158 @param value:the value if the attribute.
159 @type value: unicode;
160 """
161 if title!='' :
162 self.text[title]=value
163
164 - def add(self,tense,pronoun,verbconjugated):
165 """
166 Add a new conjugation to display.
167 @param tense: tense of the added conjuagtion.
168 @type tense: unicode;
169 @param pronoun: pronoun of the added conjuagtion.
170 @type pronoun: unicode;
171 @param verbconjugated:aded conjuagtion.
172 @type verbconjugated:unicode;
173
174 """
175 if tense not in self.tab_conjug.keys():
176 self.tab_conjug[tense]={}
177 self.tab_conjug[tense][pronoun]=verbconjugated
178
179
180
184 """
185 Display The conjugation result for a list of tenses, with a display mode.
186 Set the display mode as:
187 - 'Text':
188 - 'HTML':
189 - 'HTMLColoredDiacritics':
190 - 'DICT':
191 - 'CSV':
192 - 'GUI':
193 - 'TABLE':
194 - 'XML':
195 - 'TeX':
196 - 'ROWS':
197 @param mode: the given mode to display result;
198 @type mode: unicode;
199 @param listtense: the given tenses list to display result;
200 @type listtense: list of unicode;
201 @return: the result in a specified dispaly mode.
202 @rtype: according to display mode.
203 """
204 if mode=='Text':
205 return self.display_text(listtense)
206 elif mode=='HTML':
207 return self.display_html(listtense)
208 elif mode=='HTMLColoredDiacritics':
209 return self.display_html_colored_diacritics(listtense)
210 elif mode=='DICT':
211 return self.display_dict(listtense)
212 elif mode=='CSV':
213 return self.display_csv(listtense)
214 elif mode=='GUI':
215 return self.display_table(listtense)
216 elif mode=='TABLE':
217 return self.display_table(listtense)
218 elif mode=='XML':
219 return self.display_xml(listtense)
220 elif mode.upper()=='TeX'.upper():
221 return self.display_tex(listtense)
222 elif mode=='ROWS'.upper():
223 return self.display_rows(listtense)
224 else:
225 return self.display_text(listtense)
226
227 - def display_text(self,listtense=TableTense):
228 """
229 Display The conjugation result for a list of tenses, as text.
230 @param listtense: the given tenses list to display result;
231 @type listtense: list of unicode;
232 @return: the result as text.
233 @rtype: uunicode.
234 """
235 text = u""
236 for title in self.text.keys():
237 text+= u"%s: %s\n" %(title, self.text[title])
238 text+= u"\t"
239 text+=u"\t".join(listtense);
240 for pronoun in PronounsTable:
241 text+= u"\n%s" %(pronoun)
242 for tense in listtense:
243 if pronoun in self.tab_conjug[tense].keys():
244 text+= u"\t%s" %(self.tab_conjug[tense][pronoun])
245 return text
246
247
249 """
250 Display The conjugation result for a list of tenses, as comma separeted value text.
251 every line contains:
252 example:
253 >>> اللزوم/التعدي: متعدي
254 الفعل: مَنَحَ
255 نوع الفعل: فعل ثلاثي
256 ;الماضي المعلوم;المضارع المعلوم;المضارع المجزوم;المضارع المنصوب;المضارع المؤكد الثقيل;الأمر;الأمر المؤكد;الماضي المجهول;المضارع المجهول;المضارع المجهول المجزوم;المضارع المجهول المنصوب;المضارع المؤكد الثقيل المجهول
257 أنا;مَنَحْتُ;أَمْنَحُ;أَمْنَحْ;أَمْنَحَ;أَمْنَحَنَّ;;;مُنِحْتُ;أُمْنَحُ;أُمْنَحْ;أُمْنَحَ;أُمْنَحَنَّ
258 نحن;مَنَحْنَا;نَمْنَحُ;نَمْنَحْ;نَمْنَحَ;نَمْنَحَنَّ;;;مُنِحْنَا;نُمْنَحُ;نُمْنَحْ;نُمْنَحَ;نُمْنَحَنَّ
259 أنت;مَنَحْتَ;تَمْنَحُ;تَمْنَحْ;تَمْنَحَ;تَمْنَحَنَّ;اِمْنَحْ;اِمْنَحَنَّ;مُنِحْتَ;تُمْنَحُ;تُمْنَحْ;تُمْنَحَ;تُمْنَحَنَّ
260
261
262 @param listtense: the given tenses list to display result;
263 @type listtense: list of unicode;
264 @return: the result as text in row.
265 @rtype: unicode.
266 """
267 text = u""
268 for title in self.text.keys():
269 text+= u"%s: %s\n" %(title,self.text[title])
270 text+= u";".join(listtense);
271 text+=u"\n";
272 for pronoun in PronounsTable:
273 text+= u"%s" %(pronoun)
274 for tense in listtense:
275
276 if pronoun in self.tab_conjug[tense].keys():
277 text+= u";%s" %(self.tab_conjug[tense][pronoun])
278 text+= u"\n"
279 return text
280
281
282
283
285 """
286 Display The conjugation result for a list of tenses, as text in rows.
287 every row contains:
288 - unvocalized conjugation,
289 - unvocalized conjugation,
290 - pronoun
291 - tense,
292 - transitive,
293 - original verb
294 - tasrif bab
295
296 @param listtense: the given tenses list to display result;
297 @type listtense: list of unicode;
298 @return: the result as text in row.
299 @rtype: unicode.
300 """
301 text = u""
302
303 transitive="0";
304 if self.transitive:transitive='1';
305 for pronoun in PronounsTable:
306
307 for tense in listtense:
308
309 if self.tab_conjug[tense][pronoun]!="":
310 text+= "\t".join([
311 ar_strip_marks_keepshadda(self.tab_conjug[tense][pronoun]),
312 self.tab_conjug[tense][pronoun],
313 TabDisplay[pronoun],
314 TabDisplay[tense],
315 transitive,
316 self.verb,
317 self.bab,
318 ]);
319 text+= u"\n"
320 return text
321
322
323
324
325
326
327
328
329
331 """
332 Display The conjugation result for a list of tenses, as HTML.
333 @param listtense: the given tenses list to display result;
334 @type listtense: list of unicode;
335 # @return: the result as HTML.
336 @rtype: unicode.
337 """
338 indicativeTenses=[];
339 passiveTenses=[];
340 for t in listtense:
341 if t in TableIndicativeTense:
342 indicativeTenses.append(t);
343 else:
344 passiveTenses.append(t);
345 text = u""
346 text+= u"<h3>%s : %s - %s</h3>\n" %(self.verb,self.verb,self.future_form)
347
348
349 text+= u"<ul>\n"
350 for title in self.text.keys():
351 text+= u"<li><b>%s:</b> %s</li>\n" %(title,self.text[title])
352 text+= u"</ul>\n\n"
353
354 for mode in("indicative","passive"):
355 if mode=="indicative":
356 listtenseToDisplay=indicativeTenses;
357
358 else:
359 listtenseToDisplay=passiveTenses;
360 text+="<br/>"
361 if len(listtenseToDisplay) >0:
362 text+= u"<table class='resultarea' border=1 cellspacing=0>\n"
363 text+= u"<tr><th> </th>"
364 for tense in listtenseToDisplay:
365 text+= u"<th>%s</th>" %(tense)
366 text+= u"</tr>\n"
367 for pronoun in PronounsTable:
368 text+= u"<tr>"
369 text+= u"<th>%s</th>" %(pronoun)
370 for tense in listtenseToDisplay:
371 text+= u"<td> %s</td>" %(self.tab_conjug[tense][pronoun])
372 text+=u"</tr>\n"
373 text+=u"</table>\n"
374 return text
375
376
377
378
379
380
381
383 """
384 Display The conjugation result for a list of tenses, as HTML with colored vocalization.
385 @param listtense: the given tenses list to display result;
386 @type listtense: list of unicode;
387 @return: the result as HTML.
388 @rtype: unicode.
389 """
390 text = self.display_html(listtense)
391
392 text=self.highlight_diacritics_html(text);
393 return text;
394
396 """
397 Highlight dfiactitics in the HTML text.
398 @param text: the given text;
399 @type text: unicode.
400 @return: the result as HTML.
401 @rtype: unicode.
402 """
403 hight_text=u"";
404 lefttag=u"<span class='tashkeel'>"
405 righttag=u"</span>"
406 for i in range(len(text)):
407 if text[i] in (FATHA,DAMMA, KASRA, SUKUN):
408 if (i>0 and text[i-1] not in (ALEF,ALEF_HAMZA_ABOVE,WAW_HAMZA,ALEF_MADDA, DAL,THAL,WAW,REH,ZAIN,SHADDA)) and (i+1<len(text) and text[i+1] not in (" ","<")):
409 hight_text+=u"".join([lefttag,TATWEEL, text[i],righttag]);
410 else :
411
412 hight_text+=u"".join([lefttag," ", text[i],righttag]);
413 else:
414 hight_text+=text[i];
415 return hight_text;
416
418 """
419 Display The conjugation result for a list of tenses, as array.
420 @param listtense: the given tenses list to display result;
421 @type listtense: list of unicode;
422 @return: the result as table, the table[0] contains pronouns.
423 @rtype: dict with number indice.
424 """
425 table={}
426
427 j=0;
428 table[0]={0:u"الضمائر"}
429 for j in range(len(listtense)):
430 table[0][j+1]=listtense[j];
431 i=1;
432 for pronoun in PronounsTable:
433 table[i]={}
434 table[i][0]=pronoun;
435 j=1
436 for tense in listtense:
437 table[i][j]=self.tab_conjug[tense][pronoun]
438 j=j+1
439 i=i+1
440 return table
441
442
443
444
445
446
447
449 """
450 Display The conjugation result for a list of tenses, as python dict.
451 @param listtense: the given tenses list to display result;
452 @type listtense: list of unicode;
453 @return: the result as python dict.
454 @rtype: dict.
455 """
456 table={}
457 for tense in listtense:
458 table[tense]=self.tab_conjug[tense];
459
460 return table;
461
463 """
464 Display The conjugation result for a list of tenses, as XML.
465 @param listtense: the given tenses list to display result;
466 @type listtense: list of unicode;
467 @return: the result as XML.
468 @rtype: unicode.
469 """
470 text = u""
471 text+= u"<verb_conjugation>\n"
472 text+= u"\t<proprety name='verb' value='%s'/>\n" %(self.verb)
473 for title in self.text.keys():
474 text+= u"\t<proprety name='%s' value='%s'/>\n" %(title,self.text[title])
475 for tense in listtense:
476 text+= u"\t<tense name='%s'>\n" %(tense)
477 for pronoun in PronounsTable:
478 if self.tab_conjug[tense][pronoun]!="":
479 text+= u"\t\t<conjugation pronoun='%s' value='%s'/>\n" %(pronoun,self.tab_conjug[tense][pronoun])
480 text+= u"\t</tense>\n"
481 text+= u"</verb_conjugation>"
482 return text
483
485 """
486 Display The conjugation result for a list of tenses, as TeX.
487 @param listtense: the given tenses list to display result;
488 @type listtense: list of unicode;
489 @return: the result as TeX format.
490 @rtype: unicode.
491 """
492 text = u""
493 text+= u"\\environment qutrub-layout\n"
494 text+= u"\\starttext\n"
495
496 text+= u"\\Title{%s}\n" %(self.verb)
497
498 text+= u"\\startitemize\n"
499 for title in self.text.keys():
500 if title == u" الكتابة الداخلية للفعل ":
501 text+= u"\\item {\\bf %s} \\DeShape{%s}\n" %(title,self.text[title])
502 else:
503 text+= u"\\item {\\bf %s} %s\n" %(title,self.text[title])
504 text+= u"\\stopitemize\n"
505
506 text+= u"\\starttable[|lB|l|l|l|l|l|]\n"
507 text+= u"\\HL[3]\n\\NC"
508 for tense in listtense:
509 text+= u"\\NC {\\bf %s}" %(tense)
510 text+= u"\\SR\n\\HL\n"
511 for pronoun in PronounsTable:
512 text+= u"\\NC %s" %(pronoun)
513 for tense in listtense:
514 text+= u"\\NC %s" %(self.tab_conjug[tense][pronoun])
515 text+= u"\\AR\n"
516 text+= u"\\LR\\HL[3]\n"
517 text+= u"\\stoptable\n"
518
519 text+= u"\\stoptext"
520 return text
521