Created
January 11, 2014 03:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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