#
# Investigate the CD-5 index of Dan Tawfik's works
#

export MAINDB?=tawfik

export DEPENDENCIES=populate

include ../common/Makefile

populate: $(CROSSREF_DIR) tawfik-works.db
	$(TIME) alexandria3k --data-source Crossref "$(CROSSREF_DIR)" \
	  --populate "$(MAINDB).db" \
	  --debug progress \
	  --attach-databases 'tw:tawfik-works.db' \
	  --columns works.id \
	    works.doi \
	    works.published_year \
	    works.issn_print \
	  --row-selection 'EXISTS (SELECT 1 FROM tw.tawfik_works WHERE works.issn_print = tawfik_works.issn_print AND works.published_year = Cast(tawfik_works.published_year AS integer))'
	touch $@

# Rough approximation of D. Tawfik's works for hand-cleaning
reports/tawfik-works.txt: $(CROSSREF_DIR)
	mkdir -p reports
	$(TIME) alexandria3k --data-source Crossref $(CROSSREF_DIR) \
	  --partition --query-file tawfik-works.sql >$@

# The text file is generated by hand by cleaning the corresponding report
tawfik-works.db: tawfik-works.txt tawfik_works.sql
	rm -f $@
	sqlite3 $@ <tawfik_works.sql
