You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No 'category_depth' metadata returned for markdown partitioning? #2675
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'}}
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 :)
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.
@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.
Activity
scanny commentedon Apr 24, 2024
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 :)hranalytics commentedon Jun 27, 2024
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.
scanny commentedon Jun 30, 2024
@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.
rfctr(html): replace html parser (#3218)