Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (74 sloc) 2.665 kB
# Copyright 2009 Kevin J. Menard Jr.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'rubygems'
require 'ai4r'
require 'memoize'
require 'repository'
require 'watcher'
require 'cache'
class DataLoader
def self.load_watchings
Cache.fetch('watchings') do
data_labels = ['user_id', 'repo_id']
data_items = []
IO.foreach(File.join(data_dir, 'data.txt')) do |line|
data_items << line.strip.split(':')
end
data_set = Ai4r::Data::DataSet.new(:data_labels => data_labels, :data_items => data_items)
data_set
end
end
def self.load_repositories
Cache.fetch('repositories') do
@@repositories ||= {}
return @@repositories unless @@repositories.empty?
relationships = {}
IO.foreach(File.join(data_dir, 'repos.txt')) do |line|
repo_id, repo_data = line.strip.split(':')
name, created_at, parent_id = repo_data.split(',')
# Add the repository to the result hash.
@@repositories[repo_id] = Repository.new(repo_id, name, created_at)
# Keep track of parent-child relationships.
relationships[repo_id] = parent_id unless parent_id.nil?
end
# Now that all the repositories have been loaded, establish any parent-child relationships.
relationships.each do |child_id, parent_id|
@@repositories[child_id].parent = @@repositories[parent_id]
end
# Load in the watchers.
watchers = {}
IO.foreach(File.join(data_dir, 'data.txt')) do |line|
user_id, repo_id = line.strip.split(':')
watcher = watchers[user_id] || Watcher.new(user_id)
watchers[user_id] = watcher
@@repositories[repo_id].watchers << watcher
end
@@repositories
end
end
def self.load_predictings
Cache.fetch('predictings') do
data_labels = ['user_id']
data_items = []
IO.foreach(File.join(data_dir, 'test.txt')) do |line|
data_items << [line.strip]
end
data_set = Ai4r::Data::DataSet.new(:data_labels => data_labels, :data_items => data_items)
data_set
end
end
def self.data_dir
@@data_dir ||= 'data'
end
end
Jump to Line
Something went wrong with that request. Please try again.