Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test_unstructured/cleaners/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,13 @@ def test_clean(text, extra_whitespace, dashes, bullets, lowercase, trailing_punc
def test_bytes_string_to_string():
text = "\xe6\xaf\x8f\xe6\x97\xa5\xe6\x96\xb0\xe9\x97\xbb"
assert core.bytes_string_to_string(text, "utf-8") == "每日新闻"


def test_index_adjustment_maps_cleaned_index_back_to_original():
text = "ITEM 1. BUSINESS"
cleaned, moved_indices = core.clean_extra_whitespace_with_index_run(text)
assert cleaned == "ITEM 1. BUSINESS"
cleaned_index = cleaned.index("B")
original_index = core.index_adjustment_after_clean_extra_whitespace(cleaned_index, moved_indices)
assert text[original_index] == cleaned[cleaned_index] == "B"
assert original_index == 12
2 changes: 1 addition & 1 deletion unstructured/cleaners/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,4 @@ def clean_extra_whitespace_with_index_run(text: str) -> Tuple[str, np.ndarray]:


def index_adjustment_after_clean_extra_whitespace(index, moved_indices) -> int:
return int(index - moved_indices[index])
return int(index + moved_indices[index])