Data Models
The newspaper.utils module defines key data structures used throughout the newspaper processing workflow. These models represent bounding boxes, articles, pages, and IIIF manifests.
YOLOBox
A YOLOBox represents a detected region or element on a page (such as text blocks, headings, or images) along with its geometric polygon coordinates, classification, and optional text or ordering details.
Attributes
| Attribute | Type | Description |
|---|---|---|
|
|
Unique identifier for the box. |
|
|
Category/class label of the detected bounding box element. |
|
|
List of |
|
|
Detection confidence score. |
|
|
Optional OCR/extracted text contained within this box. |
|
|
Optional sequence index indicating the reading order position. |
Properties & Methods
-
geometry(Polygon): Computes and caches a ShapelyPolygoninstance representing the box’s geometry. -
overlap(other: Polygon) → float: Calculates the proportion of the target polygon (other) covered by this box. Returns0.0if there is no intersection or if either geometry is invalid. -
format_polygon(width: int, height: int) → list[int]: Converts and normalizes polygon coordinates relative to the image dimensions (widthandheight) into a standard bounding box format suitable for layout reading models.
Article
An Article represents a logical document entity composed of multiple detected layout parts across pages.
Attributes
| Attribute | Type | Description |
|---|---|---|
|
|
Name or identifier of the article. |
|
|
List of |
JSON Example
{
"name": "1",
"parts": [
{
"name": "box_001",
"type": "ARTICLE-TITLE",
"polygon": [[120, 300], [850, 300], [850, 350], [120, 350]],
"confidence": 0.94,
"text": "LA GAZETTE DU MATIN",
"order": 1
},
{
"name": "box_002",
"type": "ARTICLE-TEXT",
"polygon": [[120, 360], [480, 360], [480, 750], [120, 750]],
"confidence": 0.89,
"text": "Le grand évènement d'hier a réuni...",
"order": 2
}
]
}
Page
A Page represents a single page from a publication, holding reference metadata, image information, and associated layout detections.
Attributes
| Attribute | Type | Description |
|---|---|---|
|
|
Page identifier or page number label. |
|
|
IIIF image URL for the page resource. |
|
|
Optional tuple specifying |
|
|
Optional local file path where the page image or metadata is stored. |
|
|
Collection of |
Methods
-
cast_for_reading_order(reader_classes: list[str]) → ReadingPage: Transforms the page and its boxes into aReadingPagestructure compatible withlayout_readeralgorithms.
JSON Example
{
"name": "1",
"url": "https://gallica.bnf.fr/iiif/ark:/12148/bpt6k41008602/f1/full/,2500/0/native.jpg",
"size": [1765, 2500],
"path": "/tmp/manifest/images/1.jpg",
"boxes": [
{
"name": "box_001",
"type": "ARTICLE-TITLE",
"polygon": [[120, 300], [850, 300], [850, 350], [120, 350]],
"confidence": 0.94,
"text": "LA GAZETTE DU MATIN",
"order": 1
}
]
}
Manifest
A Manifest manages top-level IIIF document manifest data, representing a complete publication volume or issue.
Attributes
| Attribute | Type | Description |
|---|---|---|
|
|
Remote URL of the IIIF manifest JSON. |
|
|
Optional hash string for caching or version verification. |
|
|
Optional local path where the downloaded manifest JSON is saved. |
|
|
List of |
|
|
List of |
Methods
-
parse(image_height: int) → None: Downloads the remote IIIF manifest fromurl(if not already local), parses the canvas sequence, and populates thepageslist with IIIF image URLs formatted to the specifiedimage_height.
JSON Example
{
"url": "https://gallica.bnf.fr/iiif/ark:/12148/bpt6k41008602/manifest.json",
"hash": "4d5ab18d8f53e386153b06295ab45a0d",
"path": "/tmp/4d5ab18d8f53e386153b06295ab45a0d/manifest.json",
"pages": [
{
"name": "1",
"url": "https://gallica.bnf.fr/iiif/ark:/12148/bpt6k41008602/f1/full/,2500/0/native.jpg",
"size": [1765, 2500],
"path": "/tmp/4d5ab18d8f53e386153b06295ab45a0d/images/1.jpg",
"boxes": [
{
"name": "box_001",
"type": "ARTICLE-TITLE",
"polygon": [[120, 300], [850, 300], [850, 350], [120, 350]],
"confidence": 0.94,
"text": "LA GAZETTE DU MATIN",
"order": 1
}
]
}
],
"articles": [
{
"name": "1",
"parts": [
{
"name": "box_001",
"type": "ARTICLE-TITLE",
"polygon": [[120, 300], [850, 300], [850, 350], [120, 350]],
"confidence": 0.94,
"text": "LA GAZETTE DU MATIN",
"order": 1
}
]
}
]
}