bin/rubyfca in rubyfca-0.2.2 vs bin/rubyfca in rubyfca-0.2.4
- old
+ new
@@ -1,44 +1,38 @@
#!/usr/bin/env ruby
-# -*- coding: utf-8 -*-
-Encoding.default_external = "UTF-8"
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
+require 'trollop'
require 'rubyfca'
+require 'ruby_graphviz'
################ parse options ##########
opts = Trollop::options do
- version RubyFCA::VERSION
+ version = File.read(File.dirname(__FILE__) + "/../VERSION")
banner <<-EOS
RubuFCA converts Conexp CXT data to Graphviz dot format.
Usage:
rubyfca [options] <source file> <output file>
where:
<source file>
- ".cxt", ".csv"
+ ".cxt"
<output file>
."dot", ".png", ".jpg", or ".eps"
[options]:
EOS
+ opt :circle, "Use circle shaped concept nodes", :default=> false
opt :full, "Do not contract concept labels", :default=> false
- opt :coloring, "Color concept nodes [0 = none (default), 1 = lightblue/pink, 2 = monochrome]", :default => 0
- opt :straight, "Straighten edges (available when output format is either png, jpg, svg, pdf, or eps)", :default => false
- opt :nodesep, "Size of separation between sister nodes (from 0.1 to 5.0)", :default => 0.4
- opt :ranksep, "Size of separation between ranks (from 0.1 to 5.0)", :default => 0.2
opt :legend, "Print the legend of concept nodes (available only when using circle node shape)", :default => false
- opt :circle, "Use circle shaped concept nodes", :default=> false
-
+ opt :coloring, "Color concept nodes", :default => false
+ opt :straight, "Straighten edges (available when output format is either png, jpg, or eps)", :default => false
end
-Trollop::die :coloring, "must be 0, 1, or 2" if (opts[:coloring] > 2 || opts[:coloring] < 0)
-Trollop::die :ranksep, "must be within 0.1 - 5.0" if (opts[:ranksep] < 0.1 || opts[:ranksep] > 5.0)
-Trollop::die :nodesep, "must be within 0.1 - 5.0" if (opts[:nodesep] < 0.1 || opts[:nodesep] > 5.0)
+
############### main program ###############
if ARGV.size != 2
showerror("Input and output files are not set properly", 1)
end
@@ -50,21 +44,19 @@
# extract input and output file types
#
input_type = filename1.slice(/\.[^\.]+\z/).split(//)[1..-1].join("")
output_type = filename2.slice(/\.[^\.]+\z/).split(//)[1..-1].join("")
-if (input_type !~ /\A(cxt|csv)\z/ || output_type !~ /\A(dot|png|jpg|svg|pdf|eps)\z/)
+if (input_type !~ /\A(cxt|csv)\z/ || output_type !~ /\A(dot|png|jpg|eps)\z/)
showerror("These file extensions are not (yet) supported.", 1)
end
#
-# input data is kept as plain text
+# input cxt data is kept as plain text
#
-f = File.open(filename1, "r:UTF-8:UTF-8")
-
+f = File.open(filename1, "r")
inputdata = f.read
-inputdata.gsub!(/\r\n?/){"\n"}
f.close
#
# ask for confirmation of overwriting an exisiting file
#
@@ -78,11 +70,11 @@
#
# context data is converted to a hash table
#
begin
- ctxt = FormalContext.new(inputdata, input_type, !opts[:full])
+ ctxt = FormalContext.new(inputdata, opts[:full])
ctxt.calcurate
# rescue => e
# puts e
# showerror("Source data may have problems. Process aborted.", 1)
end
@@ -97,12 +89,8 @@
end
when "png"
ctxt.generate_img(filename2, "png", opts)
when "jpg"
ctxt.generate_img(filename2, "jpg", opts)
-when "svg"
- ctxt.generate_img(filename2, "svg", opts)
-when "pdf"
- ctxt.generate_img(filename2, "pdf", opts)
when "eps"
ctxt.generate_img(filename2, "eps", opts)
end