def test_suprasegmental_cluster_creation_illegal(self): bfm1 = BinaryFeaturesModel() bfm2 = BinaryFeaturesModel() character1 = BaseCharacter(bfm1, 'a') character3 = SuprasegmentalCharacter(bfm1, 'b') character4 = SuprasegmentalCharacter(bfm2, 'c') nf1 = NormalisedForm('{}{}'.format(SNFM, HAS_FEATURE)) # A SuprasegmentalCluster must be initialised with at least # one suprasegmental character or a normalised form. self.assertRaises(IllegalArgumentError, SuprasegmentalCluster, bfm1) # A SuprasegmentalCluster must not be initialised with both # suprasegmental characters and a normalised form. self.assertRaises(IllegalArgumentError, SuprasegmentalCluster, bfm1, suprasegmental_characters=[character3], normalised_form=nf1) # All of the characters in a cluster must be associated with # the same binary features model. self.assertRaises(MismatchedModelsError, SuprasegmentalCluster, bfm1, suprasegmental_characters=[character4]) # All of the characters in a cluster must be suprasegmental. self.assertRaises(MismatchedTypesError, SuprasegmentalCluster, bfm1, suprasegmental_characters=[character1, character3])
def test_base_cluster_creation_illegal(self): bfm1 = BinaryFeaturesModel() bfm2 = BinaryFeaturesModel() character1 = BaseCharacter(bfm1, 'a') character2 = DiacriticCharacter(bfm2, 'b') character3 = DiacriticCharacter(bfm1, 'd') character4 = SpacingCharacter(bfm1, 'e') nf1 = NormalisedForm('{}{}'.format(BNFM, HAS_FEATURE)) # A BaseCluster must be initialised with either a base # character or a normalised form. self.assertRaises(IllegalArgumentError, BaseCluster, bfm1) # A BaseCluster must not be initialised with both a normalised # form and any other argument. self.assertRaises(IllegalArgumentError, BaseCluster, bfm1, base_character=character1, normalised_form=nf1) self.assertRaises(IllegalArgumentError, BaseCluster, bfm1, diacritic_characters=[character3], normalised_form=nf1) self.assertRaises(IllegalArgumentError, BaseCluster, bfm1, spacing_characters=[character4], normalised_form=nf1) # All of the characters in a BaseCluster must be associated with # the same binary features model. self.assertRaises(MismatchedModelsError, BaseCluster, bfm1, base_character=character1, diacritic_characters=[character2]) # A BaseCluster expects specific types of characters in its # arguments. self.assertRaises(MismatchedTypesError, BaseCluster, bfm1, base_character=character3) self.assertRaises(MismatchedTypesError, BaseCluster, bfm1, base_character=character1, diacritic_characters=[character4]) self.assertRaises(MismatchedTypesError, BaseCluster, bfm1, base_character=character1, spacing_characters=[character3])
def test_feature_value_illegal(self): # The Feature must belong to the same BinaryFeaturesModel as # the Character. character = SuprasegmentalCharacter(self.bfm, 'a') bfm2 = BinaryFeaturesModel() feature1 = SuprasegmentalFeature(bfm2, 'voiced') self.assertRaises(MismatchedModelsError, character.get_feature_value, feature1) self.assertRaises(MismatchedModelsError, character.set_feature_value, feature1, HAS_FEATURE) # The Feature's type (subclass) must be appropriate to the # type (subclass) of the Character. feature2 = BaseFeature(self.bfm, 'stressed') self.assertRaises(MismatchedTypesError, character.get_feature_value, feature2) self.assertRaises(MismatchedTypesError, character.set_feature_value, feature2, HAS_FEATURE) # A SuprasegmentalCharacter must have a feature value for all # SuprasegmentalFeatures. feature3 = SuprasegmentalFeature(self.bfm, 'syllabic') self.assertRaises(InvalidCharacterError, character.get_feature_value, feature3) # Only certain values are permitted. self.assertRaises(IllegalArgumentError, character.set_feature_value, feature3, True)
def test_object_caching(self): # Creating a Feature with the same name as an existing # Feature must return the existing Feature, if both are # associated with the same BinaryFeaturesModel. feature1 = BaseFeature(self.bfm, 'voiced') feature2 = BaseFeature(self.bfm, 'voiced') self.assertEqual(feature1, feature2) feature3 = BaseFeature(self.bfm, 'consonantal') self.assertNotEqual(feature1, feature3) bfm2 = BinaryFeaturesModel() feature4 = BaseFeature(bfm2, 'voiced') self.assertNotEqual(feature1, feature4) # It is an error to create a Feature with the same IPA form # but of a different type (subclass). self.assertRaises(InvalidFeatureError, SuprasegmentalFeature, self.bfm, 'voiced') # Initialisation of a Feature should happen only once. character1 = BaseCharacter(self.bfm, 'a') character1.set_feature_value(feature1, HAS_FEATURE) self.assertEqual(feature1.get_value_characters(HAS_FEATURE), set([character1])) feature5 = BaseFeature(self.bfm, 'voiced') self.assertEqual(feature1.get_value_characters(HAS_FEATURE), set([character1])) feature6 = SuprasegmentalFeature(self.bfm, 'syllabic') character2 = SuprasegmentalCharacter(self.bfm, 'b') character2.set_feature_value(feature6, HAS_FEATURE) self.assertEqual(feature6.get_value_characters(HAS_FEATURE), set([character2])) feature7 = SuprasegmentalFeature(self.bfm, 'syllabic') self.assertEqual(feature6.get_value_characters(HAS_FEATURE), set([character2]))
def setUp (self): self.bfm = BinaryFeaturesModel() self.anterior = BaseFeature(self.bfm, 'anterior') self.back = BaseFeature(self.bfm, 'back') self.coronal = BaseFeature(self.bfm, 'coronal') self.long = BaseFeature(self.bfm, 'long') self.voiced = BaseFeature(self.bfm, 'voiced')
def _populate_binary_features_model(self): self.bfm = BinaryFeaturesModel() self.anterior = BaseFeature(self.bfm, 'anterior') self.back = BaseFeature(self.bfm, 'back') self.coronal = BaseFeature(self.bfm, 'coronal') self.long = BaseFeature(self.bfm, 'long') self.voiced = BaseFeature(self.bfm, 'voiced') self.p = BaseCharacter(self.bfm, 'p') self.p.set_feature_value(self.anterior, HAS_FEATURE) self.p.set_feature_value(self.back, NOT_HAS_FEATURE) self.p.set_feature_value(self.coronal, NOT_HAS_FEATURE) self.p.set_feature_value(self.long, NOT_HAS_FEATURE) self.p.set_feature_value(self.voiced, NOT_HAS_FEATURE) self.b = BaseCharacter(self.bfm, 'b') self.b.set_feature_value(self.anterior, HAS_FEATURE) self.b.set_feature_value(self.back, NOT_HAS_FEATURE) self.b.set_feature_value(self.coronal, NOT_HAS_FEATURE) self.b.set_feature_value(self.long, NOT_HAS_FEATURE) self.b.set_feature_value(self.voiced, HAS_FEATURE) self.t = BaseCharacter(self.bfm, 't') self.t.set_feature_value(self.anterior, HAS_FEATURE) self.t.set_feature_value(self.back, NOT_HAS_FEATURE) self.t.set_feature_value(self.coronal, HAS_FEATURE) self.t.set_feature_value(self.long, NOT_HAS_FEATURE) self.t.set_feature_value(self.voiced, NOT_HAS_FEATURE) self.d = BaseCharacter(self.bfm, 'd') self.d.set_feature_value(self.anterior, HAS_FEATURE) self.d.set_feature_value(self.back, NOT_HAS_FEATURE) self.d.set_feature_value(self.coronal, HAS_FEATURE) self.d.set_feature_value(self.long, NOT_HAS_FEATURE) self.d.set_feature_value(self.voiced, HAS_FEATURE) self.q = BaseCharacter(self.bfm, 'q') self.q.set_feature_value(self.anterior, NOT_HAS_FEATURE) self.q.set_feature_value(self.back, HAS_FEATURE) self.q.set_feature_value(self.coronal, NOT_HAS_FEATURE) self.q.set_feature_value(self.long, NOT_HAS_FEATURE) self.q.set_feature_value(self.voiced, NOT_HAS_FEATURE) self.ring = DiacriticCharacter(self.bfm, '̥') self.ring.set_feature_value(self.anterior, INAPPLICABLE_FEATURE) self.ring.set_feature_value(self.back, INAPPLICABLE_FEATURE) self.ring.set_feature_value(self.coronal, INAPPLICABLE_FEATURE) self.ring.set_feature_value(self.long, INAPPLICABLE_FEATURE) self.ring.set_feature_value(self.voiced, NOT_HAS_FEATURE) self.caret = DiacriticCharacter(self.bfm, '̬') self.caret.set_feature_value(self.anterior, INAPPLICABLE_FEATURE) self.caret.set_feature_value(self.back, INAPPLICABLE_FEATURE) self.caret.set_feature_value(self.coronal, INAPPLICABLE_FEATURE) self.caret.set_feature_value(self.long, INAPPLICABLE_FEATURE) self.caret.set_feature_value(self.voiced, HAS_FEATURE) self.ː = SpacingCharacter(self.bfm, 'ː') self.ː.set_feature_value(self.anterior, INAPPLICABLE_FEATURE) self.ː.set_feature_value(self.back, INAPPLICABLE_FEATURE) self.ː.set_feature_value(self.coronal, INAPPLICABLE_FEATURE) self.ː.set_feature_value(self.long, HAS_FEATURE) self.ː.set_feature_value(self.voiced, INAPPLICABLE_FEATURE)
def setUp(self): self.bfm = BinaryFeaturesModel() self.phrase = SuprasegmentalFeature(self.bfm, 'phrase') self.stressed = SuprasegmentalFeature(self.bfm, 'stressed') self.syllabic = SuprasegmentalFeature(self.bfm, 'syllabic') self.a = SuprasegmentalCharacter(self.bfm, 'a') self.a.set_feature_value(self.phrase, HAS_FEATURE) self.a.set_feature_value(self.stressed, INAPPLICABLE_FEATURE) self.a.set_feature_value(self.syllabic, NOT_HAS_FEATURE) self.b = SuprasegmentalCharacter(self.bfm, 'b') self.b.set_feature_value(self.phrase, INAPPLICABLE_FEATURE) self.b.set_feature_value(self.stressed, NOT_HAS_FEATURE) self.b.set_feature_value(self.syllabic, INAPPLICABLE_FEATURE)
def test_normalised_form_cluster_creation(self): # Test that the correct subclass of Cluster is created from a # normalised form. bfm = BinaryFeaturesModel() feature1 = BaseFeature(bfm, 'anterior') feature2 = SuprasegmentalFeature(bfm, 'long') character1 = BaseCharacter(bfm, 'a') character1.set_feature_value(feature1, HAS_FEATURE) character2 = SuprasegmentalCharacter(bfm, 'b') character2.set_feature_value(feature2, HAS_FEATURE) nf1 = NormalisedForm('{}{}'.format(BNFM, HAS_FEATURE)) nf2 = NormalisedForm('{}{}'.format(SNFM, HAS_FEATURE)) cluster1 = Cluster(bfm, normalised_form=nf1) cluster2 = Cluster(bfm, normalised_form=nf2) self.assertTrue(isinstance(cluster1, BaseCluster)) self.assertTrue(isinstance(cluster2, SuprasegmentalCluster)) self.assertRaises(IllegalArgumentError, Cluster, '')
def test_object_caching(self): # Creating a Character with the same IPA form as an existing # Character must return the existing Character, if both are # associated with the same BinaryFeaturesModel. character1 = BaseCharacter(self.bfm, 'a') character2 = BaseCharacter(self.bfm, 'a') self.assertEqual(character1, character2) character3 = BaseCharacter(self.bfm, 'b') self.assertNotEqual(character1, character3) bfm2 = BinaryFeaturesModel() character4 = BaseCharacter(bfm2, 'a') self.assertNotEqual(character1, character4) # It is an error to create a Character with the same IPA form # but of a different type (subclass). self.assertRaises(InvalidCharacterError, DiacriticCharacter, self.bfm, 'a') # Initialising of the Character should happen only once. feature = BaseFeature(self.bfm, 'voiced') character1.set_feature_value(feature, HAS_FEATURE) self.assertEqual(character1.get_feature_value(feature), HAS_FEATURE) character5 = BaseCharacter(self.bfm, 'a') self.assertEqual(character1.get_feature_value(feature), HAS_FEATURE) character6 = DiacriticCharacter(self.bfm, 'c') character6.set_feature_value(feature, HAS_FEATURE) self.assertEqual(character6.get_feature_value(feature), HAS_FEATURE) character7 = DiacriticCharacter(self.bfm, 'c') self.assertEqual(character6.get_feature_value(feature), HAS_FEATURE) character8 = SpacingCharacter(self.bfm, 'd') character8.set_feature_value(feature, HAS_FEATURE) self.assertEqual(character8.get_feature_value(feature), HAS_FEATURE) character9 = SpacingCharacter(self.bfm, 'd') self.assertEqual(character8.get_feature_value(feature), HAS_FEATURE) character10 = SuprasegmentalCharacter(self.bfm, 'e') feature2 = SuprasegmentalFeature(self.bfm, 'syllabic') character10.set_feature_value(feature2, HAS_FEATURE) self.assertEqual(character10.get_feature_value(feature2), HAS_FEATURE) character11 = SuprasegmentalCharacter(self.bfm, 'e') self.assertEqual(character10.get_feature_value(feature2), HAS_FEATURE)
def setUp(self): self.bfm = BinaryFeaturesModel()
def setUp(self): super().setUp() self.binary_features_model = BinaryFeaturesModel() self.ruleset = Ruleset(self.binary_features_model)
def setUp(self): self.bfm = BinaryFeaturesModel() Character._cache = {}