Spaces:
Runtime error
Runtime error
Delete languages.py
Browse files- languages.py +0 -182
languages.py
DELETED
|
@@ -1,182 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Language Registry & Constants for AI4Bharat Pralekha Dataset
|
| 3 |
-
Covers 12 Indic languages + English with full Unicode metadata.
|
| 4 |
-
"""
|
| 5 |
-
from __future__ import annotations
|
| 6 |
-
from dataclasses import dataclass, field
|
| 7 |
-
from typing import Dict, List, Optional, Tuple
|
| 8 |
-
import unicodedata
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# ─────────────────────────────────────────────
|
| 12 |
-
# Script Unicode Block Definitions
|
| 13 |
-
# ─────────────────────────────────────────────
|
| 14 |
-
SCRIPT_UNICODE_BLOCKS: Dict[str, List[Tuple[int, int]]] = {
|
| 15 |
-
"Devanagari": [(0x0900, 0x097F), (0xA8E0, 0xA8FF)],
|
| 16 |
-
"Bengali": [(0x0980, 0x09FF)],
|
| 17 |
-
"Gurmukhi": [(0x0A00, 0x0A7F)],
|
| 18 |
-
"Gujarati": [(0x0A80, 0x0AFF)],
|
| 19 |
-
"Odia": [(0x0B00, 0x0B7F)],
|
| 20 |
-
"Tamil": [(0x0B80, 0x0BFF)],
|
| 21 |
-
"Telugu": [(0x0C00, 0x0C7F)],
|
| 22 |
-
"Kannada": [(0x0C80, 0x0CFF)],
|
| 23 |
-
"Malayalam": [(0x0D00, 0x0D7F)],
|
| 24 |
-
"Sinhala": [(0x0D80, 0x0DFF)],
|
| 25 |
-
"Arabic": [(0x0600, 0x06FF), (0x0750, 0x077F), (0xFB50, 0xFDFF), (0xFE70, 0xFEFF)],
|
| 26 |
-
"Latin": [(0x0000, 0x007F), (0x0080, 0x00FF), (0x0100, 0x017F)],
|
| 27 |
-
"Cyrillic": [(0x0400, 0x04FF)],
|
| 28 |
-
"CJK": [(0x4E00, 0x9FFF), (0x3400, 0x4DBF)],
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
SCRIPT_TO_DIRECTION: Dict[str, str] = {
|
| 32 |
-
"Devanagari": "LTR",
|
| 33 |
-
"Bengali": "LTR",
|
| 34 |
-
"Gurmukhi": "LTR",
|
| 35 |
-
"Gujarati": "LTR",
|
| 36 |
-
"Odia": "LTR",
|
| 37 |
-
"Tamil": "LTR",
|
| 38 |
-
"Telugu": "LTR",
|
| 39 |
-
"Kannada": "LTR",
|
| 40 |
-
"Malayalam": "LTR",
|
| 41 |
-
"Arabic": "RTL",
|
| 42 |
-
"Latin": "LTR",
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
@dataclass
|
| 47 |
-
class LanguageInfo:
|
| 48 |
-
code: str # Pralekha subset code (ben, hin, ...)
|
| 49 |
-
name: str # Full English name
|
| 50 |
-
script: str # Primary script name
|
| 51 |
-
iso639_1: Optional[str] # ISO 639-1 two-letter code
|
| 52 |
-
iso639_3: str # ISO 639-3 three-letter code
|
| 53 |
-
label_id: int # Numeric label for ML models
|
| 54 |
-
unicode_ranges: List[Tuple[int, int]] = field(default_factory=list)
|
| 55 |
-
direction: str = "LTR"
|
| 56 |
-
family: str = "Indo-Aryan"
|
| 57 |
-
native_name: str = ""
|
| 58 |
-
romanization_scheme: Optional[str] = None # IAST, ISO 15919, etc.
|
| 59 |
-
shares_script_with: List[str] = field(default_factory=list)
|
| 60 |
-
|
| 61 |
-
def char_in_script(self, char: str) -> bool:
|
| 62 |
-
cp = ord(char)
|
| 63 |
-
return any(lo <= cp <= hi for lo, hi in self.unicode_ranges)
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
# ─────────────────────────────────────────────
|
| 67 |
-
# Language Registry (12 Indic + English)
|
| 68 |
-
# ─────────────────────────────────────────────
|
| 69 |
-
LANGUAGE_REGISTRY: Dict[str, LanguageInfo] = {
|
| 70 |
-
"ben": LanguageInfo(
|
| 71 |
-
code="ben", name="Bengali", script="Bengali",
|
| 72 |
-
iso639_1="bn", iso639_3="ben", label_id=0,
|
| 73 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Bengali"],
|
| 74 |
-
direction="LTR", family="Indo-Aryan",
|
| 75 |
-
native_name="বাংলা",
|
| 76 |
-
romanization_scheme="ISO 15919",
|
| 77 |
-
),
|
| 78 |
-
"eng": LanguageInfo(
|
| 79 |
-
code="eng", name="English", script="Latin",
|
| 80 |
-
iso639_1="en", iso639_3="eng", label_id=1,
|
| 81 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Latin"],
|
| 82 |
-
direction="LTR", family="Germanic",
|
| 83 |
-
native_name="English",
|
| 84 |
-
),
|
| 85 |
-
"guj": LanguageInfo(
|
| 86 |
-
code="guj", name="Gujarati", script="Gujarati",
|
| 87 |
-
iso639_1="gu", iso639_3="guj", label_id=2,
|
| 88 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Gujarati"],
|
| 89 |
-
direction="LTR", family="Indo-Aryan",
|
| 90 |
-
native_name="ગુજરાતી",
|
| 91 |
-
romanization_scheme="ISO 15919",
|
| 92 |
-
),
|
| 93 |
-
"hin": LanguageInfo(
|
| 94 |
-
code="hin", name="Hindi", script="Devanagari",
|
| 95 |
-
iso639_1="hi", iso639_3="hin", label_id=3,
|
| 96 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Devanagari"],
|
| 97 |
-
direction="LTR", family="Indo-Aryan",
|
| 98 |
-
native_name="हिन्दी",
|
| 99 |
-
romanization_scheme="IAST",
|
| 100 |
-
shares_script_with=["mar"],
|
| 101 |
-
),
|
| 102 |
-
"kan": LanguageInfo(
|
| 103 |
-
code="kan", name="Kannada", script="Kannada",
|
| 104 |
-
iso639_1="kn", iso639_3="kan", label_id=4,
|
| 105 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Kannada"],
|
| 106 |
-
direction="LTR", family="Dravidian",
|
| 107 |
-
native_name="ಕನ್ನಡ",
|
| 108 |
-
),
|
| 109 |
-
"mal": LanguageInfo(
|
| 110 |
-
code="mal", name="Malayalam", script="Malayalam",
|
| 111 |
-
iso639_1="ml", iso639_3="mal", label_id=5,
|
| 112 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Malayalam"],
|
| 113 |
-
direction="LTR", family="Dravidian",
|
| 114 |
-
native_name="മലയാളം",
|
| 115 |
-
),
|
| 116 |
-
"mar": LanguageInfo(
|
| 117 |
-
code="mar", name="Marathi", script="Devanagari",
|
| 118 |
-
iso639_1="mr", iso639_3="mar", label_id=6,
|
| 119 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Devanagari"],
|
| 120 |
-
direction="LTR", family="Indo-Aryan",
|
| 121 |
-
native_name="मराठी",
|
| 122 |
-
romanization_scheme="IAST",
|
| 123 |
-
shares_script_with=["hin"],
|
| 124 |
-
),
|
| 125 |
-
"ori": LanguageInfo(
|
| 126 |
-
code="ori", name="Odia", script="Odia",
|
| 127 |
-
iso639_1="or", iso639_3="ori", label_id=7,
|
| 128 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Odia"],
|
| 129 |
-
direction="LTR", family="Indo-Aryan",
|
| 130 |
-
native_name="ଓଡ଼ିଆ",
|
| 131 |
-
),
|
| 132 |
-
"pan": LanguageInfo(
|
| 133 |
-
code="pan", name="Punjabi", script="Gurmukhi",
|
| 134 |
-
iso639_1="pa", iso639_3="pan", label_id=8,
|
| 135 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Gurmukhi"],
|
| 136 |
-
direction="LTR", family="Indo-Aryan",
|
| 137 |
-
native_name="ਪੰਜਾਬੀ",
|
| 138 |
-
),
|
| 139 |
-
"tam": LanguageInfo(
|
| 140 |
-
code="tam", name="Tamil", script="Tamil",
|
| 141 |
-
iso639_1="ta", iso639_3="tam", label_id=9,
|
| 142 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Tamil"],
|
| 143 |
-
direction="LTR", family="Dravidian",
|
| 144 |
-
native_name="தமிழ்",
|
| 145 |
-
),
|
| 146 |
-
"tel": LanguageInfo(
|
| 147 |
-
code="tel", name="Telugu", script="Telugu",
|
| 148 |
-
iso639_1="te", iso639_3="tel", label_id=10,
|
| 149 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Telugu"],
|
| 150 |
-
direction="LTR", family="Dravidian",
|
| 151 |
-
native_name="తెలుగు",
|
| 152 |
-
),
|
| 153 |
-
"urd": LanguageInfo(
|
| 154 |
-
code="urd", name="Urdu", script="Arabic",
|
| 155 |
-
iso639_1="ur", iso639_3="urd", label_id=11,
|
| 156 |
-
unicode_ranges=SCRIPT_UNICODE_BLOCKS["Arabic"],
|
| 157 |
-
direction="RTL", family="Indo-Aryan",
|
| 158 |
-
native_name="اردو",
|
| 159 |
-
romanization_scheme="ALA-LC",
|
| 160 |
-
),
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
# Derived mappings
|
| 164 |
-
LABEL_TO_CODE: Dict[int, str] = {v.label_id: k for k, v in LANGUAGE_REGISTRY.items()}
|
| 165 |
-
CODE_TO_LABEL: Dict[str, int] = {k: v.label_id for k, v in LANGUAGE_REGISTRY.items()}
|
| 166 |
-
ALL_LANGUAGE_CODES: List[str] = sorted(LANGUAGE_REGISTRY.keys())
|
| 167 |
-
NUM_CLASSES: int = len(LANGUAGE_REGISTRY)
|
| 168 |
-
|
| 169 |
-
# Script families for analysis
|
| 170 |
-
DRAVIDIAN_LANGUAGES = {"kan", "mal", "tam", "tel"}
|
| 171 |
-
INDO_ARYAN_LANGUAGES = {"ben", "guj", "hin", "mar", "ori", "pan", "urd"}
|
| 172 |
-
DEVANAGARI_LANGUAGES = {"hin", "mar"}
|
| 173 |
-
RTL_LANGUAGES = {"urd"}
|
| 174 |
-
|
| 175 |
-
# Confusable pairs (share script or similar features)
|
| 176 |
-
CONFUSABLE_PAIRS = [
|
| 177 |
-
("hin", "mar"), # Both Devanagari
|
| 178 |
-
("tam", "mal"), # Related Dravidian scripts
|
| 179 |
-
("kan", "tel"), # Related Dravidian scripts
|
| 180 |
-
("hin", "urd"), # Same spoken language, different scripts
|
| 181 |
-
("ben", "ori"), #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