<commit_before>module Classification
  class Server < Sinatra::Base

    TOTAL = '__TOTAL__'
    TOTAL_TABLE = ['classification', ENV['RACK_ENV'], TOTAL].join('.')

    configure :development, :test do
      enable :dump_error
    end

    enable :logging

    use Rack::Auth::Basic do |username, password|
      password == '<PASSWORD>'
    end

    # get a list of categories
    get('/categories') do
      data = ddb.list_tables.body['TableNames']
      status(200)
      body(data.to_json)
    end

    # categorize a set of tokens
    post('/categories') do
      tokens = JSON.parse(request.body.read)

      categories_data = ddb2.get_items(TOTAL_TABLE, [TOTAL])

      categories = categories_data.first['categories']['SS']

      probabilities = {}
      categories.each do |category|
        probabilities[category] = get_probability(category, tokens)
      end

      status(200)<commit_msg>properly limit categories list per user<commit_after>module Classification
  class Server < Sinatra::Base

    TOTAL = '__TOTAL__'
    TOTAL_TABLE = ['classification', ENV['RACK_ENV'], TOTAL].join('.')

    configure :development, :test do
      enable :dump_error
    end

    enable :logging

    use Rack::Auth::Basic do |username, password|
      password == '<PASSWORD>'
    end

    # get a list of categories
    get('/categories') do
      categories_data = ddb2.get_items(TOTAL_TABLE, [TOTAL])
      categories = categories_data.first['categories']['SS']
      status(200)
      body(categories.to_json)
    end

    # categorize a set of tokens
    post('/categories') do
      tokens = JSON.parse(request.body.read)

      categories_data = ddb2.get_items(TOTAL_TABLE, [TOTAL])
      categories = categories_data.first['categories']['SS']

      probabilities = {}
      categories.each do |category|
        probabilities[category] = get_probability(category, tokens)
      end

      status(200)
{'fraction_non_alphanumeric': 0.1151229722658294, 'fraction_numerical': 0.007849293563579277, 'mean_word_length': 3.059447983014862, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2985319', 'n_tokens_mistral': 600, 'n_tokens_neox': 552, 'n_words': 133}