def test_normalised_form (self): feature1 = BaseFeature(self.bfm, 'anterior') character1 = DiacriticCharacter(self.bfm, 'a') character1.set_feature_value(feature1, HAS_FEATURE) self.assertEqual(character1.normalised_form, NormalisedForm( '{0}{1}'.format(BNFM, HAS_FEATURE))) # Adding a feature changes the normalised form. feature2 = BaseFeature(self.bfm, 'dental') character1.set_feature_value(feature2, INAPPLICABLE_FEATURE) self.assertEqual(character1.normalised_form, NormalisedForm( '{0}{1}{2}'.format(BNFM, HAS_FEATURE, INAPPLICABLE_FEATURE))) # The order of the normalised form feature values is # alphabetical by feature name. feature3 = BaseFeature(self.bfm, 'consonantal') character1.set_feature_value(feature3, NOT_HAS_FEATURE) self.assertEqual(character1.normalised_form, NormalisedForm( '{0}{1}{2}{3}'.format(BNFM, HAS_FEATURE, NOT_HAS_FEATURE, INAPPLICABLE_FEATURE))) # Renaming a feature may change the normalised form. feature1.name = 'vocalic' self.assertEqual(character1.normalised_form, NormalisedForm( '{0}{1}{2}{3}'.format(BNFM, NOT_HAS_FEATURE, INAPPLICABLE_FEATURE, HAS_FEATURE))) # Changing a feature value changes the normalised form. character1.set_feature_value(feature1, NOT_HAS_FEATURE) self.assertEqual(character1.normalised_form, NormalisedForm( '{0}{1}{2}{1}'.format(BNFM, NOT_HAS_FEATURE, INAPPLICABLE_FEATURE))) # Removing a feature value changes the normalised form. feature2.delete() self.assertEqual(character1.normalised_form, NormalisedForm( '{0}{1}{1}'.format(BNFM, NOT_HAS_FEATURE)))
def test_name(self): feature = BaseFeature(self.bfm, 'voiced') self.assertEqual(feature.name, 'voiced') # Feature names can be set. feature.name = 'vocalic' self.assertEqual(feature.name, 'vocalic') # Feature names must be unique across all features in a binary # features model. feature2 = SuprasegmentalFeature(self.bfm, 'consonantal') self.assertRaises(InvalidFeatureError, setattr, feature2, 'name', 'vocalic') # Setting the name to the existing name should not raise an error. feature2.name = 'consonantal' self.assertEqual(feature2.name, 'consonantal')
def test_name (self): feature = BaseFeature(self.bfm, 'voiced') self.assertEqual(feature.name, 'voiced') # Feature names can be set. feature.name = 'vocalic' self.assertEqual(feature.name, 'vocalic') # Feature names must be unique across all features in a binary # features model. feature2 = SuprasegmentalFeature(self.bfm, 'consonantal') self.assertRaises(InvalidFeatureError, setattr, feature2, 'name', 'vocalic') # Setting the name to the existing name should not raise an error. feature2.name = 'consonantal' self.assertEqual(feature2.name, 'consonantal')
def test_normalised_form(self): feature1 = BaseFeature(self.bfm, 'anterior') character1 = DiacriticCharacter(self.bfm, 'a') character1.set_feature_value(feature1, HAS_FEATURE) self.assertEqual(character1.normalised_form, NormalisedForm('{0}{1}'.format(BNFM, HAS_FEATURE))) # Adding a feature changes the normalised form. feature2 = BaseFeature(self.bfm, 'dental') character1.set_feature_value(feature2, INAPPLICABLE_FEATURE) self.assertEqual( character1.normalised_form, NormalisedForm('{0}{1}{2}'.format(BNFM, HAS_FEATURE, INAPPLICABLE_FEATURE))) # The order of the normalised form feature values is # alphabetical by feature name. feature3 = BaseFeature(self.bfm, 'consonantal') character1.set_feature_value(feature3, NOT_HAS_FEATURE) self.assertEqual( character1.normalised_form, NormalisedForm('{0}{1}{2}{3}'.format(BNFM, HAS_FEATURE, NOT_HAS_FEATURE, INAPPLICABLE_FEATURE))) # Renaming a feature may change the normalised form. feature1.name = 'vocalic' self.assertEqual( character1.normalised_form, NormalisedForm('{0}{1}{2}{3}'.format(BNFM, NOT_HAS_FEATURE, INAPPLICABLE_FEATURE, HAS_FEATURE))) # Changing a feature value changes the normalised form. character1.set_feature_value(feature1, NOT_HAS_FEATURE) self.assertEqual( character1.normalised_form, NormalisedForm('{0}{1}{2}{1}'.format(BNFM, NOT_HAS_FEATURE, INAPPLICABLE_FEATURE))) # Removing a feature value changes the normalised form. feature2.delete() self.assertEqual( character1.normalised_form, NormalisedForm('{0}{1}{1}'.format(BNFM, NOT_HAS_FEATURE)))
def test_normalised_form (self): feature1 = BaseFeature(self.bfm, 'anterior') character = BaseCharacter(self.bfm, 'n') character.set_feature_value(feature1, HAS_FEATURE) self.assertEqual(character.normalised_form, NormalisedForm( '{0}{1}'.format(BNFM, HAS_FEATURE))) # Adding a feature changes the normalised form. feature2 = BaseFeature(self.bfm, 'dental') # For a BaseCharacter, all features must have a value. self.assertRaises(InvalidCharacterError, getattr, character, 'normalised_form') character.set_feature_value(feature2, NOT_HAS_FEATURE) self.assertEqual(character.normalised_form, NormalisedForm( '{0}{1}{2}'.format(BNFM, HAS_FEATURE, NOT_HAS_FEATURE))) # The order of the normalised form feature values is # alphabetical by feature name. feature3 = BaseFeature(self.bfm, 'consonantal') character.set_feature_value(feature3, HAS_FEATURE) self.assertEqual(character.normalised_form, NormalisedForm( '{0}{1}{1}{2}'.format(BNFM, HAS_FEATURE, NOT_HAS_FEATURE))) # Renaming a feature may change the normalised form. feature3.name = 'vocalic' self.assertEqual(character.normalised_form, NormalisedForm( '{0}{1}{2}{1}'.format(BNFM, HAS_FEATURE, NOT_HAS_FEATURE))) # Changing a feature value changes the normalised form. character.set_feature_value(feature1, NOT_HAS_FEATURE) self.assertEqual(character.normalised_form, NormalisedForm( '{0}{2}{2}{1}'.format(BNFM, HAS_FEATURE, NOT_HAS_FEATURE))) # Removing a feature value changes the normalised form. feature3.delete() self.assertEqual(character.normalised_form, NormalisedForm( '{0}{1}{1}'.format(BNFM, NOT_HAS_FEATURE))) # Adding a feature of a different type does not change the # normalised form. feature4 = SuprasegmentalFeature(self.bfm, 'syllabic') self.assertEqual(character.normalised_form, NormalisedForm( '{0}{1}{1}'.format(BNFM, NOT_HAS_FEATURE)))