-
Notifications
You must be signed in to change notification settings - Fork 550
/
constants.py
204 lines (186 loc) · 5.48 KB
/
constants.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import os
from enum import Enum
class Source(Enum):
PDFMINER = "pdfminer"
OCR_TESSERACT = "ocr_tesseract"
OCR_PADDLE = "ocr_paddle"
class OCRMode(Enum):
INDIVIDUAL_BLOCKS = "individual_blocks"
FULL_PAGE = "entire_page"
class PartitionStrategy:
AUTO = "auto"
FAST = "fast"
OCR_ONLY = "ocr_only"
HI_RES = "hi_res"
SORT_MODE_XY_CUT = "xy-cut"
SORT_MODE_BASIC = "basic"
SORT_MODE_DONT = "dont"
OCR_AGENT_TESSERACT_OLD = "tesseract"
OCR_AGENT_PADDLE_OLD = "paddle"
OCR_AGENT_TESSERACT = "unstructured.partition.utils.ocr_models.tesseract_ocr.OCRAgentTesseract"
OCR_AGENT_PADDLE = "unstructured.partition.utils.ocr_models.paddle_ocr.OCRAgentPaddle"
OCR_AGENT_MODULES_WHITELIST = os.getenv(
"OCR_AGENT_MODULES_WHITELIST",
"unstructured.partition.utils.ocr_models.tesseract_ocr,"
"unstructured.partition.utils.ocr_models.paddle_ocr",
).split(",")
UNSTRUCTURED_INCLUDE_DEBUG_METADATA = os.getenv("UNSTRUCTURED_INCLUDE_DEBUG_METADATA", False)
# Note(yuming): Default language for paddle OCR
# soon will be able to specify the language down through partition() as well
DEFAULT_PADDLE_LANG = os.getenv("DEFAULT_PADDLE_LANG", "en")
# this field is defined by pytesseract/unstructured.pytesseract
TESSERACT_TEXT_HEIGHT = "height"
TESSERACT_LANGUAGES_SPLITTER = "+"
# source: https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html
# All languages have been changed to lowercase and have been altered to remove dates and "(contrib)"
# Ex: "Greek, Ancient (to 1453) (contrib)" -> "greek, ancient"
# Where it seemed appropriate, languages have been split into multiple keys with the same value.
# Ex: "greek, modern":"ell", "greek":"ell", "chinese - simplified":"chi_sim", "chinese":"chi_sim",
# On tesseract-ocr.github.io, "Spanish" matches with both "spa_old" and "spa".
# Here, it only matches with "spa" and "spanish - old":"spa_old" was added.
TESSERACT_LANGUAGES_AND_CODES = {
"afrikaans": "afr",
"amharic": "amh",
"arabic": "ara",
"assamese": "asm",
"azerbaijani": "aze",
"azerbaijani - cyrilic": "aze_cyrl",
"belarusian": "bel",
"bengali": "ben",
"tibetan": "bod",
"bosnian": "bos",
"breton": "bre",
"bulgarian": "bul",
"catalan; Valencian": "cat",
"cebuano": "ceb",
"czech": "ces",
"chinese - simplified": "chi_sim",
"chinese": "chi_sim",
"chinese - traditional": "chi_tra",
"cherokee": "chr",
"corsican": "cos",
"welsh": "cym",
"danish": "dan",
"danish - fraktur": "dan_frak",
"german": "deu",
"german - fraktur (contrib)": "deu_frak", # "contrib" not removed because it would repeat key
"dzongkha": "dzo",
"greek, modern": "ell",
"greek": "ell",
"english": "eng",
"english, middle": "enm",
"esperanto": "epo",
"math / equation detection module": "equ",
"estonian": "est",
"basque": "eus",
"faroese": "fao",
"persian": "fas",
"filipino (old - tagalog)": "fil",
"filipino": "fil",
"finnish": "fin",
"french": "fra",
"german - fraktur": "frk",
"french, middle": "frm",
"western frisian": "fry",
"scottish gaelic": "gla",
"irish": "gle",
"galician": "glg",
"greek, ancient": "grc",
"gujarati": "guj",
"haitian": "hat",
"haitian creole": "hat",
"hebrew": "heb",
"hindi": "hin",
"croatian": "hrv",
"hungarian": "hun",
"armenian": "hye",
"inuktitut": "iku",
"indonesian": "ind",
"icelandic": "isl",
"italian": "ita",
"italian - old": "ita_old",
"javanese": "jav",
"japanese": "jpn",
"kannada": "kan",
"georgian": "kat",
"georgian - old": "kat_old",
"kazakh": "kaz",
"central khmer": "khm",
"kirghiz": "kir",
"kyrgyz": "kir",
"kurmanji (kurdish - latin script)": "kmr",
"korean": "kor",
"korean (vertical)": "kor_vert",
"kurdish (arabic script)": "kur",
"lao": "lao",
"latin": "lat",
"latvian": "lav",
"lithuanian": "lit",
"luxembourgish": "ltz",
"malayalam": "mal",
"marathi": "mar",
"macedonian": "mkd",
"maltese": "mlt",
"mongolian": "mon",
"maori": "mri",
"malay": "msa",
"burmese": "mya",
"nepali": "nep",
"dutch": "nld",
"flemish": "nld",
"norwegian": "nor",
"occitan": "oci",
"oriya": "ori",
"orientation and script detection module": "osd",
"panjabi": "pan",
"punjabi": "pan",
"polish": "pol",
"portuguese": "por",
"pushto": "pus",
"pashto": "pus",
"quechua": "que",
"romanian": "ron",
"moldavian": "ron",
"moldovan": "ron",
"russian": "rus",
"sanskrit": "san",
"sinhala": "sin",
"sinhalese": "sin",
"slovak": "slk",
"slovak - fraktur": "slk_frak",
"slovenian": "slv",
"sindhi": "snd",
"spanish": "spa",
"castilian": "spa",
"spanish - old": "spa_old",
"castilian - old": "spa_old",
"albanian": "sqi",
"serbian": "srp",
"serbian - latin": "srp_latn",
"sundanese": "sun",
"swahili": "swa",
"swedish": "swe",
"syriac": "syr",
"tamil": "tam",
"tatar": "tat",
"telugu": "tel",
"tajik": "tgk",
"tagalog": "tgl",
"thai": "tha",
"tigrinya": "tir",
"tonga": "ton",
"turkish": "tur",
"uighur": "uig",
"uyghur": "uig",
"ukrainian": "ukr",
"urdu": "urd",
"uzbek": "uzb",
"uzbek - cyrilic": "uzb_cyrl",
"vietnamese": "vie",
"yiddish": "yid",
"yoruba": "yor",
}
# 2 ** 31 - 1, max byte size for image data
TESSERACT_MAX_SIZE = 2147483647
# default image colors
IMAGE_COLOR_DEPTH = 32