#!/bin/sh

echo "Starting script for importing dumps"
echo "Reading dumps to process from dumps_to_import.txt"
while read -r line ; do
    # Initialize folder, unpack and sort. $line has the full path
		echo "Processing file: $line"
    folder_new_name=$(echo "$line" | grep -oP 'wikidata-\K[^-]+')
    echo "Name of folder: $folder_new_name"
		
		# Create dir (if it not exists already)
		mkdir $folder_new_name
		kgtk import-wikidata -i $line --node "$folder_new_name"/nodefile.tsv --edge "$folder_new_name"/edgefile.tsv --qual "$folder_new_name"/qualfile.tsv   
		kgtk sort -i "$folder_new_name"/edgefile.tsv -c 'id' -o "$folder_new_name"/edgefile_sorted.tsv
		# Remove edge file (to save a little space)
#		rm "$folder_new_name"/edgefile.tsv
done < dumps_to_import.txt
#dumps_to_import.txt
echo "COMPLETED. Now execute calculate_deltas.sh to calculate deltas"
