Skip to content

Instantly share code, notes, and snippets.

@moedusa
Created March 14, 2011 18:13
Show Gist options
  • Save moedusa/869573 to your computer and use it in GitHub Desktop.
Save moedusa/869573 to your computer and use it in GitHub Desktop.
hoatzin classifier
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