#!/bin/sh

echo "###Script for calculating graph stats###"

folder=$PWD
for entry in "$folder"/*
do
  #echo "Processing: $entry"
	file_name=$(basename $entry)
	FILE="$entry"/edgefile_sorted.tsv
	if [ -f "$FILE" ]; then
		pr="$entry"/pagerank.undirected.summary.txt
		if [ ! -f "$pr" ]; then
	    echo "Processing $FILE"
			# Touch file so we can run the script without overlap in pageranks
			touch "$entry"/pagerank.undirected.summary.txt
			kgtk query --debug --graph-cache /wikidata.sqlite3.db -i "$entry"/edgefile_sorted.tsv -i datatypes.tsv -o "$entry"/claims.wikibase-item.tsv.gz \
 --match 'edgefile_sorted: (n1)-[l {label: p}]->(n2), datatypes: (p)-[:datatype]->(:`wikibase-item`)' \
 --return 'l as id, n1 as node1, p as label, n2 as node2' \
 --order-by 'l'
 
 
			kgtk graph-statistics -i "$entry"/claims.wikibase-item.tsv.gz -o "$entry"/pagerank.undirected.tsv.gz \
    --page-rank-property undirected_pagerank \
    --pagerank --statistics-only --hits\
    --log "$entry"/pagerank.undirected.summary.txt --print-top-n 100
    
			rm /wikidata.sqlite3.db
		fi
	fi
done


