<commit_before>package org.datacite.conres.view;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.datacite.conres.model.Model;
import org.datacite.conres.model.Pair;

public class CslJsonRepresentation {
    public static JSONObject writeJSON(Model mr) {
        try {
            JSONArray authors = new JSONArray();
            for (String  p : mr.getCreators()) {
                authors.put(new JSONObject().put("literal", p));
            }

            JSONObject issued = new JSONObject();
            Integer year = Integer.valueOf(mr.getPublicationYear());
            issued.put("date-parts", new JSONArray().put(new JSONArray().put(year)));

            String type = "misc";
            for (Pair p : mr.getResourceTypes()){
                if (p.getKey().toUpperCase().equals("DATASET")){
                    type = "dataset";
                    break;
                }
            }

            return new JSONObject()
                .put("type", type)
                .put("DOI", mr.getDoi())
                .put("URL", "https://doi.org/" + mr.getDoi())
                .put("title", mr.getTitles().get(0).getValue())
                .put("publisher", mr.getPublisher())
                .put("issued", issued)
                .put("author", authors);
        } catch (JSONException je) {
            return null;
        }<commit_msg>correctly format personal names in citeproc JSON. Closes #28<commit_after>package org.datacite.conres.view;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.datacite.conres.model.Model;
import org.datacite.conres.model.Pair;

import java.util.List;
import java.util.Arrays;

public class CslJsonRepresentation {
    public static JSONObject writeJSON(Model mr) {
        try {
            JSONArray authors = new JSONArray();
            for (String  p : mr.getCreators()) {
                if (p.contains(",")) {
                    List<String> pList = Arrays.asList(p.split(", ", 2));
                    authors.put(new JSONObject()
                        .put("family", pList.get(0))
                        .put("given", pList.get(1)));
                } else {
                    authors.put(new JSONObject().put("literal", p));
                }
            }

            JSONObject issued = new JSONObject();
            Integer year = Integer.valueOf(mr.getPublicationYear());
            issued.put("date-parts", new JSONArray().put(new JSONArray().put(year)));

            String type = "misc";
            for (Pair p : mr.getResourceTypes()) {
                if (p.getKey().toUpperCase().equals("DATASET")) {
                    type = "dataset";
                    break;
                }
            }

            return new JSONObject()
                .put("type", type)
                .put("DOI", mr.getDoi())
                .put("URL", "https://doi.org/" + mr.getDoi())
                .put("title", mr.getTitles().get(0).getValue())
                .put("publisher", mr.getPublisher())
                .put("issued", issued)
                .put("author", authors);
        } catch (JSONException je) {
            return null;
        }
{'fraction_non_alphanumeric': 0.13762019230769232, 'fraction_numerical': 0.0021033653846153845, 'mean_word_length': 1.7376644736842106, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '257808', 'n_tokens_mistral': 968, 'n_tokens_neox': 923, 'n_words': 181}