<commit_before>require 'sequel'
require 'classifier/bayes'

module KaratSleuth::Storage
	
	# Get an instance of the SQLite sequel object
	def self.db
		@db ||= Sequel.connect 'sqlite://karat-sleuth.db'
	end

	# Module to add support to the Bayes classifier for persisting the
	# classifications.
	#
	# This will store classifications into the sequel database
	module Bayes

		# Save the current Bayesian categories into the KaratSleuth sequel
		# database
		def persist
			db = KaratSleuth::Storage.db

			# Ensure the classifications table exists. This will only create the
			# table if it doesn't already exist
			db.create_table? :classifications do
				primary_key :id

				String  :category
				String  :word
				Integer :tally
			end

			classes = db[:classifications]

			@categories.each do |category, words|
				words.each do |word, tally|
					classes.insert :category => category.to_s, :word => word.to_s, :tally => tally
				end
			end

			true
		end

		# Load the classifications back in from the KaratSleuth sequel database
		def reload!

		end
	end

	# Patch in the persistence methods to the Bayes Classifier
	Classifier::Bayes.send(:include, Bayes)
end<commit_msg>Prepend Bayes storage module<commit_after>require 'sequel'
require 'classifier/bayes'

module KaratSleuth::Storage
	
	# Get an instance of the SQLite sequel object
	def self.db
		@db ||= Sequel.connect 'sqlite://karat-sleuth.db'
	end

	# Module to add support to the Bayes classifier for persisting the
	# classifications.
	#
	# This will store classifications into the sequel database
	module Bayes

		# Save the current Bayesian categories into the KaratSleuth sequel
		# database
		def persist
			db = KaratSleuth::Storage.db

			# Ensure the classifications table exists. This will only create the
			# table if it doesn't already exist
			db.create_table? :classifications do
				primary_key :id

				String  :category
				String  :word
				Integer :tally
			end

			classes = db[:classifications]

			@categories.each do |category, words|
				words.each do |word, tally|
					classes.insert :category => category.to_s, :word => word.to_s, :tally => tally
				end
			end

			true
		end

		# Load the classifications back in from the KaratSleuth sequel database
		def reload!

		end
	end

	# Patch in the persistence methods to the Bayes Classifier
	Classifier::Bayes.send(:prepend, Bayes)
end
{'fraction_non_alphanumeric': 0.06977721731820093, 'fraction_numerical': 0.0, 'mean_word_length': 3.507575757575758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1047231', 'n_tokens_mistral': 859, 'n_tokens_neox': 704, 'n_words': 264}