Did I find the right examples for you? yes no

All Samples(14)  |  Call(12)  |  Derive(0)  |  Import(2)
Detects the language from the value given based on ranges defined in active language packs.

:param unicode value: Input string.
:param int num_words: Number of words to base decision on.
:param bool fail_silently:
:param bool heavy_check: If given, heavy checks would be applied when simple checks
    don't give any results. Heavy checks are language specific and do not apply
    to a common logic. Heavy language detection is defined in the ``detect``
    method of each language pack.
:return str: Language code.

        def detect_language(text, num_words=None, fail_silently=True, heavy_check=False):
    """
    Detects the language from the value given based on ranges defined in active language packs.

    :param unicode value: Input string.
    :param int num_words: Number of words to base decision on.
    :param bool fail_silently:
    :param bool heavy_check: If given, heavy checks would be applied when simple checks
        don't give any results. Heavy checks are language specific and do not apply
        to a common logic. Heavy language detection is defined in the ``detect``
        method of each language pack.
    :return str: Language code.
    """
    ensure_autodiscover()

    if num_words is None:
        num_words = get_setting('LANGUAGE_DETECTION_MAX_NUM_KEYWORDS')

    most_common_words = extract_most_common_words(text, num_words=num_words)

    counter = Counter()

    available_language_packs = get_available_language_packs()

    for word, occurrencies in most_common_words:
        for letter in word:
            for language_pack in available_language_packs:
                if language_pack.detectable and language_pack.contains(letter):
                    counter[language_pack.language_code] += 1
                    continue
    try:
        return counter.most_common(1)[0][0]
    except Exception as e:
        if get_setting('DEBUG'):
            logger.debug(str(e))

    if not fail_silently:
        raise LanguageDetectionError(_("""Can't detect language for the text "%s" given.""") % text)
        


src/t/r/transliterate-1.6/src/transliterate/test.py   transliterate(Download)
from transliterate import defaults
#from transliterate.utils import get_available_language_codes, translit, detect_language, slugify
from transliterate import get_available_language_codes, translit, detect_language, slugify
#from transliterate.utils import get_available_language_packs
from transliterate import get_available_language_packs
    def test_21_language_detection_armenian(self):
        """
        Testing language detection. Detecting Amenian.
        """
        res = detect_language(self.armenian_text)
    def test_22_language_detection_georgian(self):
        """
        Testing language detection. Detecting Georgian.
        """
        res = detect_language(self.georgian_text)
        """
        #set_setting('DEBUG', True)
        res = detect_language(self.greek_text)
        #reset_to_defaults_settings()
        self.assertEqual(res, 'el')
    def __test_24_language_detection_hebrew(self):
        """
        Testing language detection. Detecting Hebrew.
        """
        res = detect_language(self.hebrew_text)

src/t/r/transliterate-HEAD/src/transliterate/test.py   transliterate(Download)
from transliterate import defaults
#from transliterate.utils import get_available_language_codes, translit, detect_language, slugify
from transliterate import get_available_language_codes, translit, detect_language, slugify
#from transliterate.utils import get_available_language_packs
from transliterate import get_available_language_packs
    def test_21_language_detection_armenian(self):
        """
        Testing language detection. Detecting Amenian.
        """
        res = detect_language(self.armenian_text)
    def test_22_language_detection_georgian(self):
        """
        Testing language detection. Detecting Georgian.
        """
        res = detect_language(self.georgian_text)
        """
        #set_setting('DEBUG', True)
        res = detect_language(self.greek_text)
        #reset_to_defaults_settings()
        self.assertEqual(res, 'el')
    def __test_24_language_detection_hebrew(self):
        """
        Testing language detection. Detecting Hebrew.
        """
        res = detect_language(self.hebrew_text)