<commit_before>require 'expcalc'

class Net_parser
	def self.load(options)
		net = nil
		if options[:input_format] == 'pair'
		  net = load_network_by_pairs(options[:input_file], options[:layers], options[:split_char])
		elsif options[:input_format] == 'bin'
		  net = load_network_by_bin_matrix(options[:input_file], options[:node_file], options[:layers])
		elsif options[:input_format] == 'matrix'
		  net = load_network_by_plain_matrix(options[:input_file], options[:node_file], options[:layers], options[:splitChar])
		else
		  raise("ERROR: The format #{options[:input_format]} is not defined")
		end
		return net
	end

	def self.load_network_by_pairs(file, layers, split_character="\t")
		net = Network.new(layers.map{|layer| layer.first})
		File.open(file).each do |line|
			line.chomp!
			pair = line.split(split_character)
			node1 = pair[0]
			node2 = pair[1]
			net.add_node(node1, net.set_layer(layers, node1))
			net.add_node(node2, net.set_layer(layers, node2))
			net.add_edge(node1, node2)	
		end
		return net
	end

	def self.load_network_by_bin_matrix(net, input_file, node_file, layers)
		net = Network.new(layers.map{|layer| layer.first})
		node_names = load_input_list(node_file)
		net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='npy'), node_names, node_names]
		return net
	end

	def self.load_network_by_plain_matrix(input_file, node_file, layers, splitChar="\t")
		net = Network.new(layers.map{|layer| layer.first})
		node_names = load_input_list(node_file)
		net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='txt', splitChar=splitChar), node_names, node_names]
		return net
	end

	private
	def load_input_list(file)
		return File.open(file).readlines.map!{|line| line.chomp}
	end
end<commit_msg>fixing error in load bin matrix method<commit_after>require 'expcalc'

class Net_parser
	def self.load(options)
		net = nil
		if options[:input_format] == 'pair'
		  net = load_network_by_pairs(options[:input_file], options[:layers], options[:split_char])
		elsif options[:input_format] == 'bin'
		  net = load_network_by_bin_matrix(options[:input_file], options[:node_file], options[:layers])
		elsif options[:input_format] == 'matrix'
		  net = load_network_by_plain_matrix(options[:input_file], options[:node_file], options[:layers], options[:splitChar])
		else
		  raise("ERROR: The format #{options[:input_format]} is not defined")
		end
		return net
	end

	def self.load_network_by_pairs(file, layers, split_character="\t")
		net = Network.new(layers.map{|layer| layer.first})
		File.open(file).each do |line|
			line.chomp!
			pair = line.split(split_character)
			node1 = pair[0]
			node2 = pair[1]
			net.add_node(node1, net.set_layer(layers, node1))
			net.add_node(node2, net.set_layer(layers, node2))
			net.add_edge(node1, node2)	
		end
		return net
	end

	def self.load_network_by_bin_matrix(input_file, node_file, layers)
		net = Network.new(layers.map{|layer| layer.first})
		node_names = load_input_list(node_file)
		net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='npy'), node_names, node_names]
		return net
	end

	def self.load_network_by_plain_matrix(input_file, node_file, layers, splitChar="\t")
		net = Network.new(layers.map{|layer| layer.first})
		node_names = load_input_list(node_file)
		net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='txt', splitChar=splitChar), node_names, node_names]
		return net
	end

	private
	def load_input_list(file)
		return File.open(file).readlines.map!{|line| line.chomp}
	end
end
{'fraction_non_alphanumeric': 0.13656509695290858, 'fraction_numerical': 0.00554016620498615, 'mean_word_length': 5.762172284644195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4013583', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1289, 'n_words': 240}