<commit_before>import os
import shutil

from address_normalizer.deduping.storage.base import *

def cleanup_db_dir(config):
    db_dir = config['STORAGE_ROCKSDB_DIR']
    if config.get('CLEAN_DB_ON_START', False) and os.path.exists(db_dir):
        shutil.rmtree(db_dir)
    else:
        lock_path = os.path.join(db_dir, 'LOCK')
        if os.path.exists(lock_path):
            os.unlink()
    return db_dir

def db_from_config(config):
    storage_type = config.get('STORAGE', storage_types.NOP)

    if storage_type == storage_types.NOP:
        return NopStorage()
    elif storage_type == storage_types.LEVELDB:
        import address_normalizer.deduping.storage.level as level
        db_dir = cleaned_db_dir(config)
        return level.LevelDBNearDupeStorage(level.LevelDB(db_dir))
    elif storage_type == storage_types.ROCKSDB:
        import address_normalizer.deduping.storage.rocks as rocks
        import rocksdb
        db_dir = cleaned_db_dir(config)
        return rocks.RocksDBNearDupeStorage(rocksdb.RocksDB(db_dir, rocksdb.Options(create_if_missing=True)))<commit_msg>[fix] name<commit_after>import os
import shutil

from address_normalizer.deduping.storage.base import *

def cleanup_db_dir(config):
    db_dir = config['STORAGE_ROCKSDB_DIR']
    if config.get('CLEAN_DB_ON_START', False) and os.path.exists(db_dir):
        shutil.rmtree(db_dir)
    else:
        lock_path = os.path.join(db_dir, 'LOCK')
        if os.path.exists(lock_path):
            os.unlink()
    return db_dir

def db_from_config(config):
    storage_type = config.get('STORAGE', storage_types.NOP)

    if storage_type == storage_types.NOP:
        return NopStorage()
    elif storage_type == storage_types.LEVELDB:
        import address_normalizer.deduping.storage.level as level
        db_dir = cleanup_db_dir(config)
        return level.LevelDBNearDupeStorage(level.LevelDB(db_dir))
    elif storage_type == storage_types.ROCKSDB:
        import address_normalizer.deduping.storage.rocks as rocks
        import rocksdb
        db_dir = cleanup_db_dir(config)
        return rocks.RocksDBNearDupeStorage(rocksdb.RocksDB(db_dir, rocksdb.Options(create_if_missing=True)))
{'fraction_non_alphanumeric': 0.0928735632183908, 'fraction_numerical': 0.0, 'mean_word_length': 3.6495726495726495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2058063', 'n_tokens_mistral': 728, 'n_tokens_neox': 724, 'n_words': 122}