Skip to content

Instantly share code, notes, and snippets.

Embed
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>
<html>
<head>
<!-- http://chasen.org/~taku/software/TinySegmenter/ -->
<script type="text/javascript" src="tiny_segmenter.js" charset="UTF-8"></script>
<script>
var segmenter = new TinySegmenter();
function countWords() {
s = document.getElementById("inputText").value;
toks = segmenter.segment(s);
document.getElementById("wordcount").innerHTML = toks.length;
}
</script>
</head>
<body>
<form action="">
<textarea name="inputText" id="inputText" onKeyUp="countWords();">Text</textarea>
<br/>
<p id="wordcount"></p>
</form>
</body>
</html>
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.