Files
Poc-dashboard/schema-mappings/base-mapping.js
2025-10-15 11:28:10 +02:00

210 lines
5.7 KiB
JavaScript

// Base mapping structure for all ODMDB schemas
export const createSchemaMapping = (schemaData, objectName) => {
if (!schemaData || !schemaData.properties) {
return {
objectName,
available: false,
error: "Schema not found or invalid",
properties: {},
synonyms: {},
indexes: [],
};
}
const properties = schemaData.properties;
const synonyms = {};
const fieldMappings = {};
// Generate comprehensive synonyms for each field
Object.entries(properties).forEach(([fieldName, fieldDef]) => {
const fieldSynonyms = generateFieldSynonyms(
fieldName,
fieldDef,
objectName
);
fieldMappings[fieldName] = {
field: fieldName,
title: fieldDef.title?.toLowerCase(),
description: fieldDef.description?.toLowerCase(),
type: fieldDef.type,
synonyms: fieldSynonyms,
};
// Index by synonyms
fieldSynonyms.forEach((synonym) => {
synonyms[synonym.toLowerCase()] = fieldName;
});
// Index by title
if (fieldDef.title) {
synonyms[fieldDef.title.toLowerCase()] = fieldName;
}
});
// Extract indexes if available
const indexes = schemaData.apxidx
? schemaData.apxidx.map((idx) => ({
name: idx.name,
type: idx.type,
keyval: idx.keyval,
}))
: [];
// Extract access rights if available
const accessRights = schemaData.apxaccessrights || {};
return {
objectName,
available: true,
propertyCount: Object.keys(properties).length,
properties: fieldMappings,
synonyms,
indexes,
accessRights,
rawSchema: schemaData,
};
};
// Generate field-specific synonyms based on field name and context
const generateFieldSynonyms = (fieldName, fieldDef, objectName) => {
const synonyms = [];
// Add the field name itself
synonyms.push(fieldName);
// Add title if available
if (fieldDef.title) {
synonyms.push(fieldDef.title.toLowerCase());
}
// Common patterns across all objects
const commonPatterns = {
// Identity & References
alias: ["id", "identifier", "username", "user id"],
owner: ["owner", "belongs to", "owned by"],
// Dates & Timestamps
dt_create: [
"created",
"creation date",
"new",
"recent",
"since",
"registration date",
],
dt_update: ["updated", "last update", "modified", "last modified"],
dt_publish: ["published", "publication date", "went live"],
dt_close: ["closed", "closing date", "ended"],
// Contact Information
email: ["contact", "mail", "contact email", "e-mail"],
phone: ["telephone", "phone number", "contact number"],
// Status & State
state: ["status", "condition", "current state"],
status: ["state", "condition", "current status"],
// Location
location: ["where", "place", "address", "position"],
// Descriptions
description: ["desc", "details", "info", "about"],
shortdescription: ["short desc", "summary", "brief", "overview"],
// Common business fields
siret: ["company id", "business id", "organization id"],
sirets: ["companies", "businesses", "organizations"],
};
// Object-specific patterns
const objectSpecificPatterns = {
seekers: {
seekstatus: [
"status",
"availability",
"looking",
"job search status",
"urgency",
],
seekworkingyear: [
"experience",
"years of experience",
"work experience",
"career length",
],
seekjobtitleexperience: [
"job titles",
"positions",
"roles",
"work history",
],
salaryexpectation: [
"salary",
"pay",
"compensation",
"wage",
"expected salary",
],
seeklocation: [
"location",
"where",
"work location",
"preferred location",
],
skills: ["competencies", "abilities", "technical skills"],
mbti: ["personality", "personality type", "MBTI", "profile"],
},
jobads: {
jobadid: ["job id", "ad id", "posting id"],
jobtitle: ["job title", "position", "role", "job name"],
salary: ["pay", "compensation", "wage", "remuneration"],
joblocation: ["job location", "work location", "where"],
description: ["job description", "details", "requirements"],
state: ["status", "publication status", "availability"],
},
recruiters: {
sirets: ["companies", "businesses", "clients", "employers"],
tipsadvice: ["tips", "advice", "articles", "guidance"],
},
persons: {
firstname: ["first name", "given name", "name"],
lastname: ["last name", "family name", "surname"],
dt_birth: ["birth date", "birthday", "date of birth", "age"],
},
};
// Apply common patterns
if (commonPatterns[fieldName]) {
synonyms.push(...commonPatterns[fieldName]);
}
// Apply object-specific patterns
if (
objectSpecificPatterns[objectName] &&
objectSpecificPatterns[objectName][fieldName]
) {
synonyms.push(...objectSpecificPatterns[objectName][fieldName]);
}
// Generate semantic synonyms based on field name patterns
if (fieldName.includes("salary")) {
synonyms.push("pay", "compensation", "wage", "remuneration");
}
if (fieldName.includes("location")) {
synonyms.push("where", "place", "address", "position");
}
if (fieldName.includes("experience")) {
synonyms.push("background", "history", "expertise");
}
if (fieldName.includes("skill")) {
synonyms.push("competencies", "abilities", "talents");
}
if (fieldName.includes("date") || fieldName.startsWith("dt_")) {
synonyms.push("when", "time", "timestamp");
}
return [...new Set(synonyms)]; // Remove duplicates
};
export default createSchemaMapping;