<commit_before>#!/usr/bin/python
# -*- coding: UTF-8 -*-

import lltk
import lltk.generic
import lltk.caching
import lltk.exceptions

from flask import Flask
from flask import jsonify, request

__author__ = '<NAME>'
__author_email__ = '<EMAIL>'
__version__ = '0.1.0'

DEBUG = True
CACHING = True
NAME = 'lltk-restful'
HOST = '127.0.0.1'
PORT = 5000

app = Flask(NAME)

if DEBUG:
	app.debug = True
	lltk.config['debug'] = True
if not CACHING:
	lltk.caching.disable()

@app.route('/lltk/<string:language>/<string:method>/<string:word>', methods = ['GET'])
@app.route('/lltk/<string:language>/<string:method>/<path:extraargs>/<string:word>', methods = ['GET'])
def lltkapi(language, method, word, extraargs = tuple()):
	''' Returns LLTK's results as a JSON document. '''

	data = dict()
	data['language'] = language
	data['method'] = method
	data['word'] = word
	data['result'] = None

	if hasattr(lltk.generic, method) and callable(getattr(lltk.generic, method)):
		function = getattr(lltk.generic, method)
		if not isinstance(extraargs, tuple):
			extraargs = tuple(extraargs.split('/'))
		kwargs = request.args.to_dict()
		data['result'] = function(language, word, *extraargs, **kwargs)
	else:
		return http_404(NotImplementedError)

	return jsonify(data)

if __name__ == '__main__':

	app.run(
		host = HOST,
		port = PORT
	)
<commit_msg>Add info() route<commit_after>#!/usr/bin/python
# -*- coding: UTF-8 -*-

import lltk
import lltk.generic
import lltk.caching
import lltk.exceptions

from flask import Flask
from flask import jsonify, request

__author__ = '<NAME>'
__author_email__ = '<EMAIL>'
__version__ = '0.1.0'

DEBUG = True
CACHING = True
NAME = 'lltk-restful'
HOST = '127.0.0.1'
PORT = 5000

app = Flask(NAME)

if DEBUG:
	app.debug = True
	lltk.config['debug'] = True
if not CACHING:
	lltk.caching.disable()

@app.route('/lltk/<string:language>/<string:method>/<string:word>', methods = ['GET'])
@app.route('/lltk/<string:language>/<string:method>/<path:extraargs>/<string:word>', methods = ['GET'])
def lltkapi(language, method, word, extraargs = tuple()):
	''' Returns LLTK's results as a JSON document. '''

	data = dict()
	data['language'] = language
	data['method'] = method
	data['word'] = word
	data['result'] = None

	if hasattr(lltk.generic, method) and callable(getattr(lltk.generic, method)):
		function = getattr(lltk.generic, method)
		if not isinstance(extraargs, tuple):
			extraargs = tuple(extraargs.split('/'))
		kwargs = request.args.to_dict()
		data['result'] = function(language, word, *extraargs, **kwargs)
	else:
		return http_404(NotImplementedError)

	return jsonify(data)

@app.route('/lltk/info', methods = ['GET'])
def info():

	data = dict()
	data['server'] = 'Language Learning Toolkit ResRESTful API'
	data['version'] = __version__
	data['lltk-version'] = lltk.config['version']
	return jsonify(data)

if __name__ == '__main__':

	app.run(
		host = HOST,
		port = PORT
	)

{'fraction_non_alphanumeric': 0.16912521440823328, 'fraction_numerical': 0.011663807890222984, 'mean_word_length': 4.890909090909091, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '193922', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1043, 'n_words': 245}