Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of using TinySegmenter.js to tokenize Japanese and provide the word count of the input from a textbox.
<!DOCTYPE html>
<!-- -->
<script type="text/javascript" src="tiny_segmenter.js" charset="UTF-8"></script>
var segmenter = new TinySegmenter();
function countWords() {
s = document.getElementById("inputText").value;
toks = segmenter.segment(s);
document.getElementById("wordcount").innerHTML = toks.length;
<form action="">
<textarea name="inputText" id="inputText" onKeyUp="countWords();">Text</textarea>
<p id="wordcount"></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.