CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
missing.js67 linesDownload Raw Back to test
1import { emojiComponents } from "../data.js";2import { getUnqualifiedEmojiSequence } from "../cleanup.js";3import { getEmojiSequenceKeyword } from "../format.js";4import { replaceEmojiComponentsInCombinedSequence } from "./components.js";5/**6* Find missing emojis7*8* Result includes missing items, which are extended from items that needs to9* be copied. To identify which emojis to copy, source object should include10* something like `iconName` key that points to icon sequence represents.11*/12function findMissingEmojis(sequences, testDataTree) {13	const results = [];14	const existingItems = Object.create(null);15	const copiedItems = Object.create(null);16	sequences.forEach((item) => {17		const key = getEmojiSequenceKeyword(getUnqualifiedEmojiSequence(item.sequence));18		if (!existingItems[key] || existingItems[key].sequence.length < item.sequence.length) existingItems[key] = item;19	});20	const iterate = (type, parentTree, parentValues, parentItem, deep) => {21		const childTree = parentTree.children?.[type];22		if (!childTree) return;23		const range = emojiComponents[type];24		for (let number = range[0]; number < range[1]; number++) {25			const values = {26				"hair-style": [...parentValues["hair-style"]],27				"skin-tone": [...parentValues["skin-tone"]]28			};29			values[type].push(number);30			const sequence = replaceEmojiComponentsInCombinedSequence(childTree.item.sequence, values);31			const key = getEmojiSequenceKeyword(getUnqualifiedEmojiSequence(sequence));32			const oldItem = existingItems[key];33			let item;34			if (oldItem) item = oldItem;35			else {36				item = copiedItems[key];37				if (!item) {38					item = {39						...parentItem,40						sequence41					};42					if (item.sequenceKey) item.sequenceKey = key;43					copiedItems[key] = item;44					results.push(item);45				}46			}47			if (deep || oldItem) for (const key in values) iterate(key, childTree, values, item, deep);48		}49	};50	const parse = (key, deep) => {51		const treeItem = testDataTree[key];52		const rootItem = existingItems[treeItem.item.sequenceKey];53		if (!rootItem) return;54		const values = {55			"skin-tone": [],56			"hair-style": []57		};58		for (const key in values) iterate(key, treeItem, values, rootItem, deep);59	};60	for (const key in testDataTree) {61		parse(key, false);62		parse(key, true);63	}64	return results;65}66export { findMissingEmojis };67 
basant307/AI_Governance_Project · CoolFace