lib/rubyfca.rb in rubyfca-0.2.10 vs lib/rubyfca.rb in rubyfca-0.2.11
- old
+ new
@@ -1,15 +1,20 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
## lib/rubyfca.rb -- Formal Concept Analysis tool in Ruby
## Author:: Yoichiro Hasebe (mailto: yohasebe@gmail.com)
## Kow Kuroda (mailto: kuroda@nict.go.jp)
-## Copyright:: Copyright 2010 Yoichiro Hasebe and Kow Kuroda
+## Copyright:: Copyright 2009 Yoichiro Hasebe and Kow Kuroda
## License:: GNU GPL version 3
-# -*- coding: utf-8 -*-
+$: << File.dirname(__FILE__) + "/rubyfca"
require 'csv'
require 'ruby_graphviz'
+require 'version'
+require 'trollop'
private
## Take two arrays each consisting of 0s and 1s and create their logical disjunction
def create_and_ary(a, b)
@@ -43,10 +48,11 @@
## Converte cxt data to three basic structures of objects, attributes, and matrix
def initialize(input, mode, label_contraction = false)
if input.size == 0
showerror("File is empty", 1)
end
+ input.gsub!(" ", " ")
begin
case mode
when /cxt\z/
read_cxt(input)
when /csv\z/
@@ -83,13 +89,14 @@
end
end
def remove_blank(input)
blank_removed = ""
- input.each do |line|
- unless /^\s*$/ =~ line
- blank_removed << line
+ input.split("\n").each do |line|
+ line = line.strip
+ unless /\A\s*\z/ =~ line
+ blank_removed << line + "\n"
end
end
blank_removed
end
@@ -99,10 +106,10 @@
end
newary
end
## Apply a formal concept analysis on the matrix
- def calculate
+ def calcurate
@concepts, @extM, @intM = ganter_alg(@matrix)
@relM, @reltrans, @rank = create_rel(@intM)
@gammaM, @muM = gammaMu(@extM, @intM, @matrix)
end