<commit_before>class DictController < ApplicationController
	before_action :default_params, :only => :index
	before_action :validate_params, :only => :index

	# GET /dict
	def index
		@query = {}
		@results = {}

		has_search = !params[:s].nil?
		if !has_search
			return
		end

		term = params[:s]
		iscript = params[:iscript] # TODO: transliterate if needed
		oscript = params[:oscript] # TODO: add transliteration if needed
		dicts = params[:dict]

		@query = {
			:term => term,
			:iscript => iscript,
			:oscript => oscript,
			:dicts => dicts,
		}

		begin
			dicts.each do |dict_handle|
				dict = Dictionary.find_by handle: dict_handle
				results = dict.matches(term)
				@results[dict] = results
			end
		rescue Dictionary::DBError => e
			flash[:error] = "Error during search: #{e.class} #{e.message}"
		end
	end

	# GET /dict/:id # <- FIXME update to a better path
	def show
	end

	def default_params
		if !params[:s]
			return
		end

		params[:iscript] ||= 'slp1'
		params[:oscript] ||= 'devanagari'
		params[:dict] ||= []
	end

	def validate_params
		# TODO: raise if problems detected
	end
end<commit_msg>Monier as the default dictionary<commit_after>class DictController < ApplicationController
	before_action :default_params, :only => :index
	before_action :validate_params, :only => :index

	# GET /dict
	def index
		@query = {}
		@results = {}

		has_search = !params[:s].nil?
		if !has_search
			return
		end

		term = params[:s]
		iscript = params[:iscript] # TODO: transliterate if needed
		oscript = params[:oscript] # TODO: add transliteration if needed
		dicts = params[:dict]

		@query = {
			:term => term,
			:iscript => iscript,
			:oscript => oscript,
			:dicts => dicts,
		}

		begin
			dicts.each do |dict_handle|
				dict = Dictionary.find_by handle: dict_handle
				results = dict.matches(term)
				@results[dict] = results
			end
		rescue Dictionary::DBError => e
			flash[:error] = "Error during search: #{e.class} #{e.message}"
		end
	end

	# GET /dict/:id # <- FIXME update to a better path
	def show
	end

	def default_params
		if !params[:s]
			return
		end

		params[:iscript] ||= 'slp1'
		params[:oscript] ||= 'devanagari'
		params[:dict] ||= ['mw'] # FIXME: use all dictionaries if no dict has been specified
	end

	def validate_params
		# TODO: raise if problems detected
	end
end
{'fraction_non_alphanumeric': 0.12559139784946236, 'fraction_numerical': 0.0008602150537634409, 'mean_word_length': 3.5252918287937742, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '649853', 'n_tokens_mistral': 903, 'n_tokens_neox': 789, 'n_words': 224}