hexenq / kuroshiro-analyzer-kuromoji Goto Github PK
View Code? Open in Web Editor NEWKuromoji morphological analyzer for kuroshiro.
License: MIT License
Kuromoji morphological analyzer for kuroshiro.
License: MIT License
var kuroshiro = new Kuroshiro();
kuroshiro.init(new KuromojiAnalyzer())
.then(function () {
return kuroshiro.convert("感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!", { to: "hiragana" });
})
.then(function(result){
console.log(result);
})
this code is working on the homepage .
i put the kuroshiro.min.js and kuroshiro-analyzer-kuromoji.min.js on head like this
i copied these two file from node_modules and paste it outside on a folder called distfile.
the code above seems tow work only on one page. and the other page i get the error 404 not found.
i even copied the dict folder from the kuromoji and paste it outside like this as some people mention on other issues. but it doesnt seem to work in my case.
kuroshiro.init(new KuromojiAnalyzer({ dictPath: "dict/" }))
Hi! I'm trying to integrate Kuroshiro into this project (https://github.com/mikesteele/dual-captions) to allow users to have Kanji captions on YouTube & Netflix with Romaji captions underneath.
I have issues when I try to Kuroshiro.init(new KuromojiAnalyzer())
. It's looking in my local filesystem for the dict files when (I think?) it should be bundling the files.
Here's the steps I took:
Cloned kuroshiro
& kuroshiro-analyzer-kuromoji
. I built both with npm run build
and copied the min.js
files to a folder.
Created index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="kuroshiro.min.js"></script>
<script src="kuroshiro-analyzer-kuromoji.min.js"></script>
</head>
<body></body>
</html>
On trying to initialize Kuroshiro in the browser, I see:
Why is it looking in the filesystem for these dict files when I browserified them?
DictionaryLoader.js:51:37
function (callback) {
async.map([ "base.dat.gz", "check.dat.gz" ], function (filename, _callback) {
loadArrayBuffer(path.join(dic_path, filename), function (err, buffer) {
if(err) {
return _callback(err);
}
_callback(null, buffer);
});
}, function (err, buffers) {
if(err) {
return callback(err);
}
var base_buffer = new Int32Array(buffers[0]);
var check_buffer = new Int32Array(buffers[1]);
dic.loadTrie(base_buffer, check_buffer);
callback(null);
});
JavaScript Code on domain-a.com using kuroshiro.js and kuroshiro-analyzer-kuromoji.js built using npm run build
:
kuroshiro.init(new KuromojiAnalyzer({ dict: "https://domain-b.com/js/kuromoji/dict" }));
This request will fail as the URL is mangled to https:/domain-b.com/js/kuromoji/dict
, which will cause the XMLHttpRequest to attempt to load it from https://domain-a.com/domain-b.com/js/kuromoji/dict
instead.
This is caused by the posix version of path.normalize()
:
// path.normalize(path)
// posix version
exports.normalize = function(path) {
// *snip*
// Normalize the path
// Before: "https://domain-b.com/js/kuromoji/dict"
path = normalizeArray(filter(path.split('/'), function(p) { // ["https:", "", "domain-b.com", "js", "kuromoji", "dict"]
return !!p;
}), !isAbsolute).join('/'); // "https:/domain-b.com/js/kuromoji/dict"
// *snip*
};
The URL is split into its components using path.split('/')
, which results in one empty element between the "https" and "domain-b.com" elements, which is then filtered out by return !!p
, resulting in the missing slash.
As a temporary workaround, one could replace the snippet with the following, which still filters normal paths but retains paths with a protocol:
path = path.split('/');
if(!path[0].includes(":")) {
path = normalizeArray(filter(path, function(p) {
return !!p;
}), !isAbsolute);
}
path = path.join('/');
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.