Changeset 704

Show
Ignore:
Timestamp:
10/25/07 16:12:27 (6 years ago)
Author:
gyuque
Message:

lang/javascript/ruby/syobodic/proc1.rb

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/syobodic/proc1.rb

    r702 r704  
    11require 'net/http' 
    22require 'kconv' 
    3 $KCODE = "UTF-8" 
     3require 'jcode' 
     4$KCODE = "UTF8" 
    45 
    56$SYOBO_SERVER = "cal.syoboi.jp" 
    67 
     8class Splitter 
     9        def initialize(t,k) 
     10                @text = t 
     11                @kana = k 
     12        end 
     13end 
     14 
    715class SyoboTitle 
     16        attr_reader :title 
     17        attr_reader :kana 
     18 
    819        def read_from_line(ln) 
     20                ln.chomp! 
     21                ln.gsub!(/^[ *],/,"") 
     22 
     23                ln.gsub!(/^([0-9]+),/, "") 
     24                raise "cannot read tid" if !($&) 
     25                @tid = $1.to_i 
     26 
     27                ln.gsub!(/^\"([^\"]+)\",/, "") 
     28                raise "cannot read title" if !($&) 
     29                @title = $1 
     30 
     31                ln.gsub!(/^\"([^\"]+)\",/, "") 
     32                raise "cannot read kana" if !($&) 
     33                @kana = $1 
     34 
     35                ln.gsub!(/^\"([^\"]+)\"/, "") 
     36                @abbr = $1 
     37 
     38                @abbr = nil if @abbr == "" 
     39 
    940        end 
    1041 
     
    1849                        raise "cannot found h1" if !($&) 
    1950                        @title = $1 
     51                        @title.gsub!("&","&") 
    2052 
    2153                        rbody =~ /<th>よみ<\/th><td>([^<]+)<\/td>/ 
     
    3365        def print 
    3466                mark = @abbr ? "*" : " " 
    35                 puts "#{mark},#{@tid},\"#{@title}\",\"#{@kana}\",\"#{@abbr}\"".kconv(Kconv::SJIS, Kconv::UTF8) 
     67                puts "#{mark},#{@tid},\"#{@title}\",\"#{@kana}\",\"#{@abbr}\"" 
    3668        end 
    3769end 
     
    5183end 
    5284 
    53 makeRawList(1200, 1250) 
     85def splitWords(rawlist_fn) 
     86        list = [] 
     87 
     88        File.open(rawlist_fn) {|f| 
     89                f.each {|ln| 
     90                        t = SyoboTitle.new 
     91                        t.read_from_line(ln) 
     92 
     93                        s = Splitter.new(t.title, t.kana) 
     94                } 
     95        } 
     96end 
     97 
     98# ----------------------------- 
     99 
     100if ARGV.length == 1 
     101        splitWords(ARGV[0]) 
     102else 
     103        makeRawList(1150, 1250) 
     104end