<commit_before>// LICENSE : MIT
"use strict";
import kuromoji from "kuromoji";
import path from "path";
import Deferred from "./Deferred";
const kuromojiDir = require.resolve("kuromoji");
const options = {dicPath: path.join(kuromojiDir, "../../dict") + "/"};
const deferred = new Deferred();
// cache for tokenizer
let _tokenizer = null;
// lock boolean
let isLoading = false;
export function getTokenizer() {
    if (_tokenizer) {
        return Promise.resolve(_tokenizer);
    }
    if (isLoading) {
        return deferred.promise;
    }
    isLoading = true;
    // load dict
    kuromoji.builder(options).build(function (err, tokenizer) {
        if (err) {
            return deferred.reject(err);
        }
        _tokenizer = tokenizer;
        deferred.resolve(tokenizer);
    });
    return deferred.promise;
}
export default function kuromojin(text) {
    return getTokenizer().then(tokenizer => {
        return tokenizer.tokenize(text);
    })
}<commit_msg>chore(src): export tokenize function<commit_after>// LICENSE : MIT
"use strict";
import kuromoji from "kuromoji";
import path from "path";
import Deferred from "./Deferred";
const kuromojiDir = require.resolve("kuromoji");
const options = {dicPath: path.join(kuromojiDir, "../../dict") + "/"};
const deferred = new Deferred();
// cache for tokenizer
let _tokenizer = null;
// lock boolean
let isLoading = false;
export function getTokenizer() {
    if (_tokenizer) {
        return Promise.resolve(_tokenizer);
    }
    if (isLoading) {
        return deferred.promise;
    }
    isLoading = true;
    // load dict
    kuromoji.builder(options).build(function (err, tokenizer) {
        if (err) {
            return deferred.reject(err);
        }
        _tokenizer = tokenizer;
        deferred.resolve(tokenizer);
    });
    return deferred.promise;
}
export function tokenize(text) {
    return getTokenizer().then(tokenizer => {
        return tokenizer.tokenize(text);
    })
}
export default tokenize;
{'fraction_non_alphanumeric': 0.13010590015128592, 'fraction_numerical': 0.0, 'mean_word_length': 3.048979591836735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6226681', 'n_tokens_mistral': 604, 'n_tokens_neox': 600, 'n_words': 155}