<commit_before>#!/usr/bin/env python

"""Open Annotation adapter server."""

__author__ = '<NAME>'
__license__ = 'MIT'

import sys
import json

import flask

from render import render_resource

DEBUG = True

app = flask.Flask(__name__)

@app.route('/echo/', methods=['PUT', 'POST'])
@render_resource
def echo():
    """Echo back received data, possibly in a different representation."""
    # force for JSON-LD: application/ld+json is not recognized by
    # older Flask versions.
    data = flask.request.get_json(force=True)
    return { 'data': data }

def main(argv):
    app.run(debug=DEBUG)

if __name__ == '__main__':
    sys.exit(main(sys.argv))<commit_msg>expand request JSON-LD data<commit_after>#!/usr/bin/env python

"""Open Annotation adapter server."""

__author__ = '<NAME>'
__license__ = 'MIT'

import sys
import json

import flask

import oajson

from render import render_resource

DEBUG = True

app = flask.Flask(__name__)

def get_content_type(request):
    """Return Content-Type from Flask request."""
    return reques.mimetype

def get_json(request, abort_on_failure=True):
    """Return JSON from Flask request."""
    try:
        # force for JSON-LD: application/ld+json is not recognized by
        # older Flask versions.
        return flask.request.get_json(force=True)
    except Exception, e:
        if abort_on_failure:
            # TODO: attach a JSON structure describing the error.
            flask.abort(400, 'failed to load JSON (Content-Type: %s)' %
                        flask.request.mimetype)
        else:
            raise

@app.route('/echo/', methods=['PUT', 'POST'])
@render_resource
def echo():
    """Echo back received data, possibly in a different representation."""
    data = get_json(flask.request, True)
    # Output rendering functions expect expanded JSON-LD
    # TODO: provide a way for the client to assign base
    data = oajson.expand(data, base=flask.request.base_url)
    return { 'data': data }

def main(argv):
    app.run(debug=DEBUG)

if __name__ == '__main__':
    sys.exit(main(sys.argv))
{'fraction_non_alphanumeric': 0.12063953488372094, 'fraction_numerical': 0.0014534883720930232, 'mean_word_length': 3.4123931623931623, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4752353', 'n_tokens_mistral': 640, 'n_tokens_neox': 629, 'n_words': 191}