internetarchive / iiif

The official Internet Archive IIIF service
GNU General Public License v3.0
21 stars 4 forks source link

support for OCR text as annotations (v3/v2) #48

Closed saracarl closed 1 month ago

saracarl commented 6 months ago

<moved from https://github.com/ArchiveLabs/iiif.archivelab.org/issues/80 I'd recommend reading that one for the whole discussion, but I pulled most of the comments in here.>

OCR text created by the derivation process can be exposed as annotations for books and image-based media, enabling presentation and consumption of the text by IIIF clients.

saracarl commented 6 months ago

Q: Where should the @context live in the manifest, now that we've embedded the annotation pages within the manifest?

A: At the top of the manifest, along with the IIIF presentation API context. NB: the IIIF presentation API @context statement should be last, since it overrides other values.

Q: Should these plaintext representations of a page of text be in a rendering element within the canvas, or in an annotation targeting the full canvas?

A: Philosophically speaking, rendering is probably better. However, from a UI perspective, viewers are likely to present it to the user as a downloadable link (as one would with a PDF file). That behavior is probably not desired for some OCR -- for example when a user cannot read Fraktur typefaces, and wants to read the text of the page alongside the facsimile.

Current plan is to implement it in one direction and test in viewers.

saracarl commented 6 months ago

Note from 9/7/2023: We should place the text granularity context after the IIIF presentation context in the v2 manifest, but before it in the v3 manifest.

saracarl commented 6 months ago

This is Johannes OCR viewer: https://mirador-textoverlay.netlify.app/ (To test with)

saracarl commented 6 months ago

When we drop this manifest: https://gist.githubusercontent.com/benwbrum/e7e2fb9962a6aaba2cc0d6ae8f1b6d98/raw/df2598dd8a67ef941c2e03fa07dbe9485f736a9c/ia_ocr_annotation_mockup_v2.json Into Mirador, the annotations don't show up.

Here's how the OCR text annotation is modeled in the manifest:

"otherContent": [
   {
      "@id": "https://iiif.archivelab.org/iiif/rbmsbk_ap2-v4_2001_V55N4$9/ocr",
      "@type": "sc:AnnotationList",
      "label": "OCR Text",
      "resources": [
         {
            "@type": "oa:Annotation",
            "motivation": "sc:painting",
            "textGranularity": "page",
            "on": "https://iiif.archivelab.org/iiif/books/rbmsbk_ap2-v4_2001_V55N4$9/canvas",
            "resource": {
               "@id": "https://api.archivelab.org/books/rbmsbk_ap2-v4_2001_V55N4/pages/9/plaintext",
               "@type": "dctypes:Text",
               "format": "text/plain"
            }
         }
      ]
   }
]

Any idea why not?

saracarl commented 6 months ago

The gist is a v2 manifest; therefore the annotations need to be "seeAlso" or "rendering" (more correctly rendering, but seeAlso is likely better supported.)

The annotation seems right for v3; at least it matches the recipe. Where to test?? Maybe Johannes' mirador that takes hOCR or Alto would show it? Or perhaps it won't because it's just text?

saracarl commented 6 months ago

As mentioned I think this is syntacticlly correct and matches the recipe:

https://iiif.io/api/cookbook/recipe/0068-newspaper/

but in v2 its probably seeAlso or rendering

glenrobson commented 4 months ago

Ben to look at creating a mock up for v3 manifest.

saracarl commented 4 months ago

The problem @benwbrum ran into is a limitation of the viewers: the OCR text can be in AnnotationPages which are external to the manifest, linked in the id property of the Annotation within the AnnotationPage. The motivation should be supplementing, following the second use case in https://iiif.io/api/cookbook/recipe/0231-transcript-meta-recipe/

To get over viewer problems making to hops (Manifest->AnnotiationPage->OCR URI), we will try these strategies (Glen is adding that below)

glenrobson commented 4 months ago

Two options:

  1. Bring the external annotation into the Manifest
  2. Mike can write a annotation page endpoint which will generate a annotationPage with the text content retrieved from the file.
glenrobson commented 3 months ago

Maybe able to use the service mentioned in: https://github.com/internetarchive/iiif/issues/21

glenrobson commented 3 months ago

Can also just copy and paste the code from:

https://github.com/ArchiveLabs/api.archivelab.org/blob/082c29bace2149d9c02d6b490d006fa27de0b447/server/api/archive.py#L240

Which uses the archive infrasturcure.

Example with djvu: https://archive.org/details/journalofexpedit00ford

glenrobson commented 3 months ago

Example: https://ia801302.us.archive.org/fulltext/inside.php?item_id=journalofexpedit00ford&doc=journalofexpedit00ford&path=/31/items/journalofexpedit00ford&q=ford

glenrobson commented 3 months ago

Fulltext not so great as requires a search term.

glenrobson commented 3 months ago

Action findout what parameters are avilaible for BookReaderGetTextWrapper.php service.

benwbrum commented 2 months ago

Since all of our handy helper functions rely on the archivelabs services, it looks like the best option is to produce annotations from the DjVu XML file itself. This can be done (probably most easily) at word-level granularity.

Next step is to pseudocode the conversion from DjVu XML file representing multiple canvases into a set of annotations per canvas.

FromThePage code that converts IA DjVu into canvas-specific text:

benwbrum commented 2 months ago

To produce the leaf-level annotations for canvas https://iiif.archive.org/iiif/journalofexpedit00ford$4/canvas of https://iiif.archive.org/iiif/3/journalofexpedit00ford/manifest.json (with the page number/canvas label of 5),

To produce page-level annotations without coordinate values,

To produce paragraph-level or line-level annotations, follow the page-level annotation strategy for the appropriate PARAGRAPH or LINE element, but find the minimum/maximum coordinates from the WORD elements to generate a line/paragraph region fragment.

benwbrum commented 1 month ago

It looks like DJVU coordinates are lower-left x,y; upper right x,y!

benwbrum commented 1 month ago
<LINE>
<WORD coords="444,1353,635,1294" x-confidence="10">[David </WORD>
<WORD coords="635,1336,782,1294" x-confidence="7">Ford </WORD>
<WORD coords="782,1335,894,1305" x-confidence="2">was </WORD>
<WORD coords="894,1335,941,1305" x-confidence="10">a </WORD>
<WORD coords="941,1335,1112,1292" x-confidence="31">native </WORD>

Converting these into IIIF-style upper-left x,y; w,h wil ltake some calculations

glenrobson commented 1 month ago
<WORD coords="444,1353,635,1294" x-confidence="10">[David </WORD>
<WORD coords="lx,by,rx,ty" x-confidence="10">[David </WORD>

x = lx y = ty w = rx - lx h = by - ty