Created
March 14, 2011 18:13
-
-
Save moedusa/869573 to your computer and use it in GitHub Desktop.
hoatzin classifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Classifier | |
DB_PATHS = { | |
:metadata => "#{Rails.root}/db/hoatzin/metadata", | |
:model => "#{Rails.root}/db/hoatzin/model" | |
} | |
class << self | |
def classify(input) | |
classifier = Hoatzin::Classifier.new(DB_PATHS) | |
classifier.classify(input) | |
end | |
def train(category, input) | |
prepare_db_files | |
hoatzin = Hoatzin::Classifier.new | |
if input.is_a? Array | |
input.each do |input_str| | |
hoatzin.train(category, input_str) | |
end | |
else | |
hoatzin.train(category, input) | |
end | |
hoatzin.sync | |
hoatzin.save( DB_PATHS.merge({:update => true}) ) | |
end | |
private | |
def prepare_db_files | |
DB_PATHS.each_value do |val| | |
FileUtils.touch(val) unless File.file?(val) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment