<commit_before><commit_msg>Add script to remodel musicMedium to a structured value<commit_after>MUSICMEDIUM_TYPE = 'MusicMedium'
MUSICMEDIUM_PROPERTY = 'musicMedium'


boolean remodelToStructuredValue(term) {
    def remodelledTerm = []

    //Create musicMedium object and add to list
    term[MUSICMEDIUM_PROPERTY].each {
        def map = [:]
        map << ['@type':MUSICMEDIUM_TYPE]
        map << ['label':it]
        remodelledTerm << map
    }
    term[MUSICMEDIUM_PROPERTY] = remodelledTerm
    return true

}

void findAndFixValuesInData(data, obj) {
    if (obj instanceof List) {
        obj.each {
            findAndFixValuesInData(data, it)
        }
    }
    else if (obj instanceof Map) {
        obj.each { key, value ->
            checkValueInData(data, obj, key, value)
        }
    }
}

void checkValueInData(data, container, key, value) {

    if (key == MUSICMEDIUM_PROPERTY) {
        if (remodelToStructuredValue(container))
            data.scheduleSave(false)
    }
    else {
        findAndFixValuesInData(data, value)
    }
}


selectBySqlWhere('''
        data::text LIKE '%"musicMedium"%'
        ''') { data ->

    // guard against missing entity
    if (data.graph.size() < 2) {
        return
    }

    // Skipping record
    data.graph[1..-1].each {
        findAndFixValuesInData(data, it)
    }
}
{'fraction_non_alphanumeric': 0.11202389843166542, 'fraction_numerical': 0.0022404779686333084, 'mean_word_length': 2.4271099744245523, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 5, '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': '4434221', 'n_tokens_mistral': 445, 'n_tokens_neox': 434, 'n_words': 90}