Skip to content

Node.js API #63896

Description

Affected URL(s)

alexandercarlis2-dotcom/pull-requit#2 (comment)

Description of the problem

https://discord.gg/moe97bokhttps://g.dev/Moelwintunhttps://github.com/alexandercarlis2-dotcom/pull-requit/issues/2#issue-4392389608Image

Image Image

// Sample extracted text string from the Myanmar NRC card image
const nrcText = ၆(ကက)မိတ္တူနိုင်ငံသားစိစစ်ရေးကတ်ပြား အမှတ် ၁၂ / မဂဒ(နိုင်)၁၅၀၅၀၆ ရက်စွဲ ၂၂ . ၆ . ၂၀၂၂ အမည် မောင်မိုးလွင်ထွန်း ဖခင်အမည် ဦးဝင်းခိုင် မွေးသက္ကရာဇ် ၂၀ . ၈ . ၁၉၉၇ လူမ/ဘာသာ ဗမာ / ဗုဒ္ဓ ထုတ်ပေးသူလက်မှတ် အမြင့် 5' 9 " သွေးအုပ်စု AB လာဘ် အမည် ထင်ရှားသည့်အမှတ်အသား ဝဲလက်မမှဲ့ ရှိ;

/**

  • Parses OCR text from a Myanmar NRC card into a structured object.

  • @param {string} text - The raw text extracted from the image.

  • @returns {Object} Structured data fields.
    */
    function parseMyanmarNRC(text) {
    const data = {
    cardType: "နိုင်ငံသားစိစစ်ရေးကတ်ပြား (မိတ္တူ)",
    nrcNumber: "",
    issueDate: "",
    name: "",
    fatherName: "",
    dateOfBirth: "",
    ethnicityReligion: "",
    height: "",
    bloodType: "",
    distinguishingMark: ""
    };

    // Clean up text lines
    const lines = text.split('\n').map(line => line.trim());

    lines.forEach(line => {
    if (line.includes("အမှတ်")) {
    data.nrcNumber = line.replace(/အမှတ်\s*/, "").trim();
    } else if (line.includes("ရက်စွဲ")) {
    data.issueDate = line.replace(/ရက်စွဲ\s*/, "").trim();
    } else if (line.includes("အမည်") && !line.includes("ဖခင်") && !line.includes("အမှတ်အသား")) {
    data.name = line.replace(/အမည်\s*/, "").trim();
    } else if (line.includes("ဖခင်အမည်")) {
    data.fatherName = line.replace(/ဖခင်အမည်\s*/, "").trim();
    } else if (line.includes("မွေးသက္ကရာဇ်")) {
    data.dateOfBirth = line.replace(/မွေးသက္ကရာဇ်\s*/, "").trim();
    } else if (line.includes("လူမ/ဘာသာ")) {
    data.ethnicityReligion = line.replace(/လူမ/ဘာသာ\s*/, "").trim();
    } else if (line.includes("အမြင့်") || line.includes("သွေးအုပ်စု")) {
    // Extract height and blood type using regex
    const heightMatch = line.match(/အမြင့်\s*([၀-၉\d\s'".-/]+)/);
    const bloodMatch = line.match(/သွေးအုပ်စု\s*([A-Za-z+-]+)/);

         if (heightMatch) data.height = heightMatch[1].trim();
         if (bloodMatch) data.bloodType = bloodMatch[1].trim();
     } else if (line.includes("ထင်ရှားသည့်အမှတ်အသား")) {
         data.distinguishingMark = line.replace(/.*ထင်ရှားသည့်အမှတ်အသား\s*/, "").trim();
     }
    

    });

    return data;
    }

// Execute and log the parsed data
const parsedNRCData = parseMyanmarNRC(nrcText);
console.log(JSON.stringify(parsedNRCData, null, 2));

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions