<commit_before>import os
import json
from neurovault.apps.statmaps.models import CognitiveAtlasTask,\
    CognitiveAtlasContrast
    
dir = os.path.abspath(os.path.dirname(__file__))

json_content = open(os.path.join(dir, "../neurovault/apps/statmaps/migrations/cognitiveatlas_tasks.json")).read()
json_content = json_content.decode("utf-8").replace('\t', '').replace("&#39;", "'")
data = json.loads(json_content)
CognitiveAtlasTask.objects.all().delete()
CognitiveAtlasContrast.objects.all().delete()
for item in data:
    task = CognitiveAtlasTask(name=item["name"], cog_atlas_id=item["id"])
    task.save()
    for contrast in item["contrasts"]:
        contrast = CognitiveAtlasContrast(name=contrast["conname"], cog_atlas_id=contrast["conid"], task=task)
        contrast.save()<commit_msg>Updated the cog atlas term update script<commit_after>import os
import json
from neurovault.apps.statmaps.models import CognitiveAtlasTask,\
    CognitiveAtlasContrast
    
dir = os.path.abspath(os.path.dirname(__file__))

json_content = open(os.path.join(dir, "../neurovault/apps/statmaps/migrations/cognitiveatlas_tasks.json")).read()
json_content = json_content.decode("utf-8").replace('\t', '').replace("&#39;", "'")
data = json.loads(json_content)
for item in data:
    task, _ = CognitiveAtlasTask.objects.update_or_create(cog_atlas_id=item["id"], defaults={"name":item["name"]})
    task.save()
    for contrast in item["contrasts"]:
        contrast, _ = CognitiveAtlasContrast.objects.update_or_create(cog_atlas_id=contrast["conid"], defaults={"name":contrast["conname"], "task":task})
        contrast.save()
{'fraction_non_alphanumeric': 0.1587104773713577, 'fraction_numerical': 0.0037197768133911966, 'mean_word_length': 5.868085106382979, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, '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': '6603211', 'n_tokens_mistral': 559, 'n_tokens_neox': 535, 'n_words': 79}