wip
This commit is contained in:
parent
cc89f0c75c
commit
afd28d934e
26 changed files with 2103 additions and 427 deletions
23
data-pipeline/utils/check-if-json-exists.ts
Normal file
23
data-pipeline/utils/check-if-json-exists.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue