Esempio n. 1
0
 def decode_triverb(self, verb_table, limit):
     """ readlines from files """
     verb_list = []
     for fields in verb_table:
         if len(fields)  >= 4:
                                 #الفعل  الجذر   باب التصريف T   id
             vdict= {"verb": fields[0],
             "root":fields[1],
             "haraka":araby.name(get_future_type_entree(fields[2])),
             "transitive":fields[3],
             }
             verb_list.append(vdict)
     return verb_list
Esempio n. 2
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"))
Esempio n. 3
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")
Esempio n. 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")
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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