Polyglot Language Code Matching Function

  • Share this:

Code introduction


This function uses the Detector class from the Polyglot library to detect the language code of a text and checks if the detected language code matches the given one.


Technology Stack : Polyglot, Detector

Code Type : Function

Code Difficulty : Intermediate


                
                    
def polyglot_random_language检测(arg1, arg2):
    import polyglot
    from polyglot.detect import Detector

    text = arg1
    language_code = arg2

    detector = Detector(text)
    detected_language = detector.language.code

    return detected_language == language_code