CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
iso2022.js114 linesDownload Raw Back to encoding
1"use strict";2var __importDefault = (this && this.__importDefault) || function (mod) {3    return (mod && mod.__esModule) ? mod : { "default": mod };4};5Object.defineProperty(exports, "__esModule", { value: true });6exports.ISO_2022_CN = exports.ISO_2022_KR = exports.ISO_2022_JP = void 0;7const match_1 = __importDefault(require("../match"));8class ISO_2022 {9    constructor() {10        this.escapeSequences = [];11    }12    name() {13        return 'ISO_2022';14    }15    match(det) {16        let i, j;17        let escN;18        let hits = 0;19        let misses = 0;20        let shifts = 0;21        let confidence;22        const text = det.inputBytes;23        const textLen = det.inputLen;24        scanInput: for (i = 0; i < textLen; i++) {25            if (text[i] == 0x1b) {26                checkEscapes: for (escN = 0; escN < this.escapeSequences.length; escN++) {27                    const seq = this.escapeSequences[escN];28                    if (textLen - i < seq.length)29                        continue checkEscapes;30                    for (j = 1; j < seq.length; j++)31                        if (seq[j] != text[i + j])32                            continue checkEscapes;33                    hits++;34                    i += seq.length - 1;35                    continue scanInput;36                }37                misses++;38            }39            if (text[i] == 0x0e || text[i] == 0x0f)40                shifts++;41        }42        if (hits == 0)43            return null;44        confidence = (100 * hits - 100 * misses) / (hits + misses);45        if (hits + shifts < 5)46            confidence -= (5 - (hits + shifts)) * 10;47        return confidence <= 0 ? null : (0, match_1.default)(det, this, confidence);48    }49}50class ISO_2022_JP extends ISO_2022 {51    constructor() {52        super(...arguments);53        this.escapeSequences = [54            [0x1b, 0x24, 0x28, 0x43],55            [0x1b, 0x24, 0x28, 0x44],56            [0x1b, 0x24, 0x40],57            [0x1b, 0x24, 0x41],58            [0x1b, 0x24, 0x42],59            [0x1b, 0x26, 0x40],60            [0x1b, 0x28, 0x42],61            [0x1b, 0x28, 0x48],62            [0x1b, 0x28, 0x49],63            [0x1b, 0x28, 0x4a],64            [0x1b, 0x2e, 0x41],65            [0x1b, 0x2e, 0x46],66        ];67    }68    name() {69        return 'ISO-2022-JP';70    }71    language() {72        return 'ja';73    }74}75exports.ISO_2022_JP = ISO_2022_JP;76class ISO_2022_KR extends ISO_2022 {77    constructor() {78        super(...arguments);79        this.escapeSequences = [[0x1b, 0x24, 0x29, 0x43]];80    }81    name() {82        return 'ISO-2022-KR';83    }84    language() {85        return 'kr';86    }87}88exports.ISO_2022_KR = ISO_2022_KR;89class ISO_2022_CN extends ISO_2022 {90    constructor() {91        super(...arguments);92        this.escapeSequences = [93            [0x1b, 0x24, 0x29, 0x41],94            [0x1b, 0x24, 0x29, 0x47],95            [0x1b, 0x24, 0x2a, 0x48],96            [0x1b, 0x24, 0x29, 0x45],97            [0x1b, 0x24, 0x2b, 0x49],98            [0x1b, 0x24, 0x2b, 0x4a],99            [0x1b, 0x24, 0x2b, 0x4b],100            [0x1b, 0x24, 0x2b, 0x4c],101            [0x1b, 0x24, 0x2b, 0x4d],102            [0x1b, 0x4e],103            [0x1b, 0x4f],104        ];105    }106    name() {107        return 'ISO-2022-CN';108    }109    language() {110        return 'zh';111    }112}113exports.ISO_2022_CN = ISO_2022_CN;114//# sourceMappingURL=iso2022.js.map
basant307/AI_Governance_Project · CoolFace