diff options
| author | Patrick Simianer <patrick@lilt.com> | 2026-02-26 10:05:59 +0000 |
|---|---|---|
| committer | Patrick Simianer <patrick@lilt.com> | 2026-02-26 10:05:59 +0000 |
| commit | b31ace79ea5f6b3f279c544cd3a443d6fbf2a24d (patch) | |
| tree | 31f2b599fa5f6996aeb134390d58deb63eefe04a /sample | |
| parent | 8805e95ae94d798c6441f7e1b72c90e049563f17 (diff) | |
Diffstat (limited to 'sample')
| -rwxr-xr-x | sample | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -1,15 +1,15 @@ #!/usr/bin/env ruby -require 'optimist' +require "optimist" -STDIN.set_encoding 'utf-8' -STDOUT.set_encoding 'utf-8' +STDIN.set_encoding "utf-8" +STDOUT.set_encoding "utf-8" opts = Optimist::options do banner "sample --size <n> [--shuffle] --file <line separated data>" opt :size, "Sample P % or # lines from file or N.", :type => :float opt :shuffle, "Sample is shuffled.", :type => :bool - opt :file, "Input file.", :type => :string, :default => '-' + opt :file, "Input file.", :type => :string, :default => "-" opt :output_index, "Output index number.", :type => :bool opt :N, "Sample --size from N items.", :type => :int, :default => -1 opt :absolute, "Sample absolute number of items.", :type => :bool @@ -19,10 +19,10 @@ input = [] index = [] i = 0 if opts[:N] == -1 - if opts[:file] == '-' + if opts[:file] == "-" file = STDIN else - file = File.new opts[:file], 'r' + file = File.new opts[:file], "r" end while line = file.gets input << line @@ -36,7 +36,6 @@ end sample = [] if !opts[:absolute] sample = index.sample(index.size*(opts[:size]/100.0)) - sample = index.sample(index.size*(opts[:size]/100.0)) else sample = index.sample(opts[:size]) end @@ -56,4 +55,3 @@ while idx = sample.shift end end end - |
