Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created February 16, 2015 11:49
Show Gist options
  • Save cocodrips/41c64b461c85bb22a326 to your computer and use it in GitHub Desktop.
Save cocodrips/41c64b461c85bb22a326 to your computer and use it in GitHub Desktop.
TinySegmenterで名詞を取り出す(精度△ 早さ◎)
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