diff options
| author | AlisaLinUwU <alisalinuwu@gmail.com> | 2025-01-26 11:43:33 +0500 | 
|---|---|---|
| committer | AlisaLinUwU <alisalinuwu@gmail.com> | 2025-01-26 11:43:33 +0500 | 
| commit | a27c7763ed6a4f094ab65c49f176a2d9bde09f89 (patch) | |
| tree | 8c48e103f3bfc09d61ce2c231ba6d392221dbb0a /src/main/java/info/selflearner/ocr_telegram/model | |
Initializemain
Diffstat (limited to 'src/main/java/info/selflearner/ocr_telegram/model')
| -rw-r--r-- | src/main/java/info/selflearner/ocr_telegram/model/Passport.java | 70 | 
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/info/selflearner/ocr_telegram/model/Passport.java b/src/main/java/info/selflearner/ocr_telegram/model/Passport.java new file mode 100644 index 0000000..4e8a0a7 --- /dev/null +++ b/src/main/java/info/selflearner/ocr_telegram/model/Passport.java @@ -0,0 +1,70 @@ +package info.selflearner.ocr_telegram.model; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class Passport { +    public char type; +    public Character subtype; +    public String issuer; +    public String surname; +    public String givenNames; +    public String number; +    public String nationality; +    public LocalDate dateOfBirth; +    public Character sex; +    public LocalDate expirationDate; +    public String personalNumber; +    public int[] mrzLinesConfidence; + +    public Passport(char type, Character subtype, String issuer, String surname, String givenNames, String number, String nationality, LocalDate dateOfBirth, Character sex, LocalDate expirationDate, String personalNumber, int[] mrzLinesConfidence) { +        this.type = type; +        this.subtype = subtype; +        this.issuer = issuer; +        this.surname = surname; +        this.givenNames = givenNames; +        this.number = number; +        this.nationality = nationality; +        this.dateOfBirth = dateOfBirth; +        this.sex = sex; +        this.expirationDate = expirationDate; +        this.personalNumber = personalNumber; +        this.mrzLinesConfidence = mrzLinesConfidence; +    } + +    public Passport(String[] mrzLines, int[] mrzLinesConfidence) { +        this.type = mrzLines[0].charAt(0); +        this.subtype = mrzLines[0].charAt(1) == '<' ? null : mrzLines[0].charAt(0); +        this.issuer = mrzLines[0].substring(2, 5); +        this.surname = mrzLines[0].substring(5, mrzLines[0].indexOf('<', 6)); +        this.givenNames = mrzLines[0].substring(surname.length() + 7, mrzLines[0].indexOf('<', surname.length() + 8)); +        this.number = mrzLines[1].substring(0, 9); +        this.nationality = mrzLines[1].substring(10, 13); +        if (Integer.parseInt("20" + mrzLines[1].substring(13, 15)) < LocalDate.now().getYear()) { +            this.dateOfBirth = LocalDate.of(Integer.parseInt("20" + mrzLines[1].substring(13, 15)), Integer.parseInt(mrzLines[1].substring(15, 17)), Integer.parseInt(mrzLines[1].substring(17, 19))); +        } else { +            this.dateOfBirth = LocalDate.of(Integer.parseInt("19" + mrzLines[1].substring(13, 15)), Integer.parseInt(mrzLines[1].substring(15, 17)), Integer.parseInt(mrzLines[1].substring(17, 19))); +        } +        this.sex = mrzLines[1].charAt(20) != '<' ? mrzLines[1].charAt(20) : null; +        this.expirationDate = LocalDate.of(Integer.parseInt("20" + mrzLines[1].substring(21, 23)), Integer.parseInt(mrzLines[1].substring(23, 25)), Integer.parseInt(mrzLines[1].substring(25, 27))); +        this.personalNumber = mrzLines[1].substring(28, 42); +        this.mrzLinesConfidence = mrzLinesConfidence; +    } + +    @Override +    public String toString() { +        return "*Passport*\n" + +                "Type: `" + type + "`\n" + +                "Subtype: `" + subtype + "`\n" + +                "Issuer: `" + issuer + "`\n" + +                "Surname: `" + surname + "`\n" + +                "Given names: `" + givenNames + "`\n" + +                "Number: `" + number + "`\n" + +                "Nationality: `" + nationality + "`\n" + +                "Date of birth: `" + dateOfBirth.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")) + "`\n" + +                "Gender: `" + sex + "`\n" + +                "Expiration date: `" + expirationDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")) + "`\n" + +                "Personal number: `" + personalNumber + "`\n"; +    } +} +  |