Skip to content

feat: capture images/figures #3606

Description

@joelgwebber

Describe the bug
Perhaps on the cusp between bug and feature. When parsing html pages, I found it surprising that any sub-tree wrapped in a <figure> is silently removed in partition_html(). Common cases include just about every Wikipedia article, which often contain useful image urls and text descriptions in <figure>s.

I haven't dug in much further, but from a quick examination of the code, it looks like this may extend to other less-common element types.

To Reproduce

from unstructured.partition.html import partition_html

elems = partition_html(url="https://en.wikipedia.org/wiki/Neo-Riemannian_theory")
def find(text: str):
    for elem in elems:
        if elem.text.find(text) >= 0:
            print("found it:\n", elem)
            return
    print("nope")

find("loose collection of ideas") # finds this in the initial paragraph
find("minor as upside down major") # can't find this because it's buried in a figure

Expected behavior
That the <figure> contents would either be found by default, or with an option controlling which elements to skip.

Environment Info
I don't have a local build going yet, but I promise it's a trivial repro in any environment.

Activity

  1. scanny commented on Sep 10, 2024

    @scanny
    Contributor

    @joelgwebber this behavior is as designed, so not a bug per se.

    <figure> is classified as a "removed block" for HTML parsing purposes:
    https://github.com/Unstructured-IO/unstructured/blob/main/unstructured/partition/html/parser.py#L986
    https://github.com/Unstructured-IO/unstructured/blob/main/unstructured/partition/html/parser.py#L517

    We don't currently capture image URLs, although that is something that I've seen requested. There's some question as to how to represent those in the element-stream and metadata, so you might want to weigh in on that. I suppose I'm inclined for them to become Image elements, then the link could go in the metadata as .metadata.image_url and any caption we could detect could go into Image.text. The same behavior would be applied to <img> elements.

  2. added
    enhancementNew feature or request
    and removed
    bugSomething isn't working
    on Sep 10, 2024
  3. changed the title [-]bug/skipping-figures[/-] [+]feat: capture images/figures[/+] on Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions