2 # TODO: replace_text 統合テーブルによる置換
5 require 'rexml/document'
7 SOURCE_DIR = File.join(File.dirname(__FILE__), '..', 'htdocs', 'swjz')
8 TARGET_DIR = File.join(File.dirname(__FILE__), '..', 'htdocs', 'unified')
11 def initialize(filename)
12 source_file = File.new(File.join(SOURCE_DIR, filename))
13 @doc = REXML::Document.new(source_file)
14 @out = File.open(File.join(TARGET_DIR, filename), "w")
16 def replace_char(s, pattern, char)
17 s.gsub!(pattern, char)
19 def replace_text(s) # TODO: 統合テーブルの導入
20 replace_char(s, /告/u, '吿')
21 replace_char(s, /㑹/u, '會')
22 replace_char(s, /緫/u, '總')
23 replace_char(s, /尢/u, '尤')
24 replace_char(s, /𡵉/u, '𡴆')
25 replace_char(s, /備/u, '僃')
26 replace_char(s, /彚/u, '彙')
27 replace_char(s, /𨕖/u, '選')
28 replace_char(s, /䖍/u, '虔')
33 td.replace_child(text, REXML::Text.new(content))
36 REXML::XPath.each(@doc.root, path) do |td|
37 REXML::XPath.each(td, 'text()') do |text|
43 unify_texts("//td[@class = 'body']") # 段注
44 unify_texts("//table[@class = 'part_wordnum']/tr/td") # 部首末
45 unify_texts("//span[@class = 'explanation']") # 説解
50 Dir.foreach(SOURCE_DIR) do |filename|
51 if filename =~ /^.*\.html$/ then
52 unifier = Unifier.new(filename)