def test_iter(): key_sum = 0 val_sum = 0 h = PreshMap() for i in range(56, 24, -3): h[i] = i * 2 key_sum += i val_sum += i * 2 for key, value in h.items(): key_sum -= key val_sum -= value assert key_sum == 0 assert val_sum == 0
def test_resize(): h = PreshMap(4) h[4] = 12 for i in range(10, 100): value = int(i * (random.random() + 1)) h[i] = value assert h[4] == 12
def test(): logging.info("Starting") a = {} a = PreshMap() #a = judy.JudyIntObjectMap() #db = pickledb.load("pickledb.db", False) dict_size = 100000000 keys = np.random.randint(0, 1000000000000, dict_size) values = np.random.randint(0, 1000000000, dict_size).astype(np.float64) logging.info("Creating") a = IntFloatDict(keys, values) logging.info("Done") return #a = dict(zip(np.random.randint(0, 100000000000, dict_size), np.random.randint(0, 100000000000, dict_size))) for i in range(0, 10000): if i % 1000000 == 0: print(i) number = randint(0, 10000000000000) a[number] = randint(0, 3000000000) #db.set(str(number), randint(0, 3000000000)) #db.dump() logging.info("writing to file") with open("testdict.pckl", "wb") as f: pickle.dump(a, f, protocol=4) logging.info("Wrote to file")
def test_one_and_empty(): # See Issue #21 table = PreshMap() for i in range(100, 110): table[i] = i del table[i] assert table[0] == None
def test_insert(): h = PreshMap() assert h[1] is None h[1] = 5 assert h[1] == 5 h[2] = 6 assert h[1] == 5 assert h[2] == 6
def test_zero_key(): h = PreshMap() h[0] = 6 h[5] = 12 assert h[0] == 6 assert h[5] == 12 for i in range(500, 1000): h[i] = i * random.random() assert h[0] == 6 assert h[5] == 12
def main(): nlp = English(parser=False, tagger=False, entity=False) gazetteer = [u'M.I.A.', 'Shiny Happy People', 'James E. Jones'] example_text = u'The artist M.I.A. did a cover of Shiny Happy People. People is not an entity.' pattern_ids = PreshMap() max_length = 0 for pattern_str in gazetteer: pattern = nlp.tokenizer(pattern_str) bilou_tags = get_bilou(len(pattern)) for word, tag in zip(pattern, bilou_tags): lexeme = nlp.vocab[word.orth] lexeme.set_flag(tag, True) pattern_ids[hash_string(pattern.text)] = True max_length = max(max_length, len(pattern)) matcher = make_matcher(nlp.vocab, max_length) doc = nlp(example_text) matches = get_matches(matcher, pattern_ids, doc) merge_matches(doc, matches) for token in doc: print(token.text, token.ent_type_)
def test_zero_values(): table = PreshMap() table[10] = 0 assert table[10] == 0 assert table[11] is None