game_set_match 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rvmrc +60 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/game_set_match.gemspec +26 -0
- data/lib/game_set_match/version.rb +3 -0
- data/lib/game_set_match.rb +8 -0
- data/lib/matcher.rb +85 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a4bf9f5e0c42f285b77053654bd1fda69b6a1223
|
4
|
+
data.tar.gz: 182bc872d271844332cf83649ca75d082305d864
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5397788b8d72c6501f105f3cdaebb5ed4ba934ca99174484f1da48d20ec9bbb5bf32e9535681ba535f9083d9cdcb72042c2709d51b09676cc9a91a20cff41b5b
|
7
|
+
data.tar.gz: 863c3b1e67756d0f935b0c35eec06a02b2943b6106d759ae10985a50986d515020735cae6f06d48ecc796be90aaefe265553cbb7312ab33fd420648cfd3e87c9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 2.3.1@game_set_match" > .rvmrc
|
9
|
+
environment_id="ruby-2.3.1@game_set_match"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.27.0 (master)" # 1.10.1 seems like a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
+
do
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
+
then \. "${__hook}" || true
|
30
|
+
fi
|
31
|
+
done
|
32
|
+
unset __hook
|
33
|
+
if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
|
34
|
+
then
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)\n" # show the user the ruby and gemset they are using in green
|
37
|
+
else printf "%b" "Using: $GEM_HOME\n" # don't use colors in non-interactive shells
|
38
|
+
fi
|
39
|
+
fi
|
40
|
+
else
|
41
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
42
|
+
rvm --create "$environment_id" || {
|
43
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
44
|
+
return 1
|
45
|
+
}
|
46
|
+
fi
|
47
|
+
|
48
|
+
# If you use bundler, this might be useful to you:
|
49
|
+
# if [[ -s Gemfile ]] && {
|
50
|
+
# ! builtin command -v bundle >/dev/null ||
|
51
|
+
# builtin command -v bundle | GREP_OPTIONS="" \command \grep $rvm_path/bin/bundle >/dev/null
|
52
|
+
# }
|
53
|
+
# then
|
54
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
55
|
+
# gem install bundler
|
56
|
+
# fi
|
57
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
58
|
+
# then
|
59
|
+
# bundle install | GREP_OPTIONS="" \command \grep -vE '^Using|Your bundle is complete'
|
60
|
+
# fi
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Piper Gragg
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# GameSetMatch
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'game_set_match'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install game_set_match
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
Let's say you have two lists of songs: filenames and user inputs. You want to match user inputs to filenames that you have.
|
21
|
+
|
22
|
+
```
|
23
|
+
filenames = ['01 - Lana Del Rey.mp4', '04 - The Heebee Jeeby Experience', '05 - Woodstock: What I learned']
|
24
|
+
user_inputs = ['the_ heebee jeeby experience', 'lana del ray', 'woodstok what I learned']
|
25
|
+
GameSetMatch.new(filenames, user_inputs) =>
|
26
|
+
{"the_ heebee jeeby experience"=>"04 - The Heebee Jeeby Experience",
|
27
|
+
"lana del ray"=>"01 - Lana Del Rey.mp4",
|
28
|
+
"woodstok what I learned"=>"05 - Woodstock: What I learned"}
|
29
|
+
```
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pgragg/game_set_match.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
44
|
+
|
45
|
+
## TODO
|
46
|
+
Title words which belong to fewer objects should be weighted more heavily, since they are more unique.
|
47
|
+
Longer title words should be weighted more heavily.
|
48
|
+
Commonly used words should not be considered when weighting titles (the, an, a, or, etc.)
|
49
|
+
Users should have the option of outputting a list of indices or of matched objects.
|
50
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "game_set_match"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'game_set_match/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "game_set_match"
|
8
|
+
spec.version = GameSetMatch::VERSION
|
9
|
+
spec.authors = ["Piper Gragg"]
|
10
|
+
spec.email = ["pipergragg@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Allow matching of terms in two enumerable sets.}
|
13
|
+
spec.homepage = "https://github.com/pgragg/game_set_match"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
data/lib/matcher.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
class Matcher
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
def initialize(set1, set2)
|
5
|
+
@set1 = set1
|
6
|
+
@set2 = set2
|
7
|
+
@set1_index = {}
|
8
|
+
@inverted_set1_index = {}
|
9
|
+
@set2_index = {}
|
10
|
+
@inverted_set2_index = {}
|
11
|
+
@recommendations = {}
|
12
|
+
@output = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def match
|
16
|
+
create_indices
|
17
|
+
create_inverted_indices
|
18
|
+
match_by_inverted_indices
|
19
|
+
lookup_output_values_by_index
|
20
|
+
return @output
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def remove_extra_symbols(string)
|
26
|
+
alphabet = Set.new(('a'..'z').to_a)
|
27
|
+
newString = string.to_s.downcase.to_s
|
28
|
+
newString.gsub!('_', ' ')
|
29
|
+
newString.gsub!('.m4a', '')
|
30
|
+
newString.gsub!('.mp4', '')
|
31
|
+
words = newString.split(' ')
|
32
|
+
new_words = []
|
33
|
+
words.each do |word|
|
34
|
+
new_words << word.split('').keep_if {|s| alphabet.include?(s)}.join('')
|
35
|
+
end
|
36
|
+
newString = new_words.join(' ')
|
37
|
+
newString
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_indices
|
41
|
+
@set1.each_with_index do |value_of_set_1, index|
|
42
|
+
@set1_index[index] = value_of_set_1
|
43
|
+
end
|
44
|
+
@set2.each_with_index do |value_of_set_2, index|
|
45
|
+
@set2_index[index] = value_of_set_2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def create_inverted_indices
|
49
|
+
@set1_index.each do |index, value_of_set_1|
|
50
|
+
words = remove_extra_symbols(value_of_set_1).split(' ')
|
51
|
+
words.each do |word|
|
52
|
+
@inverted_set1_index[word] ||= Set.new
|
53
|
+
@inverted_set1_index[word] << index
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@set2_index.each do |index, value_of_set_2|
|
57
|
+
words = remove_extra_symbols(value_of_set_2).split(' ')
|
58
|
+
words.each do |word|
|
59
|
+
@inverted_set2_index[word] ||= Set.new
|
60
|
+
@inverted_set2_index[word] << index
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def match_by_inverted_indices
|
66
|
+
@inverted_set2_index.each do |word, value_of_set_2_ids|
|
67
|
+
Array(@inverted_set1_index[word]).each do |set_1_member_id|
|
68
|
+
@recommendations[set_1_member_id] ||= {}
|
69
|
+
value_of_set_2_ids.each do |id|
|
70
|
+
@recommendations[set_1_member_id][id] ||= 0
|
71
|
+
@recommendations[set_1_member_id][id] += 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def lookup_output_values_by_index
|
78
|
+
@recommendations.each do |set_1_member_id, set_2_member_indices|
|
79
|
+
max_index = set_2_member_indices.max_by{|k,v| v}[0]
|
80
|
+
value_of_set_2 = @set2_index[max_index]
|
81
|
+
@output[value_of_set_2] = @set1_index[set_1_member_id]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: game_set_match
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Piper Gragg
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- pipergragg@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".rvmrc"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- game_set_match.gemspec
|
73
|
+
- lib/game_set_match.rb
|
74
|
+
- lib/game_set_match/version.rb
|
75
|
+
- lib/matcher.rb
|
76
|
+
homepage: https://github.com/pgragg/game_set_match
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.6.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Allow matching of terms in two enumerable sets.
|
100
|
+
test_files: []
|