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