Last active
September 20, 2020 13:10
-
-
Save khuyentran1401/c458dc52450625783f46134641c00b23 to your computer and use it in GitHub Desktop.
Detect whether a text is English
This file contains hidden or 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
| import spacy | |
| from spacy_langdetect import LanguageDetector | |
| def is_english(text: str) -> bool: | |
| '''Detect whether a text is English | |
| Return True of the text is in English''' | |
| nlp = spacy.load('en') | |
| nlp.add_pipe(LanguageDetector(), name='language_detector', last=True) | |
| return nlp(text)._.language['language'] == 'en' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment