blob: 137e73137db68b96363cbc9399eb390b23f62230 [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
5# Discover all *.i5.xml files in SRC_DIR
6I5_FILES := $(wildcard $(SRC_DIR)/*.i5.xml)
7BASENAMES := $(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 Kupietz463da332026-03-08 13:19:15 +010031.PHONY: all clean test index korap check-src pre-krill krill
Marc Kupietz89a44072025-12-11 07:14:00 +010032
Marc Kupietz5b3ecc02025-12-15 14:43:09 +010033.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)/%.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 Kupietz99ff2b02026-06-05 08:54:37 +020045 @if [ -z "$$(find "$(SRC_DIR)" -maxdepth 1 -name '*.i5.xml' -print -quit 2>/dev/null)" ] && \
46 [ -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 Kupietz15b313d2025-12-11 12:20:56 +010079$(KORAPXMLTOOL_MODELS_PATH)/de.marmot:
80 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +010081 curl -sL -o $@ https://cistern.cis.lmu.de/marmot/models/CURRENT/spmrl/de.marmot
82
Marc Kupietz15b313d2025-12-11 12:20:56 +010083$(KORAPXMLTOOL_MODELS_PATH)/german.mco:
84 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +010085 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
86
Marc Kupietz15b313d2025-12-11 12:20:56 +010087$(KORAPXMLTOOL_MODELS_PATH)/dereko_domains_s.classifier:
88 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
89 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/models/$@
90
91$(KORAPXMLTOOL_MODELS_PATH)/german-fast.tagger:
92 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +010093 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
94
Marc Kupietz15b313d2025-12-11 12:20:56 +010095$(KORAPXMLTOOL_MODELS_PATH)/germanSR.ser.gz:
96 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +010097 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
98
Marc Kupietz15b313d2025-12-11 12:20:56 +010099$(KORAPXMLTOOL_MODELS_PATH)/de-pos-maxent.bin:
100 mkdir -p $(KORAPXMLTOOL_MODELS_PATH)
Marc Kupietz89a44072025-12-11 07:14:00 +0100101 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
102
Marc Kupietz15b313d2025-12-11 12:20:56 +0100103$(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 +0100104 $(KORAPXMLTOOL) -T marmot:models/de.marmot -P malt:models/german.mco -t zip --force -D $(BUILD_DIR) $<
Marc Kupietz5b3ecc02025-12-15 14:43:09 +0100105
Marc Kupietz15b313d2025-12-11 12:20:56 +0100106$(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 +0100107 $(KORAPXMLTOOL) -T corenlp -P corenlp -t zip --force -D $(BUILD_DIR) $<
108
Marc Kupietz15b313d2025-12-11 12:20:56 +0100109$(BUILD_DIR)/%.opennlp.zip: $(BUILD_DIR)/%.zip $(KORAPXMLTOOL_MODELS_PATH)/de-pos-maxent.bin bin/korapxmltool
Marc Kupietz89a44072025-12-11 07:14:00 +0100110 $(KORAPXMLTOOL) -T opennlp -t zip --force -D $(BUILD_DIR) $<
111
Marc Kupietz800f9bb2025-12-11 17:30:24 +0100112$(BUILD_DIR)/%.cmc.zip: $(BUILD_DIR)/%.zip bin/korapxmltool
Marc Kupietz5b3ecc02025-12-15 14:43:09 +0100113 $(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 +0100114
Marc Kupietza2876eb2026-03-07 22:03:17 +0100115$(BUILD_DIR)/%.gender.zip: $(BUILD_DIR)/%.zip bin/conllu-gender
Marc Kupietz463da332026-03-08 13:19:15 +0100116 $(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 +0100117
Marc Kupietz89a44072025-12-11 07:14:00 +0100118# udpipe target removed as requested
119# %.ud.zip: %.zip
120# $(KORAPXMLTOOL) $< | pv | ./scripts/udpipe2 | conllu2korapxml > $@
121
Marc Kupietza2876eb2026-03-07 22:03:17 +0100122KRILL_PREREQS := $(foreach base,$(BASENAMES),$(BUILD_DIR)/$(base).zip $(BUILD_DIR)/$(base).marmot-malt.zip $(BUILD_DIR)/$(base).tree_tagger.zip $(BUILD_DIR)/$(base).spacy.zip $(BUILD_DIR)/$(base).corenlp.zip $(BUILD_DIR)/$(base).opennlp.zip $(BUILD_DIR)/$(base).gender.zip)
Marc Kupietz4292bc02026-03-07 16:12:52 +0100123
124pre-krill: check-src $(KRILL_PREREQS)
125
Marc Kupietza2876eb2026-03-07 22:03:17 +0100126$(BUILD_DIR)/%.krill.tar: $(BUILD_DIR)/%.zip $(BUILD_DIR)/%.marmot-malt.zip $(BUILD_DIR)/%.tree_tagger.zip $(BUILD_DIR)/%.spacy.zip $(BUILD_DIR)/%.corenlp.zip $(BUILD_DIR)/%.opennlp.zip $(BUILD_DIR)/%.gender.zip
Marc Kupietz4292bc02026-03-07 16:12:52 +0100127 $(KORAPXMLTOOL) --non-word-tokens -f -t krill -D $(BUILD_DIR) $(basename $<)*.zip
Marc Kupietz89a44072025-12-11 07:14:00 +0100128
Marc Kupietz463da332026-03-08 13:19:15 +0100129krill: $(foreach base,$(BASENAMES),$(BUILD_DIR)/$(base).krill.tar)
130
Marc Kupietz15b313d2025-12-11 12:20:56 +0100131$(TARGET_DIR)/index: $(foreach base,$(BASENAMES),$(BUILD_DIR)/$(base).krill.tar)
132 make lib/Krill-Indexer.jar
133 touch lib/krill.cfg
134 mkdir -p $(TARGET_DIR)
135 java -jar lib/Krill-Indexer.jar -c lib/krill.cfg --progress -i $(subst " ",;,$^) -o $@
136
137korap: check-src $(TARGET_DIR)/index
Marc Kupietze7807322026-06-05 08:55:41 +0200138 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 +0100139
140$(TARGET_DIR)/index.tar.xz: $(TARGET_DIR)/index
141 tar -I 'xz -T0' -C $(dir $<) -cf $@ $(notdir $<)
142
143clean:
144 rm -rf $(BUILD_DIR) $(TARGET_DIR)