<commit_before>package whelk.api

import groovy.util.logging.Slf4j as Log

import javax.servlet.http.*

import whelk.util.Tools

import whelk.*
import whelk.component.*
import whelk.exception.*
import whelk.plugin.*

import se.kb.libris.utils.isbn.*

@Log
class FormatterAPI extends BasicAPI {

    String description = "API to transform between formats the whelk is capable of handling."
    void doHandle(HttpServletRequest request, HttpServletResponse response, List pathVars) {
        if (request.method == "POST") {
            String requestedContentType = request.getParameter("to")
            if (request.getContentLength() == 0) {
                log.warn("[${this.id}] Received no content to reformat.")
                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No content received.")
            } else {
                Document doc = new Document().withData(Tools.normalizeString(request.getInputStream().getText("UTF-8"))).withEntry(["contentType":request.contentType, "timestamp": new Date().getTime()])<commit_msg>cut everything after ; in contentType<commit_after>package whelk.api

import groovy.util.logging.Slf4j as Log

import javax.servlet.http.*

import whelk.util.Tools

import whelk.*
import whelk.component.*
import whelk.exception.*
import whelk.plugin.*

import se.kb.libris.utils.isbn.*

@Log
class FormatterAPI extends BasicAPI {

    String description = "API to transform between formats the whelk is capable of handling."
    void doHandle(HttpServletRequest request, HttpServletResponse response, List pathVars) {
        if (request.method == "POST") {
            String requestedContentType = request.getParameter("to")
            if (request.getContentLength() == 0) {
                log.warn("[${this.id}] Received no content to reformat.")
                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No content received.")
            } else {
                String ctype = (request.contentType.contains(";") ? request.contentType.substring(0,request.contentType.indexOf(";")) : request.contentType)
                Document doc = new Document().withData(Tools.normalizeString(request.getInputStream().getText("UTF-8"))).withEntry(["contentType":ctype, "timestamp": new Date().getTime()])
{'fraction_non_alphanumeric': 0.11819389110225764, 'fraction_numerical': 0.003098716246126605, 'mean_word_length': 3.5934959349593494, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '133050', 'n_tokens_mistral': 629, 'n_tokens_neox': 608, 'n_words': 152}