Class: SangsooNam::Jekyll::TFIDFRelatedPosts
- Inherits:
-
Object
- Object
- SangsooNam::Jekyll::TFIDFRelatedPosts
- Defined in:
- lib/jekyll-related-blog-posts.rb
Instance Method Summary collapse
- #add_post(post) ⇒ Object
- #build(site) ⇒ Object
-
#initialize ⇒ TFIDFRelatedPosts
constructor
A new instance of TFIDFRelatedPosts.
Constructor Details
#initialize ⇒ TFIDFRelatedPosts
Returns a new instance of TFIDFRelatedPosts.
11 12 13 14 15 16 |
# File 'lib/jekyll-related-blog-posts.rb', line 11 def initialize @docs = Array.new @keywords = Array.new @tags_and_categories = Array.new @stopwords_filter = Stopwords::Snowball::Filter.new('en') end |
Instance Method Details
#add_post(post) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll-related-blog-posts.rb', line 18 def add_post(post) = post.data['tags'].map { |e| "@tag:" + e }.map(&:to_sym) categories = post.data['categories'].map { |e| "@category:" + e }.map(&:to_sym) doc = { post: post, content: (stem(post.content) + stem(post.data['title']) + + categories) } @docs << doc @keywords += doc[:content] @tags_and_categories += + categories end |
#build(site) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jekyll-related-blog-posts.rb', line 30 def build(site) @keywords.uniq! @tags_and_categories.uniq! @weights = custom_weights(@tags_and_categories) = (site.config['related_posts_count'] || 4) @docs.each do |doc| doc[:post].instance_variable_set(:@related_posts,[doc].map { |x| x[:post] }) end end |