<commit_before><html>
<head>
	<title>Build schemaData.js</title>
</head>
<body>
<p>This script builds schemaData.js, which contains Zotero schema information for the connector.</p>
<p id="result"></p>
<script src="../include.js"></script>
<script type="text/javascript">
	Zotero.Promise.coroutine(function* (){
		// Create schema
		var schema = {"itemTypes":{}, "creatorTypes":{}, "fields":{}};
		var types = Zotero.ItemTypes.getTypes();

		var fieldIDs = yield Zotero.DB.columnQueryAsync("SELECT fieldID FROM fieldsCombined");
	  var baseMappedFields = Zotero.ItemFields.getBaseMappedFields();
		
		for (let fieldID of fieldIDs) {
			var fieldObj = [/* name */Zotero.ItemFields.getName(fieldID)];
			try {
				fieldObj.push(/* localizedString */Zotero.getString("itemFields." + fieldObj.name));
			} catch(e) {
				fieldObj.push(/* name -> localizedString */fieldObj[0]);
			}
			fieldObj.push(/* isBaseField */ !baseMappedFields.includes(fieldID));
			schema.fields[fieldID] = fieldObj;
		}

		// names, localizedStrings, creatorTypes, and fields for each item type
		for (let type of types) {
			var fieldIDs = Zotero.ItemFields.getItemTypeFields(type.id);
			var baseFields = {};
			for (let fieldID in fieldIDs) {
				if (baseMappedFields.includes(fieldID)) {
					baseFields[fieldID] = Zotero.ItemFields.getBaseIDFromTypeAndField(type.id, fieldID);
				}
			}

			var icon = Zotero.ItemTypes.getImageSrc(type.name);
			icon = icon.substr(icon.lastIndexOf("/")+1);

			try {
				var creatorTypes = Zotero.CreatorTypes.getTypesForItemType(type.id).map((creatorType) => creatorType.id);
			} catch (e) {
				creatorTypes = [];
			}
			var primaryCreatorType = Zotero.CreatorTypes.getPrimaryIDForType(type.id);
			if(creatorTypes[0] != primaryCreatorType) {
				creatorTypes.splice(creatorTypes.indexOf(primaryCreatorType), 1);
				creatorTypes.unshift(primaryCreatorType);
			}

			schema.itemTypes[type.id] = [
							/* name */type.name,
							/* localizedString */Zotero.ItemTypes.getLocalizedString(type.name),
							/* creatorTypes */creatorTypes,
							/* fields */ fieldIDs,
							/* baseFields */baseFields,
							/* icon */icon
			];

		}

		var types = Zotero.CreatorTypes.getTypes();
		for (let type of types) {
			schema.creatorTypes[type.id] = [
							/* name */type.name,
							/* localizedString */Zotero.CreatorTypes.getLocalizedString(type.name)
			];
		}

		// Write to file
	  var nsIFilePicker = Components.interfaces.nsIFilePicker;
		var fp = Components.classes["@mozilla.org/filepicker;1"]
			.createInstance(nsIFilePicker);
		fp.init(window, Zotero.getString('dataDir.selectDir'), nsIFilePicker.modeGetFolder);
		
		let resultElem = document.getElementById('result');<commit_msg>Fix whitespace and description in build_typeSchemaData.html<commit_after><html>
<head>
	<title>Build schemaData.js</title>
</head>
<body>
<p>This script builds typeSchemaData.js, which contains Zotero schema information for the connector.</p>
<p id="result"></p>
<script src="../include.js"></script>
<script type="text/javascript">
	Zotero.Promise.coroutine(function* (){
		// Create schema
		var schema = {"itemTypes":{}, "creatorTypes":{}, "fields":{}};
		var types = Zotero.ItemTypes.getTypes();

		var fieldIDs = yield Zotero.DB.columnQueryAsync("SELECT fieldID FROM fieldsCombined");
		var baseMappedFields = Zotero.ItemFields.getBaseMappedFields();
		
		for (let fieldID of fieldIDs) {
			var fieldObj = [/* name */Zotero.ItemFields.getName(fieldID)];
			try {
				fieldObj.push(/* localizedString */Zotero.getString("itemFields." + fieldObj.name));
			} catch(e) {
				fieldObj.push(/* name -> localizedString */fieldObj[0]);
			}
			fieldObj.push(/* isBaseField */ !baseMappedFields.includes(fieldID));
			schema.fields[fieldID] = fieldObj;
		}

		// names, localizedStrings, creatorTypes, and fields for each item type
		for (let type of types) {
			var fieldIDs = Zotero.ItemFields.getItemTypeFields(type.id);
			var baseFields = {};
			for (let fieldID in fieldIDs) {
				if (baseMappedFields.includes(fieldID)) {
					baseFields[fieldID] = Zotero.ItemFields.getBaseIDFromTypeAndField(type.id, fieldID);
				}
			}

			var icon = Zotero.ItemTypes.getImageSrc(type.name);
			icon = icon.substr(icon.lastIndexOf("/")+1);

			try {
				var creatorTypes = Zotero.CreatorTypes.getTypesForItemType(type.id).map((creatorType) => creatorType.id);
			} catch (e) {
				creatorTypes = [];
			}
			var primaryCreatorType = Zotero.CreatorTypes.getPrimaryIDForType(type.id);
			if(creatorTypes[0] != primaryCreatorType) {
				creatorTypes.splice(creatorTypes.indexOf(primaryCreatorType), 1);
				creatorTypes.unshift(primaryCreatorType);
			}

			schema.itemTypes[type.id] = [
							/* name */type.name,
							/* localizedString */Zotero.ItemTypes.getLocalizedString(type.name),
							/* creatorTypes */creatorTypes,
							/* fields */ fieldIDs,
							/* baseFields */baseFields,
							/* icon */icon
			];

		}

		var types = Zotero.CreatorTypes.getTypes();
		for (let type of types) {
			schema.creatorTypes[type.id] = [
							/* name */type.name,
							/* localizedString */Zotero.CreatorTypes.getLocalizedString(type.name)
			];
		}

		// Write to file
		var nsIFilePicker = Components.interfaces.nsIFilePicker;
		var fp = Components.classes["@mozilla.org/filepicker;1"]
			.createInstance(nsIFilePicker);
		fp.init(window, Zotero.getString('dataDir.selectDir'), nsIFilePicker.modeGetFolder);
		
		let resultElem = document.getElementById('result');
{'fraction_non_alphanumeric': 0.14528508771929824, 'fraction_numerical': 0.001827485380116959, 'mean_word_length': 3.935076645626691, 'pattern_counts': {'":': 6, '<': 29, '<?xml version=': 0, '>': 33, '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': '5522162', 'n_tokens_mistral': 2098, 'n_tokens_neox': 1773, 'n_words': 326}