lab_1_classify_profile package
Submodules
Lab 1.
Language detection
- lab_1_classify_profile.main.FreqDictType
Frequency dictionary. Contains pairs of token and its frequency.
- lab_1_classify_profile.main.ProfileType
Language profile of a text. Contains language name, frequency dictionary and number of tokens.
- lab_1_classify_profile.main.calculate_frequencies(tokens)
Calculates frequencies of given tokens
- lab_1_classify_profile.main.calculate_mse(predicted, actual)
Calculates mean squared error between predicted and actual values.
- lab_1_classify_profile.main.check_profile(profile)
Checks profile structure
- Parameters:
profile (ProfileType) – Profile to check
- Returns:
Returns True if the profile has right structure and types, otherwise returns False.
- Return type:
- lab_1_classify_profile.main.collect_profiles(paths_to_profiles)
Collects profiles for a given path.
- Parameters:
paths_to_profiles (Sequence[str]) – Sequence of paths to the profiles
- Returns:
Sequence of loaded profiles. Returns None in case of incorrect input types.
- Return type:
Sequence[ProfileType] | None
- lab_1_classify_profile.main.compare_profiles_by_mse(unknown_profile, profile_to_compare)
Compares two language profiles using the MSE metric.
- Parameters:
unknown_profile (ProfileType) – Unknown profile
profile_to_compare (ProfileType) – Profile to compare the unknown profile with
- Returns:
The distance between the profiles. In case of corrupt input arguments or invalid profile structure, None is returned.
- Return type:
float | None
- lab_1_classify_profile.main.compare_profiles_by_top_n(unknown_profile, profile_to_compare, top_n)
Compares profiles and calculates the distance using top n words
- lab_1_classify_profile.main.create_language_profile(language, text, stop_words)
Creates a language profile
- lab_1_classify_profile.main.detect_language_advanced(unknown_profile, known_profiles, top_n)
Detects the language of an unknown profile.
- Parameters:
unknown_profile (ProfileType) – Profile to determine the language of
known_profiles (Sequence[ProfileType]) – Known profiles
top_n (int) – Number of popular words
- Returns:
Sorted sequence of tuples containing a language and a distance via both metrics. The sequence is sorted by best MSE value, then by best Top-N value. Returns None in case of incorrect input types.
- Return type:
- lab_1_classify_profile.main.detect_language_by_mse(unknown_profile, profile_1, profile_2)
Detects the language of an unknown profile.
- Parameters:
unknown_profile (ProfileType) – Profile to determine the language of
profile_1 (ProfileType) – Known profile
profile_2 (ProfileType) – Another known profile
- Returns:
Unknown profile language. Returns None in case of incorrect input types.
- Return type:
str | None
- lab_1_classify_profile.main.detect_language_by_top_n(unknown_profile, profile_1, profile_2, top_n)
Detects the language of an unknown profile
- Parameters:
unknown_profile (ProfileType) – Unknown profile
profile_1 (ProfileType) – Profile for comparison
profile_2 (ProfileType) – Another profile for comparison
top_n (int) – Number of the most common words
- Returns:
Unknown profile language. Returns None in case of incorrect input types.
- Return type:
str | None
- lab_1_classify_profile.main.get_top_n_words(freq_dict, top_n)
Finds the most common words
- lab_1_classify_profile.main.load_profile(path_to_file)
Loads a language profile.
- Parameters:
path_to_file (str) – Path to the language profile
- Returns:
Loaded profile. Returns None in case of incorrect input types.
- Return type:
ProfileType | None
- lab_1_classify_profile.main.print_report(unknown_profile, metrics_stats, top_n)
Prints report for detection of language.
- Parameters:
- Return type:
None
In case of incorrect type inputs, does not print anything.
- lab_1_classify_profile.main.remove_stop_words(tokens, stop_words)
Removes stop words
- lab_1_classify_profile.main.save_profile(profile, save_path)
Saves a language profile
- lab_1_classify_profile.main.tokenize(text)
Splits a text into tokens, converts the tokens into lowercase, removes punctuation and other symbols from words