# Last edited on 2012-05-06 01:21:26 by stolfilocal 
# Voynichese token/word length distributions
# 
# Makefile for computing the Voynichese token and word length
# histograms for text, labels, and everything together, in terms of
# basic glyphs and OKOKOKO elements, for raw, good, and bad
# subsamples.
# 
# It also generates comparison plots of the good and raw histograms
# (basic glyphs only), in order to ensure that the good-word selection
# did not introduce any significant bias in the length statistics.
#

MAKEFILE := vms-length-hists.make

LANG := voyn
BOOKS := maj prs lab 

.PHONY: all bgly-cmp-plots qoko-hists

all: bgly-cmp-plots qoko-hists

bgly-cmp-plots:
	for book in ${BOOKS}; do \
	  for qual in raw gud bad; do \
            ${MAKE} BOOK=$$book ELEM=bgly QUAL=$$qual \
              -f ${MAKEFILE} histograms; \
	  done; \
          for tkwd in t w; do \
            ${MAKE} BOOK=$$book TKWD=$$tkwd \
              -f ${MAKEFILE} single-cmp-plot; \
          done; \
	done

qoko-hists:
	for elem in bgly qoko; do \
	  ${MAKE} BOOK=maj ELEM=qoko QUAL=gud \
            -f ${MAKEFILE} histograms; \
	done

######################################################################
# Recursive make for each Voynichese "book".
# Caller must define 
#  ${BOOK} = "maj", "lab", etc.

BOOK := BOOK.IS.UNDEFINED
ifneq "${BOOK}" "BOOK.IS.UNDEFINED"

SAMPLE_TOT_DIR := ${LANG}/${BOOK}/tot.1

######################################################################
# Recursive make for each Voynichese "book" and token/word counting.
# Caller must define ${BOOK} and
#   ${TKWD} = "t" (tokens) or "w" (words).

TKWD := TKWD.IS.UNDEFINED
ifneq "${TKWD}" "TKWD.IS.UNDEFINED"

RAW_LHI := ${SAMPLE_TOT_DIR}/raw-fact-bgly-${TKWD}.lhi
GUD_LHI := ${SAMPLE_TOT_DIR}/gud-fact-bgly-${TKWD}.lhi

LHI_FILES := dat/${RAW_LHI} dat/${GUD_LHI}

HIST_PLOT := ${SAMPLE_TOT_DIR}/cleanup-${TKWD}-len-cmp
HIST_PLOT_PNG := ${HIST_PLOT}.png
HIST_PLOT_EPS := ${HIST_PLOT}.eps

.PHONY: single-cmp-plot

single-cmp-plot: fig/${HIST_PLOT_PNG}

PLOT_OPTS := -freqs
ifeq "${BOOK}" "voyl"
  PLOT_OPTS := ${PLOT_OPTS} -noylabels
endif

fig/${HIST_PLOT_PNG}: ${LHI_FILES} \
             compare-elem-count-distribs \
             ${MAKEFILE}
	@echo "generating dat/${HIST_PLOT}..."
	mkdir -p fig/${SAMPLE_TOT_DIR}
	compare-elem-count-distribs ${PLOT_OPTS} \
	    dat/${RAW_LHI} 'full'    1.00 1 1 \
	    dat/${GUD_LHI} 'clean'   1.00 2 2 \
	  fig/${HIST_PLOT}
	update-paper-include fig/${HIST_PLOT_PNG} exp/${HIST_PLOT_PNG}
	update-paper-include fig/${HIST_PLOT_EPS} exp/${HIST_PLOT_EPS}

endif
# End of ${BOOK}/${TKWD} rules
######################################################################

endif
# End of ${BOOK} rules
######################################################################


######################################################################
# Recursive make for each Voynichese "book".
# Caller must define 
#  ${BOOK} = "maj", "lab", etc.

BOOK := BOOK.IS.UNDEFINED
ifneq "${BOOK}" "BOOK.IS.UNDEFINED"

${SAMPLE_TOT_DIR} := ${LANG}/${BOOK}/tot.1

######################################################################
# Recursive make for each Voynichese "book", 
# and element type. Caller must define  ${BOOK} and
#   ${ELEM} = "bgly" or "qoko".

ELEM := ELEM.IS.UNDEFINED
ifneq "${ELEM}" "ELEM.IS.UNDEFINED"

######################################################################
# Recursive make for each Voynichese "book", element type, 
# and sample quality. Caller must define ${BOOK}, ${ELEM} and
#   ${QUAL} = "raw", "gud", or "bad";

QUAL := QUAL.IS.UNDEFINED
ifneq "${QUAL}" "QUAL.IS.UNDEFINED"

.PHONY: histograms

T_LHI := ${SAMPLE_TOT_DIR}/${QUAL}-fact-${ELEM}-t.lhi
W_LHI := ${SAMPLE_TOT_DIR}/${QUAL}-fact-${ELEM}-w.lhi

LHI_MAKEFILE := tw-length-hists.make

histograms:
	${MAKE} -f ${LHI_MAKEFILE} \
          LANG=${LANG} BOOK=${BOOK} ELEM=${ELEM} QUAL=${QUAL} \
          all

endif
# End of ${BOOK}/${ELEM}/${QUAL} rules
######################################################################

endif
# End of ${BOOK}/${ELEM} rules
######################################################################

endif
# End of ${BOOK} rules
######################################################################