rankum 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bfcd33262f5033679e1a112d87cebdbae692f61
4
+ data.tar.gz: 07bf96be3547b2b68667e2370dca1a59021b5ba9
5
+ SHA512:
6
+ metadata.gz: 92f1d306c828df791b98e774c52c3cc39d2177039e059ad315fd62415a3275f2c5196f016392c153c3fd74da002c508ae07281908a19c2c6b579b8d5fa20959b
7
+ data.tar.gz: 90c2b8a7ed0c28b0aff6c992018892ff51ccffd87474c435c6e46556fc998daae0a5e5a7c054d55cb5bb6b12f1cf13f25668614d7de74a8ce134c983c1e3840d
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --order random
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+ ruby "2.2.3"
3
+
4
+ gem "rspec"
5
+ gem "byebug"
6
+
7
+ gem "mixlib-cli", "~> 1.5.0"
8
+ gem "paint", "~> 1.0.1"
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ byebug (8.2.2)
5
+ diff-lcs (1.2.5)
6
+ mixlib-cli (1.5.0)
7
+ paint (1.0.1)
8
+ rspec (3.4.0)
9
+ rspec-core (~> 3.4.0)
10
+ rspec-expectations (~> 3.4.0)
11
+ rspec-mocks (~> 3.4.0)
12
+ rspec-core (3.4.4)
13
+ rspec-support (~> 3.4.0)
14
+ rspec-expectations (3.4.0)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.4.0)
17
+ rspec-mocks (3.4.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.4.0)
20
+ rspec-support (3.4.1)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ byebug
27
+ mixlib-cli (~> 1.5.0)
28
+ paint (~> 1.0.1)
29
+ rspec
30
+
31
+ BUNDLED WITH
32
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Rankum
2
+ A tool to compare search ranks using flexible quality rank metrics.
3
+ It helps to evaluate how good your search results are ranked when compared to a perfect (ideal) rank.
4
+
5
+ ## Rank Metrics
6
+ To help you out, Rankum extract some metrics to "measure" search rank relevancy.
7
+
8
+ ##### FCP (Fraction Concordant pairs)
9
+ Basically, this metric counts how many pairs occuring on perfect rank are also on actual search rank.
10
+ Supposing search results are A, B, C, D and E items. For this pefect rank, we have 10 pair combinations (AB, AC, AD, AE, BC, BD, BE, CD, CE, DE).
11
+ **FCP measures the fraction (percentage) of these pairs on actual ranks.**
12
+
13
+ ## Install
14
+
15
+ ```ruby
16
+ gem install rankum
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ##### Command-line mode
22
+
23
+ Options:
24
+ ```shell
25
+ -m, --metric metric Metric used to compare search ranks
26
+ -a, --actual_rank actual_rank_file_path Actual Rank file (only for RankFileReader strategy)
27
+ -p, --perfect_rank perfect_rank_file_path Perfect Rank file (only for RankFileReader strategy)
28
+ -r, --rank_reader rank_reader Strategy to to read your ranks
29
+ ```
30
+
31
+ ```shell
32
+ $ rankum -m FCP -r RankFileReader -p perfect_rank.txt -a my_rank.txt
33
+ ```
34
+ ![Rankum output](http://thecodeknight.herokuapp.com/img/rankum_output.png)
data/bin/rankum ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rankum'
4
+
5
+ cli = Rankum::CLI.new
6
+ cli.parse_options
7
+
8
+ result = Rankum::Runners::RankumCLI.run(cli.config)
9
+ result.output.each do |line|
10
+ puts line
11
+ end
@@ -0,0 +1,58 @@
1
+ require_relative "../utils/fcp_pair"
2
+ require_relative "../utils/interactor"
3
+
4
+ module Rankum
5
+ module Metrics
6
+ class FCPCalculator
7
+ include Rankum::Utils::Interactor
8
+
9
+ def self.run context
10
+ FCPCalculator.new(context).run
11
+ end
12
+
13
+ def run
14
+ execute { context.value = calculate_fcp }
15
+ end
16
+
17
+ private
18
+ def perfect_rank_pairs
19
+ @perfect_rank_pairs ||= Rankum::Utils::FCPPair.to_h(perfect_rank)
20
+ end
21
+
22
+ def actual_rank_pairs
23
+ @actual_rank_pairs ||= Rankum::Utils::FCPPair.to_a(actual_rank)
24
+ end
25
+
26
+ def calculate_fcp
27
+ total_pairs = perfect_rank_pair_count
28
+
29
+ actual_rank_pairs.each do |pair|
30
+ if perfect_rank_pairs[pair] > 0
31
+ perfect_rank_pairs[pair] -= 1
32
+ end
33
+ end
34
+
35
+ not_matched_pairs = perfect_rank_pair_count
36
+ result = (total_pairs - not_matched_pairs).to_f / total_pairs
37
+ result > 0 ? result : 0
38
+ end
39
+
40
+ def perfect_rank_pair_count
41
+ perfect_rank_pairs.reduce(0) { |acc, (k,v)| acc += v }
42
+ end
43
+
44
+ def rank_reader
45
+ @reader ||= context.rank_reader
46
+ end
47
+
48
+ def perfect_rank
49
+ @perfect_rank ||= rank_reader.perfect_rank
50
+ end
51
+
52
+ def actual_rank
53
+ @actual_rank ||= rank_reader.actual_rank
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,35 @@
1
+ module Rankum
2
+ module Readers
3
+ class RankFileReader
4
+
5
+ def initialize
6
+ @perfect_rank = []
7
+ @actual_rank = []
8
+ end
9
+
10
+ def add_perfect_rank_path path
11
+ @perfect_rank = [] unless @perfect_rank.empty?
12
+ @perfect_rank = to_array(path)
13
+ end
14
+
15
+ def add_actual_rank_path path
16
+ @actual_rank = [] unless @actual_rank.empty?
17
+ @actual_rank = to_array(path)
18
+ end
19
+
20
+ def perfect_rank
21
+ @perfect_rank
22
+ end
23
+
24
+ def actual_rank
25
+ @actual_rank
26
+ end
27
+
28
+ private
29
+ def to_array rank_path
30
+ IO.readlines(rank_path).map { |item| item.strip}
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,43 @@
1
+ require_relative "../utils/interactor"
2
+ require 'paint'
3
+
4
+ module Rankum
5
+ module Runners
6
+ class CLIOutputer
7
+ include Rankum::Utils::Interactor
8
+
9
+ def self.run context={}
10
+ CLIOutputer.new(context).run
11
+ end
12
+
13
+ def run
14
+ execute do
15
+ fail! unless raw_value
16
+ context.value = round(raw_value)
17
+ context.output = output
18
+ end
19
+ end
20
+
21
+ private
22
+ def raw_value
23
+ @raw_value ||= context.value
24
+ end
25
+
26
+ def round value
27
+ (value * 100).round(2)
28
+ end
29
+
30
+ def output
31
+ lines = []
32
+ lines << "Rankum"
33
+ lines << "------------"
34
+ lines << "Metric: #{context.metric}"
35
+
36
+ color = raw_value > 0.7 ? :green : :red
37
+ lines << "Similarity: #{Paint["#{context.value} %", color, :bright]}"
38
+ lines
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "../metrics/fcp_calculator"
2
+ require_relative "../readers/rank_file_reader"
3
+ require_relative "../utils/interactor"
4
+
5
+ module Rankum
6
+ module Runners
7
+ class CLISetup
8
+ include Rankum::Utils::Interactor
9
+
10
+ def self.run context
11
+ CLISetup.new(context).run
12
+ end
13
+
14
+ def run
15
+ execute { context.rank_reader = rank_reader }
16
+ end
17
+
18
+ private
19
+ def rank_reader
20
+ reader = Object::const_get("::Rankum::Readers::#{context.rank_reader}").new
21
+
22
+ reader.add_perfect_rank_path(context.perfect_rank)
23
+ reader.add_actual_rank_path(context.actual_rank)
24
+
25
+ reader
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ require "interactor"
2
+ require_relative "../metrics/fcp_calculator"
3
+ require_relative "cli_setup"
4
+ require_relative "cli_outputer"
5
+
6
+ module Rankum
7
+ module Runners
8
+ class RankumCLI
9
+ include Rankum::Utils::Interactor
10
+
11
+ def self.run context
12
+ RankumCLI.new(context).run
13
+ end
14
+
15
+ def run
16
+ organize Rankum::Runners::CLISetup,
17
+ Rankum::Metrics::FCPCalculator,
18
+ Rankum::Runners::CLIOutputer
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Rankum
2
+ module Utils
3
+ module FCPPair
4
+
5
+ class Rankum::Utils::Pair < Struct.new(:actual, :next); end
6
+
7
+ def self.to_a(rank)
8
+ rank.each_with_index.inject([]) do |pairs, (item, idx)|
9
+ rank[(idx + 1)..-1].each { |next_item| pairs << Pair.new(item, next_item) }
10
+ pairs
11
+ end
12
+ end
13
+
14
+ def self.to_h(rank)
15
+ to_a(rank).inject(Hash.new(0)) do |pairs, item|
16
+ pairs[item] += 1
17
+ pairs
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ require "ostruct"
2
+
3
+ module Rankum
4
+ module Utils
5
+ module Interactor
6
+
7
+ def initialize context={}
8
+ @context = OpenStruct.new(context)
9
+ end
10
+
11
+ def execute
12
+ begin
13
+ yield
14
+ exit if @context.fail?
15
+ success!
16
+ rescue Exception => e
17
+ fail!
18
+ end
19
+
20
+ @context
21
+ end
22
+
23
+ def organize *interactors
24
+ interactors.each do |interactor|
25
+ context_hash = @context.to_h
26
+ context = interactor.run(context_hash)
27
+
28
+ @context = OpenStruct.new(context_hash.merge!(context.to_h))
29
+ end
30
+
31
+ @context
32
+ end
33
+
34
+ def context
35
+ @context
36
+ end
37
+
38
+ def fail!
39
+ @context.send("success?=",false)
40
+ @context.send("fail?=",true)
41
+ end
42
+
43
+ def success!
44
+ @context.send("success?=",true)
45
+ @context.send("fail?=",false)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
data/lib/rankum.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "mixlib/cli"
2
+ require_relative "rankum/runners/rankum_cli"
3
+
4
+ module Rankum
5
+ class CLI
6
+ include Mixlib::CLI
7
+
8
+ option :metric,
9
+ :short => "-m metric",
10
+ :long => "--metric metric",
11
+ :default => "fcp",
12
+ :description => "Metric used to compare search ranks"
13
+
14
+ option :rank_reader,
15
+ :short => "-r rank_reader",
16
+ :long => "--rank_reader rank_reader",
17
+ :default => "RankFileReader",
18
+ :description => "Strategy to to read your ranks"
19
+
20
+ option :perfect_rank,
21
+ :short => "-p perfect_rank_file_path",
22
+ :long => "--perfect_rank perfect_rank_file_path",
23
+ :description => "Perfect Rank file (only valid for RankFileReader strategy)"
24
+
25
+ option :actual_rank,
26
+ :short => "-a actual rank_file_path",
27
+ :long => "--actual_rank actual_rank_file_path",
28
+ :description => "Actual Rank file (only valid for RankFileReader strategy)"
29
+ end
30
+ end
data/rankum.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "rankum"
3
+ spec.version = "1.0.0"
4
+
5
+ spec.author = "Felipe Besson"
6
+ spec.email = "flpbesson@gmail.com"
7
+ spec.date = "2016-05-06"
8
+ spec.summary = "Measure search rank quality"
9
+ spec.description = "A gem to compare search ranks using flexible quality rank metrics"
10
+ spec.homepage = "https://github.com/besson/rankum"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files`.split("\n")
14
+ spec.test_files = spec.files.grep(/^spec/)
15
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+
17
+ spec.add_dependency("mixlib-cli", "~> 1.5")
18
+ spec.add_dependency("paint", "~> 1.0")
19
+ end
@@ -0,0 +1,26 @@
1
+ Z
2
+ Y
3
+ X
4
+ W
5
+ V
6
+ U
7
+ T
8
+ S
9
+ R
10
+ Q
11
+ P
12
+ O
13
+ N
14
+ M
15
+ L
16
+ K
17
+ J
18
+ I
19
+ H
20
+ G
21
+ F
22
+ E
23
+ D
24
+ C
25
+ B
26
+ A
@@ -0,0 +1,26 @@
1
+ A
2
+ B
3
+ C
4
+ D
5
+ E
6
+ F
7
+ G
8
+ H
9
+ I
10
+ J
11
+ K
12
+ L
13
+ M
14
+ N
15
+ O
16
+ P
17
+ Q
18
+ R
19
+ S
20
+ T
21
+ U
22
+ V
23
+ W
24
+ X
25
+ Y
26
+ Z
@@ -0,0 +1,5 @@
1
+ hot
2
+ hot
3
+ fresh
4
+ vip
5
+ piv
@@ -0,0 +1,76 @@
1
+ require_relative "../../../lib/rankum/metrics/fcp_calculator"
2
+ require_relative "../../../lib/rankum/utils/fcp_pair"
3
+
4
+ module Rankum
5
+ module Metrics
6
+ describe FCPCalculator do
7
+ let(:perfect_rank) { ["A", "B", "C", "D", "E"] }
8
+ let(:reader) do
9
+ double("rank_reader", :perfect_rank => perfect_rank, :actual_rank => actual_rank)
10
+ end
11
+
12
+ context "when actual rank is equal to perfect rank" do
13
+ let(:actual_rank) { perfect_rank }
14
+
15
+ it "should get 1.0 as FCP value" do
16
+ calculator = FCPCalculator.run(rank_reader: reader)
17
+ expect(calculator).to be_a_success
18
+ expect(calculator.value).to eq(1.0)
19
+ end
20
+ end
21
+
22
+ context "when actual rank is totally different from the perfect one" do
23
+ let(:actual_rank) { ["F", "G", "H", "I", "J"] }
24
+
25
+ it "should get 0 as FCP value" do
26
+ calculator = FCPCalculator.run(rank_reader: reader)
27
+ expect(calculator).to be_a_success
28
+ expect(calculator.value).to eq(0)
29
+ end
30
+ end
31
+
32
+ context "when actual rank is the reversed from the perfect one" do
33
+ let(:actual_rank) { ["E", "D", "C", "B", "A"] }
34
+
35
+ it "should get 0 as FCP value" do
36
+ calculator = FCPCalculator.run(rank_reader: reader)
37
+ expect(calculator).to be_a_success
38
+ expect(calculator.value).to eq(0)
39
+ end
40
+ end
41
+
42
+ context "when some pairs are incorrect" do
43
+ let(:actual_rank) { ["B", "A", "C", "E", "D"] }
44
+
45
+ it "should get 0.8 as FCP value" do
46
+ calculator = FCPCalculator.run(rank_reader: reader)
47
+ expect(calculator).to be_a_success
48
+ expect(calculator.value).to eq(0.8)
49
+ end
50
+ end
51
+
52
+ context "when has duplicated pairs and one wrong position" do
53
+ let(:perfect_rank) { ["hot", "hot", "fresh", "vip", "piv"] }
54
+ let(:actual_rank) { ["hot", "hot", "fresh", "piv", "vip"] }
55
+
56
+ it "should get 0.9 as FCP value" do
57
+ calculator = FCPCalculator.run(rank_reader: reader)
58
+ expect(calculator).to be_a_success
59
+ expect(calculator.value).to eq(0.9)
60
+ end
61
+ end
62
+
63
+ context "when duplicated pairs do not occur on actual rank" do
64
+ let(:perfect_rank) { ["hot", "hot", "fresh", "vip", "piv"] }
65
+ let(:actual_rank) { ["hot", "fresh", "fresh", "vip", "piv"] }
66
+
67
+ it "should get 0.7 as FCP value" do
68
+ calculator = FCPCalculator.run(rank_reader: reader)
69
+ expect(calculator).to be_a_success
70
+ expect(calculator.value).to eq(0.7)
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,49 @@
1
+ require_relative "../../../lib/rankum/readers/rank_file_reader"
2
+
3
+ module Rankum
4
+ module Readers
5
+ describe RankFileReader do
6
+ let(:subject) { RankFileReader.new }
7
+
8
+ context "when adding a path to the perfect rank as a txt file" do
9
+ let(:perfect_rank_path) { "spec/fixtures/perfect_rank.txt" }
10
+ before { subject.add_perfect_rank_path(perfect_rank_path) }
11
+
12
+ it "should convert to a list" do
13
+ expect(subject.perfect_rank).to be_a_kind_of(Array)
14
+ end
15
+
16
+ it "should add position number to each item rank" do
17
+ expected_list = ("A".."Z").to_a
18
+ expect(subject.perfect_rank).to eq(expected_list)
19
+ end
20
+ end
21
+
22
+ context "when adding a path to the actual rank as a txt file" do
23
+ let(:actual_rank_path) { "spec/fixtures/actual_rank.txt" }
24
+ before { subject.add_actual_rank_path(actual_rank_path) }
25
+
26
+ it "should convert to a list" do
27
+ expect(subject.actual_rank).to be_a_kind_of(Array)
28
+ end
29
+
30
+ it "should add position number to each item rank" do
31
+ expected_list = ("A".."Z").to_a.reverse
32
+ expect(subject.actual_rank).to eq(expected_list)
33
+ end
34
+ end
35
+
36
+ context "when has repeated pairs" do
37
+ let(:rank_path) { "spec/fixtures/repeated_rank.txt" }
38
+ before { subject.add_perfect_rank_path(rank_path) }
39
+ let(:expected_list) { ["hot", "hot", "fresh", "vip", "piv"] }
40
+
41
+ it "should returned a ordered list" do
42
+ expect(subject.perfect_rank).to eq(expected_list)
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,36 @@
1
+ require_relative "../../../lib/rankum/runners/cli_outputer"
2
+
3
+ module Rankum
4
+ module Runners
5
+ describe CLIOutputer do
6
+
7
+ context "when has a result value" do
8
+ it "should round value" do
9
+ result = CLIOutputer.run(value: 0.4242)
10
+
11
+ expect(result).to be_a_success
12
+ expect(result.value).to eq(42.42)
13
+ end
14
+
15
+ it "should return output lines" do
16
+ result = CLIOutputer.run(value: 0.4242, metric: "FCP")
17
+ output = result.output
18
+
19
+ expect(result).to be_a_success
20
+ expect(output[0]).to eq("Rankum")
21
+ expect(output[1]).to match(/-.*/)
22
+ expect(output[2]).to match(/Metric: [\s|\S].*/)
23
+ expect(output[3]).to eq("Similarity: #{Paint["42.42 %", :red, :bright]}")
24
+ end
25
+ end
26
+
27
+ context "when result is nil" do
28
+ it "should fail" do
29
+ result = CLIOutputer.run
30
+ expect(result).to be_a_fail
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require_relative "../../../lib/rankum/runners/cli_setup"
2
+
3
+ module Rankum
4
+ module Runners
5
+ describe CLISetup do
6
+
7
+ context "when receiving valid parameters" do
8
+ let(:cli_params) do
9
+ {
10
+ metric: "fcp",
11
+ rank_reader: "RankFileReader",
12
+ perfect_rank: "spec/fixtures/perfect_rank.txt",
13
+ actual_rank: "spec/fixtures/actual_rank.txt"
14
+ }
15
+ end
16
+
17
+ it "should set up parameters" do
18
+ result = CLISetup.run(cli_params)
19
+
20
+ expect(result).to be_a_success
21
+ expect(result.rank_reader).to be_a_kind_of(Rankum::Readers::RankFileReader)
22
+ end
23
+
24
+ it "should add ranks to rank file reader" do
25
+ reader = CLISetup.run(cli_params).rank_reader
26
+ list = ("A".."Z").to_a
27
+ reversed_list = ("A".."Z").to_a.reverse
28
+
29
+ expect(reader.perfect_rank).to eq(list)
30
+ expect(reader.actual_rank).to eq(reversed_list)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,35 @@
1
+ require_relative "../../../lib/rankum/utils/fcp_pair"
2
+
3
+ module Rankum
4
+ module Utils
5
+ describe FCPPair do
6
+
7
+ context "when receiving a rank as an array" do
8
+ let(:rank) { ["A", "A", "C", "D", "E"] }
9
+ let(:pair_array) { [ Pair.new("A","A"), Pair.new("A","C"), Pair.new("A","D"), Pair.new("A", "E"),
10
+ Pair.new("A","C"), Pair.new("A","D"), Pair.new("A", "E"),
11
+ Pair.new("C","D"), Pair.new("C","E"),
12
+ Pair.new("D", "E") ] }
13
+
14
+ let(:pair_hash) do
15
+ { Pair.new("A","A") => 1,
16
+ Pair.new("A","C") => 2,
17
+ Pair.new("A","D") => 2,
18
+ Pair.new("A", "E") => 2,
19
+ Pair.new("C","D") => 1,
20
+ Pair.new("C","E") => 1,
21
+ Pair.new("D", "E") => 1 }
22
+ end
23
+
24
+ it "should return an array of pairs" do
25
+ expect(FCPPair.to_a(rank)).to eq(pair_array)
26
+ end
27
+
28
+ it "should return a hash of pair occurences" do
29
+ expect(FCPPair.to_h(rank)).to eq(pair_hash)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
File without changes
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rankum
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Felipe Besson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mixlib-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: A gem to compare search ranks using flexible quality rank metrics
42
+ email: flpbesson@gmail.com
43
+ executables:
44
+ - rankum
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - bin/rankum
55
+ - lib/rankum.rb
56
+ - lib/rankum/metrics/fcp_calculator.rb
57
+ - lib/rankum/readers/rank_file_reader.rb
58
+ - lib/rankum/runners/cli_outputer.rb
59
+ - lib/rankum/runners/cli_setup.rb
60
+ - lib/rankum/runners/rankum_cli.rb
61
+ - lib/rankum/utils/fcp_pair.rb
62
+ - lib/rankum/utils/interactor.rb
63
+ - rankum.gemspec
64
+ - spec/fixtures/actual_rank.txt
65
+ - spec/fixtures/perfect_rank.txt
66
+ - spec/fixtures/repeated_rank.txt
67
+ - spec/rankum/metrics/fcp_calculator_spec.rb
68
+ - spec/rankum/readers/rank_file_reader_spec.rb
69
+ - spec/rankum/runners/cli_outputer_spec.rb
70
+ - spec/rankum/runners/cli_setup_spec.rb
71
+ - spec/rankum/utils/fcp_pair_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/besson/rankum
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Measure search rank quality
97
+ test_files:
98
+ - spec/fixtures/actual_rank.txt
99
+ - spec/fixtures/perfect_rank.txt
100
+ - spec/fixtures/repeated_rank.txt
101
+ - spec/rankum/metrics/fcp_calculator_spec.rb
102
+ - spec/rankum/readers/rank_file_reader_spec.rb
103
+ - spec/rankum/runners/cli_outputer_spec.rb
104
+ - spec/rankum/runners/cli_setup_spec.rb
105
+ - spec/rankum/utils/fcp_pair_spec.rb
106
+ - spec/spec_helper.rb