-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
192 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test_unstructured/documents/html_files/example_with_alternative_text.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<body class="Document" id="897a8a47377c4ad6aab839a929879537"> | ||
<div class="Page" data-page-number="1" id="3a6b156a81764e17be128264241f8136"> | ||
<header class="Header" id="6135aeb6-9558-46e2-9da4-473a74db3e9d"> | ||
<img alt="New York logo" class="Logo" id="33d66969-b274-4f88-abaa-e7f258b1595f"/> | ||
<img alt="A line graph showing the comparison of 5 year cumulative total return for stocks" class="Image" id="40c32fd8-9a02-42b8-a587-884293881090"/> | ||
</header> | ||
</div> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
test_unstructured/documents/unstructured_json_output/example_with_alternative_text.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[ | ||
{ | ||
"element_id": "3a6b156a81764e17be128264241f8136", | ||
"metadata": { | ||
"category_depth": 0, | ||
"filetype": "text/html", | ||
"languages": [ | ||
"eng" | ||
], | ||
"page_number": 1, | ||
"parent_id": "897a8a47377c4ad6aab839a929879537", | ||
"text_as_html": "<div class=\"Page\" data-page-number=\"1\" id=\"3a6b156a81764e17be128264241f8136\" />" | ||
}, | ||
"text": "", | ||
"type": "UncategorizedText" | ||
}, | ||
{ | ||
"element_id": "6135aeb6-9558-46e2-9da4-473a74db3e9d", | ||
"metadata": { | ||
"category_depth": 1, | ||
"filetype": "text/html", | ||
"languages": [ | ||
"eng" | ||
], | ||
"page_number": 1, | ||
"parent_id": "3a6b156a81764e17be128264241f8136", | ||
"text_as_html": "<header class=\"Header\" id=\"6135aeb6-9558-46e2-9da4-473a74db3e9d\" />" | ||
}, | ||
"text": "", | ||
"type": "UncategorizedText" | ||
}, | ||
{ | ||
"element_id": "33d66969-b274-4f88-abaa-e7f258b1595f", | ||
"metadata": { | ||
"category_depth": 2, | ||
"filetype": "text/html", | ||
"languages": [ | ||
"eng" | ||
], | ||
"page_number": 1, | ||
"parent_id": "6135aeb6-9558-46e2-9da4-473a74db3e9d", | ||
"text_as_html": "<img class=\"Logo\" alt=\"New York logo\" id=\"33d66969-b274-4f88-abaa-e7f258b1595f\" />" | ||
}, | ||
"text": "New York logo", | ||
"type": "Image" | ||
}, | ||
{ | ||
"element_id": "40c32fd8-9a02-42b8-a587-884293881090", | ||
"metadata": { | ||
"category_depth": 2, | ||
"filetype": "text/html", | ||
"languages": [ | ||
"eng" | ||
], | ||
"page_number": 1, | ||
"parent_id": "6135aeb6-9558-46e2-9da4-473a74db3e9d", | ||
"text_as_html": "<img class=\"Image\" alt=\"A line graph showing the comparison of 5 year cumulative total return for stocks\" id=\"40c32fd8-9a02-42b8-a587-884293881090\" />" | ||
}, | ||
"text": "A line graph showing the comparison of 5 year cumulative total return for stocks", | ||
"type": "Image" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from unstructured.partition.html import partition_html | ||
|
||
|
||
def test_alternative_image_text_can_be_included(): | ||
# language=HTML | ||
html = """ | ||
<div class="Page"> | ||
<img src="my-logo.png" alt="ALT TEXT Logo"/> | ||
</div> | ||
""" | ||
_, image_to_text_alt_mode = partition_html( | ||
text=html, | ||
image_alt_mode="to_text", | ||
html_parser_version="v2", | ||
) | ||
assert "ALT TEXT Logo" in image_to_text_alt_mode.text | ||
|
||
_, image_none_alt_mode = partition_html( | ||
text=html, | ||
image_alt_mode=None, | ||
html_parser_version="v2", | ||
) | ||
assert "ALT TEXT Logo" not in image_none_alt_mode.text | ||
|
||
|
||
def test_alternative_image_text_can_be_included_when_nested_in_paragraph(): | ||
# language=HTML | ||
html = """ | ||
<div class="Page"> | ||
<p class="Paragraph"> | ||
<img src="my-logo.png" alt="ALT TEXT Logo"/> | ||
</p> | ||
</div> | ||
""" | ||
_, paragraph_to_text_alt_mode = partition_html( | ||
text=html, | ||
image_alt_mode="to_text", | ||
html_parser_version="v2", | ||
) | ||
assert "ALT TEXT Logo" in paragraph_to_text_alt_mode.text | ||
|
||
_, paragraph_none_alt_mode = partition_html( | ||
text=html, | ||
image_alt_mode=None, | ||
html_parser_version="v2", | ||
) | ||
assert "ALT TEXT Logo" not in paragraph_none_alt_mode.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.16.6" # pragma: no cover | ||
__version__ = "0.16.7" # pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters