Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,29 @@
if File.exist? "index.dat"
@data = Marshal.load open("index.dat")
else
@data = {}
end
# Let's give the string class the ability to tokenize itsself into lowercase
# words with no punctuation.
class String
def index_sanitize
self.split.collect do |token|
token.downcase.gsub(/\W/, '')
end
end
end
# Just implementing a simple inverted index here.
ARGV.each do |filename|
open filename do |file|
file.read.index_sanitize.each do |word|
@data[word] ||= []
@data[word] << filename unless @data[word].include? filename
end
end
end
open("index.dat", "w") do |index|
index.write Marshal.dump(@data)
end

View file

@ -0,0 +1,22 @@
if File.exist? "index.dat"
@data = Marshal.load open("index.dat")
else
raise "The index data file could not be located."
end
class String
def index_sanitize
self.split.collect do |token|
token.downcase.gsub(/\W/, '')
end
end
end
# Take anything passed in on the command line in any form and break it
# down the same way we did when making the index.
ARGV.join(' ').index_sanitize.each do |word|
@result ||= @data[word]
@result &= @data[word]
end
p @result