Example #1
0
 def test_get_random_substring_list(self):
     text = "Welcome to where time stands still"
     computed_list = get_random_substring_list(
         string=text,
         list_size=3,
         substring_size=6
     )
     self.assertEquals(len(computed_list), 3)
     self.assertEquals(len(computed_list[0]), 6)
     self.assertEquals(len(computed_list[1]), 6)
     self.assertEquals(len(computed_list[2]), 6)
     self.assertTrue(computed_list[0] in text)
     self.assertTrue(computed_list[1] in text)
     self.assertTrue(computed_list[2] in text)
Example #2
0
def load_dataset(fileprefix):
    dataset_filename = "%s_dataset_dict.pck" % fileprefix
    global dataset_dict
    global text

    print "Loading dataset..."
    if exists(dataset_filename):
        print "    Reading dataset from %s..." % dataset_filename
        dataset_dict = unpickle(dataset_filename)
    else:
        print "    Computing dataset..."
        dataset_dict = {}
        for i in xrange(1, 11):
            item_size = substring_size(i)
            dataset_dict[i] = get_random_substring_list(\
                text, LIST_SIZE, item_size)
        print "    Writing dataset to %s..." % dataset_filename
        picklefy(dataset_filename, dataset_dict)
        print "    Done."