示例#1
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")
示例#2
0
def main():
    filename, all, future, past, passive, imperative, confirmed, future_moode, display_format = grabargs(
    )
    try:
        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("utf")
    #print line
    text = u""
    print text
    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 = do_sarf(word, future_type, all, past, future, passive,
                           imperative, future_moode, confirmed, transitive,
                           display_format)
            print text.encode("utf8")
示例#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")
示例#4
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
示例#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", 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