blob: 931a485f1e0060d7f172251fd2ce0eb105e31cc8 [file] [log] [blame]
Marc Kupietz4292bc02026-03-07 16:12:52 +01001SHELL := /bin/bash
Marc Kupietz89a44072025-12-11 07:14:00 +01002SRC_DIR ?= I5
Marc Kupietze7807322026-06-05 08:55:41 +02003KORAP_PORT ?= 64543
Marc Kupietz89a44072025-12-11 07:14:00 +01004
Marc Kupietz9adff672026-06-09 17:18:17 +02005# Discover all *.i5.xml files in SRC_DIR, excluding inlined tagged copies (*-TAG.i5.xml)
6I5_FILES := $(filter-out %-TAG.i5.xml,$(wildcard $(SRC_DIR)/*.i5.xml))
Marc Kupietz89a44072025-12-11 07:14:00 +01007BASENAMES := $(patsubst %.i5.xml,%,$(notdir $(I5_FILES)))
8
Marc Kupietz99ff2b02026-06-05 08:54:37 +02009# Standard TEI P5 support
10TEI_DIR ?= TEI
11TEI_FILES := $(wildcard $(TEI_DIR)/*.xml)
12TEI_ZIP_NAME ?= tei
13TEI_FLAGS ?= --auto-textsigle 'TEI/XYZ.00001' # --xmlid-to-textsigle '([A-Z]+)\.(.*)\.([0-9]+)\.*([0-9])@$$1/$$2/$$3$$4'
14export TEI_FLAGS
15
16ifneq ($(TEI_FILES),)
17BASENAMES += $(TEI_ZIP_NAME)
18endif
19
Marc Kupietz89a44072025-12-11 07:14:00 +010020BUILD_DIR = build
Marc Kupietz15b313d2025-12-11 12:20:56 +010021TARGET_DIR ?= ./target
Marc Kupietz89a44072025-12-11 07:14:00 +010022MAX_THREADS ?= 8 # $(shell nproc)
23MAKE ?= make -j $(shell nproc)
Marc Kupietz15b313d2025-12-11 12:20:56 +010024# KORAPXMLTOOL_HEAP ?= $(shell echo "$$(($(MAX_THREADS) * 2500))")
Marc Kupietz89a44072025-12-11 07:14:00 +010025KORAPXMLTOOL ?= ./bin/korapxmltool
Marc Kupietz15b313d2025-12-11 12:20:56 +010026KORAPXMLTOOL_MODELS_PATH ?= models
Marc Kupietz4292bc02026-03-07 16:12:52 +010027DOCKER_CPU_SHARES ?= # e.g. 512 for lower priority (default Docker value is 1024)
Marc Kupietz89a44072025-12-11 07:14:00 +010028
29.DELETE_ON_ERROR:
30
Marc Kupietz19fa4482026-06-07 15:03:56 +020031.PHONY: all clean test index korap check-src pre-krill krill meta
Marc Kupietz89a44072025-12-11 07:14:00 +010032
Marc Kupietz19fa4482026-06-07 15:03:56 +020033.PRECIOUS: $(BUILD_DIR)/%.zip $(BUILD_DIR)/%.tree_tagger.zip $(BUILD_DIR)/%.marmot-malt.zip $(BUILD_DIR)/%.spacy.zip $(BUILD_DIR)/%.corenlp.zip $(BUILD_DIR)/%.cmc.zip $(BUILD_DIR)/%.opennlp.zip $(BUILD_DIR)/%.meta.xml $(BUILD_DIR)/%.krill.tar %.i5.xml
Marc Kupietz89a44072025-12-11 07:14:00 +010034
Marc Kupietz15b313d2025-12-11 12:20:56 +010035all: check-src korap
Marc Kupietz89a44072025-12-11 07:14:00 +010036
Marc Kupietz15b313d2025-12-11 12:20:56 +010037index: check-src $(TARGET_DIR)/index
38
39check-src:
Marc Kupietz99ff2b02026-06-05 08:54:37 +020040 @if [ ! -d "$(SRC_DIR)" ] && [ ! -d "$(TEI_DIR)" ]; then \
41 echo "Error: Neither SRC_DIR '$(SRC_DIR)' nor TEI_DIR '$(TEI_DIR)' exists."; \
42 echo "Please place your .i5.xml files in '$(SRC_DIR)' or your TEI .xml files in '$(TEI_DIR)'."; \
Marc Kupietz15b313d2025-12-11 12:20:56 +010043 exit 1; \
44 fi
Marc Kupietz9adff672026-06-09 17:18:17 +020045 @if [ -z "$$(find "$(SRC_DIR)" -maxdepth 1 -name '*.i5.xml' ! -name '*-TAG.i5.xml' -print -quit 2>/dev/null)" ] && \
Marc Kupietz99ff2b02026-06-05 08:54:37 +020046 [ -z "$$(find "$(TEI_DIR)" -maxdepth 1 -name '*.xml' -print -quit 2>/dev/null)" ]; then \
47 echo "Error: No .i5.xml files found in '$(SRC_DIR)' and no .xml files found in '$(TEI_DIR)'."; \
Marc Kupietz15b313d2025-12-11 12:20:56 +010048 exit 1; \
49 fi
Marc Kupietz89a44072025-12-11 07:14:00 +010050
51$(BUILD_DIR)/%.zip: $(SRC_DIR)/%.i5.xml
52 mkdir -p $(BUILD_DIR)
Marc Kupietz4292bc02026-03-07 16:12:52 +010053 docker run --rm -i $(if $(DOCKER_CPU_SHARES),--cpu-shares $(DOCKER_CPU_SHARES)) korap/tei2korapxml:latest -l warn -s -tk - < $< > $@ 2> >(tee $(@:.zip=.log) >&2)
54# docker run --rm $(if $(DOCKER_CPU_SHARES),--cpu-shares $(DOCKER_CPU_SHARES)) -v $(abspath $<):/input.i5.xml:ro korap/tei2korapxml:latest --progress -l warn -s -tk /input.i5.xml > $@ 2> >(tee $(@:.zip=.log) >&2)
55 printf "%s\t%s\n" "$$(grep -c '<idsText ' $<)" "$$(unzip -l $@ | grep data.xml | wc -l)"
Marc Kupietz89a44072025-12-11 07:14:00 +010056
Marc Kupietz99ff2b02026-06-05 08:54:37 +020057$(BUILD_DIR)/$(TEI_ZIP_NAME).zip: $(TEI_FILES)
58 mkdir -p $(BUILD_DIR)
59 docker run --rm --entrypoint /bin/sh $(if $(DOCKER_CPU_SHARES),--cpu-shares $(DOCKER_CPU_SHARES)) -v "$(abspath $(TEI_DIR)):/input:ro" korap/tei2korapxml:latest -c 'tei2korapxml -l warn -s -tk '"$$TEI_FLAGS"' /input/*.xml' > $@ 2> >(tee $(@:.zip=.log) >&2)
60 printf "%s\t%s\n" "$$(cat $^ | grep -c '<teiHeader')" "$$(unzip -l $@ | grep data.xml | wc -l)"
61
Marc Kupietz89a44072025-12-11 07:14:00 +010062
63$(BUILD_DIR)/%.tree_tagger.zip: $(BUILD_DIR)/%.zip bin/korapxmltool
Marc Kupietz5b3ecc02025-12-15 14:43:09 +010064 $(KORAPXMLTOOL) -j 1 -T treetagger -t zip --force -D $(BUILD_DIR) $<
Marc Kupietz89a44072025-12-11 07:14:00 +010065# $(KORAPXMLTOOL) $< | pv | docker run --rm -i korap/conllu2treetagger -l german | conllu2korapxml > $@
66
67$(BUILD_DIR)/%.spacy.zip: $(BUILD_DIR)/%.zip bin/korapxmltool
Marc Kupietz15b313d2025-12-11 12:20:56 +010068 $(KORAPXMLTOOL) -P spacy -t zip --force -D $(BUILD_DIR) $<
Marc Kupietz89a44072025-12-11 07:14:00 +010069
Marc Kupietz15b313d2025-12-11 12:20:56 +010070lib/Krill-Indexer.jar:
71 mkdir -p lib
72 curl -sL -o $@ https://github.com/korap/Krill/releases/latest/download/Krill-Indexer.jar
Marc Kupietz5b3ecc02025-12-15 14:43:09 +010073
Marc Kupietz89a44072025-12-11 07:14:00 +010074bin/korapxmltool:
75 mkdir -p bin
Marc Kupietz15b313d2025-12-11 12:20:56 +010076 curl -sL -o $@ https://github.com/korap/korapxmltool/releases/latest/download/korapxmltool
Marc Kupietz89a44072025-12-11 07:14:00 +010077 chmod +x $@
78
Marc Kupietzc5239812026-06-05 08:56:46 +020079bin/conllu-gender:
80 mkdir -p bin
81 curl -sL -o $@ https://github.com/KorAP/conllu-gender/releases/latest/download/conllu-gender
82 chmod +x $@
83
Marc Kupietz15b313d2025-12-11 12:20:56 +010084$(KORAPXMLTOOL_MODELS_PATH)/de.marmot:
85 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +010086 curl -sL -o $@ https://cistern.cis.lmu.de/marmot/models/CURRENT/spmrl/de.marmot
87
Marc Kupietz15b313d2025-12-11 12:20:56 +010088$(KORAPXMLTOOL_MODELS_PATH)/german.mco:
89 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +010090 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
91
Marc Kupietz15b313d2025-12-11 12:20:56 +010092$(KORAPXMLTOOL_MODELS_PATH)/dereko_domains_s.classifier:
93 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
94 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/models/$@
95
96$(KORAPXMLTOOL_MODELS_PATH)/german-fast.tagger:
97 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +010098 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
99
Marc Kupietz15b313d2025-12-11 12:20:56 +0100100$(KORAPXMLTOOL_MODELS_PATH)/germanSR.ser.gz:
101 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +0100102 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
103
Marc Kupietz15b313d2025-12-11 12:20:56 +0100104$(KORAPXMLTOOL_MODELS_PATH)/de-pos-maxent.bin:
105 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +0100106 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
107
Marc Kupietz15b313d2025-12-11 12:20:56 +0100108$(BUILD_DIR)/%.marmot-malt.zip: $(BUILD_DIR)/%.zip $(KORAPXMLTOOL_MODELS_PATH)/de.marmot $(KORAPXMLTOOL_MODELS_PATH)/german.mco bin/korapxmltool
Marc Kupietz89a44072025-12-11 07:14:00 +0100109 $(KORAPXMLTOOL) -T marmot:models/de.marmot -P malt:models/german.mco -t zip --force -D $(BUILD_DIR) $<
Marc Kupietz5b3ecc02025-12-15 14:43:09 +0100110
Marc Kupietz15b313d2025-12-11 12:20:56 +0100111$(BUILD_DIR)/%.corenlp.zip: $(BUILD_DIR)/%.zip $(KORAPXMLTOOL_MODELS_PATH)/german-fast.tagger $(KORAPXMLTOOL_MODELS_PATH)/germanSR.ser.gz bin/korapxmltool
Marc Kupietz89a44072025-12-11 07:14:00 +0100112 $(KORAPXMLTOOL) -T corenlp -P corenlp -t zip --force -D $(BUILD_DIR) $<
113
Marc Kupietz15b313d2025-12-11 12:20:56 +0100114$(BUILD_DIR)/%.opennlp.zip: $(BUILD_DIR)/%.zip $(KORAPXMLTOOL_MODELS_PATH)/de-pos-maxent.bin bin/korapxmltool
Marc Kupietz89a44072025-12-11 07:14:00 +0100115 $(KORAPXMLTOOL) -T opennlp -t zip --force -D $(BUILD_DIR) $<
116
Marc Kupietz800f9bb2025-12-11 17:30:24 +0100117$(BUILD_DIR)/%.cmc.zip: $(BUILD_DIR)/%.zip bin/korapxmltool
Marc Kupietz5b3ecc02025-12-15 14:43:09 +0100118 $(KORAPXMLTOOL) -j 1 -A "docker run --rm -i korap/conllu-cmc -s" -l error -F cmc -t zip --force -D $(BUILD_DIR) $<
Marc Kupietz800f9bb2025-12-11 17:30:24 +0100119
Marc Kupietza2876eb2026-03-07 22:03:17 +0100120$(BUILD_DIR)/%.gender.zip: $(BUILD_DIR)/%.zip bin/conllu-gender
Marc Kupietz463da332026-03-08 13:19:15 +0100121 $(KORAPXMLTOOL) -j 1 -A "bin/conllu-gender -s" -l WARNING -F gender -t zip --force -D $(BUILD_DIR) $<
Marc Kupietza2876eb2026-03-07 22:03:17 +0100122
Marc Kupietz19fa4482026-06-07 15:03:56 +0200123# --- Stand-off metadata annotations -----------------------------------------
124WIKI_TAXONOMY_IMAGE ?= korap/wiki-taxonomy
125
Marc Kupietz49773a62026-06-09 17:35:45 +0200126# Pass --gpus=all to GPU-capable docker runs when CUDA GPUs are actually usable:
127# nvidia-smi must succeed on the host and Docker must expose the nvidia runtime.
128# Probed once at parse time; override by setting GPU_FLAG (e.g. GPU_FLAG= to disable).
129GPU_FLAG ?= $(shell if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi >/dev/null 2>&1 && \
130 docker info --format '{{json .Runtimes}}' 2>/dev/null | grep -qi nvidia; then echo --gpus=all; fi)
131
Marc Kupietz19fa4482026-06-07 15:03:56 +0200132# Wikipedia top-level topic-domain classification (annotation: wikidomain).
133# Unlike the foundry annotations this yields a single stand-off metadata XML per
134# corpus, not a per-text zip. The model is baked into the image, so nothing to mount.
135$(BUILD_DIR)/%.wikidomain.meta.xml: $(BUILD_DIR)/%.zip bin/korapxmltool
136 set -o pipefail; $(KORAPXMLTOOL) -t now $< \
Marc Kupietz49773a62026-06-09 17:35:45 +0200137 | docker run --rm -i $(GPU_FLAG) $(if $(DOCKER_CPU_SHARES),--cpu-shares $(DOCKER_CPU_SHARES)) \
Marc Kupietz19fa4482026-06-07 15:03:56 +0200138 $(WIKI_TAXONOMY_IMAGE) --topk 2 --threshold 0.4 > $@ 2> >(tee $(@:.xml=.log) >&2)
139
Marc Kupietz89a44072025-12-11 07:14:00 +0100140# udpipe target removed as requested
141# %.ud.zip: %.zip
142# $(KORAPXMLTOOL) $< | pv | ./scripts/udpipe2 | conllu2korapxml > $@
143
Marc Kupietz19fa4482026-06-07 15:03:56 +0200144# Active annotation layers to run and package into Krill. Most produce a per-text
145# foundry zip; those also listed in META_ANNOTATIONS instead produce a single
146# stand-off metadata XML per corpus (auto-detected by korapxmltool).
147ANNOTATIONS ?= marmot-malt tree_tagger spacy corenlp opennlp wikidomain
148META_ANNOTATIONS ?= wikidomain
Marc Kupietzc5239812026-06-05 08:56:46 +0200149
Marc Kupietz19fa4482026-06-07 15:03:56 +0200150# Build artifact produced by annotation $(2) for base $(1): a stand-off .meta.xml
151# for meta-type annotations, otherwise a foundry .zip.
152artifact = $(BUILD_DIR)/$(1).$(2).$(if $(filter $(2),$(META_ANNOTATIONS)),meta.xml,zip)
153# Meta-type annotations that are actually active (must be passed to krill explicitly,
154# since the recipe globs *.zip only).
155ACTIVE_META := $(filter $(META_ANNOTATIONS),$(ANNOTATIONS))
156
157KRILL_PREREQS := $(foreach base,$(BASENAMES),$(BUILD_DIR)/$(base).zip $(foreach ann,$(ANNOTATIONS),$(call artifact,$(base),$(ann))))
Marc Kupietz4292bc02026-03-07 16:12:52 +0100158
159pre-krill: check-src $(KRILL_PREREQS)
160
Marc Kupietz19fa4482026-06-07 15:03:56 +0200161# Build just the stand-off metadata layers without indexing.
162meta: check-src $(foreach base,$(BASENAMES),$(foreach ann,$(ACTIVE_META),$(BUILD_DIR)/$(base).$(ann).meta.xml))
163
164# The base zip, every annotation zip, and every stand-off meta XML are folded into
165# one Krill tar. korapxmltool auto-detects the .meta.xml stand-off inputs.
166$(BUILD_DIR)/%.krill.tar: $(BUILD_DIR)/%.zip $(foreach ann,$(ANNOTATIONS),$(call artifact,%,$(ann)))
167 $(KORAPXMLTOOL) --non-word-tokens -f -t krill -D $(BUILD_DIR) $(basename $<)*.zip $(foreach ann,$(ACTIVE_META),$(BUILD_DIR)/$*.$(ann).meta.xml)
Marc Kupietz89a44072025-12-11 07:14:00 +0100168
Marc Kupietz463da332026-03-08 13:19:15 +0100169krill: $(foreach base,$(BASENAMES),$(BUILD_DIR)/$(base).krill.tar)
170
Marc Kupietz15b313d2025-12-11 12:20:56 +0100171$(TARGET_DIR)/index: $(foreach base,$(BASENAMES),$(BUILD_DIR)/$(base).krill.tar)
172 make lib/Krill-Indexer.jar
173 touch lib/krill.cfg
174 mkdir -p $(TARGET_DIR)
175 java -jar lib/Krill-Indexer.jar -c lib/krill.cfg --progress -i $(subst " ",;,$^) -o $@
176
177korap: check-src $(TARGET_DIR)/index
Marc Kupietze7807322026-06-05 08:55:41 +0200178 curl -s https://raw.githubusercontent.com/KorAP/KorAP-Docker/master/compose.yaml | sed 's/64543:64543/$(KORAP_PORT):64543/g' | COMPOSE_PROFILES='export' INDEX='$(TARGET_DIR)/index' docker compose -p korap -f - --profile=lite --profile=example up
Marc Kupietz89a44072025-12-11 07:14:00 +0100179
180$(TARGET_DIR)/index.tar.xz: $(TARGET_DIR)/index
181 tar -I 'xz -T0' -C $(dir $<) -cf $@ $(notdir $<)
182
183clean:
184 rm -rf $(BUILD_DIR) $(TARGET_DIR)