middleman-blog-similar 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +14 -3
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +6 -0
  5. data/README.md +63 -19
  6. data/features/damerau_levenshtein.feature +5 -5
  7. data/features/levenshtein.feature +5 -5
  8. data/features/word_frequency.feature +15 -0
  9. data/fixtures/test-app/source/2014-05-08-article0.md +1 -0
  10. data/fixtures/test-app/source/2014-05-10-article2.md +2 -1
  11. data/fixtures/test-app/source/2014-05-11-article3.md +2 -1
  12. data/fixtures/test-app/source/2014-05-14-article6.md +1 -1
  13. data/fixtures/test-app/source/layouts/article.slim +2 -2
  14. data/lib/middleman-blog-similar/algorithm.rb +19 -0
  15. data/lib/middleman-blog-similar/algorithm/damerau_levenshtein.rb +7 -0
  16. data/lib/middleman-blog-similar/algorithm/levenshtein.rb +7 -0
  17. data/lib/middleman-blog-similar/algorithm/unigrams.csv +21089 -0
  18. data/lib/middleman-blog-similar/algorithm/word_frequency.rb +69 -0
  19. data/lib/middleman-blog-similar/algorithm/word_frequency/mecab.rb +20 -0
  20. data/lib/middleman-blog-similar/algorithm/word_frequency/tree_tagger.rb +20 -0
  21. data/lib/middleman-blog-similar/blog_article_extensions.rb +20 -11
  22. data/lib/middleman-blog-similar/extension.rb +10 -7
  23. data/lib/middleman-blog-similar/helpers.rb +6 -12
  24. data/lib/middleman-blog-similar/version.rb +1 -1
  25. data/middleman-blog-similar.gemspec +3 -2
  26. data/spec/middleman-blog-similar/algorithm/damerau_levenshtein_spec.rb +42 -0
  27. data/spec/middleman-blog-similar/algorithm/levenshtein_spec.rb +42 -0
  28. data/spec/middleman-blog-similar/algorithm/word_frequency/mecab_spec.rb +41 -0
  29. data/spec/middleman-blog-similar/algorithm/word_frequency/tree_tagger_spec.rb +52 -0
  30. data/spec/middleman-blog-similar/algorithm/word_frequency_spec.rb +73 -0
  31. data/spec/middleman-blog-similar/algorithm_spec.rb +40 -0
  32. data/spec/spec_helper.rb +26 -2
  33. metadata +37 -7
  34. data/lib/middleman-blog-similar/engines/base.rb +0 -27
  35. data/lib/middleman-blog-similar/engines/damerau_levenshtein.rb +0 -15
  36. data/lib/middleman-blog-similar/engines/levenshtein.rb +0 -15
  37. data/spec/middleman-blog-similar/engines/base_spec.rb +0 -4
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'middleman-blog-similar/algorithm/word_frequency'
3
+
4
+ describe 'Middleman::Blog::Similar::Algorithm' do
5
+ let(:app) {
6
+ middleman_app('test-app') {
7
+ activate :similar
8
+ }
9
+ }
10
+ let(:article) { app.sitemap.find_resource_by_destination_path '/2014/05/08/article0.html' }
11
+ let(:algorithm) { article.similarity_algorithm }
12
+ describe(:app) {
13
+ describe(:similarity_algorithm) {
14
+ subject { app.similarity_algorithm }
15
+ it { should be ::Middleman::Blog::Similar::Algorithm::WordFrequency }
16
+ }
17
+ }
18
+ describe(:similarity_algorithm) {
19
+ describe(:articles) {
20
+ subject { algorithm.articles.map(&:url) }
21
+ it {
22
+ should eq [
23
+ "/2014/05/14/article6.html",
24
+ "/2014/05/13/article5.html",
25
+ "/2014/05/12/article4.html",
26
+ "/2014/05/11/article3.html",
27
+ "/2014/05/10/article2.html",
28
+ "/2014/05/09/article1.html",
29
+ "/2014/05/08/article0.html"
30
+ ]
31
+ }
32
+ }
33
+ }
34
+ describe(:article) {
35
+ describe(:similarity_algorithm) {
36
+ subject { algorithm }
37
+ it { should be_a_kind_of ::Middleman::Blog::Similar::Algorithm::WordFrequency }
38
+ }
39
+ }
40
+ end
@@ -8,9 +8,33 @@ require "middleman-core"
8
8
  require "middleman-blog"
9
9
  require "middleman-blog/helpers"
10
10
 
11
+ module SpecHelpers
12
+ include FileUtils
11
13
 
12
- # Memo: https://github.com/middleman/middleman/issues/737#issuecomment-14122832
13
- module SpecHelpers; end
14
+ def middleman_app fixture_path, &block
15
+ tmp_dir = File.expand_path("../../tmp", __FILE__)
16
+ fixture_dir = File.expand_path("../../fixtures", __FILE__)
17
+ fixture_tmp = File.join tmp_dir, "rspec"
18
+ root_dir = File.join fixture_tmp, fixture_path
19
+ rmtree fixture_tmp
20
+ mkdir_p tmp_dir
21
+ cp_r fixture_dir, fixture_tmp
22
+ ENV["MM_SOURCE"] = 'source'
23
+ ENV["MM_ROOT"] = root_dir
24
+ initialize_commands = @initialize_commands || []
25
+ initialize_commands.unshift block
26
+ initialize_commands.unshift lambda {
27
+ set :environment, :development
28
+ set :show_exceptions, false
29
+ activate :blog
30
+ }
31
+ Middleman::Application.server.inst do
32
+ initialize_commands.each do |p|
33
+ instance_exec(&p)
34
+ end
35
+ end
36
+ end
37
+ end
14
38
 
15
39
  Spork.prefork do
16
40
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-blog-similar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atsushi Nagase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-11 00:00:00.000000000 Z
11
+ date: 2014-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fast-stemmer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.2
41
55
  description: Similar article extension for middleman-blog
42
56
  email:
43
57
  - a@ngs.io
@@ -57,6 +71,7 @@ files:
57
71
  - features/damerau_levenshtein.feature
58
72
  - features/levenshtein.feature
59
73
  - features/support/env.rb
74
+ - features/word_frequency.feature
60
75
  - fixtures/test-app/source/2014-05-08-article0.md
61
76
  - fixtures/test-app/source/2014-05-09-article1.md
62
77
  - fixtures/test-app/source/2014-05-10-article2.md
@@ -69,17 +84,26 @@ files:
69
84
  - fixtures/test-app/source/layouts/article.slim
70
85
  - fixtures/test-app/source/page.html.slim
71
86
  - lib/middleman-blog-similar.rb
87
+ - lib/middleman-blog-similar/algorithm.rb
88
+ - lib/middleman-blog-similar/algorithm/damerau_levenshtein.rb
89
+ - lib/middleman-blog-similar/algorithm/levenshtein.rb
90
+ - lib/middleman-blog-similar/algorithm/unigrams.csv
91
+ - lib/middleman-blog-similar/algorithm/word_frequency.rb
92
+ - lib/middleman-blog-similar/algorithm/word_frequency/mecab.rb
93
+ - lib/middleman-blog-similar/algorithm/word_frequency/tree_tagger.rb
72
94
  - lib/middleman-blog-similar/blog_article_extensions.rb
73
- - lib/middleman-blog-similar/engines/base.rb
74
- - lib/middleman-blog-similar/engines/damerau_levenshtein.rb
75
- - lib/middleman-blog-similar/engines/levenshtein.rb
76
95
  - lib/middleman-blog-similar/extension.rb
77
96
  - lib/middleman-blog-similar/helpers.rb
78
97
  - lib/middleman-blog-similar/version.rb
79
98
  - lib/middleman_extension.rb
80
99
  - middleman-blog-similar.gemspec
81
100
  - spec/helper_spec.rb
82
- - spec/middleman-blog-similar/engines/base_spec.rb
101
+ - spec/middleman-blog-similar/algorithm/damerau_levenshtein_spec.rb
102
+ - spec/middleman-blog-similar/algorithm/levenshtein_spec.rb
103
+ - spec/middleman-blog-similar/algorithm/word_frequency/mecab_spec.rb
104
+ - spec/middleman-blog-similar/algorithm/word_frequency/tree_tagger_spec.rb
105
+ - spec/middleman-blog-similar/algorithm/word_frequency_spec.rb
106
+ - spec/middleman-blog-similar/algorithm_spec.rb
83
107
  - spec/middleman-blog-similar/extension_spec.rb
84
108
  - spec/spec_helper.rb
85
109
  homepage: https://github.com/ngs/middleman-blog-similar
@@ -110,6 +134,7 @@ test_files:
110
134
  - features/damerau_levenshtein.feature
111
135
  - features/levenshtein.feature
112
136
  - features/support/env.rb
137
+ - features/word_frequency.feature
113
138
  - fixtures/test-app/source/2014-05-08-article0.md
114
139
  - fixtures/test-app/source/2014-05-09-article1.md
115
140
  - fixtures/test-app/source/2014-05-10-article2.md
@@ -122,7 +147,12 @@ test_files:
122
147
  - fixtures/test-app/source/layouts/article.slim
123
148
  - fixtures/test-app/source/page.html.slim
124
149
  - spec/helper_spec.rb
125
- - spec/middleman-blog-similar/engines/base_spec.rb
150
+ - spec/middleman-blog-similar/algorithm/damerau_levenshtein_spec.rb
151
+ - spec/middleman-blog-similar/algorithm/levenshtein_spec.rb
152
+ - spec/middleman-blog-similar/algorithm/word_frequency/mecab_spec.rb
153
+ - spec/middleman-blog-similar/algorithm/word_frequency/tree_tagger_spec.rb
154
+ - spec/middleman-blog-similar/algorithm/word_frequency_spec.rb
155
+ - spec/middleman-blog-similar/algorithm_spec.rb
126
156
  - spec/middleman-blog-similar/extension_spec.rb
127
157
  - spec/spec_helper.rb
128
158
  has_rdoc:
@@ -1,27 +0,0 @@
1
- module Middleman
2
- module Blog
3
- module Similar
4
- module Engines
5
- class Base
6
- attr_reader :article, :app
7
- def initialize(article)
8
- @article = article
9
- end
10
- def similar_articles
11
- @similar_articles ||= articles
12
- .reject{|a| a == article }
13
- .map{|a| [distance(a), a] }
14
- .sort{|x, y| x[0] <=> y[0] }
15
- .map{|a| a[1] }
16
- end
17
- def distance a
18
- 0
19
- end
20
- def articles
21
- article.blog_controller.data.articles
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,15 +0,0 @@
1
- require 'damerau-levenshtein'
2
-
3
- module Middleman
4
- module Blog
5
- module Similar
6
- module Engines
7
- class DamerauLevenshtein < Base
8
- def distance(a)
9
- ::DamerauLevenshtein.distance article.body, a.body
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- require 'levenshtein'
2
-
3
- module Middleman
4
- module Blog
5
- module Similar
6
- module Engines
7
- class Levenshtein < Base
8
- def distance(a)
9
- ::Levenshtein.distance(article.body, a.body)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Middleman::Blog::Similar::Engines::Base' do
4
- end