
TMP ?= /tmp

vpath %.lst $(TMP)

%.fst2: %.grf
	Grf2Fst2 $<
	# Flattening fst2 because of a bug in Fst2List
	Flatten $@ FST

%.lst: %.fst2
	Fst2List -t s -o $(TMP)/$@ $<

%.bin: %.dic
	CheckDic $< DELAF
	Compress $<

%.dic: %.lst
	# mv $< $@
	# because Fst2List does not consider variables, we have to insert the lemmata "by hand":
	recode u6..u8 < $< | perl -pe 's/^STEM(.+)STEM(.*),\$$STEM/$$1$$2,$$1/; s/STEM//g;' | recode u8..u6/21 > $@

all: num.bin # numcard.bin

# The intermediate plain text dictionary will be in the size of approx. 26 GB,
# By this way we can downsize it to 5 GB:
fake: num.fst2
	# replace lemmatization information by variable A..Z
	cat $< | fake_dict.pl > num2.fst2
	# expand this to a 5 GB DELAF-dictionary
	Fst2List -t s -o $(TMP)/num2.lst num2.fst2
	# compressing this requires a 64bit platform with at least 8 GB memory!
	Compress $(TMP)/num2.lst
	# restore the original lemmatization information
	# (replace.list generated by fake_dict.pl)
	cat num2.inf | recode u6..u8 | perl -p replace.list | recode u8..u6/21 > num3.inf
	mv num2.bin num.bin
	mv num3.inf num.inf

