<commit_before>import Foundation

/**
Class that gets dictionary of translations and turn it into `LoadedTranslation`s.
*/
final class TranslationsLoader {
    
    /**
    Converts dictionary into array of `LoadedTranslation`s.
    
    :params: dictionary A dictionary with content of file which contains 
        translations.
    :returns: Array of `LoadedTranslation` objects from specified file.
    */
    class func loadTranslations(json: Dictionary<String, AnyObject>) -> [LoadedTranslation] {
        var loadedTranslations = [LoadedTranslation]()
        for (key, value) in json {
            if value is String {
                loadedTranslations.append(LoadedTranslation(type: .Simple, key: key, content: [key: value]))
            } else {
                let dictionary = value as! JSONDictionary
                if let type = detectElementType(dictionary) {
                    loadedTranslations.append(LoadedTranslation(type: type, key: key, content: dictionary))
                } else {
                    print("Translation type is not supported for: \(dictionary)")
                }
            }
        }
        
        return loadedTranslations
    }
    
    /**
    Analyzes passed dictionary and checks its content to match it to some translation type.
    
    :params: element A dictionary that will be analyzed.
    :returns: translation type of a dictionary.
    */
    private class func detectElementType(element: JSONDictionary) -> LoadedTranslationType? {
        // Method counts dicts and strings occurences and return proper type.
        var dicts = 0
        var strings = 0
        
        // Count every string or dict occurence.
        for (_, value) in element {
            if value is String {
                strings++
            } else if value is Dictionary<String, AnyObject> {
                dicts++
            }
        }
        
        /*
        If there is only string then check if the keys are length variations or
        contain some expressions. IF there is some dict and some strings (or no
        strings) then mark it as expressions with length variations.
        */
        if strings > 0 && dicts == 0 {
            let key = element.keys.first!
            let toIndex = key.startIndex.advancedBy(1)
            return key.substringToIndex(toIndex) == "@" ? .WithLengthVariations : .WithExpressions
        } else if strings >= 0 && dicts > 0 {
            return .WithExpressionsAndLengthVariations
        }<commit_msg>Suppresed few warnings<commit_after>import Foundation

/**
Class that gets dictionary of translations and turn it into `LoadedTranslation`s.
*/
final class TranslationsLoader {
    
    /**
    Converts dictionary into array of `LoadedTranslation`s.
    
    :params: dictionary A dictionary with content of file which contains 
        translations.
    :returns: Array of `LoadedTranslation` objects from specified file.
    */
    class func loadTranslations(json: Dictionary<String, AnyObject>) -> [LoadedTranslation] {
        var loadedTranslations = [LoadedTranslation]()
        for (key, value) in json {
            if value is String {
                loadedTranslations.append(LoadedTranslation(type: .Simple, key: key, content: [key: value]))
            } else {
                let dictionary = value as! JSONDictionary
                if let type = detectElementType(dictionary) {
                    loadedTranslations.append(LoadedTranslation(type: type, key: key, content: dictionary))
                } else {
                    print("Translation type is not supported for: \(dictionary)")
                }
            }
        }
        
        return loadedTranslations
    }
    
    /**
    Analyzes passed dictionary and checks its content to match it to some translation type.
    
    :params: element A dictionary that will be analyzed.
    :returns: translation type of a dictionary.
    */
    private class func detectElementType(element: JSONDictionary) -> LoadedTranslationType? {
        // Method counts dicts and strings occurences and return proper type.
        var dicts = 0
        var strings = 0
        
        // Count every string or dict occurence.
        for (_, value) in element {
            if value is String {
                strings += 1
            } else if value is Dictionary<String, AnyObject> {
                dicts += 1
            }
        }
        
        /*
        If there is only string then check if the keys are length variations or
        contain some expressions. IF there is some dict and some strings (or no
        strings) then mark it as expressions with length variations.
        */
        if strings > 0 && dicts == 0 {
            let key = element.keys.first!
            let toIndex = key.startIndex.advancedBy(1)
            return key.substringToIndex(toIndex) == "@" ? .WithLengthVariations : .WithExpressions
        } else if strings >= 0 && dicts > 0 {
            return .WithExpressionsAndLengthVariations
        }
{'fraction_non_alphanumeric': 0.072495518820952, 'fraction_numerical': 0.003186616211909978, 'mean_word_length': 1.9839572192513368, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5383964', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1177, 'n_words': 450}