Module media_analyzer.filters.language_filter
Expand source code
from langdetect import detect
class LanguageFilter():
"""Filter for filtering content by a language"""
def __init__(self, language="en"):
"""Created a LanguageFilter for given language. Default language is 'en'."""
super().__init__()
self.language = language
@classmethod
def filter(cls, content):
"""Return the language label, return error if can't detect"""
language = None
try:
language = detect(content)
except:
language = "error"
return language
Classes
class LanguageFilter (language='en')
-
Filter for filtering content by a language
Created a LanguageFilter for given language. Default language is 'en'.
Expand source code
class LanguageFilter(): """Filter for filtering content by a language""" def __init__(self, language="en"): """Created a LanguageFilter for given language. Default language is 'en'.""" super().__init__() self.language = language @classmethod def filter(cls, content): """Return the language label, return error if can't detect""" language = None try: language = detect(content) except: language = "error" return language
Static methods
def filter(content)
-
Return the language label, return error if can't detect
Expand source code
@classmethod def filter(cls, content): """Return the language label, return error if can't detect""" language = None try: language = detect(content) except: language = "error" return language