Skip to content

Instantly share code, notes, and snippets.

@alexbowe
Created January 11, 2014 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbowe/8366628 to your computer and use it in GitHub Desktop.
Save alexbowe/8366628 to your computer and use it in GitHub Desktop.
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