
GREW  = grew
GRS   = ../grs/surf_synt_main.grs
SEQ   = full
BASE  = 7.0-tiny

self_doc:
	@echo "======= Experiment on Sequoia parsing with Grew rules ======="
	@echo "Parameters are:"
	@echo " - GREW= ${GREW}"
	@echo " - GRS= ${GRS}"
	@echo " - SEQ= ${SEQ}"
	@echo " - BASE= ${BASE} (available values are: trunk, 7.0, 8.0 and 7.0-tiny)"
	@echo "Targets are: "
	@echo " - eval:        evaluate attachement score of Grew parsing (on gold POS) against reference"
	@echo " - diff:        make the diff between Grew parsing outpus (on gold POS) and reference"
	@echo " - force_parse: force parsing (for instance when rules have changed)"
	@echo " - purge:       remove everything in _build folder"
	@echo "============================================================"

purge:
	rm -rf _build/*

# ===============================================================================================
# Build file for sequoia-trunk
# ===============================================================================================

init: _build/sequoia-${BASE}._gold.conll

suc: _build/sequoia-${BASE}._suc.conll

parse: _build/sequoia-${BASE}._parse.conll

force_parse:
	rm -f _build/sequoia-${BASE}._parse.conll
	@make parse

eval: _build/sequoia-${BASE}._parse.conll _build/sequoia-${BASE}._gold.conll
	ocaml str.cma ../tools/attachment_score.ml _build/sequoia-${BASE}._parse.conll _build/sequoia-${BASE}._gold.conll

diff: _build/sequoia-${BASE}._diff.html
	@echo '----------------------------------------------------'
	@echo 'open _build/sequoia-${BASE}._diff.html in your browser'
	@echo '----------------------------------------------------'

corpus:	_build/sequoia-${BASE}._parse.corpus

# ===============================================================================================
# wget files for different versions of sequoia
# ===============================================================================================
_build/sequoia-trunk._gold.conll:
	mkdir -p _build
	wget https://gitlab.inria.fr/sequoia/deep-sequoia/raw/master/trunk/sequoia.surf.conll -O $@

_build/sequoia-7.0._gold.conll:
	mkdir -p _build
	wget https://gitlab.inria.fr/sequoia/deep-sequoia/raw/master/tags/sequoia-7.0/sequoia.surf.conll -O $@

_build/sequoia-7.0-tiny._gold.conll:
	mkdir -p _build
	wget https://gitlab.inria.fr/sequoia/deep-sequoia/raw/master/tags/sequoia-7.0/sequoia.surf.conll -O _build/tmp
	head -259 _build/tmp > $@
	rm -f _build/tmp

_build/sequoia-8.0._gold.conll:
	mkdir -p _build
	wget https://gitlab.inria.fr/sequoia/deep-sequoia/raw/master/tags/sequoia-8.0/sequoia.surf.conll -O $@

# ===============================================================================================
# Generic rules for splitting, parsing and diffing
# ===============================================================================================

# _build a "_suc"" file from "_gold": keep only phon and pos from conll
%._suc.conll: %._gold.conll
	ocaml str.cma ../tools/conll2pos.ml $< $@

# parse sentences in "_suc.conll", result in file "_parse.conll"
%._parse.conll: %._suc.conll
	${GREW} -det -out_conll -grs ${GRS} -seq ${SEQ} -i $< -f $@

# split a conll file
%.split: %.conll
	ocaml str.cma ../tools/splitter.ml $< $@

# _build diff for GOLD POS-tagged sentence
%._diff.html: %._parse.split %._gold.split
	dep_diff -ref -d1 $(word 1,$^) -d2 $(word 2,$^) -svg $@_svg -html $@ -score

# Run corpus mode in the GOLD POS-tagged corpus, result in _gold_CORPUS/
%._parse.corpus: %._suc.conll
	${GREW} -corpus -no_init -grs ${GRS} -seq ${SEQ} -i $< -o $@
