<commit_before>cimport ccygroonga

def init():
    return ccygroonga.grn_init()

cdef class Database:
    cdef ccygroonga.grn_ctx* _c_ctx
    cdef ccygroonga.grn_obj* _c_db

    def __cinit__(self, ccygroonga.grn_ctx* c_ctx, ccygroonga.grn_obj* c_db):
        self._c_ctx = c_ctx
        self._c_db = c_db

cdef class Context:
    cdef ccygroonga.grn_ctx* _c_ctx

    def __cinit__(self):
        self._c_ctx = ccygroonga.grn_ctx_open(0)

    def db_create(self, path):
        c_path = path.encode('UTF-8')
        c_db = ccygroonga.grn_db_create(self._c_ctx, c_path, NULL)
        return Database(self._c_ctx, c_db)

    def fin(self):
        return ccygroonga.grn_ctx_fin(self._c_ctx)

def fin():
    return ccygroonga.grn_fin()<commit_msg>Write a factory function to create a Database instance<commit_after>cimport ccygroonga

def init():
    return ccygroonga.grn_init()

def fin():
    return ccygroonga.grn_fin()

cdef new_database(ccygroonga.grn_ctx* c_ctx, ccygroonga.grn_obj* c_db):
    db = Database()
    db._c_ctx = c_ctx
    db._c_db = c_db

cdef class Database:
    cdef ccygroonga.grn_ctx* _c_ctx
    cdef ccygroonga.grn_obj* _c_db

cdef class Context:
    cdef ccygroonga.grn_ctx* _c_ctx

    def __cinit__(self):
        self._c_ctx = ccygroonga.grn_ctx_open(0)

    def db_create(self, path):
        c_path = path.encode('UTF-8')
        c_db = ccygroonga.grn_db_create(self._c_ctx, c_path, NULL)
        return new_database(self._c_ctx, c_db)

    def fin(self):
        return ccygroonga.grn_ctx_fin(self._c_ctx)
{'fraction_non_alphanumeric': 0.09641693811074918, 'fraction_numerical': 0.0026058631921824105, 'mean_word_length': 3.302521008403361, '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': '450857', 'n_tokens_mistral': 657, 'n_tokens_neox': 649, 'n_words': 118}