ontocast.tool.converter¶
Document conversion tools for OntoCast.
This module provides functionality for converting various document formats into structured data that can be processed by the OntoCast system.
Attributes¶
CONVERTER_CACHE_FORMAT_VERSION = 2
module-attribute
¶
CONVERTER_REPAIR_RULES_VERSION = 2
module-attribute
¶
FixedProfile = Literal['fast', 'lean', 'ocr']
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
ConverterTool
¶
Bases: Tool
Tool for converting documents to native DoclingDocument format.
This class provides functionality for converting various document formats into DoclingDocument objects that can be processed by the OntoCast system. It includes caching to avoid re-converting the same documents.
Attributes:
| Name | Type | Description |
|---|---|---|
supported_extensions |
set[str]
|
Suffixes this install converts:
|
cache |
Any
|
Cacher instance for caching conversion results. |
Source code in ontocast/tool/converter.py
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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
Attributes¶
cache = Field(default=None, exclude=True)
class-attribute
instance-attribute
¶
converter_config = converter_config or ConverterConfig()
class-attribute
instance-attribute
¶
supported_extensions = Field(default_factory=set, description='File suffixes this install converts')
class-attribute
instance-attribute
¶
Methods:¶
__call__(file_input, *, filename=None)
¶
Convert a document to a DoclingDocument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_input
|
bytes | str | Path
|
The input file as either bytes, string, or pathlib.Path. |
required |
filename
|
str | None
|
Name of an uploaded file given as bytes. Docling picks text formats (Markdown, AsciiDoc) by name, not content. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DoclingDocument |
DoclingDocument
|
The converted document. |
Source code in ontocast/tool/converter.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
__init__(cache=None, converter_config=None, **kwargs)
¶
Initialize the converter tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache
|
Cacher | None
|
Optional shared Cacher instance. If None, creates a new one. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in ontocast/tool/converter.py
cache_config(filename, profile=None)
¶
Config part of the conversion cache key for a file called filename.
Keyed by the resolved config, so a document converted under auto
shares its entry with the same document under the profile auto
chose. The accepted suffix set is left out, so widening or narrowing it
re-converts nothing. The suffix joins the key only beyond PDF and PPTX,
whose keys predate it: other formats are chosen by name, and the same
bytes parse differently as Markdown and as AsciiDoc.
Source code in ontocast/tool/converter.py
ensure_converter(profile=None)
¶
Return the Docling converter for profile, building it on first use.
Exposed so a server can warm the models at startup instead of making the
first request pay for loading the layout, OCR and table-structure models.
Without profile, the configured one (fast under auto).
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The shared docling |
Any
|
docling is an optional dependency resolved lazily. |
Source code in ontocast/tool/converter.py
resolve_profile(content, filename)
¶
The fixed profile a document converts with.
auto checks a PDF's text layer: fast when it has one, ocr
when its pages are images only. Other formats take fast; it differs
from ocr only in PDF options.
Source code in ontocast/tool/converter.py
Functions:¶
build_document_converter(config)
¶
Build a Docling DocumentConverter from OntoCast converter settings.
config is taken as given; resolve an auto profile first
(ConverterConfig.resolved).