File size: 2,795 Bytes
a1195ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13ce884
a1195ff
 
 
13ce884
 
 
 
a1195ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import fs from "node:fs";
import path from "node:path";
import crypto from "node:crypto";
import { fileURLToPath } from "node:url";

const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const dataDir = path.join(root, "data");
const files = [
  "printer_brand_research_matrix.csv",
  "competitor_product_research_matrix.csv",
  "source_library.csv"
];

function parseCsv(input) {
  const rows = [];
  let row = [];
  let field = "";
  let quoted = false;

  for (let i = 0; i < input.length; i += 1) {
    const char = input[i];
    const next = input[i + 1];
    if (quoted && char === '"' && next === '"') {
      field += '"';
      i += 1;
    } else if (char === '"') {
      quoted = !quoted;
    } else if (char === "," && !quoted) {
      row.push(field);
      field = "";
    } else if ((char === "\n" || char === "\r") && !quoted) {
      if (char === "\r" && next === "\n") i += 1;
      row.push(field);
      if (row.some((value) => value !== "")) rows.push(row);
      row = [];
      field = "";
    } else {
      field += char;
    }
  }

  if (field !== "" || row.length > 0) {
    row.push(field);
    rows.push(row);
  }

  const [headers, ...values] = rows;
  return values.map((cells, rowIndex) => {
    if (cells.length !== headers.length) {
      throw new Error(`Column mismatch on row ${rowIndex + 2}: expected ${headers.length}, received ${cells.length}`);
    }
    return Object.fromEntries(headers.map((header, index) => [header, cells[index]]));
  });
}

const manifest = {
  name: "MaxDecals Knowledge Base Database",
  version: "0.1.0",
  published: "2026-07-18",
  license: "CC-BY-4.0",
  publisher: "MaxDecals USA",
  canonical_url: "https://maxdecals.us/pages/knowledge-hub",
  repository: "https://github.com/funkiki-david/MaxDecals-Knowledge-Base-Database",
  dataset_mirror: "https://huggingface.co/datasets/funkikitech/MaxDecals-Knowledge-Base-Database",
  datasets: []
};

for (const file of files) {
  const csvPath = path.join(dataDir, file);
  const input = fs.readFileSync(csvPath, "utf8");
  const records = parseCsv(input);
  const jsonlName = file.replace(/\.csv$/, ".jsonl");
  const jsonlPath = path.join(dataDir, jsonlName);
  const jsonl = `${records.map((record) => JSON.stringify(record)).join("\n")}\n`;
  fs.writeFileSync(jsonlPath, jsonl, "utf8");

  manifest.datasets.push({
    name: file.replace(/\.csv$/, ""),
    csv: `data/${file}`,
    jsonl: `data/${jsonlName}`,
    rows: records.length,
    csv_sha256: crypto.createHash("sha256").update(input).digest("hex"),
    jsonl_sha256: crypto.createHash("sha256").update(jsonl).digest("hex")
  });
}

fs.writeFileSync(path.join(root, "dataset_manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
console.log(JSON.stringify(manifest, null, 2));