lila/data-pipeline/utils/check-if-json-exists.ts
2026-07-06 13:09:30 +02:00

23 lines
705 B
TypeScript

import fs from "fs";
import path from "path";
/**
* Checks if a JSON file for the given word exists AND contains enriched data.
* Returns false for skeleton files (missing senses array).
*/
export function isWordProcessed(word: string, outputDir: string): boolean {
const targetFilePath = path.join(outputDir, `${word}.json`);
if (!fs.existsSync(targetFilePath)) {
return false;
}
try {
const content = fs.readFileSync(targetFilePath, "utf-8");
const data = JSON.parse(content) as Record<string, unknown>;
return Array.isArray(data["senses"]) && data["senses"].length > 0;
} catch (_error: unknown) {
// Corrupted file => treat as not processed
return false;
}
}