87 lines
2.6 KiB
JavaScript
87 lines
2.6 KiB
JavaScript
// merge_ksa.js
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
function parseLine(line, ksaType) {
|
|
// Split on tabs, trim each column
|
|
const cols = line.split(/\t/).map(col => col.trim());
|
|
|
|
// If this line is the header or doesn't have enough columns, skip by returning null
|
|
if (!cols[0] || cols[0].startsWith('O*NET-SOC Code') || cols.length < 13) {
|
|
return null;
|
|
}
|
|
|
|
// columns (0..12):
|
|
// 0=O*NET-SOC Code, 1=Element ID, 2=Element Name, 3=Scale ID,
|
|
// 4=Data Value, 5=N, 6=Standard Error, 7=Lower CI, 8=Upper CI,
|
|
// 9=Recommend Suppress, 10=Not Relevant, 11=Date, 12=Domain Source
|
|
|
|
const onetSocCode = cols[0];
|
|
const elementID = cols[1];
|
|
const elementName = cols[2];
|
|
const scaleID = cols[3];
|
|
|
|
// Convert numeric columns:
|
|
const dataValueNum = parseFloat(cols[4]) || 0;
|
|
const nNum = parseFloat(cols[5]) || 0;
|
|
const standardErrorNum = parseFloat(cols[6]) || 0;
|
|
const lowerCINum = parseFloat(cols[7]) || 0;
|
|
const upperCINum = parseFloat(cols[8]) || 0;
|
|
|
|
const recommendSuppress = cols[9];
|
|
const notRelevant = cols[10];
|
|
const dateVal = cols[11];
|
|
const domainSourceVal = cols[12];
|
|
|
|
return {
|
|
onetSocCode,
|
|
elementID,
|
|
elementName,
|
|
scaleID,
|
|
dataValue: dataValueNum,
|
|
n: nNum,
|
|
standardError: standardErrorNum,
|
|
lowerCI: lowerCINum,
|
|
upperCI: upperCINum,
|
|
recommendSuppress,
|
|
notRelevant,
|
|
date: dateVal,
|
|
domainSource: domainSourceVal,
|
|
ksa_type: ksaType // e.g. "Knowledge", "Skill", "Ability"
|
|
};
|
|
}
|
|
|
|
function parseTextFile(filepath, ksaType) {
|
|
const raw = fs.readFileSync(filepath, 'utf8');
|
|
const lines = raw.split('\n').map(line => line.trim()).filter(Boolean);
|
|
|
|
const items = [];
|
|
for (const line of lines) {
|
|
const parsed = parseLine(line, ksaType);
|
|
if (parsed) {
|
|
items.push(parsed);
|
|
}
|
|
}
|
|
return items;
|
|
}
|
|
|
|
function main() {
|
|
// Adjust file paths as needed
|
|
const knowledgeFile = path.resolve('Knowledge.txt');
|
|
const skillsFile = path.resolve('Skills.txt');
|
|
const abilitiesFile = path.resolve('Abilities.txt');
|
|
|
|
const knowledgeData = parseTextFile(knowledgeFile, 'Knowledge');
|
|
const skillsData = parseTextFile(skillsFile, 'Skill');
|
|
const abilitiesData = parseTextFile(abilitiesFile, 'Ability');
|
|
|
|
// Merge them
|
|
const merged = [...knowledgeData, ...skillsData, ...abilitiesData];
|
|
|
|
// Write merged JSON
|
|
fs.writeFileSync('ksa_data.json', JSON.stringify(merged, null, 2), 'utf8');
|
|
console.log(`Wrote ${merged.length} rows to ksa_data.json (no header rows, numeric columns converted).`);
|
|
}
|
|
|
|
main();
|