コード例 #1
0
    def populate_verbal_conjugation(self, word, gramcats, conjugation_str):
        # check if word is a verb
        if conjugation_str and not word.is_verb:
            gramcats = [x.abbreviation for x in gramcats]
            self.errors.append({
                "word":
                word.term,
                "column":
                "F",
                "message":
                "only verbs can have verbal conjugation data (found {})".
                format(gramcats),
            })
            return

        raw_conjugations = [x.strip() for x in conjugation_str.split('//')]

        # check number of conjugations VS number of entries
        if len(word.clean_entries) < len(raw_conjugations):
            self.errors.append({
                "word":
                word.term,
                "column":
                "F",
                "message":
                "there are more conjugations '{}' than entries'{}'".format(
                    len(word.clean_entries), len(conjugation_str))
            })
            # invalid format, don't try to extract it!
            return

        for i, raw_conjugation in enumerate(raw_conjugations):
            if raw_conjugation:
                try:
                    validate_column_verb_conjugation(raw_conjugation)
                except ValidationError as e:
                    if not self.allow_partial:
                        self.errors.append({
                            "word": word.term,
                            "column": "F",
                            "message": str(e.message),
                        })
                    partial = True
                else:
                    partial = False
                # workaround issue 66 allow partial conjugations (or unformated data)
                if not partial or partial and self.allow_partial:
                    word.clean_entries[
                        i].clean_conjugation = VerbalConjugation(
                            raw=raw_conjugation)
コード例 #2
0
 def test_verb_linking_conjugation_model(self):
     value = """
         Los verbos capuzar y zabucar son regulares de la
         1ª conjugación. modelo. conjug. trobar (hallar)
         """
     clean_data = validate_column_verb_conjugation(value)
     self.assertIn('model', clean_data)
コード例 #3
0
 def test_bug_both_keywords(self):
     value = """
     acazegar (irregular) conjug.
     IND. pres. acaziego, acaziegas, acaziega, acazegamos, acazegaz, acaziegan;
     SUBJ. pres. acaziegue, acaziegues, acaziegue, acazeguemos, acazeguez, acazieguen;
     IMP. acaziega, acazegaz; INF. acazegar; GER. acazegando;
     PART. acazegato/a-acazegau/acazegada.
     El resto de los tiempos es regular. modelo. conjug. trobar (encontrar)
     """
     clean_data = validate_column_verb_conjugation(value)
     self.assertIn('model', clean_data)
     self.assertIn('model_word', clean_data)
コード例 #4
0
 def test_verb_conjugation_model(self):
     value = """
         Es verbo regular de la 2ª conjugación. conjug. IND. pres. bebo,
         bebes, bebe, bebemos, bebez, beben; pret. imp. bebeba,
         bebebas, bebeba, bebébanos, bebébaz, bebeban; pret. indef. bebié,
         bebiés, bebió, bebiemos, bebiez, bebioron; fut. beberé, beberás,
         beberá, beberemos, beberez, beberán; cond. beberba, beberbas,
         beberba, bebérbanos, bebérbaz, beberban; SUBJ. pres. beba, bebas,
         beba, bebamos, bebaz, beban; pret. imp. bebese, bebeses,
         bebese, bebésenos, bebésez, bebesen; IMP. bebe, bebez; INF. beber;
         GER. bebendo. PART. bebito/a.
         """
     clean_data = validate_column_verb_conjugation(value)
     self.assertIn('conjugation', clean_data)
コード例 #5
0
    def test_mood_and_tenses_keep_order(self):
        value = """
            conjug. IND. pres. tiengo, tiens/tienes, tiene/tien,
            tenemos, tenez, tienen; pret. imp. teneba, tenebas, teneba, tenébanos,
            tenébaz, teneban; pret. indef. tenié/tuve, teniés/tuves, tenió/tuvo,
            teniemos /túvenos, teniez/túvez, tenioron/tuvon; fut. tendré, tendrás,
            tendrá, tendremos, tendrez, tendrán; cond. tenerba, tenerbas, tenerba,
            tenérbanos, tenérbaz, tenerban; SUBJ. pres. tienga, tiengas, tienga,
            tiengamos/tengamos, tiengaz / tengaz, tiengan; pret. imp. tenese,
            teneses, tenese, tenésenos, tenésez, tenesen; IMP. tiene, tenez; INF.
            tener; GER. tenendo; PART. tenito/a.
        """
        conjugation_validator = VerbalConjugationValidator()

        clean_data = validate_column_verb_conjugation(value)
        conjugation = clean_data["conjugation"]
        self.assertEqual(list(conjugation.keys()), conjugation_validator.MOODS)

        for mood in conjugation_validator.MOODS:
            tenses = conjugation[mood]
            self.assertEqual(list(tenses.keys()),
                             conjugation_validator.MOOD_TENSES[mood])
コード例 #6
0
 def test_verb_conjugation_model2(self):
     value = """
         Verbo irregular. conjug. IND. pres. tiengo, tiens/tienes, tiene/tien,
         tenemos, tenez, tienen; pret. imp. teneba, tenebas, teneba, tenébanos,
         tenébaz, teneban; pret. indef. tenié/tuve, teniés/tuves, tenió/tuvo,
         teniemos /túvenos, teniez/túvez, tenioron/tuvon; fut. tendré, tendrás,
         tendrá, tendremos, tendrez, tendrán; cond. tenerba, tenerbas, tenerba,
         tenérbanos, tenérbaz, tenerban; SUBJ. pres. tienga, tiengas, tienga,
         tiengamos/tengamos, tiengaz / tengaz, tiengan; pret. imp. tenese,
         teneses, tenese, tenésenos, tenésez, tenesen; IMP. tiene, tenez; INF.
         tener; GER. tenendo; PART. tenito/a.
     """
     EXPECTED_RESULT = {
         'conjugation': {
             'IND.': {
                 'pres.': [
                     'tiengo', 'tiens/tienes', 'tiene/tien', 'tenemos',
                     'tenez', 'tienen'
                 ],
                 'pret. imp.': [
                     'teneba', 'tenebas', 'teneba', 'tenébanos', 'tenébaz',
                     'teneban'
                 ],
                 'pret. indef.': [
                     'tenié/tuve', 'teniés/tuves', 'tenió/tuvo',
                     'teniemos /túvenos', 'teniez/túvez', 'tenioron/tuvon'
                 ],
                 'fut.': [
                     'tendré', 'tendrás', 'tendrá', 'tendremos', 'tendrez',
                     'tendrán'
                 ],
                 'cond.': [
                     'tenerba', 'tenerbas', 'tenerba', 'tenérbanos',
                     'tenérbaz', 'tenerban'
                 ]
             },
             'SUBJ.': {
                 'pres.': [
                     'tienga', 'tiengas', 'tienga', 'tiengamos/tengamos',
                     'tiengaz / tengaz', 'tiengan'
                 ],
                 'pret. imp.': [
                     'tenese', 'teneses', 'tenese', 'tenésenos', 'tenésez',
                     'tenesen'
                 ]
             },
             'IMP.': {
                 '': ['tiene', 'tenez']
             },
             'INF.': {
                 '': ['tener']
             },
             'GER.': {
                 '': ['tenendo']
             },
             'PART.': {
                 '': ['tenito/a']
             }
         }
     }
     clean_data = validate_column_verb_conjugation(value)
     self.assertIn('conjugation', clean_data)
     self.assertDictEqual(clean_data, EXPECTED_RESULT)
コード例 #7
0
 def test_valid_reference_with_multiple_words(self):
     value = "modelo. conjug. caler (ser necesario)"
     clean_data = validate_column_verb_conjugation(value)
     self.assertIn('model', clean_data)
     self.assertIn('model_word', clean_data)