diff --git a/README.md b/README.md index af529146..4c966534 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Load this library as follows: You can prepare tokenizer like this: - kuromoji.builder({ dicPath: "path/to/dictionary/dir/" }).build(function (err, tokenizer) { + kuromoji.loader({ dic_path: "path/to/dictionary/dir/" }).load(function (err, tokenizer) { // tokenizer is ready var path = tokenizer.tokenize("すもももももももものうち"); console.log(path); @@ -71,7 +71,7 @@ In your HTML: In your JavaScript: - kuromoji.builder({ dicPath: "/url/to/dictionary/dir/" }).build(function (err, tokenizer) { + kuromoji.loader({ dic_path: "/url/to/dictionary/dir/" }).load(function (err, tokenizer) { // tokenizer is ready var path = tokenizer.tokenize("すもももももももものうち"); console.log(path); diff --git a/build/kuromoji.js b/build/kuromoji.js index f0f4ae91..b350760f 100644 --- a/build/kuromoji.js +++ b/build/kuromoji.js @@ -6963,64 +6963,7 @@ Tokenizer.prototype.getLattice = function (text) { module.exports = Tokenizer; -},{"./util/IpadicFormatter":22,"./viterbi/ViterbiBuilder":24,"./viterbi/ViterbiSearcher":27}],7:[function(require,module,exports){ -/* - * Copyright 2014 Takuya Asano - * Copyright 2010-2014 Atilika Inc. and contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -"use strict"; - -var Tokenizer = require("./Tokenizer"); -var DictionaryLoader = require("./loader/NodeDictionaryLoader"); - -/** - * TokenizerBuilder create Tokenizer instance. - * @param {Object} option JSON object which have key-value pairs settings - * @param {string} option.dicPath Dictionary directory path (or URL using in browser) - * @constructor - */ -function TokenizerBuilder(option) { - if (option.dicPath == null) { - this.dic_path = "dict/"; - } else { - this.dic_path = option.dicPath; - } -} - -/** - * Build Tokenizer instance by asynchronous manner - * @param {TokenizerBuilder~onLoad} callback Callback function - */ -TokenizerBuilder.prototype.build = function (callback) { - var loader = new DictionaryLoader(this.dic_path); - loader.load(function (err, dic) { - callback(err, new Tokenizer(dic)); - }); -}; - -/** - * Callback used by build - * @callback TokenizerBuilder~onLoad - * @param {Object} err Error object - * @param {Tokenizer} tokenizer Prepared Tokenizer - */ - -module.exports = TokenizerBuilder; - -},{"./Tokenizer":6,"./loader/NodeDictionaryLoader":19}],8:[function(require,module,exports){ +},{"./util/IpadicFormatter":21,"./viterbi/ViterbiBuilder":23,"./viterbi/ViterbiSearcher":26}],7:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7059,7 +7002,7 @@ function CharacterClass(class_id, class_name, is_always_invoke, is_grouping, max module.exports = CharacterClass; -},{}],9:[function(require,module,exports){ +},{}],8:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7266,7 +7209,7 @@ CharacterDefinition.prototype.lookup = function (ch) { module.exports = CharacterDefinition; -},{"../util/SurrogateAwareString":23,"./CharacterClass":8,"./InvokeDefinitionMap":12}],10:[function(require,module,exports){ +},{"../util/SurrogateAwareString":22,"./CharacterClass":7,"./InvokeDefinitionMap":11}],9:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7327,7 +7270,7 @@ ConnectionCosts.prototype.loadConnectionCosts = function (connection_costs_buffe module.exports = ConnectionCosts; -},{}],11:[function(require,module,exports){ +},{}],10:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7411,7 +7354,7 @@ DynamicDictionaries.prototype.loadUnknownDictionaries = function (unk_buffer, un module.exports = DynamicDictionaries; -},{"./ConnectionCosts":10,"./TokenInfoDictionary":13,"./UnknownDictionary":14,"doublearray":2}],12:[function(require,module,exports){ +},{"./ConnectionCosts":9,"./TokenInfoDictionary":12,"./UnknownDictionary":13,"doublearray":2}],11:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7523,7 +7466,7 @@ InvokeDefinitionMap.prototype.toBuffer = function () { module.exports = InvokeDefinitionMap; -},{"../util/ByteBuffer":21,"./CharacterClass":8}],13:[function(require,module,exports){ +},{"../util/ByteBuffer":20,"./CharacterClass":7}],12:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7677,7 +7620,7 @@ TokenInfoDictionary.prototype.getFeatures = function (token_info_id_str) { module.exports = TokenInfoDictionary; -},{"../util/ByteBuffer":21}],14:[function(require,module,exports){ +},{"../util/ByteBuffer":20}],13:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7737,7 +7680,7 @@ UnknownDictionary.prototype.loadUnknownDictionaries = function (unk_buffer, unk_ module.exports = UnknownDictionary; -},{"../util/ByteBuffer":21,"./CharacterDefinition":9,"./TokenInfoDictionary":13}],15:[function(require,module,exports){ +},{"../util/ByteBuffer":20,"./CharacterDefinition":8,"./TokenInfoDictionary":12}],14:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7807,7 +7750,7 @@ CharacterDefinitionBuilder.prototype.build = function () { module.exports = CharacterDefinitionBuilder; -},{"../CharacterDefinition":9,"../InvokeDefinitionMap":12}],16:[function(require,module,exports){ +},{"../CharacterDefinition":8,"../InvokeDefinitionMap":11}],15:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7879,7 +7822,7 @@ ConnectionCostsBuilder.prototype.build = function () { module.exports = ConnectionCostsBuilder; -},{"../ConnectionCosts":10}],17:[function(require,module,exports){ +},{"../ConnectionCosts":9}],16:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8039,7 +7982,7 @@ DictionaryBuilder.prototype.buildDoubleArray = function () { module.exports = DictionaryBuilder; -},{"../DynamicDictionaries":11,"../TokenInfoDictionary":13,"../UnknownDictionary":14,"./CharacterDefinitionBuilder":15,"./ConnectionCostsBuilder":16,"doublearray":2}],18:[function(require,module,exports){ +},{"../DynamicDictionaries":10,"../TokenInfoDictionary":12,"../UnknownDictionary":13,"./CharacterDefinitionBuilder":14,"./ConnectionCostsBuilder":15,"doublearray":2}],17:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8059,22 +8002,22 @@ module.exports = DictionaryBuilder; "use strict"; -var TokenizerBuilder = require("./TokenizerBuilder"); var DictionaryBuilder = require("./dict/builder/DictionaryBuilder"); +var DictionaryLoader = require("./loader/NodeDictionaryLoader"); // Public methods var kuromoji = { - builder: function (option) { - return new TokenizerBuilder(option); + loader: function (options) { + return new DictionaryLoader(options); }, - dictionaryBuilder: function () { + builder: function () { return new DictionaryBuilder(); } }; module.exports = kuromoji; -},{"./TokenizerBuilder":7,"./dict/builder/DictionaryBuilder":17}],19:[function(require,module,exports){ +},{"./dict/builder/DictionaryBuilder":16,"./loader/NodeDictionaryLoader":18}],18:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8099,11 +8042,11 @@ var DictionaryLoader = require("./DictionaryLoader"); /** * BrowserDictionaryLoader inherits DictionaryLoader, using jQuery XHR for download - * @param {string} dic_path Dictionary path + * @param {object} options Options for the dictionary * @constructor */ -function BrowserDictionaryLoader(dic_path) { - DictionaryLoader.apply(this, [dic_path]); +function BrowserDictionaryLoader(options) { + DictionaryLoader.call(this, options); } BrowserDictionaryLoader.prototype = Object.create(DictionaryLoader.prototype); @@ -8114,6 +8057,7 @@ BrowserDictionaryLoader.prototype = Object.create(DictionaryLoader.prototype); * @param {BrowserDictionaryLoader~onLoad} callback Callback function */ BrowserDictionaryLoader.prototype.loadArrayBuffer = function (url, callback) { + // Check if we have it cached var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.responseType = "arraybuffer"; @@ -8143,7 +8087,7 @@ BrowserDictionaryLoader.prototype.loadArrayBuffer = function (url, callback) { module.exports = BrowserDictionaryLoader; -},{"./DictionaryLoader":20,"zlibjs/bin/gunzip.min.js":5}],20:[function(require,module,exports){ +},{"./DictionaryLoader":19,"zlibjs/bin/gunzip.min.js":5}],19:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8166,15 +8110,16 @@ module.exports = BrowserDictionaryLoader; var path = require("path"); var async = require("async"); var DynamicDictionaries = require("../dict/DynamicDictionaries"); +var Tokenizer = require("../Tokenizer"); /** * DictionaryLoader base constructor * @param {string} dic_path Dictionary path * @constructor */ -function DictionaryLoader(dic_path) { +function DictionaryLoader(options) { this.dic = new DynamicDictionaries(); - this.dic_path = dic_path; + this.dic_path = options.dic_path || 'dict/'; } DictionaryLoader.prototype.loadArrayBuffer = function (file, callback) { @@ -8269,7 +8214,7 @@ DictionaryLoader.prototype.load = function (load_callback) { }); } ], function (err) { - load_callback(err, dic); + load_callback(err, new Tokenizer(dic)); }); }; @@ -8282,7 +8227,7 @@ DictionaryLoader.prototype.load = function (load_callback) { module.exports = DictionaryLoader; -},{"../dict/DynamicDictionaries":11,"async":1,"path":3}],21:[function(require,module,exports){ +},{"../Tokenizer":6,"../dict/DynamicDictionaries":10,"async":1,"path":3}],20:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8573,7 +8518,7 @@ ByteBuffer.prototype.getString = function (index) { module.exports = ByteBuffer; -},{}],22:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8642,7 +8587,7 @@ IpadicFormatter.prototype.formatUnknownEntry = function (word_id, position, type module.exports = IpadicFormatter; -},{}],23:[function(require,module,exports){ +},{}],22:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8735,7 +8680,7 @@ SurrogateAwareString.isSurrogatePair = function (ch) { module.exports = SurrogateAwareString; -},{}],24:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8838,7 +8783,7 @@ ViterbiBuilder.prototype.build = function (sentence_str) { module.exports = ViterbiBuilder; -},{"../util/SurrogateAwareString":23,"./ViterbiLattice":25,"./ViterbiNode":26}],25:[function(require,module,exports){ +},{"../util/SurrogateAwareString":22,"./ViterbiLattice":24,"./ViterbiNode":25}],24:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8900,7 +8845,7 @@ ViterbiLattice.prototype.appendEos = function () { module.exports = ViterbiLattice; -},{"./ViterbiNode":26}],26:[function(require,module,exports){ +},{"./ViterbiNode":25}],25:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8951,7 +8896,7 @@ function ViterbiNode(node_name, node_cost, start_pos, length, type, left_id, rig module.exports = ViterbiNode; -},{}],27:[function(require,module,exports){ +},{}],26:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -9055,5 +9000,5 @@ ViterbiSearcher.prototype.backward = function (lattice) { module.exports = ViterbiSearcher; -},{}]},{},[18])(18) +},{}]},{},[17])(17) }); diff --git a/demo/js/tokenize.js b/demo/js/tokenize.js index 4f700683..7ba0e231 100644 --- a/demo/js/tokenize.js +++ b/demo/js/tokenize.js @@ -71,7 +71,7 @@ vm.$watch("inputText", function (value) { // Load and prepare tokenizer -kuromoji.builder({ dicPath: DIC_URL }).build(function (error, _tokenizer) { +kuromoji.loader({ dic_path: DIC_URL }).load(function (error, _tokenizer) { if (error != null) { console.log(error); } @@ -168,4 +168,4 @@ function drawLattice () { .rankDir("LR"); renderer.layout(layout).run(g, d3.select("svg g")); } -*/ \ No newline at end of file +*/ diff --git a/example/load-node.js b/example/load-node.js index 4174ecb7..fa39bdbb 100644 --- a/example/load-node.js +++ b/example/load-node.js @@ -21,7 +21,7 @@ var kuromoji = require("../src/kuromoji"); var DIC_DIR = "dict/"; // Load dictionaries from file, and prepare tokenizer -kuromoji.builder({ dicPath: DIC_DIR }).build(function (error, tokenizer) { +kuromoji.loader({ dic_path: DIC_DIR }).load(function (error, tokenizer) { var path = tokenizer.tokenize("すもももももももものうち"); console.log(path); module.exports = tokenizer; diff --git a/gulpfile.js b/gulpfile.js index 2cafe4a3..a731eae9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -66,7 +66,7 @@ gulp.task("create-dat-files", (done) => { } const dic = new IPADic(); - const builder = kuromoji.dictionaryBuilder(); + const builder = kuromoji.builder(); // Build token info dictionary const tokenInfoPromise = dic.readTokenInfo((line) => { diff --git a/src/TokenizerBuilder.js b/src/TokenizerBuilder.js deleted file mode 100644 index 9ef5c6a2..00000000 --- a/src/TokenizerBuilder.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014 Takuya Asano - * Copyright 2010-2014 Atilika Inc. and contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -"use strict"; - -var Tokenizer = require("./Tokenizer"); -var DictionaryLoader = require("./loader/NodeDictionaryLoader"); - -/** - * TokenizerBuilder create Tokenizer instance. - * @param {Object} option JSON object which have key-value pairs settings - * @param {string} option.dicPath Dictionary directory path (or URL using in browser) - * @constructor - */ -function TokenizerBuilder(option) { - if (option.dicPath == null) { - this.dic_path = "dict/"; - } else { - this.dic_path = option.dicPath; - } -} - -/** - * Build Tokenizer instance by asynchronous manner - * @param {TokenizerBuilder~onLoad} callback Callback function - */ -TokenizerBuilder.prototype.build = function (callback) { - var loader = new DictionaryLoader(this.dic_path); - loader.load(function (err, dic) { - callback(err, new Tokenizer(dic)); - }); -}; - -/** - * Callback used by build - * @callback TokenizerBuilder~onLoad - * @param {Object} err Error object - * @param {Tokenizer} tokenizer Prepared Tokenizer - */ - -module.exports = TokenizerBuilder; diff --git a/src/kuromoji.js b/src/kuromoji.js index 4820d23e..c695bda9 100644 --- a/src/kuromoji.js +++ b/src/kuromoji.js @@ -17,15 +17,15 @@ "use strict"; -var TokenizerBuilder = require("./TokenizerBuilder"); var DictionaryBuilder = require("./dict/builder/DictionaryBuilder"); +var DictionaryLoader = require("./loader/NodeDictionaryLoader"); // Public methods var kuromoji = { - builder: function (option) { - return new TokenizerBuilder(option); + loader: function (options) { + return new DictionaryLoader(options); }, - dictionaryBuilder: function () { + builder: function () { return new DictionaryBuilder(); } }; diff --git a/src/loader/BrowserDictionaryLoader.js b/src/loader/BrowserDictionaryLoader.js index 04bfdcd1..4cb180b4 100644 --- a/src/loader/BrowserDictionaryLoader.js +++ b/src/loader/BrowserDictionaryLoader.js @@ -22,11 +22,11 @@ var DictionaryLoader = require("./DictionaryLoader"); /** * BrowserDictionaryLoader inherits DictionaryLoader, using jQuery XHR for download - * @param {string} dic_path Dictionary path + * @param {object} options Options for the dictionary * @constructor */ -function BrowserDictionaryLoader(dic_path) { - DictionaryLoader.apply(this, [dic_path]); +function BrowserDictionaryLoader(options) { + DictionaryLoader.call(this, options); } BrowserDictionaryLoader.prototype = Object.create(DictionaryLoader.prototype); @@ -37,6 +37,7 @@ BrowserDictionaryLoader.prototype = Object.create(DictionaryLoader.prototype); * @param {BrowserDictionaryLoader~onLoad} callback Callback function */ BrowserDictionaryLoader.prototype.loadArrayBuffer = function (url, callback) { + // Check if we have it cached var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.responseType = "arraybuffer"; diff --git a/src/loader/DictionaryLoader.js b/src/loader/DictionaryLoader.js index 5f88c0b7..d1156b46 100644 --- a/src/loader/DictionaryLoader.js +++ b/src/loader/DictionaryLoader.js @@ -20,15 +20,16 @@ var path = require("path"); var async = require("async"); var DynamicDictionaries = require("../dict/DynamicDictionaries"); +var Tokenizer = require("../Tokenizer"); /** * DictionaryLoader base constructor * @param {string} dic_path Dictionary path * @constructor */ -function DictionaryLoader(dic_path) { +function DictionaryLoader(options) { this.dic = new DynamicDictionaries(); - this.dic_path = dic_path; + this.dic_path = options.dic_path || 'dict/'; } DictionaryLoader.prototype.loadArrayBuffer = function (file, callback) { @@ -123,7 +124,7 @@ DictionaryLoader.prototype.load = function (load_callback) { }); } ], function (err) { - load_callback(err, dic); + load_callback(err, new Tokenizer(dic)); }); }; diff --git a/src/loader/NodeDictionaryLoader.js b/src/loader/NodeDictionaryLoader.js index 26eb7924..20eef35e 100644 --- a/src/loader/NodeDictionaryLoader.js +++ b/src/loader/NodeDictionaryLoader.js @@ -23,11 +23,11 @@ var DictionaryLoader = require("./DictionaryLoader"); /** * NodeDictionaryLoader inherits DictionaryLoader - * @param {string} dic_path Dictionary path + * @param {object} options Options for the dictionary * @constructor */ -function NodeDictionaryLoader(dic_path) { - DictionaryLoader.apply(this, [ dic_path ]); +function NodeDictionaryLoader(options) { + DictionaryLoader.call(this, options); } NodeDictionaryLoader.prototype = Object.create(DictionaryLoader.prototype); diff --git a/test/TokenizerTest.js b/test/TokenizerTest.js index 1118c372..a9e2d455 100644 --- a/test/TokenizerTest.js +++ b/test/TokenizerTest.js @@ -49,7 +49,7 @@ describe("Tokenizer for IPADic", function () { before(function (done) { this.timeout(5 * 60 * 1000); // 5 min - kuromoji.builder({ dicPath: DIC_DIR }).build(function (error, _tokenizer) { + kuromoji.loader({ dic_path: DIC_DIR }).load(function (error, _tokenizer) { tokenizer = _tokenizer; expect(tokenizer).to.be.a("object"); done(); diff --git a/test/dict/builder/DictionaryBuilderTest.js b/test/dict/builder/DictionaryBuilderTest.js index 8eee0193..4ff1f928 100644 --- a/test/dict/builder/DictionaryBuilderTest.js +++ b/test/dict/builder/DictionaryBuilderTest.js @@ -34,7 +34,7 @@ describe("DictionaryBuilder", function () { before("Build", function (done) { // Build token info dictionary - var builder = kuromoji.dictionaryBuilder(); + var builder = kuromoji.builder(); var tokenInfo = fs.readFileSync(tid_dic_file, "utf-8"); tokenInfo.split("\n").map(function (line) { builder.addTokenInfoDictionary(line); diff --git a/test/loader/DictionaryLoaderTest.js b/test/loader/DictionaryLoaderTest.js index 3264c6e2..ba91534d 100644 --- a/test/loader/DictionaryLoaderTest.js +++ b/test/loader/DictionaryLoaderTest.js @@ -27,7 +27,7 @@ describe("DictionaryLoader", function () { before(function (done) { this.timeout(5 * 60 * 1000); // 5 min - var loader = new DictionaryLoader(DIC_DIR); + var loader = new DictionaryLoader({ dic_path: DIC_DIR }); loader.load(function (err, dic) { dictionaries = dic; done(); @@ -51,8 +51,8 @@ describe("DictionaryLoader", function () { describe("DictionaryLoader about loading", function () { it("could load directory path without suffix /", function (done) { this.timeout(5 * 60 * 1000); // 5 min - - var loader = new DictionaryLoader("dict"); // not have suffix / + + var loader = new DictionaryLoader({ dic_path: "dict" }); // not have suffix / loader.load(function (err, dic) { expect(err).to.be.null; expect(dic).to.not.be.undefined; @@ -60,7 +60,7 @@ describe("DictionaryLoader about loading", function () { }); }); it("couldn't load dictionary, then call with error", function (done) { - var loader = new DictionaryLoader("non-exist/dictionaries"); + var loader = new DictionaryLoader({ dic_path: "non-exist/dictionaries"}); loader.load(function (err, dic) { expect(err).to.be.an.instanceof(Error); done(); diff --git a/test/viterbi/ViterbiBuilderTest.js b/test/viterbi/ViterbiBuilderTest.js index b5ed1d3d..e8bf3ced 100644 --- a/test/viterbi/ViterbiBuilderTest.js +++ b/test/viterbi/ViterbiBuilderTest.js @@ -26,9 +26,9 @@ describe("ViterbiBuilder", function () { before(function (done) { this.timeout(5 * 60 * 1000); // 5 min - var loader = new DictionaryLoader(DIC_DIR); - loader.load(function (err, dic) { - viterbi_builder = new ViterbiBuilder(dic); + var loader = new DictionaryLoader({ dic_path: DIC_DIR }); + loader.load(function (err, tokenizer) { + viterbi_builder = tokenizer.viterbi_builder; done(); }); });