<commit_before>/*
 * Copyright 2014 hbz NRW (http://www.hbz-nrw.de/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package helper;

import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import models.DataciteRecord;
import models.Globals;
import models.Pair;

/**
 * @author <NAME>
 *
 */
@SuppressWarnings("unchecked")
public class DataciteMapper {

	private static final String TYPE_VIDEO =
			"http://rdaregistry.info/termList/RDAMediaType/1008";
	private static final String TYPE_MISC =
			"http://purl.org/lobid/lv#Miscellaneous";

	/**
	 * @param doi the doi identifier
	 * @param ld the object as json-ld linked data in a map
	 * @return an object containing data for datacite
	 */
	public static DataciteRecord getDataciteRecord(String doi,
			Map<String, Object> map) {
		JsonNode ld = new ObjectMapper().convertValue(map, JsonNode.class);
		DataciteRecord rec = new DataciteRecord(doi);
		addSubjects(ld, rec);
		addCreators(ld, rec);
		addTitles(ld, rec);
		addPublisher(ld, rec);
		addPublicationYear(ld, rec);
		addLanguage(ld, rec);
		addDates(ld, rec);
		addAlternativeIdentifiers(ld, rec);
		addSizes(ld, rec);// http://purl.org/dc/terms/bibliographicCitation
		addFormats(ld, rec);// mime
		addResourceTypeGeneral(ld, rec);// bibliographic resource
		addResourceType(ld, rec);
		return rec;
	}

	private static void addResourceType(JsonNode ld, DataciteRecord rec) {
		rec.type = ld.at("/rdftype/0/prefLabel").asText();
		if ("Abschlussarbeit".equals(rec.type)) {
			rec.type = "Hochschulschrift";
		} else if ("Statistics".equals(rec.type)) {
			rec.type = "Statistik";
		} else if ("Leitlinien / Normschriften".equals(rec.type)) {
			rec.type = "Leitlinie";
		}
	}

	private static void addResourceTypeGeneral(JsonNode ld, DataciteRecord rec) {
		rec.typeGeneral = ld.at("/rdftype/0/@id").asText();
		play.Logger.debug(ld.asText());
		if (TYPE_VIDEO.equals(rec.typeGeneral)) {
			rec.typeGeneral = "AudioVisual";
		}
		if (TYPE_MISC.equals(rec.typeGeneral)) {
			rec.typeGeneral = "Other";
		} else {<commit_msg>fix: Audiovisual is not set correctly<commit_after>/*
 * Copyright 2014 hbz NRW (http://www.hbz-nrw.de/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package helper;

import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import models.DataciteRecord;
import models.Globals;
import models.Pair;

/**
 * @author <NAME>
 *
 */
@SuppressWarnings("unchecked")
public class DataciteMapper {

	private static final String TYPE_VIDEO =
			"http://rdaregistry.info/termList/RDAMediaType/1008";
	private static final String TYPE_MISC =
			"http://purl.org/lobid/lv#Miscellaneous";

	/**
	 * @param doi the doi identifier
	 * @param ld the object as json-ld linked data in a map
	 * @return an object containing data for datacite
	 */
	public static DataciteRecord getDataciteRecord(String doi,
			Map<String, Object> map) {
		JsonNode ld = new ObjectMapper().convertValue(map, JsonNode.class);
		DataciteRecord rec = new DataciteRecord(doi);
		addSubjects(ld, rec);
		addCreators(ld, rec);
		addTitles(ld, rec);
		addPublisher(ld, rec);
		addPublicationYear(ld, rec);
		addLanguage(ld, rec);
		addDates(ld, rec);
		addAlternativeIdentifiers(ld, rec);
		addSizes(ld, rec);// http://purl.org/dc/terms/bibliographicCitation
		addFormats(ld, rec);// mime
		addResourceTypeGeneral(ld, rec);// bibliographic resource
		addResourceType(ld, rec);
		return rec;
	}

	private static void addResourceType(JsonNode ld, DataciteRecord rec) {
		rec.type = ld.at("/rdftype/0/prefLabel").asText();
		if ("Abschlussarbeit".equals(rec.type)) {
			rec.type = "Hochschulschrift";
		} else if ("Statistics".equals(rec.type)) {
			rec.type = "Statistik";
		} else if ("Leitlinien / Normschriften".equals(rec.type)) {
			rec.type = "Leitlinie";
		}
	}

	private static void addResourceTypeGeneral(JsonNode ld, DataciteRecord rec) {
		rec.typeGeneral = ld.at("/rdftype/0/@id").asText();
		play.Logger.debug(ld.asText());
		if (TYPE_VIDEO.equals(rec.typeGeneral)) {
			rec.typeGeneral = "AudioVisual";
		} else if (TYPE_MISC.equals(rec.typeGeneral)) {
			rec.typeGeneral = "Other";
		} else {
{'fraction_non_alphanumeric': 0.12365082370763113, 'fraction_numerical': 0.005302026131414505, 'mean_word_length': 4.214215202369201, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, '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': '6620751', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1710, 'n_words': 464}