<commit_before>import itertools as itt
import logging
import os
from datetime import datetime

import networkx as nx
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.orm.exc import NoResultFound

from . import defaults
from . import models
from .utils import parse_owl
from ..constants import PYBEL_DATA
from ..parser import language
from ..utils import download_url

log = logging.getLogger('pybel')

DEFAULT_DEFINITION_CACHE_NAME = 'definitions.db'
DEFAULT_CACHE_LOCATION = os.path.join(PYBEL_DATA, DEFAULT_DEFINITION_CACHE_NAME)

DEFAULT_BELNS_ENCODING = ''.join(sorted(language.value_map))

CREATION_DATE_FMT = '%Y-%m-%dT%H:%M:%S'
PUBLISHED_DATE_FMT = '%Y-%m-%d'


def parse_datetime(s):
    """Tries to parse a datetime object from a standard datetime format or date format"""
    try:
        dt = datetime.strptime(s, CREATION_DATE_FMT)
        return dt
    except:
        try:
            dt = datetime.strptime(s, PUBLISHED_DATE_FMT)
            return dt
        except:
            raise ValueError('Incorrect datetime format for {}'.format(s))


class BaseCacheManager:
    """Creates a connection to database and a persistient session using SQLAlchemy"""

    def __init__(self, connection=None, echo=False):
        self.connection = connection if connection is not None else 'sqlite:///' + DEFAULT_CACHE_LOCATION
        self.engine = create_engine(self.connection, echo=echo)
        self.sessionmaker = sessionmaker(bind=self.engine, autoflush=False, expire_on_commit=False)
        self.session = scoped_session(self.sessionmaker)()
        self.create_database()

    def create_database(self, checkfirst=True):<commit_msg>Ensure support for sketchy CHEBI namespace files<commit_after>import itertools as itt
import logging
import os
from datetime import datetime

import networkx as nx
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.orm.exc import NoResultFound

from . import defaults
from . import models
from .utils import parse_owl
from ..constants import PYBEL_DATA
from ..parser import language
from ..utils import download_url

log = logging.getLogger('pybel')

DEFAULT_DEFINITION_CACHE_NAME = 'definitions.db'
DEFAULT_CACHE_LOCATION = os.path.join(PYBEL_DATA, DEFAULT_DEFINITION_CACHE_NAME)

DEFAULT_BELNS_ENCODING = ''.join(sorted(language.value_map))

CREATION_DATE_FMT = '%Y-%m-%dT%H:%M:%S'
PUBLISHED_DATE_FMT = '%Y-%m-%d'
PUBLISHED_DATE_FMT_2 = '%d:%m:%Y %H:%M'


def parse_datetime(s):
    """Tries to parse a datetime object from a standard datetime format or date format"""
    try:
        dt = datetime.strptime(s, CREATION_DATE_FMT)
        return dt
    except:
        try:
            dt = datetime.strptime(s, PUBLISHED_DATE_FMT)
            return dt
        except:
            try:
                dt = datetime.strptime(s, PUBLISHED_DATE_FMT_2)
                return dt
            except:
               raise ValueError('Incorrect datetime format for {}'.format(s))


class BaseCacheManager:
    """Creates a connection to database and a persistient session using SQLAlchemy"""

    def __init__(self, connection=None, echo=False):
        self.connection = connection if connection is not None else 'sqlite:///' + DEFAULT_CACHE_LOCATION
        self.engine = create_engine(self.connection, echo=echo)
        self.sessionmaker = sessionmaker(bind=self.engine, autoflush=False, expire_on_commit=False)
        self.session = scoped_session(self.sessionmaker)()
        self.create_database()

    def create_database(self, checkfirst=True):
{'fraction_non_alphanumeric': 0.08746194298367008, 'fraction_numerical': 0.0005535566011624688, 'mean_word_length': 3.8380187416331997, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1974856', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1068, 'n_words': 295}