Git Product home page Git Product logo

kuroshiro-analyzer-kuromoji's People

Contributors

hexenq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kuroshiro-analyzer-kuromoji's Issues

kuroshiro work on home page but doesnt work on another page.

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

<script type="text/javascript" src="//localhost:3000/wordpress/wp-content/themes/colorswebsite/distfile/kuroshiro.min.js?ver=1.1.0" id="kuroshiro-min-js"></script> <script type="text/javascript" src="//localhost:3000/wordpress/wp-content/themes/colorswebsite/distfile/kuroshiro-analyzer-kuromoji.min.js?ver=1.1.0" id="kuroshiro-analyzer-js"></script>

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/" }))

スクリーンショット (36)

Build isn't bundling dict files

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:

  1. Cloned kuroshiro & kuroshiro-analyzer-kuromoji. I built both with npm run build and copied the min.js files to a folder.

  2. 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:

screen shot 2018-08-13 at 12 36 46 pm

Why is it looking in the filesystem for these dict files when I browserified them?

Uncaught (in promise) TypeError: path.join is not a function

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);
        });

Loading dictionaries fails if dictionaries are hosted on different domain

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.

Workaround

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('/');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.