Sha256: f06ad9c3679ad97c8b2ee40b4480c4c77ca24be40d90d2de5a0b3d1b2db1dc0d

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

Rule Main
  input ('*.txt' or 'terminate.cmd').except('summary.txt').all
  output '*.count'.all
  output 'summary.txt'
Flow
  rule CountChar
  rule Summarize
End

Rule CountChar
  input '*.txt'.except('summary.txt')
  output '{$*}.count'
Flow
  rule ConvertToUtf8
  rule CountUTF8Char
  rule Terminate
End

Rule ConvertToUtf8
  input '*.txt'.except('summary.txt')
  output '{$*}.utf8'
Action
  iconv -c -f Shift_JIS -t UTF-8 {$I[1]} > {$O[1]}
End

Rule CountUTF8Char
  input '*.utf8'
  output '{$*}.count'.stdout
Action
#!/usr/bin/env ruby
# coding: utf-8
  table = {}
  text = File.open("{$I[1]}").read
  text.split("").each do |c|
    table[c] =  table.has_key?(c) ? table[c].succ : 1
  end
  table.keys.sort {|a,b| table[b] <=> table[a] }.each do |key|
    puts "#{key.inspect[1..-2]}:#{table[key]}"
  end
End

Rule Summarize
  input '*.count'.all
  output 'summary.txt'.stdout
Action
#!/usr/bin/env ruby
# coding: utf-8
  table = {}
  "{$I[1]}".split(" ").each do |path|
    File.read(path).split("\n").map do |line|
      c, number = line.split(":")
      table[c] = (table.has_key?(c) ? table[c] : 0) + number.to_i
    end
  end
  table.keys.sort {|a,b| table[b] <=> table[a] }.each do |key|
    puts "#{key.inspect[1..-2]}:#{table[key]}"
  end
End

Rule Terminate
  input 'terminate.cmd'
Flow
  rule &system:Terminate
End

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pione-0.4.1 example/CountChar/CountChar.pione
pione-0.4.0 example/CountChar/CountChar.pione