-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# This will evolve into word recognition | ||
|
||
#puts "initializing dict file" | ||
#puts "dict file has #{DICT.size} words" | ||
|
||
class String | ||
DICT_FILE = '/usr/share/dict/words' | ||
def dict | ||
@@dict ||= IO.readlines(DICT_FILE) | ||
end | ||
|
||
def word? | ||
!dict.grep(/^#{self}\n/i).empty? && self.size != 1 | ||
end | ||
end | ||
|
||
#test = 'thisisatest' | ||
test = 'thisisamuchlargerfuckingtest' | ||
|
||
puts "Testing: #{test}" | ||
puts "basic: #{test.word?}" | ||
|
||
@start = test.split(//).first | ||
@end = @start.dup | ||
@words = [] | ||
test.split(//).each do |char| | ||
@current = char | ||
end | ||
|
||
def gross_check(str) | ||
for i in 0..str.size - 1 do | ||
@current = str[i].chr | ||
puts "Inspecting current letter: #{@current}" | ||
j = i | ||
while j < str.size - 1 | ||
puts "checking word status of #{str[i..j]}: #{str[i..j].word?}" if str[i..j].word? | ||
j += 1 | ||
end | ||
end | ||
end | ||
|
||
def simple_check(str) | ||
i = 0 | ||
found = false | ||
while i < str.size - 1 # for the whole string | ||
j = i | ||
while j < str.size - 1 | ||
if str[i..j].word? | ||
found = true | ||
puts "word found: #{str[i..j]}" | ||
else | ||
j += 1 | ||
end | ||
while found && j < str.size - 1 | ||
j += 1 | ||
found = false unless str[i..j].word? | ||
end | ||
#puts "current word: #{str[i..j]}" | ||
end | ||
end | ||
end | ||
|
||
|
||
puts "t: #{'t'.word?}" | ||
puts "th: #{'th'.word?}" | ||
puts "thi: #{'thi'.word?}" | ||
puts "this: #{'this'.word?}" | ||
|
||
|
||
#gross_check test | ||
simple_check test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters