fantasdic r336 - in trunk: . lib lib/fantasdic lib/fantasdic/sources test test/data



Author: mblondel
Date: Sun Aug 24 07:55:10 2008
New Revision: 336
URL: http://svn.gnome.org/viewvc/fantasdic?rev=336&view=rev

Log:
    * lib/fantasdic/binary_search.rb: Reusable binary search implementation.
    This implementation is aimed for files. It should be possible to use it for
    stardict dictionary files as well.

    * lib/fantasdic/file_source.rb: Code that is common to all file-based
    dictionary sources.
    * lib/fantasdic/sources/edict_file.rb: Use the above.
    * lib/fantasdic.rb: "Require" the new files.

    * lib/fantasdic/sources/dictd_file.rb: New dictionary source. This source
    can read dictionary files aimed for the dictd server, usally a .index file
    and a .dict file. Most of the time the .dict file will be compressed in
    a custom gzip and will have extension .dict.dz. This format is not supported
    yet. A class "DictzipReader" needs be written.

    * test/test_dictd_file.rb:
    * test/data/freedict-wel-eng.dict.dz:
    * test/data/freedict-wel-eng.dict:
    * test/data/freedict-wel-eng.index: Unit test + data.


Added:
   trunk/lib/fantasdic/binary_search.rb
   trunk/lib/fantasdic/file_source.rb
   trunk/lib/fantasdic/sources/dictd_file.rb
   trunk/test/data/freedict-wel-eng.dict
   trunk/test/data/freedict-wel-eng.dict.dz   (contents, props changed)
   trunk/test/data/freedict-wel-eng.index
   trunk/test/test_dictd_file.rb
Modified:
   trunk/ChangeLog
   trunk/lib/fantasdic.rb
   trunk/lib/fantasdic/sources/edict_file.rb

Modified: trunk/lib/fantasdic.rb
==============================================================================
--- trunk/lib/fantasdic.rb	(original)
+++ trunk/lib/fantasdic.rb	Sun Aug 24 07:55:10 2008
@@ -140,4 +140,6 @@
 require 'fantasdic/utils'
 require 'fantasdic/command_line'
 require 'fantasdic/ui'
-require 'fantasdic/source_base'
\ No newline at end of file
+require 'fantasdic/binary_search'
+require 'fantasdic/source_base'
+require 'fantasdic/file_source'
\ No newline at end of file

Added: trunk/lib/fantasdic/binary_search.rb
==============================================================================
--- (empty file)
+++ trunk/lib/fantasdic/binary_search.rb	Sun Aug 24 07:55:10 2008
@@ -0,0 +1,119 @@
+# Fantasdic
+# Copyright (C) 2008 Mathieu Blondel
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+#Âwith this program; if not, write to the Free Software Foundation, Inc.,
+#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+module Fantasdic
+
+# Classes that include this module must be derived from File
+# and define the following methods:
+# 
+# - get_prev_offset (instance method)
+# - get_next_offset (instance method)
+# - get_fields (class method)
+# - get_word_end (class method)
+#
+module BinarySearch
+
+BUFFER_SIZE = 100
+
+# Returns the first match found using the comp block for comparison.
+def binary_search(word, &comp)
+    low = 0
+    high = File.size(self) - 1
+
+    while low <= high
+        mid = (low + high) / 2
+
+        start = get_next_offset(mid)
+        self.seek(start)
+
+        buf = self.read(BUFFER_SIZE)
+        return nil unless buf
+        endd = self.class.get_word_end(buf)
+
+        curr_word = buf.slice(0..endd)
+
+        case comp.call(curr_word, word)
+            when 1 # greater than
+                high = get_prev_offset(mid)
+            when -1 # less than
+                low = get_next_offset(mid)
+            when 0 # equals
+                return start
+        end
+    end
+
+    nil
+end
+
+def match_binary_search(word, &comp)
+    mid_offset = binary_search(word, &comp)
+
+    if mid_offset
+        # Since binary_search only returns one match,
+        # we have to look for possible other matches before and after
+
+        arr = []
+
+        # before
+        offset = mid_offset
+        while true
+            prev_offset = get_prev_offset(offset)
+            break if prev_offset.nil?
+            len = offset - prev_offset
+
+            fields = get_fields(prev_offset, len)
+            curr_word = fields.first
+
+            break if comp.call(curr_word, word) != 0
+
+            arr.push_head(fields)
+
+            offset = prev_offset
+        end
+
+        # after
+        offset = mid_offset
+        while true
+            next_offset = get_next_offset(offset)
+            break if next_offset.nil?
+            len = next_offset - offset
+
+            fields = get_fields(offset, len)
+            curr_word = fields.first
+
+            break if comp.call(curr_word, word) != 0
+
+            arr << fields
+
+            offset = next_offset
+        end
+
+        arr
+    else
+        []
+    end
+end
+
+def get_fields(offset, len)
+    self.seek(offset)
+    buf = self.read(len)
+    self.class.get_fields(buf)
+end
+
+
+end
+end
\ No newline at end of file

Added: trunk/lib/fantasdic/file_source.rb
==============================================================================
--- (empty file)
+++ trunk/lib/fantasdic/file_source.rb	Sun Aug 24 07:55:10 2008
@@ -0,0 +1,147 @@
+# Fantasdic
+# Copyright (C) 2008 Mathieu Blondel
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+#Âwith this program; if not, write to the Free Software Foundation, Inc.,
+#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+module Fantasdic
+module Source
+
+class FileSource < Base
+
+    class ConfigWidget < Base::ConfigWidget
+        def initialize(*arg)
+            super(*arg)
+
+            @file_extensions = [] # each element must contain [ext, desc]
+            @encodings = []
+            @choose_file_message = _("Select a file")
+        end
+
+        def to_hash
+            if ! file_chooser_button filename
+                raise Source::SourceError, _("A file must be selected!")
+            end
+
+            hash = {
+                :filename => @file_chooser_button.filename,  
+            }
+
+            if @encodings.length > 0
+                hash[:encoding] = selected_encoding
+            end
+
+            klass = self.class
+            src_class = eval(klass.to_s.split("::").slice(0...-1).join("::"))
+            src_class.new(hash).check_validity
+            hash
+        end
+
+        private
+
+        def initialize_ui
+            @file_chooser_button = Gtk::FileChooserButton.new(
+                @choose_file_message,
+                Gtk::FileChooser::ACTION_OPEN)
+
+            @file_extensions.each do |ext, desc|
+                filter = Gtk::FileFilter.new
+                filter.add_pattern(ext)
+                filter.name = desc
+
+                @file_chooser_button.add_filter(filter)
+            end
+
+            filter = Gtk::FileFilter.new
+            filter.add_pattern("*")
+            filter.name = _("All files")
+
+            @file_chooser_button.add_filter(filter)
+
+            file_label = Gtk::Label.new(_("_File:"), true)
+            file_label.xalign = 0
+
+            table = Gtk::Table.new(2, 2)
+            table.row_spacings = 6
+            table.column_spacings = 12
+            # attach(child, left, right, top, bottom,
+            #        xopt = Gtk::EXPAND|Gtk::FILL,
+            #        yopt = Gtk::EXPAND|Gtk::FILL, xpad = 0, ypad = 0)
+            table.attach(file_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL)
+            table.attach(@file_chooser_button, 1, 2, 0, 1)
+
+            if @encodings.length > 0
+                @encoding_combobox = Gtk::ComboBox.new(true)
+                @encodings.each do |encoding|
+                    @encoding_combobox.append_text(encoding)
+                end
+
+                encoding_label = Gtk::Label.new(_("_Encoding:"), true)
+                encoding_label.xalign = 0
+
+                table.attach(encoding_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL)
+                table.attach(@encoding_combobox, 1, 2, 1, 2)
+            end
+
+            self.pack_start(table)
+        end
+
+        def initialize_data
+            if @hash
+                if @hash[:filename]
+                    @file_chooser_button.filename = @hash[:filename]
+                end
+
+                if @encodings.length > 0
+                    if @hash[:encoding]
+                        case @hash[:encoding]
+                            when "UTF-8"
+                                @encoding_combobox.active = 0
+                            when "EUC-JP"
+                                @encoding_combobox.active = 1
+                        end
+                    end
+                end
+            end
+
+            if @encodings.length > 0 and (! hash or ! hash[:encoding])
+                @encoding_combobox.active = 0
+            end
+        end
+
+        def initialize_signals
+            @file_chooser_button.signal_connect("selection-changed") do
+                @on_databases_changed_block.call
+            end
+
+            if @encodings.length > 0
+                @encoding_combobox.signal_connect("changed") do
+                    if @file_chooser_button.filename
+                        @on_databases_changed_block.call
+                    end
+                end
+            end
+        end
+
+        def selected_encoding
+            n = @encoding_combobox.active
+            @encoding_combobox.model.get_iter(n.to_s)[0] if n >= 0
+        end
+
+    end # class ConfigWidget
+
+end
+
+end
+end
\ No newline at end of file

Added: trunk/lib/fantasdic/sources/dictd_file.rb
==============================================================================
--- (empty file)
+++ trunk/lib/fantasdic/sources/dictd_file.rb	Sun Aug 24 07:55:10 2008
@@ -0,0 +1,297 @@
+# Fantasdic
+# Copyright (C) 2008 Mathieu Blondel
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+#Âwith this program; if not, write to the Free Software Foundation, Inc.,
+#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+require "zlib"
+
+module Fantasdic
+module Source
+
+class DictdIndex < File
+    include BinarySearch
+
+    B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".
+          split(//)
+
+    # Returns the decoded value or nil.
+    def self.b64_decode(str)
+        str = str.split(//)
+        return 0 if str.length == 0
+
+        retval = 0
+        shiftval = 0
+
+        (str.length - 1).downto(0) do |i|
+            val = B64.index(str[i])
+            unless val
+                retval = nil
+                break
+            end
+            retval = retval | (val << shiftval)
+            shiftval += 6
+        end
+        retval
+    end
+
+    # Returns the offset of the previous word in the index or nil.
+    def get_prev_offset(offset)
+        offset -= 1
+
+        if offset - BUFFER_SIZE < 0
+            length = offset
+            offset = 0
+        else
+            offset -= BUFFER_SIZE
+            length = BUFFER_SIZE
+        end
+
+        self.seek(offset)
+        buf = self.read(length)
+
+        i = buf.rindex("\n")
+        if i.nil?
+            nil
+        else
+            offset += i + 1
+            offset            
+        end
+    end
+
+    # Returns the offset of the next word in the index or nil.
+    def get_next_offset(offset)
+        self.seek(offset)
+        buf = self.read(BUFFER_SIZE)
+
+        return nil if buf.nil?
+
+        i = buf.index("\n")
+        if i.nil?
+            nil
+        else
+            offset += i + 1
+            offset
+        end
+    end
+
+    def self.get_word_end(buf)
+        buf.index("\t") - 1
+    end
+
+    def self.get_fields(str)
+        word, word_offset, word_len = str.chomp.split("\t")
+        [word, DictdIndex.b64_decode(word_offset),
+         DictdIndex.b64_decode(word_len)]
+    end
+
+    def match_exact(word)
+        match_binary_search(word) do |s1, s2|
+            s1 <=> s2
+        end
+    end
+
+    def match_prefix(word)
+        match_binary_search(word) do |s1, s2|
+            if s1 =~ /^#{s2}/
+                0
+            else
+                s1 <=> s2
+            end
+        end
+    end
+
+    def match_suffix(word)
+        word = Regexp.escape(word)
+        self.grep(/#{word}\t/).map do |line|
+            DictdIndex.get_fields(line)
+        end.find_all do |curr_word, offset, len|
+            curr_word =~ /#{word}$/
+        end
+    end
+
+    def match_substring(word)
+        word = Regexp.escape(word)
+        self.grep(/#{word}/).map do |line|
+            DictdIndex.get_fields(line)
+        end.find_all do |curr_word, offset, len|
+            curr_word.include?(word)
+        end        
+    end
+
+    def match_word(word)
+        word = Regexp.escape(word)
+        self.grep(/#{word}/).map do |line|
+            DictdIndex.get_fields(line)
+        end.find_all do |curr_word, offset, len|
+            ret = false
+            curr_word.split(" ").each do |single_word|
+                if single_word == word
+                    ret = true
+                    break
+                end
+            end
+            ret
+        end         
+    end
+
+end
+
+class DictdFile < Base
+
+    authors ["Mathieu Blondel"]
+    title  _("Dictd file")
+    description _("Look up words in files aimed for the dictd server.")
+    license Fantasdic::GPL
+    copyright "Copyright (C) 2008 Mathieu Blondel"
+    no_databases true   
+
+    STRATEGIES_DESC = {
+        "define" => "Results match with the word exactly.",
+        "prefix" => "Results match with the beginning of the word.",
+        "word" => "Results have one word that match with the word.",
+        "substring" => "Results have a portion that contains the word.",
+        "suffix" => "Results match with the end of the word."
+    }
+
+    class ConfigWidget < FileSource::ConfigWidget
+
+        def initialize(*args)
+            super(*args)
+
+            @choose_file_message = _("Select a dictd file")
+            @file_extensions = [["*.index", _("Index files")]]
+            @encodings = []
+
+            initialize_ui
+            initialize_data
+            initialize_signals
+        end
+
+    end
+
+    def check_validity
+        n_errors = 0
+        n_lines = 0
+
+        dictd_file_open do |index_file, dict_file|
+            index_file.each_line do |line|
+                line.chomp!
+                word, offset, len = line.split("\t")
+                if offset.nil? or len.nil?
+                    n_errors += 1
+                elsif not DictdIndex.b64_decode(offset) or \
+                      not DictdIndex.b64_decode(offset)
+
+                    n_errors += 1
+                end
+
+                n_lines += 1
+
+                break if n_lines >= 1000
+            end
+        end
+
+        if (n_errors.to_f / n_lines) >= 0.2
+            raise Source::SourceError,
+                    _("This file is not a valid index file!")
+        end
+    end
+
+    def available_strategies
+        STRATEGIES_DESC
+    end
+
+    def define(db, word)        
+        db = File.basename(@hash[:filename]).slice(0...-6)
+        db_capitalize = db.capitalize
+
+        dictd_file_open do |index_file, dict_file|
+            index_file.match_exact(word).map do |match, offset, len|
+                defi = Definition.new
+                defi.word = match
+                defi.body = get_definition(dict_file, offset, len).strip
+                defi.database = db
+                defi.description = db_capitalize
+                defi
+            end
+        end
+    end
+
+    def match(db, strat, word)
+        matches = []
+
+        dictd_file_open do |index_file, dict_file|
+            matches = case strat
+                when "prefix", "suffix", "substring", "word"
+                    index_file.send("match_#{strat}", word)
+                else
+                    []
+            end.map do |match, offset, len|
+                match
+            end
+        end
+
+        hsh = {}
+        db = File.basename(@hash[:filename])
+        hsh[db] = matches unless matches.empty?
+        hsh
+    end
+
+    private
+
+    def get_definition(file, offset, len)
+        file.seek(offset)
+        file.read(len)
+    end
+
+    def dictd_file_open
+        if !File.readable? @hash[:filename]
+            raise Source::SourceError,
+                    _("Cannot open file %s.") % @hash[:filename]
+        end
+
+        dict_file = @hash[:filename].gsub(/.index$/, ".dict")
+        dict_gz_file = dict_file + ".dz"
+
+        if !File.readable? dict_file and !File.readable? dict_gz_file
+            raise Source::SourceError,
+            _("Couldn't find .dict or .dict.dz dictionary file.")
+        elsif File.readable? dict_file
+            dict_file = File.new(dict_file)
+        else
+            raise Source::SourceError,
+            "dict.dz file not implemented yet"
+        end
+
+        index_file = DictdIndex.new(@hash[:filename])
+
+        if block_given?
+            ret = yield(index_file, dict_file) 
+
+            index_file.close
+            dict_file.close
+
+            ret
+        else
+            [ hash[:filename], dict_file]
+        end
+    end
+
+end
+
+end
+end
+
+Fantasdic::Source::Base.register_source(Fantasdic::Source::DictdFile)

Modified: trunk/lib/fantasdic/sources/edict_file.rb
==============================================================================
--- trunk/lib/fantasdic/sources/edict_file.rb	(original)
+++ trunk/lib/fantasdic/sources/edict_file.rb	Sun Aug 24 07:55:10 2008
@@ -20,7 +20,7 @@
 module Fantasdic
 module Source
 
-class EdictFileBase < Base
+class EdictFileBase < FileSource
 
     STRATEGIES_DESC = {
         "define" => "Results match with the word exactly.",
@@ -39,109 +39,25 @@
     HAVE_EGREP = (File.which("egrep") and File.which("iconv") and
                   File.which("gunzip") and File.which("cat"))
 
-    class ConfigWidget < Base::ConfigWidget
-        def initialize(*arg)
-            super(*arg)
-            initialize_ui
-            initialize_data
-            initialize_signals
-        end
-
-        def to_hash
-            if ! file_chooser_button filename
-                raise Source::SourceError, _("A file must be selected!")
-            end
-            hash = {
-                :filename => @file_chooser_button.filename,
-                :encoding => selected_encoding
-            }
-            EdictFile.new(hash).check_validity
-            hash
-        end
-
-        private
+    class ConfigWidget < FileSource::ConfigWidget
 
-        def initialize_ui
-            @file_chooser_button = Gtk::FileChooserButton.new(
-                _("Select an EDICT file"),
-                Gtk::FileChooser::ACTION_OPEN)
+        def initialize(*args)
+            super(*args)
 
-            filter = Gtk::FileFilter.new
-            filter.add_pattern("*")
-            filter.name = _("All files")
+            @choose_file_message = _("Select an EDICT file")
+            @file_extensions = [["*.gz", _("Gzip-compressed files")]]
+            @encodings = ["UTF-8", "EUC-JP"]
 
-            @file_chooser_button.add_filter(filter)
-
-            filter = Gtk::FileFilter.new
-            filter.add_pattern("*.gz")
-            filter.name = _("Gzip-compressed files")
-
-            @file_chooser_button.add_filter(filter)
-
-            @encoding_combobox = Gtk::ComboBox.new(true)
-            @encoding_combobox.append_text("UTF-8")
-            @encoding_combobox.append_text("EUC-JP")
+            initialize_ui
+            initialize_data
+            initialize_signals
 
             unless HAVE_EGREP
                 @encoding_combobox.sensitive = false
             end
-
-            file_label = Gtk::Label.new(_("_File:"), true)
-            file_label.xalign = 0
-            encoding_label = Gtk::Label.new(_("_Encoding:"), true)
-            encoding_label.xalign = 0
-
-            table = Gtk::Table.new(2, 2)
-            table.row_spacings = 6
-            table.column_spacings = 12
-            # attach(child, left, right, top, bottom,
-            #        xopt = Gtk::EXPAND|Gtk::FILL,
-            #        yopt = Gtk::EXPAND|Gtk::FILL, xpad = 0, ypad = 0)
-            table.attach(file_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL)
-            table.attach(encoding_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL)
-            table.attach(@file_chooser_button, 1, 2, 0, 1)
-            table.attach(@encoding_combobox, 1, 2, 1, 2)
-
-            self.pack_start(table)
-        end
-
-        def initialize_data
-            if @hash
-                if @hash[:filename]
-                    @file_chooser_button.filename = @hash[:filename]
-                end
-                if @hash[:encoding]
-                    case @hash[:encoding]
-                        when "UTF-8"
-                            @encoding_combobox.active = 0
-                        when "EUC-JP"
-                            @encoding_combobox.active = 1
-                    end
-                end
-            end
-            if ! hash or ! hash[:encoding]
-                @encoding_combobox.active = 0
-            end
-        end
-
-        def initialize_signals
-            @file_chooser_button.signal_connect("selection-changed") do
-                @on_databases_changed_block.call
-            end
-
-            @encoding_combobox.signal_connect("changed") do
-                if @file_chooser_button.filename
-                    @on_databases_changed_block.call
-                end
-            end
         end
 
-        def selected_encoding
-            n = @encoding_combobox.active
-            @encoding_combobox.model.get_iter(n.to_s)[0] if n >= 0
-        end
-
-    end # class ConfigWidget
+    end
 
     def check_validity
         n_errors = 0

Added: trunk/test/data/freedict-wel-eng.dict
==============================================================================
--- (empty file)
+++ trunk/test/data/freedict-wel-eng.dict	Sun Aug 24 07:55:10 2008
@@ -0,0 +1,2258 @@
+
+00-database-dictfmt-1.10.10
+00-database-info
+   30. Apr. 2000
+   Database was converted to TEI format and checked into CVS
+   1.Jan 2000
+   This Database was generated from ergane (http://www.travlang.com).
+   - Thanks!
+   Copyright (C) 2000 Horst Eyermann (Horst freedict de)
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+   GNU General Public License for more details.
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+00-database-short
+   Welsh-English Freedict dictionary
+
+00-database-url
+   http://www.freedict.de
+
+Adda
+   Adam
+
+Albanwr
+   Scot; Scotsman
+
+Almaeneg
+   German; German woman
+
+Almaenwr
+   German
+
+Alpau
+   Alps
+
+Arglwydd
+   God
+
+Athen
+   Athens
+
+Awst
+   August
+
+Awstralia
+   Australia
+
+Awstria
+   Austria
+
+Beibl
+   Bible
+
+Brithwr
+   Pict
+
+Bro Morgannwg
+   Vale of Glamorgan
+
+Brython
+   Briton
+   Welshman
+
+Brythoneg
+   Welsh; Welsh language
+
+Caerdydd
+   Cardiff
+
+Caeredin
+   Edinburgh
+
+Caerefrog
+   York
+
+Caerludd
+   London
+
+Caint
+   Kent
+
+Chwefror
+   February
+
+Crist
+   Christ
+
+Cristion
+   Christian
+
+Cristionogol
+   Christian
+
+Cymraeg
+   Welsh; Welsh language
+
+Cymreig
+   Welsh
+
+Cymru
+   Wales
+
+Dafydd
+   David
+
+Dewi
+   David
+
+Dofydd
+   God
+
+Dolgelly
+   Dolgelly
+
+Dulyn
+   Dublin
+
+Duw
+   God
+
+Dydd Gwener y Groglith
+   Good Friday
+
+Ebrill
+   April
+
+Efa
+   Eva
+
+Efrog
+   York
+
+Eifftaidd
+   Egyptian
+
+Ewrob
+   Europe
+
+Fflandrys
+   Flanders
+
+Ffrainc
+   France
+
+Gorffennaf
+   July
+
+Groeg
+   Greece
+
+Groegaidd
+   Greek
+
+Groeges
+   Greek woman
+
+Groegwr
+   Greek
+
+Gwlad yr Haf
+   Somerset
+
+Gwyddel
+   Irishman
+
+Gwyddeles
+   Iriswoman
+
+Gwyddelig
+   Irish
+
+Hisbaen
+   Spain
+
+Hydref
+   October
+
+Iau
+   Jupiter
+
+Ionawr
+   January
+
+Isalmaen
+   Holland
+   Holland; the Netherlands
+
+Iwerddon
+   Ireland
+
+Iwerydd
+   Atlantic; Atlantic Ocean
+
+Lerpwl
+   Liverpool
+
+Lladin
+   Latin
+
+Llanelli
+   Llanelly
+
+Lloegr
+   England
+
+Llundain
+   London
+
+Llydaw
+   Bretagne; Brittany
+
+Mai
+   May
+
+Manceinion
+   Manchester
+
+Mawrth
+   Mars
+   March
+
+Medi
+   September
+
+Mehefin
+   June
+
+Morgannwg
+   Glamorgan
+
+MÃr Coch
+   Red Sea
+
+MÃr Tawel
+   Pacific; Pacific Ocean
+
+MÃr y Canoldir
+   Mediterranean
+
+Nadolig
+   Christmas; Yule
+
+Neifion
+   Neptune
+
+Penybont
+   Bridgend
+
+Prwsia
+   Prussia
+
+Prydain
+   Britain; Great Britain
+
+Prydeinig
+   British
+
+Prydeiniwr
+   Briton
+
+Pwyl
+   Poland
+
+Rhagfyr
+   December
+
+Rhufain
+   Rome
+
+Rhufeinaidd
+   Roman
+
+Rhufeiniad
+   Roman
+
+Rhufeinig
+   Roman
+
+Rhufeiniwr
+   Roman
+
+Rhydychen
+   Oxford
+
+Rwsia
+   Russia
+
+Sabath
+   Saturday
+
+Saboth
+   Saturday
+
+Sadwrn
+   Saturn
+
+Saesneg
+   English
+   English; English language
+
+Saesnes
+   English; Englishwoman
+
+Sais
+   Englishman; Sassenach
+   Saxon
+
+Swansea
+   Swansea
+
+Tachwedd
+   November
+
+Tafwys
+   Thames
+
+Tiddewi
+   Saint David's
+
+Twrc
+   Turk
+
+Twrci
+   Turkey
+
+Yr Aifft
+   Egypt
+
+Yr Alban
+   Scotland
+
+Yr Almaen
+   Germany
+
+Yr Eidal
+   Italy
+
+Yr Unol Daleithiau
+   United States of America; USA
+
+a
+   and
+
+abad
+   abbot
+
+abades
+   abbess
+
+abaty
+   abbey
+
+aber
+   mouth
+
+ac
+   and
+
+achos
+   as; because; for; since
+
+achosi
+   cause; reason
+
+adeg
+   time; while
+
+adeiladu
+   build; construct
+
+aderyn
+   bird
+
+adnabod
+   be acquainted with; know
+
+adref
+   home
+
+afal
+   apple
+
+afon
+   river
+
+agor
+   open; open up
+
+ail
+   second
+
+ail ar bymtheg
+   seventeenth
+
+algebra
+   algebra
+
+am
+   at; by; on; upon
+   about; concerning; on; upon
+
+amser
+   time; while
+
+anadl
+   breath
+
+anfon
+   send; transmit
+
+anghofio
+   forget
+
+anhawdd
+   difficult; hard; inconvenient
+
+annwyd
+   cold
+
+anodd
+   difficult; hard; inconvenient
+
+anrheg
+   gift; present
+
+anthem
+   corn chamomile
+
+ar
+   on; upon
+
+araf
+   slow
+
+arall
+   other; another; else
+
+arholiad
+   investigation; examination; test
+
+arian
+   money
+
+aros
+   halt; come to a halt; stop
+   remain; stay; stay over
+
+arth
+   bear
+
+arthes
+   bear
+
+arwain
+   conduct; direct; guide; head; lead
+
+ar agor
+   open
+
+ar gau
+   closed; shut
+
+ar hyd
+   along
+
+ar unwaith
+   at once; immediately; just; right away; right now
+
+ar Ãl
+   behind; after
+   after; behind
+
+asyn
+   ass; donkey
+
+at
+   at; to; toward; towards
+
+ateb
+   answer; reply; respond
+   answer; reply
+
+athro
+   instructor; teacher
+
+aur
+   gold
+
+awel
+   breeze
+
+awr
+   hour; o'clock; time
+
+awyren
+   aeroplane; airplane; plane
+   aircraft
+
+baban
+   baby
+
+bach
+   diminutive; little; small
+
+bachgen
+   boy; lad; laddie
+
+balch
+   proud
+
+banc
+   bank
+
+baner
+   flag; standard
+
+bara
+   bread; loaf
+
+bardd
+   bard
+   poet
+
+basged
+   basket
+
+bedwen
+   birch
+
+beisicl
+   bike; cycle; bicycle
+   bike; bicycle
+
+berwi
+   boil
+
+bisged
+   biscuit; cookie
+
+blaidd
+   wolf
+
+blino
+   get tired
+
+blodeuyn
+   bloom; flower
+
+blwyddyn
+   year
+
+bore
+   morning
+
+braidd
+   barely; hardly; only just; scarcely
+
+brawd
+   brother
+
+brecwast
+   breakfast
+
+brenhines
+   queen
+
+brown
+   brown
+
+brwnt
+   dirty; filthy; nasty; soiled; unclean
+
+bryn
+   hill
+
+buan
+   fast; quick; rapid; speedy; swift
+
+bugail
+   shepherd
+
+bus
+   bus; autobus; omnibus
+
+busnes
+   affair; business; business deal; case; matter
+
+buwch
+   calf
+
+bwced
+   bucket; pail
+
+bwrdd
+   table
+
+bwrw glaw
+   rain
+
+bwyd
+   food
+
+bychan
+   diminutive; little; small
+
+byd
+   world
+
+byr
+   short
+   brief; short
+
+byth
+   at some time; ever; sometime
+
+byw
+   be alive; live
+
+cadair
+   chair
+
+cadnawes
+   vixen
+
+cadno
+   fox
+
+cadw
+   hang onto; hold
+
+cael
+   get; have; receive
+
+caled
+   hard
+
+calon
+   heart
+
+canol
+   average; mean; middle
+
+cant
+   hundred; one hundred
+
+canu
+   sing
+   play
+
+cap
+   cap
+
+capel
+   chapel
+
+car
+   car
+
+caredig
+   affable; friendly; goodânatured; kind
+
+cario
+   carry; wear
+
+carreg
+   stone
+
+cartref
+   home
+
+caru
+   love
+   appreciate; like
+
+carw
+   deer
+
+castell
+   castle
+
+cath
+   cat
+
+cau
+   close; shut
+
+cawrfil
+   elephant
+
+caws
+   cheese
+
+ceffyl
+   horse
+
+cegin
+   kitchen
+
+ceinach
+   hare
+
+ceiniog
+   penny
+
+cerdded
+   march; walk
+
+chwaer
+   sister
+
+chwant
+   desire; want; wish
+
+chwarae
+   play
+
+chwe
+   six
+
+chwech
+   six
+
+chweched
+   sixth
+
+chwerthin
+   laugh
+
+chwith
+   left
+
+ci
+   dog
+
+cledd
+   sword
+
+cleddau
+   sword
+
+cleddyf
+   sword
+
+clir
+   clear; distinct; plain
+
+cloc
+   clock; watch
+
+cloch
+   bell
+
+clywed
+   hear
+
+cneuen Ffrengig
+   walnut
+
+coch
+   red
+
+codi
+   get up
+
+coeden
+   tree
+
+coffi
+   coffee
+
+cofio
+   recall; recollect; remember
+
+colli
+   lose
+
+cordyn
+   cord; rope; string
+
+cornel
+   corner
+
+cot
+   coat; overcoat
+
+craig
+   boulder
+
+credu
+   account; accredit; believe; deem
+
+creulon
+   cruel
+
+croesi
+   cross
+
+crwn
+   round
+
+crwtyn
+   boy; lad; laddie
+
+cryf
+   strong
+
+cuddio
+   conceal; hide
+
+cudyll
+   hawk
+
+curyll
+   hawk
+
+cwch
+   boat
+
+cwcw
+   cuckoo
+
+cwestiwn
+   question
+
+cwm
+   valley
+
+cwningen
+   rabbit
+
+cwpan
+   cup
+
+cwpwrdd
+   cabinet; closet; cupboard; sideboard
+
+cwrdd
+   come across; encounter; meet; see
+
+cwt
+   tail
+
+cwympo
+   drop; fall
+
+cyfaill
+   friend
+
+cyfarfod
+   come across; encounter; meet; see
+
+cyflym
+   fast; quick; rapid; speedy; swift
+
+cyllell
+   knife
+
+cymryd
+   get; lay hold of; pick up; take
+
+cyn
+   before; in front of
+
+cyngerdd
+   concert
+
+cynnes
+   warm
+
+cyntaf
+   first
+
+cyrraedd
+   accomplish; achieve; attain; get; reach
+
+cysgu
+   be asleep; sleep
+
+cywir
+   falcon
+
+cÃn
+   song
+
+cÃr
+   chorus; coir
+
+da
+   good; nice; okay
+
+dafad
+   sheep
+
+dal
+   capture; catch; grapple
+
+damwain
+   accident
+
+dan
+   below; beneath; under; underneath
+
+dangos
+   indicate; point out; show
+
+dannoedd
+   toothache
+
+dant
+   tooth
+
+darfod
+   become; come about; grow; happen
+   come about; happen; occur
+
+darllen
+   read
+
+darlun
+   painting; picture
+
+darn
+   bit; lump; piece
+
+dau
+   two
+
+dau ar bymtheg
+   seventeen
+
+dau gant
+   two hundred
+
+dawns
+   dance
+
+dawnsio
+   dance
+
+ddoe
+   yesterday
+
+deall
+   understand; realize
+
+dechrau
+   begin; commence; start
+
+deffro
+   wake; wake up
+
+deg
+   ten
+
+degfed
+   tenth
+
+deg ar hugain
+   thirty
+
+deg a deugain
+   fifty
+
+deg a phedwar ugain
+   ninety
+
+deg a thrigain
+   seventy
+
+deintydd
+   dentist
+
+desg
+   desk; writing desk; writingâdesk
+
+deuddeg
+   twelve
+
+deuddegfed
+   twelfth
+
+deugain
+   forty
+
+deunaw
+   eighteen
+
+deunawfed
+   eighteenth
+
+dewin
+   enchanter; magician; sorcerer; warlock; wizard
+
+diddorol
+   interesting
+
+digon
+   enough; sufficient
+
+dim
+   anything; something
+
+dinas
+   city; metropolis
+
+diolch
+   thank you; thanks
+
+dod
+   come
+
+dod Ã
+   bring; fetch
+
+doe
+   yesterday
+
+doenitheb
+   wisdom
+
+draig
+   dragon
+
+dringo
+   climb
+
+drwg
+   bad; miserable; nasty; poor
+   airyâfairy; frolic; frolicsome; petulant
+
+drws
+   door
+
+drwy
+   through
+
+du
+   black
+
+dweud
+   say; tell
+   narrate; relate; tell
+
+dwr
+   water
+
+dwsin
+   dozen
+
+dwy
+   two
+
+dwy ar bymtheg
+   seventeen
+
+dwy waith
+   twice
+
+dydd
+   day
+
+dydd Llun
+   Monday
+
+dydd Sadwrn
+   Sabbath
+
+dydd Sul
+   Sunday
+
+dyfod
+   come
+
+dyfod Ã
+   bring; fetch
+
+dyma
+   behold; here is; here are; look; there
+
+dyn
+   fellow; man
+
+dyna
+   there is; there are
+
+dynes
+   woman
+
+dysgu
+   teach
+   learn
+
+dywalgi
+   tiger
+
+dywedyd
+   say; tell
+   narrate; relate; tell
+
+ef
+   he; him
+   it
+
+eglwys
+   church; churchâbuilding; house of worship; place of worship
+
+ei
+   his
+   her; his; its; their
+   her
+
+ein
+   our
+
+eira
+   snow
+
+eisiau
+   need; want
+
+eistedd
+   sit
+
+eliffant
+   elephant
+
+enw
+   appellation; name
+
+er
+   since
+   from; since
+   though; although
+
+erioed
+   at some time; ever; sometime
+
+eroplÃn
+   aeroplane; airplane; plane
+   aircraft
+
+ers
+   from; since
+
+eryr
+   eagle
+
+eto
+   still; yet
+   afresh; again; all over again; anew
+   afresh; again; once more
+
+fe
+   he; him
+   it
+
+felly
+   so; such; thus
+
+ffatri
+   factory
+
+ffedog
+   apron
+
+ffenestr
+   window
+
+fferm
+   estate; farm; property; ranch
+
+ffermwr
+   farmer
+
+ffilm
+   film; motion picture; movie
+
+fforc
+   fork
+
+ffordd
+   road; route; way
+
+ffrind
+   friend
+
+ffydd
+   confidence; faith; trust
+
+ffyddlon
+   falcon
+
+ffynnon
+   fountain; source; spring
+
+fwltur
+   vulture
+
+gadael
+   absent onself; depart; go away; leave
+   accord; admit; afford; allow; permit
+
+gaeaf
+   winter
+
+gafr
+   goat
+
+gair
+   word
+
+gallu
+   be able to
+
+galw
+   call; summon
+
+gan
+   with
+
+gardd
+   garden
+
+gartref
+   at home
+
+geneth
+   girl; lass; wench
+
+geni
+   arise; be born
+
+ger
+   at; beside; by; near; nearby; near to; next to
+
+glas
+   blue
+
+glyn
+   valley
+
+gof
+   smith
+
+gofalus
+   careful; cautious
+
+gofyn
+   ask
+
+golchi
+   wash
+
+golff
+   golf
+
+gorwedd
+   lie; recline
+
+grisiau
+   staircase; stairs
+
+gwaith
+   job; work
+
+gwal
+   wall
+
+gwallt
+   hair
+
+gwas
+   boy; servant
+
+gwawr
+   dawn; daybreak
+
+gwdihÅ
+   owl
+
+gweithio
+   work
+
+gweld
+   see
+
+gwell
+   best
+   better
+
+gwely
+   bed
+
+gwers
+   lesson
+
+gwerthu
+   dispose of; sell; vend
+
+gwiber
+   adder; viper
+
+gwir
+   true
+
+gwisgo
+   wear
+
+gwlad
+   country; land
+
+gwlyb
+   wet
+
+gwlÃn
+   wool
+
+gwneud
+   achieve; act; do; make; perform
+
+gwraig
+   wife
+   woman
+
+gwrando
+   listen
+
+gwybod
+   know; know how
+
+gwyliau
+   vacation
+
+gwynt
+   wind
+
+gwyrdd
+   green
+
+gyda
+   with
+
+gynt
+   ahead; formerly; previously
+
+gÅr
+   fellow; man
+
+haf
+   summer
+
+hallt
+   salty
+
+hanes
+   story; history
+
+hanner
+   half
+
+hanner dydd
+   midday; noon
+
+hanner nos
+   midnight
+
+hapus
+   fortunate; happy
+
+hardd
+   beautiful; fine; handsome; lovely
+
+haul
+   sun
+
+hawdd
+   easy; facile
+
+heb
+   without
+
+heblaw
+   apart from; but; except; other than
+
+hebog
+   hawk
+
+heddiw
+   today
+
+heddwch
+   peace
+
+hefyd
+   also; likewise; too
+
+help
+   aid; help
+
+hen
+   old
+
+heol
+   street
+   road; route; way
+
+het
+   hat
+
+hi
+   it
+   her; she
+
+hir
+   long
+
+hoffi
+   appreciate; like
+
+hogyn
+   boy; lad; laddie
+
+hon
+   this
+
+hwn
+   this
+
+hwylio
+   sail
+
+hyfryd
+   agreeable; pleasant
+
+i
+   a; in; inside; into; on; per; within
+   for; to; in order to; per
+
+iaith
+   language; tongue
+
+iar
+   chicken; fowl
+
+iawn
+   quite; very; very much
+
+iechyd
+   health
+
+ieuanc
+   young
+
+ifanc
+   young
+
+isel
+   low
+
+lawer gwaith
+   frequently; often; regularly
+
+lladd
+   kill; liquidate; slay
+
+llaeth
+   milk
+
+llafariad
+   vowel
+
+llaw
+   hand
+
+llawen
+   cheerful; gay; merry
+
+llawr
+   floor
+
+lle
+   place
+   location; place; spot
+   room; space
+
+lleuad
+   moon
+
+llew
+   lion
+
+lliw
+   colour; dye
+
+llong
+   ship; vessel
+
+llongwr
+   sailor
+
+llosgi
+   burn
+
+llwyd
+   grey
+
+llwyddiant
+   achievement; success
+
+llwynog
+   fox
+
+llwynoges
+   vixen
+
+llyfr
+   book
+
+llyfrgell
+   library
+
+llygoden
+   mouse
+
+llygoden fawr
+   rat
+
+llygota
+   mouse
+   rat
+
+llyn
+   lake; loch
+
+llythyr
+   letter
+
+llythyrdy
+   post office
+
+mab
+   son
+
+mam
+   mother
+
+map
+   map
+
+marw
+   die; expire; pass away
+   dead
+
+mat
+   mat
+
+math
+   kind; sort
+
+mawr
+   big; great; large
+
+meddyg
+   doctor; physician
+
+medru
+   be able to
+
+melys
+   gentle; soft; sweet; tender
+
+menyn
+   butter
+
+merch
+   daughter
+   woman
+
+mewn
+   a; in; inside; into; on; per; within
+
+mil
+   thousand; one thousand
+
+miliwn
+   million
+
+milwr
+   pawn; soldier
+
+mis
+   month
+
+mochyn
+   hog; pig; swine
+
+modryb
+   aunt
+
+molecwl
+   molecule
+
+morwr
+   sailor
+
+mur
+   wall
+
+mynd
+   go
+
+mynydd
+   mountain
+
+mÃr
+   sea
+
+na
+   than
+
+nant
+   stream
+
+naw
+   nine
+
+nawfed
+   ninth
+
+neb
+   a; any; anybody; some; somebody; one; some one; some one
+
+neidr
+   serpent; snake
+
+neis
+   pretty
+
+nes
+   until; till
+
+nesaf
+   following; next
+
+neuadd
+   hall
+
+newydd
+   new; novel
+
+newyddion
+   news; novelty; something new
+
+ni
+   us; we
+
+nofel
+   novel
+
+nofio
+   float; swim
+
+nos
+   night
+
+noson
+   evening
+
+o
+   from; out of
+
+ochr
+   side
+
+oedrannus
+   old
+
+oer
+   bleak; chilly; cold
+
+ofn
+   fear
+
+ogof
+   cave; grotto
+   cave; cavern; den
+
+ond
+   but
+
+os
+   if; provided that
+
+os gwelwch yn dda
+   please
+
+o amgylch
+   about; round; around; towards
+
+o flaen
+   before; in front of
+
+paham
+   what for; wherefore; why
+
+paladr
+   beam; ray
+
+pam
+   what for; wherefore; why
+
+papur
+   paper
+
+paratoi
+   prepare
+
+parc
+   park
+
+parod
+   finished; ready; through
+
+pe
+   if; provided that
+
+pedair
+   four
+
+pedair ar bymtheg
+   nineteen
+
+pedair ar ddeg
+   fourteen
+
+pedwar
+   four
+
+pedwaredd
+   fourth
+
+pedwaredd ar bymtheg
+   nineteenth
+
+pedwaredd ar ddeg
+   fourteenth
+
+pedwar ar bymtheg
+   nineteen
+
+pedwar ar ddeg
+   fourteen
+
+pedwar ugain
+   eighty
+
+pedwar ugain a deg
+   ninety
+
+pedwerydd
+   fourth
+
+pedwerydd ar bymtheg
+   nineteenth
+
+pedwerydd ar ddeg
+   fourteenth
+
+pelydryn
+   beam; ray
+
+pen
+   summit; surface; top
+
+pensil
+   pencil
+
+pentref
+   village
+
+perllan
+   orchard
+
+peswch
+   cough
+
+piano
+   piano
+
+pib
+   pipe
+
+plismon
+   policeman
+
+pobl
+   folk; nation; people
+
+poced
+   pocket
+
+poeth
+   hot
+
+pont
+   bridge
+
+popeth
+   all; altogether; everything
+
+pori
+   graze
+
+potel
+   bottle
+
+prif
+   chief; boss
+
+prifathro
+   headmaster; head of a school
+
+prifysgol
+   university
+
+prin
+   barely; hardly; only just; scarcely
+
+priodi
+   marry; be married; get married
+
+pris
+   price
+
+prydferth
+   beautiful; fine; handsome; lovely
+
+pum
+   five
+
+pumed
+   fifth
+
+pump
+   five
+
+punt
+   pound
+
+pwll
+   pond
+
+pwy
+   of which; which one's; whose
+
+pymtheg
+   fifteen
+
+pymthegfed
+   fifteenth
+
+pÃl
+   ball
+
+rabbi
+   rabbi
+
+radio
+   radio; wireless
+
+ras
+   breed; race
+
+reis
+   rice
+
+rhad
+   cheap; inexpensive
+
+rhaff
+   cord; rope; string
+
+rhag
+   from; out of
+
+rhaid
+   necessity
+
+rhedeg
+   run
+
+rheol
+   regulation; rule
+
+rheolwr
+   manager
+
+rhoi
+   give
+
+rhosyn
+   rose
+
+rhwng
+   among; between
+
+rhwyfo
+   row
+
+rhyfedd
+   wonderful
+
+rhyfel
+   war
+
+rwber
+   rubber
+
+saith
+   seven
+
+sefyll
+   stand
+
+seithfed
+   seventh
+
+sgwar
+   plaza; square; public square
+
+siarad
+   speak; talk
+
+sicr
+   certain; sure
+
+sigar
+   cigar
+
+sigaret
+   cigarette
+
+silff
+   shelf
+
+sinema
+   cinema; movie theatre
+
+siop
+   boutique; shop; store
+
+siwgr
+   sugar
+
+siwr
+   certain; sure
+
+smocio
+   smoke
+
+stori
+   account; narrative; story; tale
+
+storm
+   storm
+
+stryd
+   street
+
+swllt
+   shilling
+
+swyddfa
+   office
+   bureau; office
+
+swynwr
+   enchanter; magician; sorcerer; warlock; wizard
+
+syched
+   thirst
+
+symud
+   move
+
+syrthio
+   drop; fall
+
+tacsi
+   taxi
+
+tafod
+   tongue
+
+tair
+   three
+
+tair ar ddeg
+   thirteen
+
+taith
+   journey; trip; voyage
+
+tal
+   tall
+
+talu
+   pay
+
+taro
+   beat; hit; strike
+
+tarw
+   bull
+
+tebot
+   teaâpot
+
+tegell
+   kettle
+
+teigr
+   tiger
+
+teisen
+   cake
+
+teledu
+   television; TV
+
+telyn
+   harp
+
+thermomedr
+   thermometer
+
+tir
+   country; land
+
+tlawd
+   miserable; poor
+   poor
+
+tlws
+   pretty
+
+torri
+   break
+   cut; slice
+
+tost
+   ill; sick
+
+traeth
+   beach
+
+tref
+   city; town
+
+treulio
+   transact money
+
+tri
+   three
+
+trigain
+   sixty
+
+trigain a deg
+   seventy
+
+tri ar ddeg
+   thirteen
+
+trwm
+   burdensome; heavy; onerous
+
+trwy
+   through
+
+trydan
+   electricity
+
+trydedd
+   third
+
+trydedd ar ddeg
+   thirteenth
+
+trydydd
+   third
+
+trydydd ar ddeg
+   thirteenth
+
+trysor
+   treasure
+
+trÃn
+   train
+
+twrci
+   turkey
+
+tyfu
+   accrue; grow
+
+tylluan
+   owl
+
+tywydd
+   weather
+
+tÃn
+   fire
+
+tÃ
+   tea
+
+tÅr
+   castle; tower
+
+uchel
+   high; lofty; tall
+
+ugain
+   twenty
+
+ugeinfed
+   twentieth
+
+un
+   one
+
+unfed ar bymtheg
+   sixteenth
+
+unfed ar ddeg
+   eleventh
+
+unwaith
+   once; one time
+
+un ar bymtheg
+   sixteen
+
+un ar ddeg
+   eleven
+
+un ar hugain
+   twentyâone
+
+wedi
+   behind; after
+   after; behind
+
+wedi blino
+   tired
+
+wedyn
+   afterwards; next; subsequently
+
+weithiau
+   several times; sometimes
+
+wrth
+   at; beside; by; near; nearby; near to; next to
+   for; during; whereas; while; whilst
+
+wyth
+   eight
+
+wythfed
+   eighth
+
+wythnos
+   week
+
+ychydig
+   a little; rather; some; somewhat; to some extent
+   little
+
+yfed
+   drink
+
+yfory
+   tomorrow
+
+ymenyn
+   butter
+
+ymhlith
+   among; between
+
+ymlaen
+   ahead; foreward; on
+
+yn
+   a; in; inside; into; on; per; within
+
+ynys
+   island
+
+yn awr
+   at present; now
+
+yn dda
+   okay; well
+
+yn erbyn
+   across from; against; in exchange for; opposed to; opposite; upon
+
+yn gynnar
+   early
+
+yn gyntaf
+   first; firstly; first of all
+
+yn hwyr
+   late
+
+yn lle
+   instead
+
+yn ofalus
+   carefully; gently; lightly
+
+yn rhad
+   cheaply
+
+yrÅan
+   at present; now
+
+ysgol
+   school
+
+ysgrifennu
+   write
+
+ysgyfarnog
+   hare
+
+ystafell
+   chamber; room
+
+Ã
+   by; by means of; on; through; with
+
+Ãb
+   ape; monke
+

Added: trunk/test/data/freedict-wel-eng.dict.dz
==============================================================================
Binary file. No diff available.

Added: trunk/test/data/freedict-wel-eng.index
==============================================================================
--- (empty file)
+++ trunk/test/data/freedict-wel-eng.index	Sun Aug 24 07:55:10 2008
@@ -0,0 +1,734 @@
+00databasealphabet	Efk	e
+00databasedictfmt11010	B	c
+00databaseinfo	d	O9
+00databaseshort	Pa	4
+00databaseurl	QS	r
+00databaseutf8	A	B
+a	1r	K
+abad	11	P
+abades	2E	S
+abaty	2W	Q
+aber	2m	P
+ac	21	L
+achos	3A	i
+achosi	3i	Z
+adda	Q9	O
+adeg	37	V
+adeiladu	4Q	e
+aderyn	4u	Q
+adnabod	4+	l
+adref	5j	P
+afal	5y	P
+afon	6B	P
+agor	6Q	X
+ail	6n	P
+ail ar bymtheg	62	f
+albanwr	RL	b
+algebra	7V	U
+almaeneg	Rm	i
+almaenwr	SI	U
+alpau	Sc	P
+am	7p	3
+amser	8g	W
+anadl	82	R
+anfon	9H	Z
+anghofio	9g	U
+anhawdd	90	q
+annwyd	+e	Q
+anodd	+u	o
+anrheg	/W	Z
+anthem	/v	a
+ar	BAJ	Q
+ar agor	BEP	R
+ar gau	BEg	Y
+ar hyd	BE4	R
+ar unwaith	BFJ	BB
+ar Ãl	BGK	q
+araf	BAZ	O
+arall	BAn	f
+arglwydd	Sr	R
+arholiad	BBG	u
+arian	BB0	Q
+aros	BCE	/
+arth	BDD	O
+arthes	BDR	Q
+arwain	BDh	u
+asyn	BG0	V
+at	BHJ	f
+ateb	BHo	x
+athen	S8	R
+athro	BIZ	e
+aur	BI3	N
+awel	BJE	Q
+awr	BJU	c
+awst	TN	Q
+awstralia	Td	Y
+awstria	T1	U
+awyren	BJw	y
+baban	BKi	P
+bach	BKx	j
+bachgen	BLU	d
+balch	BLx	Q
+banc	BMB	O
+baner	BMP	Z
+bara	BMo	V
+bardd	BM9	X
+basged	BNU	S
+bedwen	BNm	R
+beibl	UJ	Q
+beisicl	BN3	y
+berwi	BOp	P
+bisged	BO4	b
+blaidd	BPT	Q
+blino	BPj	U
+blodeuyn	BP3	b
+blwyddyn	BQS	S
+bore	BQk	R
+braidd	BQ1	v
+brawd	BRk	S
+brecwast	BR2	X
+brenhines	BSN	U
+brithwr	UZ	R
+bro morgannwg	Uq	k
+brown	BSh	Q
+brwnt	BSx	w
+bryn	BTh	O
+brython	VO	f
+brythoneg	Vt	k
+buan	BTv	r
+bugail	BUa	U
+bus	BUu	e
+busnes	BVM	5
+buwch	BWF	P
+bwced	BWU	X
+bwrdd	BWr	Q
+bwrw glaw	BW7	T
+bwyd	BXO	O
+bychan	BXc	l
+byd	BYB	O
+byr	BYP	e
+byth	BYt	m
+byw	BZT	X
+cadair	BZq	R
+cadnawes	BZ7	T
+cadno	BaO	O
+cadw	Bac	Z
+cael	Ba1	c
+caerdydd	WR	V
+caeredin	Wm	X
+caerefrog	W9	T
+caerludd	XQ	U
+caint	Xk	P
+caled	BbR	P
+calon	Bbg	Q
+canol	Bbw	g
+cant	BcQ	e
+canu	Bcu	W
+cap	BdE	M
+capel	BdQ	R
+car	Bdh	M
+caredig	Bdt	0
+cario	Beh	W
+carreg	Be3	R
+cartref	BfI	R
+caru	BfZ	i
+carw	Bf7	O
+castell	BgJ	T
+cath	Bgc	N
+cau	Bgp	U
+cawrfil	Bg9	V
+caws	BhS	Q
+ceffyl	Bhi	R
+cegin	Bhz	S
+ceinach	BiF	R
+ceiniog	BiW	S
+cerdded	Bio	Y
+chwaer	BjA	S
+chwant	BjS	e
+chwarae	Bjw	R
+chwe	BkB	N
+chwech	BkO	P
+chweched	Bkd	T
+chwefror	Xz	W
+chwerthin	Bkw	U
+chwith	BlE	Q
+ci	BlU	L
+cledd	Blf	Q
+cleddau	Blv	S
+cleddyf	BmB	S
+clir	BmT	g
+cloc	Bmz	W
+cloch	BnJ	P
+clywed	BnY	Q
+cneuen ffrengig	Bno	b
+coch	BoD	N
+codi	BoQ	Q
+coeden	Bog	Q
+coffi	Bow	R
+cofio	BpB	m
+colli	Bpn	P
+cordyn	Bp2	e
+cornel	BqU	S
+cot	Bqm	X
+craig	Bq9	S
+credu	BrP	r
+creulon	Br6	S
+crist	YJ	R
+cristion	Ya	X
+cristionogol	Yx	b
+croesi	BsM	R
+crwn	Bsd	P
+crwtyn	Bss	c
+cryf	BtI	Q
+cuddio	BtY	Z
+cudyll	Btx	Q
+curyll	BuB	Q
+cwch	BuR	O
+cwcw	Buf	Q
+cwestiwn	Buv	W
+cwm	BvF	P
+cwningen	BvU	U
+cwpan	Bvo	O
+cwpwrdd	Bv2	x
+cwrdd	Bwn	s
+cwt	BxT	N
+cwympo	Bxg	W
+cyfaill	Bx2	T
+cyfarfod	ByJ	v
+cyflym	By4	t
+cyllell	Bzl	S
+cymraeg	ZM	i
+cymreig	Zu	S
+cymru	aA	Q
+cymryd	Bz3	r
+cyn	B0i	c
+cyngerdd	B0+	V
+cynnes	B1T	Q
+cyntaf	B1j	R
+cyrraedd	B10	1
+cysgu	B2p	b
+cywir	B3E	R
+cÃn	B3V	O
+cÃr	B3j	W
+da	B35	Y
+dafad	B4R	Q
+dafydd	aQ	R
+dal	B4h	g
+damwain	B5B	V
+dan	B5W	q
+dangos	B6A	l
+dannoedd	B6l	X
+dant	B68	P
+darfod	B7L	BJ
+darllen	B8U	R
+darlun	B8l	d
+darn	B9C	a
+dau	B9c	M
+dau ar bymtheg	B9o	d
+dau gant	B+F	Z
+dawns	B+e	Q
+dawnsio	B+u	S
+ddoe	B/A	T
+deall	B/T	e
+dechrau	B/x	j
+deffro	CAU	Z
+deg	CAt	M
+deg a deugain	CBj	Y
+deg a phedwar ugain	CB7	f
+deg a thrigain	CCa	b
+deg ar hugain	CBK	Z
+degfed	CA5	R
+deintydd	CC1	V
+desg	CDK	s
+deuddeg	CD2	T
+deuddegfed	CEJ	X
+deugain	CEg	S
+deunaw	CEy	U
+deunawfed	CFG	Z
+dewi	ah	P
+dewin	CFf	5
+diddorol	CGY	Z
+digon	CGx	d
+dim	CHO	c
+dinas	CHq	b
+diolch	CIF	d
+dod	CIi	N
+dod Ã	CIv	Y
+doe	CJH	S
+doenitheb	CJZ	V
+dofydd	aw	P
+dolgelly	a/	W
+draig	CJu	R
+dringo	CJ/	R
+drwg	CKQ	BT
+drws	CLj	O
+drwy	CLx	R
+du	CMC	N
+dulyn	bV	R
+duw	bm	M
+dweud	CMP	t
+dwr	CM8	O
+dwsin	CNK	Q
+dwy	CNa	M
+dwy ar bymtheg	CNm	d
+dwy waith	COD	U
+dydd	COX	N
+dydd gwener y groglith	by	n
+dydd llun	COk	V
+dydd sadwrn	CO5	Y
+dydd sul	CPR	U
+dyfod	CPl	P
+dyfod Ã	CP0	a
+dyma	CQO	w
+dyn	CQ+	U
+dyna	CRS	d
+dynes	CRv	Q
+dysgu	CR/	Z
+dywalgi	CSY	S
+dywedyd	CSq	v
+ebrill	cZ	R
+ef	CTZ	V
+efa	cq	M
+efrog	c2	P
+eglwys	CTu	BJ
+ei	CU3	q
+eifftaidd	dF	X
+ein	CVh	M
+eira	CVt	O
+eisiau	CV7	W
+eistedd	CWR	Q
+eliffant	CWh	W
+enw	CW3	a
+er	CXR	w
+erioed	CYB	o
+eroplÃn	CYp	0
+ers	CZd	U
+eryr	CZx	P
+eto	CaA	BW
+ewrob	dc	R
+fe	CbW	V
+felly	Cbr	Z
+ffatri	CcE	T
+ffedog	CcX	R
+ffenestr	Cco	U
+fferm	Cc8	o
+ffermwr	Cdk	T
+ffilm	Cd3	m
+fflandrys	dt	X
+fforc	Ced	P
+ffordd	Ces	c
+ffrainc	eE	T
+ffrind	CfI	S
+ffydd	Cfa	j
+ffyddlon	Cf9	U
+ffynnon	CgR	l
+fwltur	Cg2	T
+gadael	ChJ	BZ
+gaeaf	Cii	R
+gafr	Ciz	O
+gair	CjB	O
+gallu	CjP	V
+galw	Cjk	W
+gan	Cj6	N
+gardd	CkH	R
+gartref	CkY	U
+geneth	Cks	d
+geni	ClJ	Y
+ger	Clh	3
+glas	CmY	O
+glyn	Cmm	Q
+gof	Cm2	O
+gofalus	CnE	e
+gofyn	Cni	O
+golchi	Cnw	Q
+golff	CoA	P
+gorffennaf	eX	U
+gorwedd	CoP	Z
+grisiau	Coo	e
+groeg	er	R
+groegaidd	e8	U
+groeges	fQ	Y
+groegwr	fo	S
+gwaith	CpG	V
+gwal	Cpb	O
+gwallt	Cpp	Q
+gwas	Cp5	W
+gwawr	CqP	Z
+gwdihÅ	Cqo	Q
+gweithio	Cq4	S
+gweld	CrK	O
+gwell	CrY	Z
+gwely	Crx	O
+gwers	Cr/	R
+gwerthu	CsQ	j
+gwiber	Csz	Y
+gwir	CtL	O
+gwisgo	CtZ	Q
+gwlad	Ctp	Y
+gwlad yr haf	f6	a
+gwlyb	CuB	O
+gwlÃn	CuP	Q
+gwneud	Cuf	r
+gwraig	CvK	Z
+gwrando	Cvj	T
+gwybod	Cv2	a
+gwyddel	gU	V
+gwyddeles	gp	Y
+gwyddelig	hB	U
+gwyliau	CwQ	V
+gwynt	Cwl	P
+gwyrdd	Cw0	R
+gyda	CxF	O
+gynt	CxT	l
+gÅr	Cx4	V
+haf	CyN	P
+hallt	Cyc	Q
+hanes	Cys	Z
+hanner	CzF	Q
+hanner dydd	CzV	d
+hanner nos	Czy	Y
+hapus	C0K	b
+hardd	C0l	s
+haul	C1R	N
+hawdd	C1e	X
+heb	C11	Q
+heblaw	C2F	v
+hebog	C20	P
+heddiw	C3D	R
+heddwch	C3U	S
+hefyd	C3m	e
+help	C4E	T
+hen	C4X	M
+heol	C4j	k
+het	C5H	M
+hi	C5T	W
+hir	C5p	N
+hisbaen	hV	S
+hoffi	C52	b
+hogyn	C6R	b
+hon	C6s	N
+hwn	C65	N
+hwylio	C7G	Q
+hydref	hn	T
+hyfryd	C7W	f
+i	C71	BI
+iaith	C89	b
+iar	C9Y	W
+iau	h6	Q
+iawn	C9u	g
+iechyd	C+O	S
+ieuanc	C+g	R
+ifanc	C+x	Q
+ionawr	iK	T
+isalmaen	id	x
+isel	C/B	N
+iwerddon	jO	V
+iwerydd	jj	l
+lawer gwaith	C/O	u
+lerpwl	kI	V
+lladd	C/8	g
+lladin	kd	R
+llaeth	DAc	Q
+llafariad	DAs	U
+llanelli	ku	W
+llaw	DBA	O
+llawen	DBO	g
+llawr	DBu	Q
+lle	DB+	2
+lleuad	DC0	Q
+llew	DDE	O
+lliw	DDS	V
+lloegr	lE	T
+llong	DDn	X
+llongwr	DD+	T
+llosgi	DER	Q
+llundain	lX	U
+llwyd	DEh	P
+llwyddiant	DEw	k
+llwynog	DFU	Q
+llwynoges	DFk	U
+llydaw	lr	e
+llyfr	DF4	P
+llyfrgell	DGH	W
+llygoden	DGd	T
+llygoden fawr	DGw	W
+llygota	DHG	Z
+llyn	DHf	U
+llythyr	DHz	T
+llythyrdy	DIG	a
+mab	DIg	M
+mai	mJ	M
+mam	DIs	P
+manceinion	mV	a
+map	DI7	M
+marw	DJH	o
+mat	DJv	M
+math	DJ7	U
+mawr	DKP	b
+mawrth	mv	Z
+meddyg	DKq	d
+medi	nI	T
+medru	DLH	V
+mehefin	nb	R
+melys	DLc	m
+menyn	DMC	R
+merch	DMT	c
+mewn	DMv	u
+mil	DNd	f
+miliwn	DN8	T
+milwr	DOP	Y
+mis	DOn	O
+mochyn	DO1	b
+modryb	DPQ	Q
+molecwl	DPg	V
+morgannwg	ns	Y
+morwr	DP1	R
+mur	DQG	N
+mynd	DQT	M
+mynydd	DQf	U
+mÃr	DQz	N
+mÃr coch	oE	W
+mÃr tawel	oa	m
+mÃr y canoldir	pA	i
+na	DRA	M
+nadolig	pi	c
+nant	DRM	Q
+naw	DRc	N
+nawfed	DRp	R
+neb	DR6	BB
+neidr	DS7	Z
+neifion	p+	U
+neis	DTU	Q
+nes	DTk	U
+nesaf	DT4	a
+neuadd	DUS	Q
+newydd	DUi	W
+newyddion	DU4	r
+ni	DVj	O
+nofel	DVx	Q
+nofio	DWB	W
+nos	DWX	O
+noson	DWl	S
+o	DW3	T
+o amgylch	DaA	s
+o flaen	Das	g
+ochr	DXK	O
+oedrannus	DXY	S
+oer	DXq	c
+ofn	DYG	N
+ogof	DYT	r
+ond	DY+	M
+os	DZK	Z
+os gwelwch yn dda	DZj	d
+paham	DbM	j
+paladr	Dbv	V
+pam	DcE	h
+papur	Dcl	Q
+paratoi	Dc1	U
+parc	DdJ	O
+parod	DdX	j
+pe	Dd6	Z
+pedair	DeT	Q
+pedair ar bymtheg	Dej	f
+pedair ar ddeg	DfC	c
+pedwar	Dfe	Q
+pedwar ar bymtheg	DhI	f
+pedwar ar ddeg	Dhn	c
+pedwar ugain	DiD	Y
+pedwar ugain a deg	Dib	e
+pedwaredd	Dfu	V
+pedwaredd ar bymtheg	DgD	k
+pedwaredd ar ddeg	Dgn	h
+pedwerydd	Di5	V
+pedwerydd ar bymtheg	DjO	k
+pedwerydd ar ddeg	Djy	h
+pelydryn	DkT	X
+pen	Dkq	d
+pensil	DlH	S
+pentref	DlZ	U
+penybont	qS	W
+perllan	Dlt	U
+peswch	DmB	R
+piano	DmS	Q
+pib	Dmi	N
+plismon	Dmv	W
+pobl	DnF	e
+poced	Dnj	R
+poeth	Dn0	O
+pont	DoC	Q
+popeth	DoS	n
+pori	Do5	P
+potel	DpI	R
+prif	DpZ	V
+prifathro	Dpu	r
+prifysgol	DqZ	Z
+prin	Dqy	t
+priodi	Drf	q
+pris	DsJ	P
+prwsia	qo	T
+prydain	q7	j
+prydeinig	re	W
+prydeiniwr	r0	W
+prydferth	DsY	w
+pum	DtI	N
+pumed	DtV	Q
+pump	Dtl	O
+punt	Dtz	P
+pwll	DuC	O
+pwy	DuQ	l
+pwyl	sK	Q
+pymtheg	Du1	U
+pymthegfed	DvJ	Z
+pÃl	Dvi	O
+rabbi	Dvw	Q
+radio	DwA	a
+ras	Dwa	U
+reis	Dwu	O
+rhad	Dw8	c
+rhaff	DxY	d
+rhag	Dx1	W
+rhagfyr	sa	V
+rhaid	DyL	U
+rhedeg	Dyf	P
+rheol	Dyu	b
+rheolwr	DzJ	U
+rhoi	Dzd	O
+rhosyn	Dzr	Q
+rhufain	sv	R
+rhufeinaidd	tA	W
+rhufeiniad	tW	V
+rhufeinig	tr	U
+rhufeiniwr	t/	V
+rhwng	Dz7	Z
+rhwyfo	D0U	P
+rhydychen	uU	V
+rhyfedd	D0j	W
+rhyfel	D05	P
+rwber	D1I	R
+rwsia	up	R
+sabath	u6	U
+saboth	vO	U
+sadwrn	vi	S
+saesneg	v0	x
+saesnes	wl	i
+sais	xH	o
+saith	D1Z	Q
+sefyll	D1p	R
+seithfed	D16	V
+sgwar	D2P	n
+siarad	D22	X
+sicr	D3N	X
+sigar	D3k	Q
+sigaret	D30	W
+silff	D4K	Q
+sinema	D4a	h
+siop	D47	f
+siwgr	D5a	Q
+siwr	D5q	X
+smocio	D6B	R
+stori	D6S	q
+storm	D68	Q
+stryd	D7M	R
+swansea	xv	U
+swllt	D7d	T
+swyddfa	D7w	l
+swynwr	D8V	6
+syched	D9P	S
+symud	D9h	P
+syrthio	D9w	X
+tachwedd	yD	W
+tacsi	D+H	P
+tafod	D+W	R
+tafwys	yZ	S
+tair	D+n	P
+tair ar ddeg	D+2	a
+taith	D/Q	g
+tal	D/w	N
+talu	D/9	N
+taro	EAK	b
+tarw	EAl	O
+tebot	EAz	U
+tegell	EBH	S
+teigr	EBZ	Q
+teisen	EBp	Q
+teledu	EB5	a
+telyn	ECT	P
+thermomedr	ECi	b
+tiddewi	yr	a
+tir	EC9	W
+tlawd	EDT	i
+tlws	ED1	Q
+torri	EEF	e
+tost	EEj	T
+traeth	EE2	R
+tref	EFH	U
+treulio	EFb	b
+tri	EF2	O
+tri ar ddeg	EGw	Z
+trigain	EGE	S
+trigain a deg	EGW	a
+trwm	EHJ	k
+trwy	EHt	R
+trydan	EH+	X
+trydedd	EIV	S
+trydedd ar ddeg	EIn	f
+trydydd	EJG	S
+trydydd ar ddeg	EJY	f
+trysor	EJ3	U
+trÃn	EKL	Q
+twrc	zF	O
+twrci	EKb	R
+twrci	zT	R
+tyfu	EKs	W
+tylluan	ELC	Q
+tywydd	ELS	T
+tÃn	ELl	O
+tÃ	ELz	M
+tÅr	EL/	X
+uchel	EMW	c
+ugain	EMy	R
+ugeinfed	END	X
+un	ENa	L
+un ar bymtheg	EO6	a
+un ar ddeg	EPU	W
+un ar hugain	EPq	e
+unfed ar bymtheg	ENl	f
+unfed ar ddeg	EOE	b
+unwaith	EOf	b
+wedi	EQI	o
+wedi blino	EQw	V
+wedyn	ERF	p
+weithiau	ERu	m
+wrth	ESU	Bf
+wyth	ETz	P
+wythfed	EUC	T
+wythnos	EUV	R
+ychydig	EUm	BH
+yfed	EVt	P
+yfory	EV8	T
+ymenyn	EWP	S
+ymhlith	EWh	b
+ymlaen	EW8	f
+yn	EXb	s
+yn awr	EYX	b
+yn dda	EYy	W
+yn erbyn	EZI	BP
+yn gynnar	EaX	U
+yn gyntaf	Ear	r
+yn hwyr	EbW	R
+yn lle	Ebn	T
+yn ofalus	Eb6	p
+yn rhad	Ecj	U
+ynys	EYH	Q
+yr aifft	zk	T
+yr alban	z3	W
+yr almaen	0N	W
+yr eidal	0j	T
+yr unol daleithiau	02	1
+yrÅan	Ec3	b
+ysgol	EdS	R
+ysgrifennu	Edj	V
+ysgyfarnog	Ed4	U
+ystafell	EeM	b
+Ã	Een	q
+Ãb	EfR	T

Added: trunk/test/test_dictd_file.rb
==============================================================================
--- (empty file)
+++ trunk/test/test_dictd_file.rb	Sun Aug 24 07:55:10 2008
@@ -0,0 +1,118 @@
+# Fantasdic
+# Copyright (C) 2008 Mathieu Blondel
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+#Âwith this program; if not, write to the Free Software Foundation, Inc.,
+#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+test_dir = File.expand_path(File.dirname(__FILE__))
+top_dir = File.expand_path(File.join(test_dir, ".."))
+lib_dir = File.expand_path(File.join(top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join(test_dir, "data"))
+$index_file = File.join($test_data_dir, "freedict-wel-eng.index")
+$dict_file = File.join($test_data_dir, "freedict-wel-eng.dict")
+$dict_dz_file = File.join($test_data_dir, "freedict-wel-eng.dict.dz")
+$LOAD_PATH.unshift(lib_dir)
+
+require "test/unit"
+require "fantasdic"
+require "fantasdic/sources/dictd_file"
+
+class TestDictdFileSource < Test::Unit::TestCase
+    include Fantasdic::Source
+
+    def test_binary_search
+        DictdIndex.open($index_file) do |index|
+            res = index.binary_search("notfound") do |s1, s2|
+                s1 <=> s2
+            end
+            assert_equal(res, nil)
+
+            res = index.binary_search("cloc") do |s1, s2|
+                s1 <=> s2
+            end
+            assert_equal(res, 2005)
+        end
+    end
+
+    def test_seek_prev_offset
+        DictdIndex.open($index_file) do |index|
+            assert_equal(index.get_prev_offset(52), 25)
+            assert_equal(index.get_prev_offset(2005), 1994)
+            assert_equal(index.get_prev_offset(25), nil)
+        end
+    end
+
+    def test_seek_next_offset
+        DictdIndex.open($index_file) do |index|
+            assert_equal(index.get_next_offset(52), 72)
+            assert_equal(index.get_next_offset(9462), 9472)
+            assert_equal(index.get_next_offset(9472), nil)
+        end
+    end
+
+    def test_match_prefix
+        DictdIndex.open($index_file) do |index|
+            assert_equal(index.match_prefix("ca").map { |a| a.first },
+["cadair", "cadnawes", "cadno", "cadw", "cael", "caerdydd", "caeredin",
+ "caerefrog", "caerludd", "caint", "caled", "calon", "canol", "cant",
+ "canu", "cap", "capel", "car", "caredig", "cario", "carreg", "cartref",
+ "caru", "carw", "castell", "cath", "cau", "cawrfil", "caws"])
+
+            assert_equal(index.match_prefix("notfound").map { |a| a.first },
+                         [])
+
+        end
+    end
+
+    def test_match_exact
+        DictdIndex.open($index_file) do |index|
+            assert_equal(index.match_exact("ca").map { |a| a.first },
+                         [])
+
+            assert_equal(index.match_exact("caredig").map { |a| a.first },
+                         ["caredig"])            
+        end
+    end
+
+    def test_match_suffix
+        DictdIndex.open($index_file) do |index|
+            assert_equal(index.match_suffix("din").map { |a| a.first },
+                         ["caeredin", "lladin"])
+
+            assert_equal(index.match_suffix("notfound").map { |a| a.first },
+                         [])
+        end
+    end
+
+    def test_match_substring
+        DictdIndex.open($index_file) do |index|
+            assert_equal(index.match_substring("hufein").map { |a| a.first },
+                         ["rhufeinaidd", "rhufeiniad", "rhufeinig",
+                          "rhufeiniwr"])
+
+            assert_equal(index.match_substring("notfound").map { |a| a.first },
+                         [])
+        end
+    end
+
+    def test_match_word
+        DictdIndex.open($index_file) do |index|
+            assert_equal(index.match_word("os").map { |a| a.first },
+                         ["os", "os gwelwch yn dda"])
+
+            assert_equal(index.match_word("notfound").map { |a| a.first },
+                         [])
+        end
+    end
+end



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]