Beispiel #1
0
def do_sarf(word,future_type,all=True,past=False,future=False,passive=False,imperative=False,future_moode=False,confirmed=False,transitive=False,display_format="HTML"):
	import libqutrub.mosaref_main as mosaref
	import libqutrub.ar_verb as ar_verb
	import libqutrub.classverb as verbclass
	import libqutrub.verb_const as verb_const
	import pyarabic.arabrepr as myrepr
	from libqutrub.verb_valid import is_valid_infinitive_verb
	valid = is_valid_infinitive_verb(word)
	listetenses=[];
	if valid:
		future_type= ar_verb.get_future_type_by_name(future_type);
		bab_sarf=0;
		vb = verbclass.VerbClass(word,transitive,future_type);
		#vb.verb_class();
		vb.set_display(display_format);
	#test the uniformate function
		if all :
			if transitive :
##    				print "transitive";
				listetenses= verb_const.TABLE_TENSE
				result= vb.conjugate_all_tenses();
			else:
##    				print "intransitive";
				listetenses = verb_const.TableIndicativeTense;
##    				print len(TableIndicativeTense)
				result= vb.conjugate_all_tenses(listetenses);
		else :
			listetenses=[];
			if past : listetenses.append(verb_const.TensePast);
			if (past and passive and transitive) : listetenses.append(verb_const.TensePassivePast)
			if future : listetenses.append(verb_const.TenseFuture);
			if (future and passive and transitive) : listetenses.append(verb_const.TensePassiveFuture)
			if (future_moode) :
				listetenses.append(verb_const.TenseSubjunctiveFuture)
				listetenses.append(verb_const.TenseJussiveFuture)
			if (confirmed) :
				if (future):listetenses.append(verb_const.TenseConfirmedFuture);
				if (imperative):listetenses.append(verb_const.TenseConfirmedImperative);
			if (future and passive and transitive and confirmed) :
				listetenses.append(verb_const.TensePassiveConfirmedFuture);
			if (passive and transitive and future_moode) :
				listetenses.append(verb_const.TensePassiveSubjunctiveFuture)
				listetenses.append(verb_const.TensePassiveJussiveFuture)
			if imperative : listetenses.append(verb_const.TenseImperative)
			result =vb.conjugate_all_tenses(listetenses);
    		#self.result["HTML"]=vb.conj_display.display("HTML",listetenses)
		#return result;
		#return vb.conj_display.display("HTML",listetenses)
		#return vb.conj_display.display("DICT",listetenses)
		mrepr = myrepr.ArabicRepr()
		return vb.conj_display.display("TABLE",listetenses)		
		return mrepr.repr(vb.conj_display.display("TABLE",listetenses))
		
		return mrepr.repr(result)
	else: return None;
Beispiel #2
0
def do_sarf(word,future_type,all=True,past=False,future=False,passive=False,imperative=False,future_moode=False,confirmed=False,transitive=False,display_format="HTML"):
    import libqutrub.mosaref_main as mosaref
    import libqutrub.ar_verb as ar_verb
    import libqutrub.classverb as verbclass
    import libqutrub.verb_const as verb_const
    import pyarabic.arabrepr as myrepr
    from libqutrub.verb_valid import is_valid_infinitive_verb
    valid = is_valid_infinitive_verb(word)
    listetenses=[];
    if valid:
        future_type= ar_verb.get_future_type_by_name(future_type);
        bab_sarf=0;
        vb = verbclass.VerbClass(word,transitive,future_type);
        #vb.verb_class();
        vb.set_display(display_format);
    #test the uniformate function
        if all :
            if transitive :
##                  print "transitive";
                listetenses= verb_const.TABLE_TENSE
                result= vb.conjugate_all_tenses();
            else:
##                  print "intransitive";
                listetenses = verb_const.TableIndicativeTense;
##                  print len(TableIndicativeTense)
                result= vb.conjugate_all_tenses(listetenses);
        else :
            listetenses=[];
            if past : listetenses.append(verb_const.TensePast);
            if (past and passive and transitive) : listetenses.append(verb_const.TensePassivePast)
            if future : listetenses.append(verb_const.TenseFuture);
            if (future and passive and transitive) : listetenses.append(verb_const.TensePassiveFuture)
            if (future_moode) :
                listetenses.append(verb_const.TenseSubjunctiveFuture)
                listetenses.append(verb_const.TenseJussiveFuture)
            if (confirmed) :
                if (future):listetenses.append(verb_const.TenseConfirmedFuture);
                if (imperative):listetenses.append(verb_const.TenseConfirmedImperative);
            if (future and passive and transitive and confirmed) :
                listetenses.append(verb_const.TensePassiveConfirmedFuture);
            if (passive and transitive and future_moode) :
                listetenses.append(verb_const.TensePassiveSubjunctiveFuture)
                listetenses.append(verb_const.TensePassiveJussiveFuture)
            if imperative : listetenses.append(verb_const.TenseImperative)
            result =vb.conjugate_all_tenses(listetenses);
            #self.result["HTML"]=vb.conj_display.display("HTML",listetenses)
        #return result;

        return vb.conj_display.display("TABLE",listetenses)
    else:
        

    else: return None;
Beispiel #3
0
def main():
    filename, all, future, past, passive, imperative, confirmed, future_moode, display_format = grabargs(
    )
    try:
        #~ fl=open(filename,encoding='utf8');
        fl = open(filename)
    except:
        print(" Error :No such file or directory: %s" % filename)
        sys.exit(0)
#
    print(filename, all, future, past, passive, imperative, confirmed,
          future_moode)
    line = fl.readline()  #.decode("utf8");
    text = u""
    verb_table = []
    nb_field = 2
    while line:
        line = line.strip('\n')
        if not line.startswith("#"):
            liste = line.split("\t")
            if len(liste) >= nb_field:
                verb_table.append(liste)


#       print " ****",text
        line = fl.readline()  #.decode("utf8");
    fl.close()
    for tuple_verb in verb_table:
        word = tuple_verb[0]

        ##        print transi
        if not is_valid_infinitive_verb(word):
            print(u"is invalid verb ")
            print(word.encode("utf8"))
        else:
            future_type = u"" + tuple_verb[1]
            future_type = get_future_type_entree(future_type)
            transitive = u"" + tuple_verb[2]
            if transitive in (u"متعدي", u"م", u"مشترك", u"ك", "t",
                              "transitive"):
                transitive = True
            else:
                transitive = False
            text = libqutrub.mosaref_main.do_sarf(word, future_type, all, past,
                                                  future, passive, imperative,
                                                  future_moode, confirmed,
                                                  transitive, display_format)
            print(text)  #.encode("utf8"))
Beispiel #4
0
def main():
    """Main function"""
    filename, alltense, future, past, passive, imperative, confirmed, \
     future_moode, display_format =  grabargs()
    try:
        fle = open(filename)
    except IOError:
        print " Error :No such file or directory: %s" % filename
        sys.exit(0)

    print filename, alltense, future, past, passive, imperative, \
     confirmed, future_moode

    line = fle.readline().decode("utf")
    text = u""
    verb_table = []
    nb_field = 2
    while line:
        if not line.startswith("#"):

            text = text + " " + line.strip()
            liste = line.split("\t")
            if len(liste) >= nb_field:
                verb_table.append(liste)

        line = fle.readline().decode("utf8")
    fle.close()

    for tuple_verb in verb_table:
        word = tuple_verb[0]

        if not verb_valid.is_valid_infinitive_verb(word):
            print u"is invalid verb ",
            print word.encode("utf8")
        else:
            future_type = u"" + tuple_verb[1]
            future_type = ar_verb.get_future_type_entree(future_type)
            transitive = u"" + tuple_verb[2]
            if transitive in (u"متعدي", u"م", u"مشترك", u"ك", "t",
                              "transitive"):
                transitive = True
            else:
                transitive = False
            text = mosaref_main.do_sarf(word, future_type, alltense, past,
                                        future, passive, imperative,
                                        future_moode, confirmed, transitive,
                                        display_format)
            print text.encode("utf8")
Beispiel #5
0
def main():
    """Main function"""
    filename, alltense, future, past, passive, imperative, confirmed, \
     future_moode, display_format =  grabargs()
    try:
        fle = open(filename)
    except IOError:
        print " Error :No such file or directory: %s" % filename
        sys.exit(0)

    print filename, alltense, future, past, passive, imperative, \
     confirmed, future_moode

    line = fle.readline().decode("utf")
    text = u""
    verb_table = []
    nb_field = 2
    while line :
        if not line.startswith("#"):

            text = text+" "+ line.strip()
            liste = line.split("\t")
            if len(liste) >= nb_field:
                verb_table.append(liste)

        line = fle.readline().decode("utf8")
    fle.close()

    for tuple_verb in verb_table:
        word = tuple_verb[0]

        if not verb_valid.is_valid_infinitive_verb(word):
            print u"is invalid verb ", 
            print word.encode("utf8")
        else:
            future_type = u""+tuple_verb[1]
            future_type = ar_verb.get_future_type_entree(future_type)
            transitive = u""+tuple_verb[2]
            if transitive in (u"متعدي", u"م", u"مشترك", u"ك", "t", 
            "transitive"):
                transitive = True
            else :
                transitive = False
            text = mosaref_main.do_sarf(word, future_type, alltense, past, 
            future, passive, imperative, future_moode, confirmed, 
            transitive, display_format)
            print text.encode("utf8")
Beispiel #6
0
 def check_fields(self, fields):
     """ check fields """
     voc = fields.get('vocalized', '')
     unvoc = fields.get('unvocalized', '')
     if not voc:
         return "Error: Empty vocalized"
     if not ar.is_arabicword(voc):
         return "Error: Invalid Arabic word "
     if not is_valid_infinitive_verb(voc):
         return "Error: Invalid Arabic infinitive verb "
     # not duplicated
     if voc in self.index:
         if len(unvoc) <= 3:
             return "Warning: Duplicated Entry "
         else:
             return "Error: Duplicated Entry "
     self.index.append(voc)
     # valid verb form
     if not ar.is_vocalized(voc):
         return "Error: Not Vocalized"
     # valid vocalization
     if not verify_tashkeel(voc):
         return "Error: Error in Vocalization "
     return "ok"
def mainly():
    """
    main test
    """
    mode = "fa3il"
    DATA_FILE = "samples/fa3il-5.csv"
    #~ DATA_FILE = "samples/maf3oul.csv"
    #~ mode = "maf3oul"
    with open(DATA_FILE) as f:
        line = f.readline().decode('utf8')
        while line :
            if not line.startswith("#"):
                liste = line.strip('\n').split("\t")
                if len(liste) >= 2 :
            
                    correct = liste[0]
                    word = liste[1].split(';')[0]
                    transitive = True
                    future_type = get_future_type(word)
                    if valid_verb.is_valid_infinitive_verb(word,True): # vocalized
                        result = generate_subject(word,  transitive, future_type)
                        fa3il = result.get("subject", u"")
                        maf3oul = result.get("object", u"")
                        inf_verb = result.get("infinitive", word)
                        debug = False
                        #~ debug = True
                        if mode == "maf3oul":
                            if debug or not correct == maf3oul:
                                print (u"\t".join([word,inf_verb,araby.name(future_type)+future_type,maf3oul, correct, str(correct==maf3oul)])).encode('utf8')
                        else:
                            if debug or not correct == fa3il:
                                print (u"\t".join([word,inf_verb,fa3il, correct, str(correct==fa3il)])).encode('utf8')

                    else:
                        print (u"\t".join([word,"","", correct, "Invalid_Verb"])).encode('utf8')                    
            line = line = f.readline().decode('utf8')
Beispiel #8
0
def do_sarf(word, future_type, alltense = True, past = False, future = False, 
passive = False, imperative = False, future_moode = False, confirmed = False,
 transitive = False, display_format = "HTML"):
    """
    The main function to conjugate verbs.
    You must specify all parameters.
    Can be used as an example to call the conjugation class.
    @param word: the givern verb. the given word must be vocalized, 
    if it's 3 letters length only, else, the verb can be unvocalized, 
     but the Shadda must be given, it' considered as letter.
    @type word: unicode.
    @param future_type: For Triliteral verbs, 
    you must give the mark of Ain in the future, 
    كة عين الفعل في المضارع. it's given as a name of haraka (فتحة، ضمة، كسرة).
    @type future_type: unicode(فتحة، ضمة، كسرة).
    @param all: conjugate in all arabic tenses.
    @type all: Boolean, default(True)
    @param past: conjugate in past tense ألماضي
    @type past: Boolean, default(False)
    @param future: conjugate in arabic present and future tenses المضارع
    @type future: Boolean, default(False)
    @param passive: conjugate in passive voice  المبني للمجهول
    @type passive: Boolean, default(False)
    @param imperative: conjugate in imperative tense الأمر
    @type imperative: Boolean, default(False)
    @param future_moode: conjugate in future moode tenses المضارع المنصوب والمجزوم
    @type future_moode: Boolean, default(False)
    @param confirmed: conjugate in confirmed cases tense المؤكّد
    @type confirmed: Boolean, default(False)
    @param transitive: the verb transitivity التعدي واللزوم
    @type transitive: Boolean, default(False)
    @param display_format: Choose the display format:
        - 'Text':
        - 'HTML':
        - 'HTMLColoredDiacritics':
        - 'DICT':
        - 'CSV':
        - 'GUI':
        - 'TABLE':
        - 'XML':
        - 'TeX':
        - 'ROWS':
    @type display_format: string, default("HTML") 
    @return: The conjugation result
    @rtype: According to display_format.
    """
    valid = verb_valid.is_valid_infinitive_verb(word)
    if valid:
        future_type = ar_verb.get_future_type_by_name(future_type)
        #~ bab_sarf = 0
        #init the verb class to treat the verb
        vbc = classverb.VerbClass(word, transitive, future_type)
        vbc.set_display(display_format)

        if alltense :
            result =  vbc.conjugate_all_tenses()
        else :
            listetenses = []
            if past :
                listetenses.append(vconst.TensePast)
            if (past and passive ) :
                listetenses.append(vconst.TensePassivePast)
            if future : 
                listetenses.append(vconst.TenseFuture)
            if (future and passive ) :
                listetenses.append(vconst.TensePassiveFuture)
            if (future_moode) :
                listetenses.append(vconst.TenseSubjunctiveFuture)
                listetenses.append(vconst.TenseJussiveFuture)
            if (confirmed) :
                if (future):
                    listetenses.append(vconst.TenseConfirmedFuture)
                if (imperative):
                    listetenses.append(vconst.TenseConfirmedImperative)
            if (future and transitive and confirmed) :
                listetenses.append(vconst.TensePassiveConfirmedFuture)
            if (passive and future_moode) :
                listetenses.append(vconst.TensePassiveSubjunctiveFuture)
                listetenses.append(vconst.TensePassiveJussiveFuture)
            if imperative :
                listetenses.append(vconst.TenseImperative)
            result  = vbc.conjugate_all_tenses(listetenses)
        return result
    else: return None
Beispiel #9
0
def do_sarf(word,
            future_type,
            alltense=True,
            past=False,
            future=False,
            passive=False,
            imperative=False,
            future_moode=False,
            confirmed=False,
            transitive=False,
            display_format="HTML"):
    """
    The main function to conjugate verbs.
    You must specify all parameters.
    Can be used as an example to call the conjugation class.
    @param word: the givern verb. the given word must be vocalized, 
    if it's 3 letters length only, else, the verb can be unvocalized, 
     but the Shadda must be given, it' considered as letter.
    @type word: unicode.
    @param future_type: For Triliteral verbs, 
    you must give the mark of Ain in the future, 
    كة عين الفعل في المضارع. it's given as a name of haraka (فتحة، ضمة، كسرة).
    @type future_type: unicode(فتحة، ضمة، كسرة).
    @param all: conjugate in all arabic tenses.
    @type all: Boolean, default(True)
    @param past: conjugate in past tense ألماضي
    @type past: Boolean, default(False)
    @param future: conjugate in arabic present and future tenses المضارع
    @type future: Boolean, default(False)
    @param passive: conjugate in passive voice  المبني للمجهول
    @type passive: Boolean, default(False)
    @param imperative: conjugate in imperative tense الأمر
    @type imperative: Boolean, default(False)
    @param future_moode: conjugate in future moode tenses المضارع المنصوب والمجزوم
    @type future_moode: Boolean, default(False)
    @param confirmed: conjugate in confirmed cases tense المؤكّد
    @type confirmed: Boolean, default(False)
    @param transitive: the verb transitivity التعدي واللزوم
    @type transitive: Boolean, default(False)
    @param display_format: Choose the display format:
        - 'Text':
        - 'HTML':
        - 'HTMLColoredDiacritics':
        - 'DICT':
        - 'CSV':
        - 'GUI':
        - 'TABLE':
        - 'XML':
        - 'TeX':
        - 'ROWS':
    @type display_format: string, default("HTML") 
    @return: The conjugation result
    @rtype: According to display_format.
    """
    valid = verb_valid.is_valid_infinitive_verb(word)
    if valid:
        future_type = ar_verb.get_future_type_by_name(future_type)
        #~ bab_sarf = 0
        #init the verb class to treat the verb
        vbc = classverb.VerbClass(word, transitive, future_type)
        vbc.set_display(display_format)

        if alltense:
            result = vbc.conjugate_all_tenses()
        else:
            listetenses = []
            if past:
                listetenses.append(vconst.TensePast)
            if (past and passive):
                listetenses.append(vconst.TensePassivePast)
            if future:
                listetenses.append(vconst.TenseFuture)
            if (future and passive):
                listetenses.append(vconst.TensePassiveFuture)
            if (future_moode):
                listetenses.append(vconst.TenseSubjunctiveFuture)
                listetenses.append(vconst.TenseJussiveFuture)
            if (confirmed):
                if (future):
                    listetenses.append(vconst.TenseConfirmedFuture)
                if (imperative):
                    listetenses.append(vconst.TenseConfirmedImperative)
            if (future and transitive and confirmed):
                listetenses.append(vconst.TensePassiveConfirmedFuture)
            if (passive and future_moode):
                listetenses.append(vconst.TensePassiveSubjunctiveFuture)
                listetenses.append(vconst.TensePassiveJussiveFuture)
            if imperative:
                listetenses.append(vconst.TenseImperative)
            result = vbc.conjugate_all_tenses(listetenses)
        return result
    else:
        return None
Beispiel #10
0
    def add_record(self, verb_row):
        """
        Add a new to the dict
        """
        self.id += 1
        v = self.treat_tuple(verb_row)
        line = ""

        # display fields to ensure corectness
        VERIFY_INPUT = False
        #~ VERIFY_INPUT =  True;
        if VERIFY_INPUT:
            self.test_entry(v)

        # conjugate the verb with speling tags
        if not valid.is_valid_infinitive_verb(v['vocalized']):
            line += u"#\t\tis invalid verb \n"
        else:
            future_type = v_ar.get_future_type_entree(v['future_type'])
            conjugTable = msrif.do_sarf(v['vocalized'], v['future_type'],
                                        v['all'], v['past'], v['future'],
                                        v['passive'], v['imperative'],
                                        v['future_moode'], v['confirmed'],
                                        v['transitive'], "DICT")
            TableEntries = {}
            if conjugTable:
                TableEntries = {}
                tags_info = self.get_verb_info(v)
                for tense in conjugTable.keys():
                    for pronoun in conjugTable[tense].keys():
                        if pronoun != const.PronounAntuma_f:
                            tags = self.get_tags(tags_info, tense, pronoun)
                            flags = svconst.TabPrefixes[tense]['full']

                            # the passive tenses dont take object suffix, only with double transitie verbs
                            if (v['transitive']
                                    and tense in const.TableIndicativeTense
                                ) or v['double_trans']:  #:

                                # add flags for suffixes
                                if v['think_trans'] and v['reflexive_trans']:
                                    flags += svconst.TabSuffixesPronominale[
                                        pronoun]['full']
                                else:
                                    flags += svconst.TabSuffixes[pronoun][
                                        'full']

                                #   add flag yeh for the الأفعال الخمسة
                                if tense == const.TenseFuture and pronoun in (
                                        const.PronounAnti, const.PronounAntuma,
                                        const.PronounAntuma_f,
                                        const.PronounAntum, const.PronounHuma,
                                        const.PronounHuma_f, const.PronounHum):
                                    flags += u"Ha"

                            # add double object suffixe, if the verb is double transitive, and the tense is indicative
                            if v['double_trans'] and tense in const.TableIndicativeTense:

                                # add flags for suffixes (double object)
                                flags += svconst.TabDisplayTagDouble[pronoun][
                                    'full']

                            #add an entree to the table entrie
                            # this allows to reduce many cases into one entree
                            if conjugTable[tense][pronoun]:
                                word_nm = araby.strip_tashkeel(
                                    conjugTable[tense][pronoun])
                                print(u'\t'.join(
                                    [word_nm, v['vocalized'],
                                     tags])).encode('utf8')

        return line
Beispiel #11
0
    def decode_verb_tuple(self, tuple_verb):
        """
        """
        #abbrevated=False;
        verb_field_number=2;
        root_field_number=1;
        verb_cat_field_number=3;
        root  = self.decode_root(tuple_verb[root_field_number].strip());        
        word  = tuple_verb[verb_field_number].strip();


        if not is_valid_infinitive_verb(word):
            return {"text":u"#\t'%s'\tis invalid verb "%word};
        else:

            model = tuple_verb[0].strip();            
            #print word.encode("utf8")
            future_type = u"-";
            future_type = araby.name(get_future_type_entree(future_type));
            verb_cat = tuple_verb[verb_cat_field_number].strip();
            # decode transitive flag
            #print "'%s'"%transitive;
            transitive = self.decode_transitive(verb_cat);
            #tenses=decode_tenses(verb_cat);
            # decode the tenses

            #init at False
            all=False;
            future=False;
            past=False;
            passive=False;
            imperative=False;
            confirmed=False;
            future_moode=False;
            # متعدي لغير العاقل
            unthink_trans=False;
            # متعدي للعاقل، تلقائيا اﻷفعال تقبل العاقل
            think_trans=True;
            #فعل قلوب
            reflexive_trans=False;
            #متعدي لمفعولين
            double_trans=False;
            if verb_cat =="A":# أمر فقط
                imperative=True;
            elif verb_cat =="D":# مبني للمجهول فقط
                passive=True;
            elif verb_cat =="I":#لاشخصي
                pass;
            elif verb_cat =="M":#جامد
                pass;
            elif    verb_cat =="P":# ماضي فقط
                past=True;
            elif    verb_cat =="Pu":# ماضي فقط لازم  مطلق
                past=True;
            elif    verb_cat =="Ry":# مضارع وأمر فقط
                future=True;
                imperative=True;
            elif    verb_cat =="Su":# ماضي ومضارع
                future=True;
                past=True;
                confirmed=True;
                future_moode=True;
            elif    verb_cat =="Sv":# ماضي ومضارع
                future=True;
                past=True;
                confirmed=True;
                future_moode=True;
            elif    verb_cat =="Sx":# ماضي ومضارع
                future=True;
                past=True;
                confirmed=True;
                future_moode=True;
            elif    verb_cat =="u":# لازم مطلق، لا مجهول ولا أمر
                future=True;
                past=True;
                confirmed=True;
                future_moode=True;
            elif    verb_cat =="v":# لازم نسبي، كل اﻷزمنة، لكن المجهول مع المفرد الغائب
                future=True;
                past=True;
                imperative=True;
                confirmed=True;
                future_moode=True;
                passive=False;
            elif    verb_cat in ("x","y", "yw", "ywz", "yy", "yz","yzw"): # ماضي فقط
                all=True;
                future=True;
                past=True;
                imperative=True;
                confirmed=True;
                future_moode=True;
                passive=False;
                if verb_cat in ("x","Sx"):
                    unthink_trans=True;
                elif verb_cat in ("yw", "ywz", "yy", "yz","yzw", "Ry"):
                    think_trans=True;
                    if verb_cat in ("ywz","yz","yzw"):
                        double_trans=True;
                    if verb_cat in ("ywz", "yw", "yzw"):
                        reflexive_trans=True;                                   
            else:
                all=True;
            nb_trans=0;
            object_type=u"----"
            reflexive_type=u"----";
            if transitive:
                transitive=u'متعد'
                nb_trans=1;
                if double_trans: 
                    nb_trans=2;
                if think_trans: 
                    object_type=u"عاقل";
                if unthink_trans: 
                    object_type=u"غيرع";
                if reflexive_trans: 
                    reflexive_type=u"فلبي";
            else: 
                transitive=u'لازم'
        ##    codify the tense;
            tenses = self.encode_tense(all, past, future, imperative, passive, future_moode, confirmed)

    ##          print ('\t'.join([word,future_type,str(transitive)])).encode('utf8');

            nb_case=0;
            suggest=u"";
            triliteral=u"غيرثل"
            if is_triliteral_verb(word):
                triliteral=u"ثلاثي"
            if False:
        # search the future haraka for the triliteral verb
                liste_verb = find_alltriverb(word, araby.FATHA,True);
        # if there are more verb forms, select the first one
                filtered = [item for item in liste_verb if item['verb'] == word]
                if filtered:
                    #~ word = liste_verb[0]["verb"]
                    haraka = filtered[0]["haraka"]
                    future_type = haraka;
                    transitive_mark = filtered[0]["transitive"].strip();
                    if transitive_mark in (u"م",u"ك"):
                        transitive = u"متعد"
                    else:
                        transitive = u"لازم"
                else:
                    return {"text":u"#gen_verb_dict: %s error no tri verb"%word}
                if  liste_verb:                        
                    if len(liste_verb)>1: 
                        #suggest=u"هل تقصد؟<br/>"
                        nb_case = len(liste_verb);
        # the other forms are suggested
                    for i in range(1,len(liste_verb)):
                        suggested_word = liste_verb[i]["verb"]
                        suggested_haraka = liste_verb[i]["haraka"]
                        suggested_transitive = liste_verb[i]["transitive"]
                        future_form = get_future_form(suggested_word,suggested_haraka);
                        suggest=u"\t".join([suggest,suggested_word,u"["+suggested_haraka+u"]"]);
                else:suggest="-"
            verb_dict = {'nb_case': str(nb_case), 
                 'word': word, 
                 'tenses': tenses, 
                 'nb_trans': nb_trans, 
                 'suggest': suggest, 
                 'triliteral': triliteral, 
                 'object_type': object_type, 
                 'verb_cat': verb_cat, 
                 'future_type': future_type, 
                 'model': model, 
                 'transitive': transitive, 
                 'root': root, 
                 'reflexive_type': reflexive_type, 
                 }
            return verb_dict
Beispiel #12
0
    def add_record(self, verb_row):
        """
        Add a new to the dict
        """
        self.id += 1
        v = self.treat_tuple(verb_row)
        line = ""

        # display fields to ensure corectness
        VERIFY_INPUT = False
        #~ VERIFY_INPUT =  True;
        if VERIFY_INPUT:
            self.test_entry(v)

        # conjugate the verb with speling tags
        if not valid.is_valid_infinitive_verb(v['vocalized']):
            line += u"#\t\tis invalid verb\n", v['vocalized'].encode("utf8")
        else:
            future_type = v_ar.get_future_type_entree(v['future_type'])
            conjugTable = msrif.do_sarf(v['vocalized'], v['future_type'],
                                        v['all'], v['past'], v['future'],
                                        v['passive'], v['imperative'],
                                        v['future_moode'], v['confirmed'],
                                        v['transitive'], "DICT")
            TableEntries = {}
            if conjugTable:
                TableEntries = {}

                for tense in conjugTable.keys():
                    for pronoun in conjugTable[tense].keys():
                        if pronoun != const.PronounAntuma_f:

                            flags = svconst.TabPrefixes[tense]['full']

                            # the passive tenses dont take object suffix, only with double transitie verbs
                            if (v['transitive']
                                    and tense in const.TableIndicativeTense
                                ) or v['double_trans']:  #:

                                # add flags for suffixes
                                if v['think_trans'] and v['reflexive_trans']:
                                    flags += svconst.TabSuffixesPronominale[
                                        pronoun]['full']
                                else:
                                    flags += svconst.TabSuffixes[pronoun][
                                        'full']

                                #   add flag yeh for the الأفعال الخمسة
                                if tense == const.TenseFuture and pronoun in (
                                        const.PronounAnti, const.PronounAntuma,
                                        const.PronounAntuma_f,
                                        const.PronounAntum, const.PronounHuma,
                                        const.PronounHuma_f, const.PronounHum):
                                    flags += u"Ha"

                            # add double object suffixe, if the verb is double transitive, and the tense is indicative
                            if v['double_trans'] and tense in const.TableIndicativeTense:

                                # add flags for suffixes (double object)
                                flags += svconst.TabDisplayTagDouble[pronoun][
                                    'full']

                            #add an entree to the table entrie
                            # this allows to reduce many cases into one entree
                            word_nm = araby.strip_tashkeel(
                                conjugTable[tense][pronoun])
                            if TableEntries.has_key(word_nm):
                                TableEntries[word_nm] += flags
                            else:
                                TableEntries[word_nm] = flags
                            #print (u'%s/%s\t%s%s'%(ar_strip_marks(conjugTable[tense][pronoun]), flags, word,verb_cat)).encode('utf8');
                # print element from the TableEntries
                for key in TableEntries.keys():
                    if key != "":
                        line += u'%s/%s\n' % (
                            key, vspell.unify_flags(TableEntries[key]))

        return line