zelkova 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +57 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +173 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/tapioca +27 -0
- data/lib/zelkova/edge.rb +26 -0
- data/lib/zelkova/graph.rb +104 -0
- data/lib/zelkova/node.rb +32 -0
- data/lib/zelkova/version.rb +4 -0
- data/lib/zelkova.rb +10 -0
- data/sorbet/config +3 -0
- data/sorbet/rbi/gems/byebug.rbi +1041 -0
- data/sorbet/rbi/gems/climate_control.rbi +46 -0
- data/sorbet/rbi/gems/coderay.rbi +92 -0
- data/sorbet/rbi/gems/eikon.rbi +48 -0
- data/sorbet/rbi/gems/ffi.rbi +560 -0
- data/sorbet/rbi/gems/method_source.rbi +64 -0
- data/sorbet/rbi/gems/minitest.rbi +422 -0
- data/sorbet/rbi/gems/pry.rbi +1949 -0
- data/sorbet/rbi/gems/rake.rbi +645 -0
- data/sorbet/rbi/gems/ruby-vips.rbi +656 -0
- data/sorbet/rbi/gems/ruby_jard.rbi +681 -0
- data/sorbet/rbi/gems/terrapin.rbi +116 -0
- data/sorbet/rbi/gems/tty-screen.rbi +66 -0
- data/sorbet/rbi/gems/zelkova.rbi +15 -0
- data/sorbet/rbi/hidden-definitions/errors.txt +34600 -0
- data/sorbet/rbi/hidden-definitions/hidden.rbi +17564 -0
- data/sorbet/rbi/sorbet-typed/lib/actionpack/all/actionpack.rbi +1138 -0
- data/sorbet/rbi/sorbet-typed/lib/actionview/all/actionview.rbi +408 -0
- data/sorbet/rbi/sorbet-typed/lib/activesupport/>=6/activesupport.rbi +37 -0
- data/sorbet/rbi/sorbet-typed/lib/activesupport/all/activesupport.rbi +1850 -0
- data/sorbet/rbi/sorbet-typed/lib/minitest/all/minitest.rbi +108 -0
- data/sorbet/rbi/sorbet-typed/lib/railties/>=6.1/railties.rbi +15 -0
- data/sorbet/rbi/sorbet-typed/lib/railties/all/railties.rbi +110 -0
- data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +276 -0
- data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
- data/sorbet/rbi/sorbet-typed/lib/rubocop/>=1.8/rubocop.rbi +12 -0
- data/sorbet/rbi/sorbet-typed/lib/rubocop-performance/~>1.6/rubocop-performance.rbi +149 -0
- data/sorbet/rbi/sorbet-typed/lib/rubocop-rails/~>2.5/rubocop-rails.rbi +328 -0
- data/sorbet/rbi/sorbet-typed/lib/thor/all/thor.rbi +905 -0
- data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +32 -0
- data/sorbet/rbi/todo.rbi +15 -0
- data/sorbet/tapioca/config.yml +13 -0
- data/sorbet/tapioca/require.rb +4 -0
- data/zelkova.gemspec +31 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 86b06cdb9578edcaa80c633a1b2205d9a01fd231aaecbc3c8721482ab960da36
|
4
|
+
data.tar.gz: b94f3080271dc65a3c4f21c7e7bf95d1ea25f3b9509825278aeea819b13bd6f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2e6e47acd4da9b54db90a18039f6af0d7635cc54e630570bbbbf3e7f9da5ebc71c5fe7acbe7aa5f2eea40ae8a0ad2c53c1534ee77932649c03f3e04e355d4bd
|
7
|
+
data.tar.gz: f9f6a520545eeaf470729a6ad1332884b6753857b8fd7535c8c3088086b8fb308460dc742a1d791b813176a8ab5247945dd07ab09068603622b95a59f9378dab
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rails
|
3
|
+
- rubocop-performance
|
4
|
+
|
5
|
+
inherit_gem:
|
6
|
+
rubocop-rails_config:
|
7
|
+
- config/rails.yml
|
8
|
+
|
9
|
+
AllCops:
|
10
|
+
Exclude:
|
11
|
+
- db/schema.rb
|
12
|
+
- 'node_modules/**/*'
|
13
|
+
- 'redis-stable/**/*'
|
14
|
+
- 'bin/**/*'
|
15
|
+
- 'vendor/**/*'
|
16
|
+
TargetRubyVersion: 3.1
|
17
|
+
|
18
|
+
# This sets us to use the standard Rails format instead of Rubocop's
|
19
|
+
# opinionated Ruby style.
|
20
|
+
Style/FrozenStringLiteralComment:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
# This sets us to use the standard Rails format instead of Rubocop's
|
24
|
+
# opinionated Ruby style.
|
25
|
+
Style/ClassAndModuleChildren:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
# Temporarily turn this off
|
29
|
+
Metrics/AbcSize:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Metrics/ClassLength:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Lint/RescueException:
|
36
|
+
Enabled: true
|
37
|
+
|
38
|
+
Lint/Debugger:
|
39
|
+
Enabled: true
|
40
|
+
|
41
|
+
Rails/HasManyOrHasOneDependent:
|
42
|
+
Enabled: true
|
43
|
+
|
44
|
+
Rails/HasAndBelongsToMany:
|
45
|
+
Enabled: true
|
46
|
+
|
47
|
+
Style/NumericPredicate:
|
48
|
+
Enabled: true
|
49
|
+
|
50
|
+
Style/HashSyntax:
|
51
|
+
EnforcedShorthandSyntax: 'never'
|
52
|
+
|
53
|
+
# This sets us to use the standard Rails format instead of Rubocop's
|
54
|
+
# opinionated Ruby style.
|
55
|
+
Layout/EmptyLinesAroundAccessModifier:
|
56
|
+
Enabled: true
|
57
|
+
EnforcedStyle: 'around'
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at cguess@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in zelkova.gemspec
|
4
|
+
|
5
|
+
gem "rake", "~> 12.0"
|
6
|
+
gem "minitest", "~> 5.0"
|
7
|
+
|
8
|
+
gem "byebug"
|
9
|
+
gem "ruby_jard"
|
10
|
+
|
11
|
+
gem "rubocop", "~> 1.27", require: false
|
12
|
+
gem "rubocop-rails", require: false # Rails specific styles
|
13
|
+
gem "rubocop-rails_config", require: false # More Rails stuff
|
14
|
+
|
15
|
+
gem "sorbet-static-and-runtime"
|
16
|
+
|
17
|
+
gem "tapioca", require: false
|
18
|
+
|
19
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zelkova (0.1.0)
|
5
|
+
eikon
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (7.0.2.4)
|
11
|
+
actionview (= 7.0.2.4)
|
12
|
+
activesupport (= 7.0.2.4)
|
13
|
+
rack (~> 2.0, >= 2.2.0)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
+
actionview (7.0.2.4)
|
18
|
+
activesupport (= 7.0.2.4)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
+
activesupport (7.0.2.4)
|
24
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
|
+
i18n (>= 1.6, < 2)
|
26
|
+
minitest (>= 5.1)
|
27
|
+
tzinfo (~> 2.0)
|
28
|
+
ast (2.4.2)
|
29
|
+
builder (3.2.4)
|
30
|
+
byebug (11.1.3)
|
31
|
+
climate_control (0.2.0)
|
32
|
+
coderay (1.1.3)
|
33
|
+
concurrent-ruby (1.1.10)
|
34
|
+
crass (1.0.6)
|
35
|
+
diff-lcs (1.5.0)
|
36
|
+
eikon (0.1.1)
|
37
|
+
ruby-vips (~> 2.1)
|
38
|
+
sorbet-runtime (>= 0.5.9204)
|
39
|
+
terrapin (~> 0.6.0)
|
40
|
+
erubi (1.10.0)
|
41
|
+
ffi (1.15.5)
|
42
|
+
i18n (1.10.0)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
loofah (2.16.0)
|
45
|
+
crass (~> 1.0.2)
|
46
|
+
nokogiri (>= 1.5.9)
|
47
|
+
method_source (1.0.0)
|
48
|
+
minitest (5.15.0)
|
49
|
+
nokogiri (1.13.4-arm64-darwin)
|
50
|
+
racc (~> 1.4)
|
51
|
+
parallel (1.22.1)
|
52
|
+
parser (3.1.2.0)
|
53
|
+
ast (~> 2.4.1)
|
54
|
+
pry (0.13.1)
|
55
|
+
coderay (~> 1.1)
|
56
|
+
method_source (~> 1.0)
|
57
|
+
racc (1.6.0)
|
58
|
+
rack (2.2.3)
|
59
|
+
rack-test (1.1.0)
|
60
|
+
rack (>= 1.0, < 3)
|
61
|
+
rails-dom-testing (2.0.3)
|
62
|
+
activesupport (>= 4.2.0)
|
63
|
+
nokogiri (>= 1.6)
|
64
|
+
rails-html-sanitizer (1.4.2)
|
65
|
+
loofah (~> 2.3)
|
66
|
+
railties (7.0.2.4)
|
67
|
+
actionpack (= 7.0.2.4)
|
68
|
+
activesupport (= 7.0.2.4)
|
69
|
+
method_source
|
70
|
+
rake (>= 12.2)
|
71
|
+
thor (~> 1.0)
|
72
|
+
zeitwerk (~> 2.5)
|
73
|
+
rainbow (3.1.1)
|
74
|
+
rake (12.3.3)
|
75
|
+
rbi (0.0.14)
|
76
|
+
ast
|
77
|
+
parser (>= 2.6.4.0)
|
78
|
+
sorbet-runtime (>= 0.5.9204)
|
79
|
+
unparser
|
80
|
+
regexp_parser (2.3.1)
|
81
|
+
rexml (3.2.5)
|
82
|
+
rubocop (1.28.2)
|
83
|
+
parallel (~> 1.10)
|
84
|
+
parser (>= 3.1.0.0)
|
85
|
+
rainbow (>= 2.2.2, < 4.0)
|
86
|
+
regexp_parser (>= 1.8, < 3.0)
|
87
|
+
rexml
|
88
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
89
|
+
ruby-progressbar (~> 1.7)
|
90
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
91
|
+
rubocop-ast (1.17.0)
|
92
|
+
parser (>= 3.1.1.0)
|
93
|
+
rubocop-minitest (0.19.1)
|
94
|
+
rubocop (>= 0.90, < 2.0)
|
95
|
+
rubocop-packaging (0.5.1)
|
96
|
+
rubocop (>= 0.89, < 2.0)
|
97
|
+
rubocop-performance (1.13.3)
|
98
|
+
rubocop (>= 1.7.0, < 2.0)
|
99
|
+
rubocop-ast (>= 0.4.0)
|
100
|
+
rubocop-rails (2.14.2)
|
101
|
+
activesupport (>= 4.2.0)
|
102
|
+
rack (>= 1.1)
|
103
|
+
rubocop (>= 1.7.0, < 2.0)
|
104
|
+
rubocop-rails_config (1.9.2)
|
105
|
+
railties (>= 5.0)
|
106
|
+
rubocop (>= 1.25.1)
|
107
|
+
rubocop-ast (>= 1.0.1)
|
108
|
+
rubocop-minitest (~> 0.15)
|
109
|
+
rubocop-packaging (~> 0.5)
|
110
|
+
rubocop-performance (~> 1.11)
|
111
|
+
rubocop-rails (~> 2.0)
|
112
|
+
ruby-progressbar (1.11.0)
|
113
|
+
ruby-vips (2.1.4)
|
114
|
+
ffi (~> 1.12)
|
115
|
+
ruby_jard (0.3.1)
|
116
|
+
byebug (>= 9.1, < 12.0)
|
117
|
+
pry (~> 0.13.0)
|
118
|
+
tty-screen (~> 0.8.1)
|
119
|
+
sorbet (0.5.9944)
|
120
|
+
sorbet-static (= 0.5.9944)
|
121
|
+
sorbet-runtime (0.5.9944)
|
122
|
+
sorbet-static (0.5.9944-universal-darwin-21)
|
123
|
+
sorbet-static-and-runtime (0.5.9944)
|
124
|
+
sorbet (= 0.5.9944)
|
125
|
+
sorbet-runtime (= 0.5.9944)
|
126
|
+
spoom (1.1.11)
|
127
|
+
sorbet (>= 0.5.9204)
|
128
|
+
sorbet-runtime (>= 0.5.9204)
|
129
|
+
thor (>= 0.19.2)
|
130
|
+
tapioca (0.7.1)
|
131
|
+
bundler (>= 1.17.3)
|
132
|
+
pry (>= 0.12.2)
|
133
|
+
rbi (~> 0.0.0, >= 0.0.14)
|
134
|
+
sorbet-runtime (>= 0.5.9204)
|
135
|
+
sorbet-static (>= 0.5.9204)
|
136
|
+
spoom (~> 1.1.0, >= 1.1.4)
|
137
|
+
thor (>= 1.2.0)
|
138
|
+
yard-sorbet
|
139
|
+
terrapin (0.6.0)
|
140
|
+
climate_control (>= 0.0.3, < 1.0)
|
141
|
+
thor (1.2.1)
|
142
|
+
tty-screen (0.8.1)
|
143
|
+
tzinfo (2.0.4)
|
144
|
+
concurrent-ruby (~> 1.0)
|
145
|
+
unicode-display_width (2.1.0)
|
146
|
+
unparser (0.6.5)
|
147
|
+
diff-lcs (~> 1.3)
|
148
|
+
parser (>= 3.1.0)
|
149
|
+
webrick (1.7.0)
|
150
|
+
yard (0.9.27)
|
151
|
+
webrick (~> 1.7.0)
|
152
|
+
yard-sorbet (0.6.1)
|
153
|
+
sorbet-runtime (>= 0.5)
|
154
|
+
yard (>= 0.9)
|
155
|
+
zeitwerk (2.5.4)
|
156
|
+
|
157
|
+
PLATFORMS
|
158
|
+
arm64-darwin-21
|
159
|
+
|
160
|
+
DEPENDENCIES
|
161
|
+
byebug
|
162
|
+
minitest (~> 5.0)
|
163
|
+
rake (~> 12.0)
|
164
|
+
rubocop (~> 1.27)
|
165
|
+
rubocop-rails
|
166
|
+
rubocop-rails_config
|
167
|
+
ruby_jard
|
168
|
+
sorbet-static-and-runtime
|
169
|
+
tapioca
|
170
|
+
zelkova!
|
171
|
+
|
172
|
+
BUNDLED WITH
|
173
|
+
2.3.11
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Christopher Guess
|
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,53 @@
|
|
1
|
+
# Zelkova
|
2
|
+
|
3
|
+
This is a pure Ruby implementation of a BK-Tree (https://signal-to-noise.xyz/post/bk-tree/) which
|
4
|
+
can be used for any sort of quick comparison for hamming distances. Usually this is for something
|
5
|
+
like spell check or auto suggestions, but it can also be utilized for image similarity search as
|
6
|
+
well.
|
7
|
+
|
8
|
+
It runs completely in memory, which makes it very quick (even at 500,000 words), this takes up a
|
9
|
+
little space, taking about 4MB for 400,000 words. Building the graph taking about 35 seconds for 400k
|
10
|
+
elements and about 1-2 seconds to search depending on the length of the search query (longer query
|
11
|
+
is longer time).
|
12
|
+
|
13
|
+
Eventually it'd be faster to rewrite this in C and toss a Ruby wrapper over it, but for now this will
|
14
|
+
work quite well for what we want it to.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'zelkova'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle install
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install zelkova
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
TODO: Write usage instructions here
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
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).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zelkova. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/zelkova/blob/master/CODE_OF_CONDUCT.md).
|
45
|
+
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the Zelkova project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/zelkova/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zelkova"
|
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
data/bin/tapioca
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'tapioca' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
12
|
+
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
14
|
+
|
15
|
+
if File.file?(bundle_binstub)
|
16
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
17
|
+
load(bundle_binstub)
|
18
|
+
else
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "rubygems"
|
25
|
+
require "bundler/setup"
|
26
|
+
|
27
|
+
load Gem.bin_path("tapioca", "tapioca")
|
data/lib/zelkova/edge.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# typed: strict
|
2
|
+
|
3
|
+
require "sorbet-runtime"
|
4
|
+
|
5
|
+
class Zelkova::Edge
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig { returns(Zelkova::Node) }
|
9
|
+
attr_reader :start_node
|
10
|
+
sig { returns(Zelkova::Node) }
|
11
|
+
attr_reader :end_node
|
12
|
+
sig { returns(Integer) }
|
13
|
+
attr_reader :weight
|
14
|
+
|
15
|
+
sig { params(start_node: Zelkova::Node, end_node: Zelkova::Node, weight: Integer).void }
|
16
|
+
def initialize(start_node, end_node, weight)
|
17
|
+
@start_node = T.let(start_node, Zelkova::Node)
|
18
|
+
@end_node = T.let(end_node, Zelkova::Node)
|
19
|
+
@weight = T.let(weight, Integer)
|
20
|
+
end
|
21
|
+
|
22
|
+
sig { returns(String) }
|
23
|
+
def inspect
|
24
|
+
"Start Word: #{self.start_node.word}, End Word: #{self.end_node.word}, Weight: #{weight}"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# typed: strict
|
2
|
+
#
|
3
|
+
require "sorbet-runtime"
|
4
|
+
require "eikon"
|
5
|
+
|
6
|
+
require_relative "node"
|
7
|
+
require_relative "edge"
|
8
|
+
|
9
|
+
class Zelkova::Graph
|
10
|
+
extend T::Sig
|
11
|
+
|
12
|
+
sig { returns(T.nilable(Zelkova::Node)) }
|
13
|
+
attr_reader :root_node
|
14
|
+
|
15
|
+
sig { returns(T::Array[Zelkova::Node]) }
|
16
|
+
attr_reader :nodes
|
17
|
+
|
18
|
+
sig { returns(Integer) }
|
19
|
+
attr_reader :depth
|
20
|
+
|
21
|
+
sig { void }
|
22
|
+
def initialize
|
23
|
+
@root_node = T.let(nil, T.nilable(Zelkova::Node))
|
24
|
+
@nodes = T.let([], T::Array[Zelkova::Node])
|
25
|
+
@depth = T.let(0, Integer)
|
26
|
+
end
|
27
|
+
|
28
|
+
sig { params(word: String).returns(Zelkova::Node) }
|
29
|
+
def add_node(word)
|
30
|
+
node = Zelkova::Node.new(word, self)
|
31
|
+
nodes << node
|
32
|
+
|
33
|
+
if @root_node.nil?
|
34
|
+
@root_node = node
|
35
|
+
@depth = 1
|
36
|
+
return node
|
37
|
+
end
|
38
|
+
|
39
|
+
current_node = T.let(@root_node, Zelkova::Node)
|
40
|
+
node_depth = 1
|
41
|
+
|
42
|
+
loop do
|
43
|
+
distance = Eikon::Comparator.compare(current_node.word, word)
|
44
|
+
break if distance.zero? # don't add if it's already in the graph
|
45
|
+
|
46
|
+
edge = current_node.edges.select { |edge| edge.weight == distance }
|
47
|
+
|
48
|
+
unless edge.empty?
|
49
|
+
current_node = T.must(edge.first).end_node
|
50
|
+
node_depth += 1
|
51
|
+
next
|
52
|
+
end
|
53
|
+
|
54
|
+
current_node.add_edge(node, distance)
|
55
|
+
break
|
56
|
+
end
|
57
|
+
|
58
|
+
@depth = node_depth if node_depth > @depth
|
59
|
+
|
60
|
+
node
|
61
|
+
end
|
62
|
+
|
63
|
+
sig { params(query: String).returns(T::Array[String]) }
|
64
|
+
def search(query)
|
65
|
+
radius = 2
|
66
|
+
candidate_nodes = []
|
67
|
+
candidate_edges = []
|
68
|
+
|
69
|
+
# just so we can start this out
|
70
|
+
candidate_edges << Zelkova::Edge.new(T.must(@root_node), T.must(@root_node), 0)
|
71
|
+
|
72
|
+
loop do
|
73
|
+
node = candidate_edges.pop.end_node
|
74
|
+
|
75
|
+
distance = Eikon::Comparator.compare(query, node.word)
|
76
|
+
candidate_nodes << { node: node, distance: distance } if distance <= radius
|
77
|
+
|
78
|
+
node.edges.each do |edge|
|
79
|
+
if edge.weight > (distance - radius) || edge.weight < (distance + radius)
|
80
|
+
candidate_edges << edge
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
break if candidate_edges.empty?
|
85
|
+
end
|
86
|
+
|
87
|
+
candidate_nodes.sort_by! { |candidate_node| candidate_node[:distance] }
|
88
|
+
candidate_nodes.map { |candidate_node| candidate_node[:node].word }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# class Comparator
|
93
|
+
# extend T::Sig
|
94
|
+
|
95
|
+
# sig { params(dhash_1: String, dhash_2: String).returns(Integer) }
|
96
|
+
# def self.compare(dhash_1, dhash_2)
|
97
|
+
# hamming_distance = 0
|
98
|
+
# dhash_1.chars.each_with_index do |character, index|
|
99
|
+
# hamming_distance += 1 if character != dhash_2.chars[index]
|
100
|
+
# end
|
101
|
+
|
102
|
+
# hamming_distance + (dhash_1.length - dhash_2.length).abs
|
103
|
+
# end
|
104
|
+
# end
|
data/lib/zelkova/node.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# typed: strict
|
2
|
+
|
3
|
+
require "sorbet-runtime"
|
4
|
+
|
5
|
+
class Zelkova::Node
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig { returns(String) }
|
9
|
+
attr_reader :word
|
10
|
+
sig { returns(T::Array[Zelkova::Edge]) }
|
11
|
+
attr_reader :edges
|
12
|
+
sig { returns(Zelkova::Graph) }
|
13
|
+
attr_reader :graph
|
14
|
+
|
15
|
+
sig { params(word: String, graph: Zelkova::Graph).void }
|
16
|
+
def initialize(word, graph)
|
17
|
+
@word = T.let(word, String)
|
18
|
+
@graph = T.let(graph, Zelkova::Graph)
|
19
|
+
|
20
|
+
@edges = T.let([], T::Array[Zelkova::Edge])
|
21
|
+
end
|
22
|
+
|
23
|
+
sig { returns(String) }
|
24
|
+
def inspect
|
25
|
+
"Word: #{self.word}, Number of Edges: #{self.edges.count}"
|
26
|
+
end
|
27
|
+
|
28
|
+
sig { params(node: Zelkova::Node, weight: Integer).void }
|
29
|
+
def add_edge(node, weight)
|
30
|
+
@edges << Zelkova::Edge.new(self, node, weight)
|
31
|
+
end
|
32
|
+
end
|
data/lib/zelkova.rb
ADDED
data/sorbet/config
ADDED