# $Id: Vortaro.rb,v 1.5 2001/10/03 17:44:19 ser Exp $

require "Radiko"

# This is an extension of the base Array class, which allows us to search
# for Strings  The searches result in the longest match; that is,
# the match() method will find the longest word with which the supplied string
# begins.  The goal is to do this in an efficient manner.
# Ex:
#	array = %w{ aa, aab, aabc, aac }
#	search_string = "aabbcc"
#	array.match( search_string )		=>		[ "aa", "aab" ]
#
# BUGS:
module EO
	class Vortaro < Hash
		def initialize file
		  	super()
			dictionary_file = File.new file
			count = 0
			dictionary_file.each do |line|
				root, type, subtype, english = line.split
				vorto = Radiko.new( root, type, subtype, english )
				self[root] = vorto
				count += 1
				if count % 40 == 0
					printf "."
					$defout.flush
				end
			end
			puts
		end
		
		def matches word
		  w = ""
		  rv = []
		  word.each_byte do |c|
			 w << "%c"%c
			 rv << self[w] unless self[w].nil?
		  end
		  rv
		end
	end
end
