Class Alto
Reads and writes ALTO (Analyzed Layout and Text Object), the XML format of library digitization that ABBYY, Tesseract and
Transkribus write: pages (Page), lines (TextLine) and words (String) with their positions, WC
confidence and LANG.
public static class Alto
- Inheritance
-
Alto
- Inherited Members
Examples
// ALTO from ABBYY, Tesseract or a library's digitization: positions in 1/10 mm or 1/1200 inch become pixels at Dpi.
IReadOnlyList<OcrResult> pages = Alto.Parse(File.ReadAllText("page.xml"), new OcrReadOptions { Dpi = 300 });
Console.WriteLine($"{pages[0].ImageSize}: {pages[0].Text}");
// Turn it into hOCR, or write ALTO 4 in pixels.
using FileStream hocr = File.Create("page.hocr");
Hocr.Write(hocr, pages);
using FileStream alto = File.Create("page-v4.xml");
Alto.Write(alto, pages);
Remarks
The reader takes ALTO 1 to 4 by element names, in any namespace. Positions in 1/10 mm or 1/1200 inch become pixels at
Dpi. A HYP hyphen joins the word before it. No DTD or schema is ever fetched. The
writer writes ALTO 4 in pixels.
Methods
Parse(string, OcrReadOptions?)
Reads every page of ALTO text.
public static IReadOnlyList<OcrResult> Parse(string alto, OcrReadOptions? options = null)
Parameters
altostringThe ALTO document.
optionsOcrReadOptionsThe limits and the resolution for physical units, or null for Default.
Returns
- IReadOnlyList<OcrResult>
One result per
Page, in document order.
Examples
// ALTO from ABBYY, Tesseract or a library's digitization: positions in 1/10 mm or 1/1200 inch become pixels at Dpi.
IReadOnlyList<OcrResult> pages = Alto.Parse(File.ReadAllText("page.xml"), new OcrReadOptions { Dpi = 300 });
Console.WriteLine($"{pages[0].ImageSize}: {pages[0].Text}");
// Turn it into hOCR, or write ALTO 4 in pixels.
using FileStream hocr = File.Create("page.hocr");
Hocr.Write(hocr, pages);
using FileStream alto = File.Create("page-v4.xml");
Alto.Write(alto, pages);
Exceptions
- ArgumentNullException
altois null.- CorruptDataException
The text is not well-formed XML, or has no
altoroot element.- LimitExceededException
The text breaks a limit of
options.
Read(Stream, OcrReadOptions?)
Reads every page of an ALTO file.
public static IReadOnlyList<OcrResult> Read(Stream stream, OcrReadOptions? options = null)
Parameters
streamStreamThe file, from its current position. It is left open.
optionsOcrReadOptionsThe limits and the resolution for physical units, or null for Default.
Returns
- IReadOnlyList<OcrResult>
One result per
Page, in file order.
Examples
// ALTO from ABBYY, Tesseract or a library's digitization: positions in 1/10 mm or 1/1200 inch become pixels at Dpi.
IReadOnlyList<OcrResult> pages = Alto.Parse(File.ReadAllText("page.xml"), new OcrReadOptions { Dpi = 300 });
Console.WriteLine($"{pages[0].ImageSize}: {pages[0].Text}");
// Turn it into hOCR, or write ALTO 4 in pixels.
using FileStream hocr = File.Create("page.hocr");
Hocr.Write(hocr, pages);
using FileStream alto = File.Create("page-v4.xml");
Alto.Write(alto, pages);
Exceptions
- ArgumentNullException
streamis null.- CorruptDataException
The file is not well-formed XML, or has no
altoroot element.- LimitExceededException
The file breaks a limit of
options.
Write(Stream, IEnumerable<OcrResult>)
Writes pages as an ALTO 4 document in UTF-8, in pixels, one Page per result.
public static void Write(Stream stream, IEnumerable<OcrResult> pages)
Parameters
streamStreamWhere to write, from its current position. It is left open.
pagesIEnumerable<OcrResult>The pages.
Examples
// ALTO from ABBYY, Tesseract or a library's digitization: positions in 1/10 mm or 1/1200 inch become pixels at Dpi.
IReadOnlyList<OcrResult> pages = Alto.Parse(File.ReadAllText("page.xml"), new OcrReadOptions { Dpi = 300 });
Console.WriteLine($"{pages[0].ImageSize}: {pages[0].Text}");
// Turn it into hOCR, or write ALTO 4 in pixels.
using FileStream hocr = File.Create("page.hocr");
Hocr.Write(hocr, pages);
using FileStream alto = File.Create("page-v4.xml");
Alto.Write(alto, pages);
Exceptions
- ArgumentNullException
streamorpagesis null.