Skip to content

Commit

Permalink
improve conditions for defaulting to 'eng' language detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Coniferish committed Oct 4, 2023
1 parent cd23a01 commit 7c33eda
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion unstructured/partition/lang.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import List

import iso639
Expand Down Expand Up @@ -228,7 +229,8 @@ def detect_languages(
if languages[0] == "":
return [""]

if text.strip() == "" or len(text) < 20:
# Default to "eng" if text is empty or it has only ascii characters and is short
if text.strip() == "" or (re.match(r"^[\x00-\x7F]+$", text) and len(text) < 20):
return ["eng"] # english as default

# set seed for deterministic langdetect outputs
Expand Down

0 comments on commit 7c33eda

Please sign in to comment.