rubyfca 0.2.5.1 → 0.2.6

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.
@@ -19,7 +19,7 @@ Install the gem:
19
19
 
20
20
  where:
21
21
  <source file>
22
- "foo.cxt"
22
+ "foo.cxt", "foo.csv"
23
23
  <output file>
24
24
  "bar.dot", "bar.png", "bar.jpg", or "bar.eps"
25
25
  [options]:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5.1
1
+ 0.2.6
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
5
  require 'trollop'
@@ -18,7 +19,7 @@ Usage:
18
19
 
19
20
  where:
20
21
  <source file>
21
- ".cxt"
22
+ ".cxt", ".csv"
22
23
  <output file>
23
24
  ."dot", ".png", ".jpg", or ".eps"
24
25
  [options]:
@@ -51,7 +52,7 @@ if (input_type !~ /\A(cxt|csv)\z/ || output_type !~ /\A(dot|png|jpg|eps)\z/)
51
52
  end
52
53
 
53
54
  #
54
- # input cxt data is kept as plain text
55
+ # input data is kept as plain text
55
56
  #
56
57
  f = File.open(filename1, "r")
57
58
  inputdata = f.read
@@ -72,7 +73,7 @@ end
72
73
  # context data is converted to a hash table
73
74
  #
74
75
  begin
75
- ctxt = FormalContext.new(inputdata, !opts[:full])
76
+ ctxt = FormalContext.new(inputdata, input_type, !opts[:full])
76
77
  ctxt.calcurate
77
78
  # rescue => e
78
79
  # puts e
@@ -4,7 +4,9 @@
4
4
  ## Copyright:: Copyright 2009 Yoichiro Hasebe and Kow Kuroda
5
5
  ## License:: GNU GPL version 3
6
6
 
7
- $KCODE ='utf-8'
7
+ # -*- coding: utf-8 -*-
8
+
9
+ require 'csv'
8
10
  require 'ruby_graphviz'
9
11
 
10
12
  private
@@ -39,22 +41,63 @@ end
39
41
  class FormalContext
40
42
 
41
43
  ## Converte cxt data to three basic structures of objects, attributes, and matrix
42
- def initialize(input, label_contraction = false)
44
+ def initialize(input, mode, label_contraction = false)
43
45
  if input.size == 0
44
46
  showerror("File is empty", 1)
45
47
  end
48
+ begin
49
+ case mode
50
+ when /cxt\z/
51
+ read_cxt(input)
52
+ when /csv\z/
53
+ read_csv(input)
54
+ end
55
+ rescue => e
56
+ showerror("Input data contains a syntax problem.", 1)
57
+ end
58
+ @label_contraction = label_contraction
59
+ end
60
+
61
+ ## process cxt data
62
+ def read_cxt(input)
46
63
  lines = input.split
47
64
  t1 = 3
48
65
  if (lines[0] !~ /B/i || (2 * lines[1].to_i + lines[2].to_i + t1) != lines.size)
49
66
  showerror("Wrong cxt format!", 1)
50
67
  end
51
-
52
- @label_contraction = label_contraction
53
-
54
68
  @objects = lines[t1..(lines[1].to_i + t1 - 1)]
55
69
  @attributes = lines[(lines[1].to_i + t1) .. (lines[1].to_i + lines[2].to_i + t1 - 1)]
56
70
  lines = lines[(lines[1].to_i + lines[2].to_i + t1) .. lines.size]
57
- @matrix = changecrosssymbol("X", "\\.", lines)
71
+ @matrix = changecrosssymbol("X", "\\.", lines)
72
+ end
73
+
74
+ # process csv data using the standard csv library
75
+ def read_csv(input)
76
+ input = remove_blank(input)
77
+ data = CSV.parse(input)
78
+ @objects = trim_ary(data.transpose.first[1..-1])
79
+ @attributes = trim_ary(data.first[1..-1])
80
+ @matrix = []
81
+ data[1..-1].each do |line|
82
+ @matrix << line[1..-1].collect { |cell| /x/i =~ cell ? 1 : 0 }
83
+ end
84
+ end
85
+
86
+ def remove_blank(input)
87
+ blank_removed = ""
88
+ input.each do |line|
89
+ unless /^\s*$/ =~ line
90
+ blank_removed << line
91
+ end
92
+ end
93
+ blank_removed
94
+ end
95
+
96
+ def trim_ary(ary)
97
+ newary = ary.collect do |cell|
98
+ cell.strip
99
+ end
100
+ newary
58
101
  end
59
102
 
60
103
  ## Apply a formal concept analysis on the matrix
@@ -345,7 +388,7 @@ class FormalContext
345
388
  "<tr><td balign=\"left\" align=\"left\" bgcolor=\"#{obj_color}\">#{obj_str}</td></tr>" +
346
389
  "</table>>"
347
390
 
348
- if !attrfull.empty? and !objfull.empty?
391
+ if !attrfull.empty? or !objfull.empty?
349
392
  legend.node("cl#{concept_id}k", :label => concept_id, :style => "invis")
350
393
  legend.node("cl#{concept_id}v", :label => leg, :fillcolor => "white")
351
394
  legend.rank("cl#{concept_id}k", "cl#{concept_id}v", :style => "invis", :length => "0.0")
@@ -5,8 +5,8 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubyfca}
8
- s.version = "0.2.5.1"
9
- s.required_ruby_version = ">=1.8.7"
8
+ s.version = "0.2.6"
9
+ s.required_ruby_version = ">=1.8.6"
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoichiro Hasebe", "Kow Kuroda"]
12
12
  s.date = %q{2009-09-14}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyfca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5.1
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichiro Hasebe
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 1.8.7
63
+ version: 1.8.6
64
64
  version:
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements: