<commit_before>var hashOf = require('../utils/hashOf');

var requireSourceTarget = function(input)
{
	// must have source and target
	if(!(input.source && input.target))
		throw new Error(u.format("Type '%s' has %s structure and thus requires `source` and `target` fields.", input.type, input.structure));

	// if we have no id, generate one using hash of s,type,t
	return input.id || hashOf([input.source,input.type,input.target]);
};

var requireId = function(input)
{
	if(!input.id)
		throw new Error(u.format("Type '%s' has %s structure and requires the `id` field", input.type, input.structure));

	return input.id;
};

// we define how identifiers are created for each structure here
var ensureIdentifier = {
	node: requireId,
	arc: requireSourcTarget,
	equivalence: requireSourceTarget
};

module.exports = function(types) {

	// for faster error reporting
	var typeNames = Object.keys(types).join(' ');

	// and type to structure name lookup
	var structureNames = R.mapObj(R.compose(R.head, Object.keys), types)

	function prepareInput(input) {
		// everything starts with a type
		if(!input.type)
			throw new Error(u.format("Input has to have a type field"));

		// it has to be defined in the config
		if(!types[input.type])
			throw new Error(u.format('Unknown type "%s", must be one of: %s', input.type, typeNames));

		// set structure name
		o.structure = structureNames[input.type]<commit_msg>typos, requires<commit_after>var R = require('ramda');
var hashOf = require('./hashOf');

var requireSourceTarget = function(input)
{
	// must have source and target
	if(!(input.source && input.target))
		throw new Error(u.format("Type '%s' has %s structure and thus requires `source` and `target` fields.", input.type, input.structure));

	// if we have no id, generate one using hash of s,type,t
	return input.id || hashOf([input.source,input.type,input.target]);
};

var requireId = function(input)
{
	if(!input.id)
		throw new Error(u.format("Type '%s' has %s structure and requires the `id` field", input.type, input.structure));

	return input.id;
};

// we define how identifiers are created for each structure here
var ensureIdentifier = {
	node: requireId,
	arc: requireSourceTarget,
	equivalence: requireSourceTarget
};

module.exports = function(types) {

	// for faster error reporting
	var typeNames = Object.keys(types).join(' ');

	// and type to structure name lookup
	var structureNames = R.mapObj(R.compose(R.head, Object.keys), types)

	function prepareInput(input) {
		// everything starts with a type
		if(!input.type)
			throw new Error(u.format("Input has to have a type field"));

		// it has to be defined in the config
		if(!types[input.type])
			throw new Error(u.format('Unknown type "%s", must be one of: %s', input.type, typeNames));

		// set structure name
		o.structure = structureNames[input.type]
{'fraction_non_alphanumeric': 0.13485915492957745, 'fraction_numerical': 0.0, 'mean_word_length': 4.300373134328358, 'pattern_counts': {'":': 0, '<': 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': '1822085', 'n_tokens_mistral': 901, 'n_tokens_neox': 858, 'n_words': 291}