gradio-ttw-api / gradio_ttw_api /detect_chinese.py
freemt
Merge
94e5748
raw
history blame contribute delete
511 Bytes
"""Detcet chinese.
True if containing any of [一-﨩]
'\u4e00' <= char <= '\u9fff', False otherwise
"""
def detect_chinese(text):
"""Detcet chinese.
Args:
text: string
True if containing any of [一-﨩], False otherwise
'\u4e00' <= char <= '\u9fff', False otherwise
if punctuation needs to be considered:
from zhon.hanzi import punctuation
'\u4e00' <= char <= '\u9fff' or char in punctuation
"""
return any("\u4e00" <= char <= "\u9fff" for char in str(text))