[Tomoe-cvs 1464] CVS update: tomoe/utils

アーカイブの一覧に戻る

Kouhei Sutou kous****@users*****
2006年 11月 30日 (木) 18:14:49 JST


Index: tomoe/utils/dictionary.rb
diff -u tomoe/utils/dictionary.rb:1.2 tomoe/utils/dictionary.rb:removed
--- tomoe/utils/dictionary.rb:1.2	Mon Jun  5 03:28:33 2006
+++ tomoe/utils/dictionary.rb	Thu Nov 30 18:14:49 2006
@@ -1,166 +0,0 @@
-#!/usr/bin/ruby
-
-require 'xml/libxml'
-
-class Point
-  def initialize(x = 0, y = 0)
-    @x = x
-    @y = y
-  end
-
-  attr_accessor :x
-  attr_accessor :y
-
-  def to_s
-    "(" +****@x*****_s + ", " +****@y*****_s + ")"
-  end
-end
-
-class Stroke
-  def initialize(points)
-    @points = points
-  end
-
-  attr_accessor :points
-
-  def to_s
-    s = "{"
-    for point in @points
-      if s != "{"
-        s += ", "
-      end
-      s += point.to_s
-    end
-    s += "}"
-    return s
-  end
-end
-
-class Letter
-  def initialize(character, strokes)
-    @character = character
-    @strokes = strokes
-  end
-
-  attr_accessor :character
-  attr_accessor :strokes
-
-  def to_s
-    s = "[" + @character + " "
-    i = 0
-    for stroke in @strokes
-      if i != 0
-        s += ", "
-      end
-      s += stroke.to_s
-      i += 1
-    end
-    s += "]"
-    return s
-  end
-end
-
-class Dictionary
-  def initialize(dictfilepath="../data/all.xml")
-    @letters = load(dictfilepath)
-    @letters_by_stroke_count = group_by_stroke_count(@letters)
-  end
-
-  attr_accessor :letters
-  attr_accessor :letters_by_stroke_count
-
-  def load(dictfilepath)
-    letters = []
-
-    doc = XML::Document.file(dictfilepath)
-    root = doc.root
-    doc.find('//dict/character').each do |node|
-      literal = node.find('literal').to_a.first
-#      puts "letter #{literal}\n"
-
-      strokes = []
-      points = []
-      node.find('strokelist/s').each do |stroke|
-	line = "#{stroke}\n"
-	index1 = 0
-	index2 = 0
-	points = []
-	index1 = line.index("(", index2)
-	while index1 != nil
-	  index1 += 1
-	  index2 = line.index(" ", index1)
-	  x = line.slice(index1, index2)
-	  index1 = index2 + 1
-	  index2 = line.index(")", index1)
-	  y = line.slice(index1, index2)
-          point = Point.new(x.to_i, y.to_i)
-          points.push(point)
-	  index1 = line.index("(", index2)
-        end
-        stroke = Stroke.new(points)
-        strokes.push(stroke)
-      end
-      letter = Letter.new("#{literal}", strokes)
-      letters.push(letter)
-    end
-
-    return letters
-  end
-
-  def group_by_stroke_count(letters)
-    letters_by_stroke_count = []
-    for letter in letters
-      i = letter.strokes.size - 1
-      if letters_by_stroke_count[i] == nil
-	letters_by_stroke_count[i] = []
-      end
-      letters_by_stroke_count[i].push(letter)
-    end
-    return letters_by_stroke_count
-  end
-
-  def to_s
-    s = ""
-    i = 0
-    for letter in @letters
-      if i != 0
-        s += ", "
-      end
-      s += letter.to_s
-      i += 1
-    end
-    return s
-  end
-
-#  def to_s_by_stroke_count
-#    s = ""
-#    for i in 0 .. @letters_by_stroke_count.size - 1
-#      stroke_count = i + 1
-#      letters = @letters_by_stroke_count[i]
-#      s += stroke_count.to_s + "�"
-#      for letter in letters
-#	s += " " + letter.character
-#      end
-#      s += "\n"
-#    end
-#    return s
-#  end
-
-  def get_letter(character)
-    for letter in @letters
-      if letter.character == character
-	return letter
-      end
-    end
-    return nil
-  end
-end
-
-if __FILE__ == $0
-  t1 = Time.now
-  d = Dictionary.new
-  t2 = Time.now
-
-#  print d.to_s_by_stroke_count
-#  print "elapsed time(sec)=" + (t2 - t1).to_s + "\n"
-end
Index: tomoe/utils/gtk2dictview.rb
diff -u tomoe/utils/gtk2dictview.rb:1.2 tomoe/utils/gtk2dictview.rb:removed
--- tomoe/utils/gtk2dictview.rb:1.2	Wed Nov  2 13:44:40 2005
+++ tomoe/utils/gtk2dictview.rb	Thu Nov 30 18:14:49 2006
@@ -1,117 +0,0 @@
-#!/usr/bin/ruby
-
-require 'gtk2'
-require 'dictionary'
-
-class Gtk2DictView
-  def initialize
-    @dict = Dictionary.new
-    create_gui
-  end
-
-  def create_gui
-    Gtk.init
-
-    window = Gtk::Window.new
-    window.signal_connect("delete_event") {
-      #true
-      false
-    }
-
-    window.signal_connect("destroy") {
-      Gtk.main_quit
-    }
-
-    box1 = Gtk::VBox.new(false, 15)
-
-    @area = Gtk::DrawingArea.new
-    @area.set_size_request(300, 300)
-    @area.signal_connect("expose_event") {
-      draw_letter
-    }
-
-    box2 = Gtk::HBox.new(false, 5)
-
-    box1.add(@area)
-    box1.add(box2)
-
-    @stroke_count_combobox = Gtk::ComboBox.new
-    for i in 1 ..****@dict*****_by_stroke_count.size
-      @stroke_count_combobox.append_text(i.to_s)
-    end
-
-    @stroke_count_combobox.signal_connect("changed") {
-      update_letter_liststore
-    }
-
-    stroke_count_label = Gtk::Label.new(GLib.convert("画", "utf-8", "euc-jp"))
-
-    @letter_liststore = Gtk::ListStore.new(String)
-    update_letter_liststore
-    @letter_comboboxentry = Gtk::ComboBoxEntry.new(@letter_liststore, 0)
-    @letter_comboboxentry.signal_connect("changed") {
-      @letter = @letters[@letter_comboboxentry.active]
-      draw_letter
-    }
-    @letter_comboboxentry.child.signal_connect("activate") {
-      letter =****@dict*****_letter(@letter_comboboxentry.child.text)
-      if letter == nil
-	dialog = Gtk::MessageDialog.new(window, Gtk::Dialog::MODAL,
-					Gtk::MessageDialog::ERROR,
-					Gtk::MessageDialog::BUTTONS_OK,
-					"character not found in dictionary")
-	dialog.run { |response| dialog.destroy }
-      else
-	@letter = letter
-      end
-      draw_letter
-    }
-
-    button = Gtk::Button.new(GLib.convert("終了", "utf-8", "euc-jp"))
-    button.signal_connect("clicked") {
-      Gtk.main_quit
-    }
-
-    box2.pack_start(@stroke_count_combobox, false, false, 0)
-    box2.pack_start(stroke_count_label, false, false, 0)
-    box2.pack_start(@letter_comboboxentry, true, true, 0)
-    box2.pack_start(button, false, false, 0)
-
-    window.border_width = 10
-    window.add(box1)
-    window.show_all
-  end
-
-  def update_letter_liststore
-    stroke_count = @stroke_count_combobox.active
-    @letters =****@dict*****_by_stroke_count[stroke_count]
-
-    @letter_liststore.clear
-    for letter in @letters
-      @letter_liststore.append[0] = letter.character
-    end
-  end
-
-  def stroke_to_points(stroke)
-    points = []
-    for point in stroke.points
-      points.push([point.x, point.y])
-    end
-    return points
-  end
-
-  def draw_letter
-    if @letter == nil
-      return
-    end
-
-    @area.window.clear
-    for stroke in****@lette*****
-      points = stroke_to_points(stroke)
-      @area.window.draw_lines(@area.style.fg_gc(@area.state), points)
-    end
-  end
-end
-
-dv = Gtk2DictView.new
-Gtk.main
Index: tomoe/utils/makexmldict.rb
diff -u tomoe/utils/makexmldict.rb:1.1 tomoe/utils/makexmldict.rb:removed
--- tomoe/utils/makexmldict.rb:1.1	Mon Jun  5 03:28:33 2006
+++ tomoe/utils/makexmldict.rb	Thu Nov 30 18:14:49 2006
@@ -1,40 +0,0 @@
-#!/usr/bin/ruby
-
-require 'xml/libxml'
-
-dictfilepath="../data/all.tdic"
-newdictfilepath="../data/generated.xml"
-
-doc = XML::Document.new()
-doc.root = XML::Node.new('dict')
-root = doc.root
-
-open(dictfilepath, "r") do |f|
-  while ((line = f.gets) != nil)
-    root << character = XML::Node.new('character')
-
-    line.chomp!
-    ch = line
-    character << literal = XML::Node.new('literal')
-    literal << ch
-
-    line = f.gets
-    line.chomp!
-    stroke_num = line[1 .. line.length].to_i
-
-    character << strokelist = XML::Node.new('strokelist')
-    strokelist['count'] = stroke_num.to_s()
-
-    strokes = []
-    for i in 1 .. stroke_num
-      line = f.gets
-      line.chomp!
-      vector_num = line[0 .. line.index(" ")].to_i
-      strokelist << stroke = XML::Node.new('s')
-      stroke['count'] = vector_num.to_s()
-      stroke << line[line.index(" ") + 1 .. line.length]
-    end
-    empty_line = f.gets
-  end
-end
-doc.save(newdictfilepath, true)


tomoe-cvs メーリングリストの案内
アーカイブの一覧に戻る