<commit_before>require 'rubygems'
require 'sinatra'
require 'json'

require File.expand_path(File.dirname(__FILE__) + "/../lib/ve")

get '/:language/:function' do
  run
end

post '/:language/:function' do
  run
end

private

def run
#  Ve.source = Ve::Local # Default
#  Ve.source = Ve::Remote.new(:url => 'http://ve.kimtaro.com/', :access_token => 'XYZ')
#  result = Ve.get(params[:text], params[:language], params[:function].to_sym)
  result = Ve.in(params[:language]).words(params[:text])

  case params[:function].to_sym
  when :words
    json = JSON.generate(result.collect(&:as_json))
  else
    json = result
  end

  if params[:callback]
    json = "#{params[:callback]}(#{result})"
  end

  json
end<commit_msg>Make JSONP work<commit_after>require 'rubygems'
require 'sinatra'
require 'json'

require File.expand_path(File.dirname(__FILE__) + "/../lib/ve")

get '/:language/:function' do
  run
end

post '/:language/:function' do
  run
end

private

def run
#  Ve.source = Ve::Local # Default
#  Ve.source = Ve::Remote.new(:url => 'http://ve.kimtaro.com/', :access_token => 'XYZ')
#  result = Ve.get(params[:text], params[:language], params[:function].to_sym)
  result = Ve.in(params[:language]).words(params[:text])

  case params[:function].to_sym
  when :words
    json = JSON.generate(result.collect(&:as_json))
  else
    json = result
  end

  if params[:callback]
    json = "#{params[:callback]}(#{json})"
  end

  json
end

{'fraction_non_alphanumeric': 0.17765440666204024, 'fraction_numerical': 0.0, 'mean_word_length': 4.262773722627737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6391578', 'n_tokens_mistral': 507, 'n_tokens_neox': 506, 'n_words': 107}