tefil 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES +10 -1
- data/VERSION +1 -1
- data/bin/columnform +1 -0
- data/bin/linesplit +48 -0
- data/example/linesplit/run.sh +6 -0
- data/example/linesplit/sample1.txt +1 -0
- data/example/linesplit/sample2.txt +2 -0
- data/example/linesplit/sample3.txt +2 -0
- data/example/linesplit/sample4.txt +5 -0
- data/lib/tefil.rb +1 -2
- data/lib/tefil/columnformer.rb +5 -0
- data/lib/tefil/fswikitomd.rb +11 -1
- data/lib/tefil/linesplitter.rb +50 -0
- data/lib/tefil/mdtofswiki.rb +5 -5
- data/lib/tefil/textfilterbase.rb +9 -0
- data/tefil.gemspec +12 -11
- data/test/test_columnformer.rb +20 -3
- data/test/test_fswikitomd.rb +130 -80
- data/test/test_linesplitter.rb +129 -0
- data/test/test_mdtofswiki.rb +55 -30
- data/test/test_textfilterbase.rb +11 -3
- metadata +11 -11
- data/bin/eachsentence +0 -24
- data/bin/statistics +0 -24
- data/example/eachsentence/sample.txt +0 -14
- data/lib/tefil/eachsentence.rb +0 -35
- data/lib/tefil/statistics.rb +0 -38
- data/test/test_eachsentence.rb +0 -123
- data/test/test_statistics.rb +0 -38
data/lib/tefil/statistics.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
class Tefil::Statistics < Tefil::TextFilterBase
|
2
|
-
|
3
|
-
HISTGRAM_LIMIT = 50
|
4
|
-
|
5
|
-
def initialize(options = {})
|
6
|
-
options[:smart_filename] = true
|
7
|
-
@minimum = options[:minimum]
|
8
|
-
super(options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def process_stream(in_io, out_io)
|
12
|
-
data = in_io.readlines.map{|l| l.to_f}
|
13
|
-
|
14
|
-
sum = 0.0
|
15
|
-
data.each { |datum| sum += datum }
|
16
|
-
|
17
|
-
average = sum / data.size.to_f
|
18
|
-
|
19
|
-
#variance
|
20
|
-
tmp = 0.0
|
21
|
-
data.each { |datum| tmp += (datum - average)**2 }
|
22
|
-
variance = tmp / data.size.to_f
|
23
|
-
|
24
|
-
#standard deviation
|
25
|
-
standard_deviation = Math::sqrt(variance)
|
26
|
-
|
27
|
-
out_io.puts "sample: #{data.size}\n"
|
28
|
-
out_io.puts "highest: #{data.max}\n"
|
29
|
-
out_io.puts "lowest: #{data.min}\n"
|
30
|
-
out_io.puts "sum: #{sum}"
|
31
|
-
out_io.puts "average: #{average}"
|
32
|
-
out_io.puts "variance: #{variance}"
|
33
|
-
out_io.puts "standard_deviation: #{standard_deviation}"
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
|
data/test/test_eachsentence.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
require "helper"
|
5
|
-
require "stringio"
|
6
|
-
|
7
|
-
# 元々の行末は保存する。
|
8
|
-
# 消すようにすると、空行などの処理が面倒になる。
|
9
|
-
class TC_EachSentence < Test::Unit::TestCase
|
10
|
-
def setup
|
11
|
-
@test00 = Tefil::EachSentence.new()
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_process_stream
|
15
|
-
# divide
|
16
|
-
in_io = StringIO.new
|
17
|
-
in_io.puts <<HERE
|
18
|
-
Abc def. Ghi jhk.
|
19
|
-
HERE
|
20
|
-
in_io.rewind
|
21
|
-
out_io = StringIO.new
|
22
|
-
@test00.process_stream(in_io, out_io)
|
23
|
-
out_io.rewind
|
24
|
-
result = out_io.read
|
25
|
-
correct = <<HERE
|
26
|
-
Abc def.
|
27
|
-
Ghi jhk.
|
28
|
-
HERE
|
29
|
-
assert_equal(correct, result)
|
30
|
-
|
31
|
-
# 行末の保存
|
32
|
-
in_io = StringIO.new
|
33
|
-
in_io.puts <<HERE
|
34
|
-
Abc def
|
35
|
-
Ghi jhk.
|
36
|
-
HERE
|
37
|
-
in_io.rewind
|
38
|
-
out_io = StringIO.new
|
39
|
-
@test00.process_stream(in_io, out_io)
|
40
|
-
out_io.rewind
|
41
|
-
result = out_io.read
|
42
|
-
correct = <<HERE
|
43
|
-
Abc def
|
44
|
-
Ghi jhk.
|
45
|
-
HERE
|
46
|
-
assert_equal(correct, result)
|
47
|
-
|
48
|
-
# indent
|
49
|
-
in_io = StringIO.new
|
50
|
-
in_io.puts <<HERE
|
51
|
-
Abc def
|
52
|
-
Ghi jhk.
|
53
|
-
HERE
|
54
|
-
in_io.rewind
|
55
|
-
out_io = StringIO.new
|
56
|
-
@test00.process_stream(in_io, out_io)
|
57
|
-
out_io.rewind
|
58
|
-
result = out_io.read
|
59
|
-
correct = <<HERE
|
60
|
-
Abc def
|
61
|
-
Ghi jhk.
|
62
|
-
HERE
|
63
|
-
assert_equal(correct, result)
|
64
|
-
|
65
|
-
# empty line
|
66
|
-
in_io = StringIO.new
|
67
|
-
in_io.puts <<HERE
|
68
|
-
Abc def.
|
69
|
-
|
70
|
-
Ghi jhk.
|
71
|
-
HERE
|
72
|
-
in_io.rewind
|
73
|
-
out_io = StringIO.new
|
74
|
-
@test00.process_stream(in_io, out_io)
|
75
|
-
out_io.rewind
|
76
|
-
result = out_io.read
|
77
|
-
correct = <<HERE
|
78
|
-
Abc def.
|
79
|
-
|
80
|
-
Ghi jhk.
|
81
|
-
HERE
|
82
|
-
assert_equal(correct, result)
|
83
|
-
|
84
|
-
# Fig.
|
85
|
-
in_io = StringIO.new
|
86
|
-
in_io.puts <<HERE
|
87
|
-
Including Fig.3. Fig. 3? Fig.
|
88
|
-
4 does' not exist.
|
89
|
-
HERE
|
90
|
-
in_io.rewind
|
91
|
-
out_io = StringIO.new
|
92
|
-
@test00.process_stream(in_io, out_io)
|
93
|
-
out_io.rewind
|
94
|
-
result = out_io.read
|
95
|
-
correct = <<HERE
|
96
|
-
Including Fig.3.
|
97
|
-
Fig. 3?
|
98
|
-
Fig.
|
99
|
-
4 does' not exist.
|
100
|
-
HERE
|
101
|
-
assert_equal(correct, result)
|
102
|
-
|
103
|
-
# Japanese kutouten
|
104
|
-
in_io = StringIO.new
|
105
|
-
in_io.puts <<HERE
|
106
|
-
あいうえお。かき
|
107
|
-
くけこ。
|
108
|
-
HERE
|
109
|
-
in_io.rewind
|
110
|
-
out_io = StringIO.new
|
111
|
-
@test00.process_stream(in_io, out_io)
|
112
|
-
out_io.rewind
|
113
|
-
result = out_io.read
|
114
|
-
correct = <<HERE
|
115
|
-
あいうえお。
|
116
|
-
かき
|
117
|
-
くけこ。
|
118
|
-
HERE
|
119
|
-
assert_equal(correct, result)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
|
data/test/test_statistics.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
require "helper"
|
5
|
-
require "stringio"
|
6
|
-
|
7
|
-
#class Tefil::IndentConverter
|
8
|
-
# public :process_stream
|
9
|
-
#end
|
10
|
-
|
11
|
-
class TC_Statistics < Test::Unit::TestCase
|
12
|
-
def setup
|
13
|
-
@s00 = Tefil::Statistics.new()
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_process_stream
|
17
|
-
# stdin -> stdout
|
18
|
-
$stdin = StringIO.new
|
19
|
-
$stdin.puts "1.0"
|
20
|
-
$stdin.puts "2.0"
|
21
|
-
$stdin.puts "3.0"
|
22
|
-
$stdin.rewind
|
23
|
-
#str = capture_stdout{}
|
24
|
-
result = capture_stdout{ @s00.filter([])}
|
25
|
-
correct =
|
26
|
-
"sample: 3\n" +
|
27
|
-
"highest: 3.0\n" +
|
28
|
-
"lowest: 1.0\n" +
|
29
|
-
"sum: 6.0\n" +
|
30
|
-
"average: 2.0\n" +
|
31
|
-
"variance: 0.6666666666666666\n" +
|
32
|
-
"standard_deviation: 0.816496580927726\n"
|
33
|
-
assert_equal(correct, result)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|