# /bin/bash

# This script retrieves the statements that correspond to time qualifiers by exploring when they were added.
# As a result, for each delta, it produces a file with the statements that had time qualifiers added later, with their date
# We do it by doing a query over the joined time qualifiers and the delta, one at a time.
# The joined file only contains qualifiers added over late 2019 and 2020, so this will calculate the number of 
# statements wchich had qualifiers added in 2020.


folder=deltas
joined_file_path=deltas_qual_temporal/joined.tsv
for entry in "$folder"/*
do
  echo "Processing: $entry"
  echo "Calculating qualifiers added in delta"
  prev="$entry"/statements_with_added_quals.tsv
  if ! [ -f "$prev" ]; then
		kgtk query --debug --graph-cache /wikidata.sqlite3.db -i "$entry"/added.tsv -i $joined_file_path --match 'added:(a)-[n]->(b), joined:(n1)-[]->(d)' --where 'n1=n' --return 'n,a as `node1`,n.label,d.date as `qual_added_on`' -o "$entry"/statements_with_added_quals.tsv
  rm /wikidata.sqlite3.db
	fi
done
