Skip to content

No 'category_depth' metadata returned for markdown partitioning? #2675

Closed

Description

@rafaelvanbelle

I tried to use the partition function on a markdown document. I would like to know for each element what the category_depth is.
Markdown has several heading levels (h1, h2, etc), thus I assumed this depth would be in the element metadata. This does not seem to be the case.

When looking at the source code for the function partition_md, I see that the markdown text is converted to html with the markdown library. In the small example below I apply both partition_md and partition_html on the original and converted markdown respectively.

When applying partition_md directly, no category_depth is returned, when first converting to html and applying partition_html then the category_depth appears in element metadata.

How is this possible? Internally partition_md calls partition_html, so why does the category_depth metadata get lost? I cannot find the piece of code in partition_md that is causing this behavior.

All help is greatly appreciated! :)

Example:

from unstructured.partition.auto import partition_md, partition_html
import markdown

markdown_text = """
# Title

Some text

## Heading 1

more text 

- a 
- b 
- c

""" 

### partition_md ###

elements = partition_md(text=markdown_text) 

print(elements[0].to_dict())
# Result: {'type': 'Title', 'element_id': '7e8cd2056da73a7fefb6cd91f4e5d199', 'text': 'Title', 'metadata': {'page_number': 1, 'languages': ['eng'], 'filetype': 'text/markdown'}}

### partition_html ###

# the function partition_md calls partition_html after transforming markdown to html. 
html_text = markdown.markdown(markdown_text)

# Apply partition_html
elements = partition_html(text=html_text)

print(elements[0].to_dict())
# Result: {'type': 'Title', 'element_id': '7e8cd2056da73a7fefb6cd91f4e5d199', 'text': 'Title', 'metadata': {'category_depth': 0, 'page_number': 1, 'languages': ['eng'], 'filetype': 'text/html'}}

Activity

  1. added
    markdown
    on Mar 20, 2024
  2. added
    enhancement
    on Apr 24, 2024
  3. scanny commented on Apr 24, 2024

    @scanny
    Contributor

    Hi @rafaelvanbelle, document hierarchy metadata (e.g. category-depth) is not yet supported for Markdown. I'll leave this issue open as an enhancement request :)

  4. hranalytics commented on Jun 27, 2024

    @hranalytics

    hello, is document hierarchy metadata (e.g. category-depth) supported for PDF at the moment? I tried it with a document using the "partition_pdf" function and it won't return the category-depth metadata.

  5. scanny commented on Jun 30, 2024

    @scanny
    Contributor

    @rafaelvanbelle, apologies, my mistake, hierarchy metadata is supported for Markdown. Actually not directly, but because partition_md() converts the MD document to HTML, and the HTML partitioner supports hierarchy metadata, Markdown gets it too.

    I believe the gap you mentioned is resolved by #3218. I can't point you to exactly what changed produced the fix, but the Markdown you provided produces elements with document hierarchy metadata.

  6. added a commit that references this issue on Jul 11, 2024
    c27e0d0
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

    enhancementmarkdown

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions