From 98d1c309307ce52ee02a6f8b3c20430845c0e1cb Mon Sep 17 00:00:00 2001 From: mikob Date: Tue, 18 Dec 2018 17:40:24 +0900 Subject: [PATCH] Removed thin abstraction layer "TokenizerBuilder" combining into loader. Made loader/builder terminology more consistent. --- README.md | 4 +- build/kuromoji.js | 121 ++++++--------------- demo/js/tokenize.js | 4 +- example/load-node.js | 2 +- gulpfile.js | 2 +- src/TokenizerBuilder.js | 55 ---------- src/kuromoji.js | 8 +- src/loader/BrowserDictionaryLoader.js | 7 +- src/loader/DictionaryLoader.js | 7 +- src/loader/NodeDictionaryLoader.js | 6 +- test/TokenizerTest.js | 2 +- test/dict/builder/DictionaryBuilderTest.js | 2 +- test/loader/DictionaryLoaderTest.js | 8 +- test/viterbi/ViterbiBuilderTest.js | 6 +- 14 files changed, 63 insertions(+), 171 deletions(-) delete mode 100644 src/TokenizerBuilder.js diff --git a/README.md b/README.md index bc4db9fd..57e32afd 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 39774663..5577e2e4 100644 --- a/build/kuromoji.js +++ b/build/kuromoji.js @@ -6935,64 +6935,7 @@ Tokenizer.prototype.getLattice = function (text) { module.exports = Tokenizer; -},{"./util/IpadicFormatter":21,"./viterbi/ViterbiBuilder":23,"./viterbi/ViterbiSearcher":26}],6:[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":5,"./loader/NodeDictionaryLoader":18}],7:[function(require,module,exports){ +},{"./util/IpadicFormatter":20,"./viterbi/ViterbiBuilder":22,"./viterbi/ViterbiSearcher":25}],6:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7031,7 +6974,7 @@ function CharacterClass(class_id, class_name, is_always_invoke, is_grouping, max module.exports = CharacterClass; -},{}],8:[function(require,module,exports){ +},{}],7:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7238,7 +7181,7 @@ CharacterDefinition.prototype.lookup = function (ch) { module.exports = CharacterDefinition; -},{"../util/SurrogateAwareString":22,"./CharacterClass":7,"./InvokeDefinitionMap":11}],9:[function(require,module,exports){ +},{"../util/SurrogateAwareString":21,"./CharacterClass":6,"./InvokeDefinitionMap":10}],8:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7299,7 +7242,7 @@ ConnectionCosts.prototype.loadConnectionCosts = function (connection_costs_buffe module.exports = ConnectionCosts; -},{}],10:[function(require,module,exports){ +},{}],9:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7383,7 +7326,7 @@ DynamicDictionaries.prototype.loadUnknownDictionaries = function (unk_buffer, un module.exports = DynamicDictionaries; -},{"./ConnectionCosts":9,"./TokenInfoDictionary":12,"./UnknownDictionary":13,"doublearray":2}],11:[function(require,module,exports){ +},{"./ConnectionCosts":8,"./TokenInfoDictionary":11,"./UnknownDictionary":12,"doublearray":2}],10:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7495,7 +7438,7 @@ InvokeDefinitionMap.prototype.toBuffer = function () { module.exports = InvokeDefinitionMap; -},{"../util/ByteBuffer":20,"./CharacterClass":7}],12:[function(require,module,exports){ +},{"../util/ByteBuffer":19,"./CharacterClass":6}],11:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7649,7 +7592,7 @@ TokenInfoDictionary.prototype.getFeatures = function (token_info_id_str) { module.exports = TokenInfoDictionary; -},{"../util/ByteBuffer":20}],13:[function(require,module,exports){ +},{"../util/ByteBuffer":19}],12:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7709,7 +7652,7 @@ UnknownDictionary.prototype.loadUnknownDictionaries = function (unk_buffer, unk_ module.exports = UnknownDictionary; -},{"../util/ByteBuffer":20,"./CharacterDefinition":8,"./TokenInfoDictionary":12}],14:[function(require,module,exports){ +},{"../util/ByteBuffer":19,"./CharacterDefinition":7,"./TokenInfoDictionary":11}],13:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7779,7 +7722,7 @@ CharacterDefinitionBuilder.prototype.build = function () { module.exports = CharacterDefinitionBuilder; -},{"../CharacterDefinition":8,"../InvokeDefinitionMap":11}],15:[function(require,module,exports){ +},{"../CharacterDefinition":7,"../InvokeDefinitionMap":10}],14:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -7851,7 +7794,7 @@ ConnectionCostsBuilder.prototype.build = function () { module.exports = ConnectionCostsBuilder; -},{"../ConnectionCosts":9}],16:[function(require,module,exports){ +},{"../ConnectionCosts":8}],15:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8011,7 +7954,7 @@ DictionaryBuilder.prototype.buildDoubleArray = function () { module.exports = DictionaryBuilder; -},{"../DynamicDictionaries":10,"../TokenInfoDictionary":12,"../UnknownDictionary":13,"./CharacterDefinitionBuilder":14,"./ConnectionCostsBuilder":15,"doublearray":2}],17:[function(require,module,exports){ +},{"../DynamicDictionaries":9,"../TokenInfoDictionary":11,"../UnknownDictionary":12,"./CharacterDefinitionBuilder":13,"./ConnectionCostsBuilder":14,"doublearray":2}],16:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8031,22 +7974,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":6,"./dict/builder/DictionaryBuilder":16}],18:[function(require,module,exports){ +},{"./dict/builder/DictionaryBuilder":15,"./loader/NodeDictionaryLoader":17}],17:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8070,11 +8013,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); @@ -8087,6 +8030,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"; @@ -8112,7 +8056,7 @@ BrowserDictionaryLoader.prototype.loadArrayBuffer = function (url, callback) { module.exports = BrowserDictionaryLoader; -},{"./DictionaryLoader":19}],19:[function(require,module,exports){ +},{"./DictionaryLoader":18}],18:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8135,15 +8079,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) { @@ -8238,7 +8183,7 @@ DictionaryLoader.prototype.load = function (load_callback) { }); } ], function (err) { - load_callback(err, dic); + load_callback(err, new Tokenizer(dic)); }); }; @@ -8251,7 +8196,7 @@ DictionaryLoader.prototype.load = function (load_callback) { module.exports = DictionaryLoader; -},{"../dict/DynamicDictionaries":10,"async":1,"path":3}],20:[function(require,module,exports){ +},{"../Tokenizer":5,"../dict/DynamicDictionaries":9,"async":1,"path":3}],19:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8542,7 +8487,7 @@ ByteBuffer.prototype.getString = function (index) { module.exports = ByteBuffer; -},{}],21:[function(require,module,exports){ +},{}],20:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8611,7 +8556,7 @@ IpadicFormatter.prototype.formatUnknownEntry = function (word_id, position, type module.exports = IpadicFormatter; -},{}],22:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8704,7 +8649,7 @@ SurrogateAwareString.isSurrogatePair = function (ch) { module.exports = SurrogateAwareString; -},{}],23:[function(require,module,exports){ +},{}],22:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8807,7 +8752,7 @@ ViterbiBuilder.prototype.build = function (sentence_str) { module.exports = ViterbiBuilder; -},{"../util/SurrogateAwareString":22,"./ViterbiLattice":24,"./ViterbiNode":25}],24:[function(require,module,exports){ +},{"../util/SurrogateAwareString":21,"./ViterbiLattice":23,"./ViterbiNode":24}],23:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8869,7 +8814,7 @@ ViterbiLattice.prototype.appendEos = function () { module.exports = ViterbiLattice; -},{"./ViterbiNode":25}],25:[function(require,module,exports){ +},{"./ViterbiNode":24}],24:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -8920,7 +8865,7 @@ function ViterbiNode(node_name, node_cost, start_pos, length, type, left_id, rig module.exports = ViterbiNode; -},{}],26:[function(require,module,exports){ +},{}],25:[function(require,module,exports){ /* * Copyright 2014 Takuya Asano * Copyright 2010-2014 Atilika Inc. and contributors @@ -9024,5 +8969,5 @@ ViterbiSearcher.prototype.backward = function (lattice) { module.exports = ViterbiSearcher; -},{}]},{},[17])(17) +},{}]},{},[16])(16) }); 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 8cbaad32..93116398 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -65,7 +65,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 a1d64f70..8ae0fd1f 100644 --- a/src/loader/BrowserDictionaryLoader.js +++ b/src/loader/BrowserDictionaryLoader.js @@ -21,11 +21,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); @@ -38,6 +38,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 51ab5d52..6fcc72e3 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 f7c55758..816b8da2 100644 --- a/src/loader/NodeDictionaryLoader.js +++ b/src/loader/NodeDictionaryLoader.js @@ -22,11 +22,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(); }); });