class Tag
Public Class Methods
analysis(text)
click to toggle source
形態素解析
# File app/models/tag.rb, line 38 def self.analysis text self.tagger.parse(text).mincost_path end
counter(words)
click to toggle source
create_with_user_tweet(user,date = nil)
click to toggle source
# File app/models/tag.rb, line 10 def self.create_with_user_tweet user,date = nil tags = [] words = self.generate(self.tweet_compression(user.tweets date)) self.counter(words).shift(20).each do |word,count| tags << create! do |record| record.user_id = user.id record.word = word record.count = count record.date = date || user.yesterday end end tags end
generate(text)
click to toggle source
単語選り分けて抜き出し
引数
'果実と梅と果実'
返り値
["果実", "梅", "果実"]
# File app/models/tag.rb, line 49 def self.generate text nouns_word = [] ignore_not_include = '名詞' ignore_include = '名詞,数' ignore_word = 'http' self.analysis(text).each do |node| next if node.word.left.text.scan(/#{ignore_not_include}/).blank? next unless node.word.left.text.scan(/#{ignore_include}/).blank? next unless node.word.surface.scan(/#{ignore_word}|^[ぁ-ん]$/).blank? nouns_word << node.word.surface end nouns_word end
Public Instance Methods
view_path()
click to toggle source
TODO tag_logとのbelongs_toの指定方法しらべる
belongs_to :tag_log, foreign_key: 'user_id'
# File app/models/tag.rb, line 6 def view_path "/user/#{user.name}/#{date.year}/#{date.month}/#{date.day}" end