Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

### Enhancements

- Speed up function `under_non_alpha_ratio` by 76% (codeflash)

### Features

### Fixes

- **change short text language detection log to debug** reduce warning level log spamming


## 0.18.13

### Enhancements
Expand Down
12 changes: 9 additions & 3 deletions unstructured/partition/text_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,17 @@ def under_non_alpha_ratio(text: str, threshold: float = 0.5):
If the proportion of non-alpha characters exceeds this threshold, the function
returns False
"""
if len(text) == 0:
if not text:
return False

alpha_count = len([char for char in text if char.strip() and char.isalpha()])
total_count = len([char for char in text if char.strip()])
alpha_count = 0
total_count = 0
for char in text:
if not char.isspace():
total_count += 1
if char.isalpha():
alpha_count += 1

return ((alpha_count / total_count) < threshold) if total_count > 0 else False


Expand Down