def test_basic_segment_properties(self): seg = Segment('') assert (str(seg) == '') assert (len(seg) == 0) assert (seg != 's') seg1 = Segment('a') seg2 = Segment('b') assert (seg1 < seg2) assert (seg1 <= seg2) assert (seg2 > seg1) assert (seg2 >= seg1)
def test_basic(self): corpus = Corpus('test') for w in self.basic_info: self.assertRaises(KeyError, corpus.find, w['spelling'], True) corpus.add_word(Word(**w)) self.assertEqual(corpus[w['spelling']], Word(**w)) self.assertEqual(corpus.find(w['spelling']), Word(**w)) self.assertTrue(w['spelling'] in corpus) self.assertEqual( corpus.inventory._data, { '#': Segment('#'), 'a': Segment('a'), 'b': Segment('b'), 'c': Segment('c'), 'd': Segment('d') })
def test_match_feature(self): for s, v in self.basic_info.items(): seg = Segment(s) seg.set_features(v) for feature, value in v.items(): for fv in ['+', '-']: if fv == value: self.assertTrue(seg.feature_match([fv + feature])) self.assertTrue(seg.feature_match(fv + feature)) else: self.assertTrue(not seg.feature_match([fv + feature]))
def test_match_feature(self): for s,v in self.basic_info.items(): seg = Segment(s) seg.set_features(v) for feature, value in v.items(): for fv in ['+','-']: if fv == value: self.assertTrue(seg.feature_match([fv+feature])) self.assertTrue(seg.feature_match(fv+feature)) else: self.assertTrue(not seg.feature_match([fv+feature]))
def test_no_syllabic_feature(): seg = Segment('') seg.set_features({'feature1':'+','feature2':'+'})
# ------------------------------------------------------------------# # TESTING # The following code will not be included in the actual PCT release, # and is here for the purposes of testing for the LIBR 559C project. # All testing is done with the Lemurian corpus - lemurian.corpus # ------------------------------------------------------------------# # Additional imports for testing purposes import pickle from corpustools.corpus.classes import Segment # Load the corpus corpus_path = "lemurian.corpus" with open(corpus_path, 'rb') as file: corpus_in = pickle.load(file) # Corpus information print("Corpus: ", corpus_in.name) print("Segments in the lemurian corpus: ", [seg for seg in corpus_in.inventory], "\n") # Informativity of a single segment print("Informativity for one segment:") print(get_informativity(corpus_in, Segment("m"), rounding=3), "\n") # Informativity for all segments in inventory print("Informativity for all segments in inventory:") output = all_informativity(corpus_in, rounding=4) for s in sorted(output.keys()): print(s, output[s]) #remove ROUNDING from output, since this is already handled in PCT's global settings
def test_no_syllabic_feature(): seg = Segment('') seg.set_features({'feature1': '+', 'feature2': '+'})
def test_no_features(): seg = Segment('')