word_zoo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -9
- data/lib/word_zoo/version.rb +1 -1
- data/lib/word_zoo.rb +29 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e22906f1b1f5f3a9121307632b7857145577c0562a6149b62f141c82d39cb039
|
4
|
+
data.tar.gz: 6962d2b35d85effefa1e81cf1f86d6cca8f03851b8a067410bf1681d3e23710d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63986a14d6daedfc8ee2018c319bcd8c0785e7d3ca10453546ede0d4efc9726a8d2877e32d5b20ef0e5d1d08ae6d20a21818a7ffbc6ea50499cb529ddfc512ae
|
7
|
+
data.tar.gz: c4269c8c7f8063c1739105f090dd5ee32c69d1d12a1ce3c2f84367e6a904e37eabef2f87845f6fae8abde007e071f73e85d9a5e7a1c883cfec49a05b04e5db9d
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# WordZoo
|
2
2
|
|
3
|
-
|
3
|
+
This gem is about saving space and time. There is a near infinite amount of words in the english language, and many word lists can reac row counts in the millions.
|
4
4
|
|
5
|
-
|
5
|
+
Using dictionary trees with letter nodes, the largest a dictionary may get is 26 to the 26th power, which is large, but manageable. In this way words like 'cat', 'catepillar' and category may consolidate thier shared prefixes.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -32,22 +32,75 @@ Or install it yourself as:
|
|
32
32
|
t.string :name
|
33
33
|
|
34
34
|
|
35
|
+
## Instance methods:
|
35
36
|
|
37
|
+
# Input a word into a word tree
|
38
|
+
input_word(word)
|
39
|
+
eg:
|
40
|
+
> example_list.input_word("lao")
|
41
|
+
=> true
|
42
|
+
> example_list.input_word("lao")
|
43
|
+
=> true
|
36
44
|
|
37
|
-
|
45
|
+
# list all words
|
46
|
+
list_words
|
47
|
+
eg:
|
48
|
+
> example_list.list_words
|
49
|
+
=> ["matt", "lao"]
|
50
|
+
|
51
|
+
|
52
|
+
# Remove a word from a tree
|
53
|
+
def remove_word(word)
|
54
|
+
eg:
|
55
|
+
> example_list.remove_word("matt")
|
56
|
+
=> true
|
57
|
+
> example_list.list_words
|
58
|
+
=> ["lao"]
|
59
|
+
|
60
|
+
# get a hash whether or not certain lengths are in the tree
|
61
|
+
word_lengths_data
|
62
|
+
eg:
|
63
|
+
> example_list.word_lengths_data
|
64
|
+
=> {"4"=>1, "3"=>1, "6"=>1}
|
65
|
+
|
66
|
+
in this example the list_words method would return: ["matt", "matter", "lao"]: there are words of lengths 4, 3 and 6 present in the example dictionary tree.
|
67
|
+
|
68
|
+
|
69
|
+
# see if the input word exists in this list
|
70
|
+
is_word?(word)
|
71
|
+
eg:
|
72
|
+
> example_list.is_word?("matt")
|
73
|
+
=> true
|
74
|
+
> example_list.is_word?("pee")
|
75
|
+
=> false
|
76
|
+
|
77
|
+
# find a random word
|
78
|
+
> example_list.find_word
|
79
|
+
=> "matt"
|
80
|
+
|
81
|
+
# view the tree as it exists as a tree object
|
82
|
+
eg:
|
83
|
+
> examplelist.tree
|
84
|
+
=> {"m"=>{"is_word"=>false, "a"=>{"is_word"=>false, "t"=>{"is_word"=>false, "t"=>{"is_word"=>true}}}}, "l"=>{"is_word"=>false, "a"=>{"is_word"=>false, "o"=>{"is_word"=>true}}}}
|
38
85
|
|
39
|
-
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.
|
40
86
|
|
41
|
-
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
## Development
|
91
|
+
|
92
|
+
After pulling down the source code from github, use this in any local active record app.
|
93
|
+
```ruby
|
94
|
+
gem 'word_zoo', '0.1.1', path: "../word_zoo"
|
95
|
+
```
|
42
96
|
|
43
97
|
## Contributing
|
44
98
|
|
45
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
99
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/laomatt/word_zoo. This project is intended to be a safe, welcoming space for collaboration.
|
100
|
+
|
101
|
+
Please create PRs and tag the authors.
|
46
102
|
|
47
103
|
## License
|
48
104
|
|
49
105
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
106
|
|
51
|
-
## Code of Conduct
|
52
|
-
|
53
|
-
Everyone interacting in the WordZoo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/word_zoo/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/word_zoo/version.rb
CHANGED
data/lib/word_zoo.rb
CHANGED
@@ -65,8 +65,35 @@ module WordZoo
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def remove_word(word)
|
68
|
-
|
69
|
-
|
68
|
+
return if word.nil?
|
69
|
+
init_tree = self.tree
|
70
|
+
word_letters = word.downcase.split('')
|
71
|
+
|
72
|
+
find_letter_in_level = lambda do |word_letters_left, lvl_tree|
|
73
|
+
letter = word_letters_left.shift
|
74
|
+
|
75
|
+
if letter.nil?
|
76
|
+
lvl_tree['is_word'] = false
|
77
|
+
return lvl_tree
|
78
|
+
end
|
79
|
+
|
80
|
+
if !lvl_tree[letter]
|
81
|
+
lvl_tree[letter] = { 'is_word' => false }
|
82
|
+
end
|
83
|
+
|
84
|
+
lvl_tree[letter] = lvl_tree[letter].merge(find_letter_in_level.call(word_letters_left, lvl_tree[letter]))
|
85
|
+
|
86
|
+
lvl_tree
|
87
|
+
end
|
88
|
+
|
89
|
+
self.letters = find_letter_in_level.call(word_letters, init_tree).to_json
|
90
|
+
|
91
|
+
# update the lengths
|
92
|
+
lengths = self.word_lengths_data
|
93
|
+
lengths[word.length] = 1
|
94
|
+
self.word_lengths = lengths.to_json
|
95
|
+
|
96
|
+
self.save!
|
70
97
|
end
|
71
98
|
|
72
99
|
# get a hash of how many words of each length exists
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: word_zoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Lao
|
8
|
+
- Malika Kassen-Lao
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
12
|
date: 2022-04-17 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
|
-
description:
|
14
|
+
description: To use this, please include WordZoo as a module in your model.
|
14
15
|
email:
|
15
16
|
- laomatt1@gmail.com
|
16
17
|
executables: []
|