Created
February 16, 2015 11:49
-
-
Save cocodrips/41c64b461c85bb22a326 to your computer and use it in GitHub Desktop.
TinySegmenterで名詞を取り出す(精度△ 早さ◎)
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
class @NounExtractor | |
constructor: () -> | |
@segmenter = new TinySegmenter() | |
extractNouns: (text) -> | |
words = @segmenter.segment(text) | |
nouns = [] | |
for word in words | |
if @isNoun(word) | |
nouns.push(word) | |
console.log nouns | |
isNoun: (word) -> | |
return @isOnlyKana(word) || @isOnlyKanji(word) | |
isOnlyKanji: (word) -> | |
return word.match(/^[亜-煕]+$/) != null | |
isOnlyKana: (word) -> | |
return word.match(/^[ァ-ヶー]+$/) != null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment