blob: 6637b46a07d5498ee899667e4cfee1f4373c4c8b [file] [log] [blame]
Marc Kupietz84da39d2024-07-25 20:23:50 +02001ifneq (,$(filter test,$(MAKECMDGOALS)))
2SRC_DIR = test/resources/DNB
Marc Kupietz9c106672024-09-30 15:01:55 +02003YEARS=13 18 23
Marc Kupietz84da39d2024-07-25 20:23:50 +02004else
Marc Kupietzbadc4282024-07-26 15:45:22 +02005SRC_DIR ?= ./DeLiKo@DNB
Marc Kupietz956aa492025-10-22 14:14:42 +02006YEARS ?= $(shell seq -w 2024 -1 2005 | sed 's/^.*\([0-9][0-9]\)/\1/')
7#YEARS ?= $(shell seq -w 2005 2023 | sed 's/^.*\([0-9][0-9]\)/\1/')
Marc Kupietz84da39d2024-07-25 20:23:50 +02008endif
Marc Kupietzdeb95462024-04-15 20:26:14 +02009
Marc Kupietz1a422662024-03-16 09:34:10 +010010BUILD_DIR = build
11TARGET_DIR ?= target
Marc Kupietzb7696992024-03-18 17:41:15 +010012DEPLOY_HOST ?= compute.ids-mannheim.de
13DEPLOY_USER ?= korap
14DEPLOY_PATH ?= /export/netapp/korap4dnb
Marc Kupietzade75722025-11-02 17:27:57 +010015MAX_THREADS ?= 8 # $(shell nproc)
Marc Kupietz975996e2024-04-13 13:46:37 +020016MAKE ?= make -j $(shell nproc)
Marc Kupietz881c1232025-10-28 15:36:48 +010017SLACK ?= slack
Marc Kupietz133333e2025-02-20 18:08:17 +010018KORAPXMLTOOL_HEAP ?= $(shell echo "$$(($(MAX_THREADS) * 2500))")
Marc Kupietz36ec6002026-03-15 17:49:54 +010019KORAPXMLTOOL ?= bin/korapxmltool
20MARMOTMALTOOL ?= bin/korapxmltool
21SPACYXMLTOOL ?= bin/korapxmltool
22KORAPXMLTOOL_MODELS_PATH ?= models
23export KORAPXMLTOOL_MODELS_PATH
24
Marc Kupietz0014c5c2024-09-30 09:12:33 +020025SAXON ?= java -Djava.util.logging.config.file=/logging.properties -cp lib/saxon-ee-12.5.jar:lib/xmlresolver-5.2.2.jar:lib/textclassifier.jar:lib/xmlresolver-5.2.2-data.jar net.sf.saxon.Transform -expand:off -catalog:"lib/dtds/xhtml11/xhtmlcatalog.xml;lib/dtds/xhtml/dtd/xhtmlcatalog.xml"
Marc Kupietz1a422662024-03-16 09:34:10 +010026
Marc Kupietz5652c812024-04-19 11:42:00 +020027.DELETE_ON_ERROR:
28
Marc Kupietzced34de2025-03-31 10:01:54 +020029.PHONY: all clean test i5 i5valid krill malt index deploy show-server-log show-server-status
Marc Kupietz1a422662024-03-16 09:34:10 +010030
Marc Kupietz16659b22024-09-14 09:53:38 +020031
Marc Kupietz36ec6002026-03-15 17:49:54 +010032.PRECIOUS: $(TARGET_DIR)/%.i5.xml $(TARGET_DIR)/dnb%.pre.i5.xml %.zip %.tree_tagger.zip %.ud.zip %.marmot-malt.zip %.spacy.zip %.corenlp.zip %.i5.xml %.tar
Marc Kupietz1a422662024-03-16 09:34:10 +010033
Marc Kupietzfeed26a2024-03-17 19:16:23 +010034all: index
Marc Kupietz1a422662024-03-16 09:34:10 +010035
Marc Kupietzdeb95462024-04-15 20:26:14 +020036krill: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).krill.tar)
Marc Kupietz3d82f562024-03-16 10:19:03 +010037
Marc Kupietzab1f3ac2024-04-16 14:56:43 +020038index: $(TARGET_DIR)/dnb.index
Marc Kupietzdeb95462024-04-15 20:26:14 +020039
Marc Kupietz956aa492025-10-22 14:14:42 +020040# EPUBS := ($shell cat .epubs_cache)
Marc Kupietz84da39d2024-07-25 20:23:50 +020041EPUBS := $(wildcard $(SRC_DIR)/**/*.epub)
42
Marc Kupietz8a1e4652024-04-21 15:55:03 +020043$(TARGET_DIR)/dnb%.i5.xml: $(TARGET_DIR)/dnb%.pre.i5.xml xslt/pass2.xsl xslt/pass3.xsl models/dereko_domains_s.classifier
Marc Kupietz28f48e12024-04-14 16:17:05 +020044 $(SAXON) -xsl:xslt/pass2.xsl $< | $(SAXON) -xsl:xslt/pass3.xsl - > $@
Marc Kupietzfa445da2024-03-16 10:46:22 +010045
Marc Kupietz84da39d2024-07-25 20:23:50 +020046$(TARGET_DIR)/dnb%.pre.i5.xml: $(patsubst %.epub,$(TARGET_DIR)/%.i5.xml,$(notdir $(EPUBS)))
Marc Kupietz93a52eb2024-07-26 18:17:17 +020047 rm -f $(TARGET_DIR)/filelist$*.txt
Marc Kupietzdeb95462024-04-15 20:26:14 +020048 head -n -1 xslt/idsCorpus-template.xml | sed -e 's/{YY}/$*/' > $@
Marc Kupietz93a52eb2024-07-26 18:17:17 +020049 @find -L $(SRC_DIR) -type f -name '*.epub' | sort -u | while read src; do \
50 f=$(TARGET_DIR)/$$(basename $${src%.epub}).i5.xml; \
Marc Kupietz9c106672024-09-30 15:01:55 +020051 if ! grep -sq "$$f" $(TARGET_DIR)/filelist$*.txt && head -500 "$$f" | grep -Eq '<pubDate type="year">..$*'; then \
Marc Kupietz93a52eb2024-07-26 18:17:17 +020052 echo $$f >> $(TARGET_DIR)/filelist$*.txt; \
Marc Kupietzb926f252024-04-14 08:57:11 +020053 cat "$$f" >> $@; \
54 fi; \
Marc Kupietz93a52eb2024-07-26 18:17:17 +020055 done
Marc Kupietz1a422662024-03-16 09:34:10 +010056 tail -n 1 xslt/idsCorpus-template.xml >> $@
57
Marc Kupietz161d0112024-07-25 11:09:04 +020058
Marc Kupietz84677242024-04-27 11:46:07 +020059test: models/dereko_domains_s.classifier i5valid test/test-xml.sh
Marc Kupietz73a26bf2024-04-26 17:36:44 +020060 bash test/test-xml.sh
Marc Kupietz1a422662024-03-16 09:34:10 +010061
Marc Kupietzdeb95462024-04-15 20:26:14 +020062i5: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).i5.xml)
Marc Kupietz157e0792024-04-13 12:46:42 +020063
Marc Kupietzdeb95462024-04-15 20:26:14 +020064i5valid: i5
65 xmllint --noout --valid $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).i5.xml)
Marc Kupietz157e0792024-04-13 12:46:42 +020066
Marc Kupietz84da39d2024-07-25 20:23:50 +020067
68$(BUILD_DIR)/%: $(SRC_DIR)/**/%.epub
Marc Kupietz7e365ee2024-09-22 12:03:06 +020069 mkdir -p $@.tmp
Marc Kupietz1a422662024-03-16 09:34:10 +010070 echo "Converting $< to $@"
Marc Kupietz7e365ee2024-09-22 12:03:06 +020071 echo "<originalPath>$<</originalPath>" > $@.tmp/originalPath.xml
72 unzip -q -o $< -d $@.tmp
73 chmod -R ug+rwX $@.tmp
74 mv $@.tmp $@
Marc Kupietz1a422662024-03-16 09:34:10 +010075
Marc Kupietzdfbc3f42024-03-16 11:46:41 +010076$(TARGET_DIR)/%.i5.xml: $(BUILD_DIR)/% xslt/epub2i5.xsl xslt/idsCorpus-template.xml
Marc Kupietz1a422662024-03-16 09:34:10 +010077 mkdir -p $(TARGET_DIR)
78 echo "Converting $< to $@"
Marc Kupietz1c3ebca2024-09-22 13:49:28 +020079 $(SAXON) -xsl:xslt/epub2i5.xsl $(shell find $< -name "*.opf") $(shell if cat `find $< -name originalPath.xml` | grep -iq buchpreis; then echo buchpreis=1; fi)> $@ || \
Marc Kupietz2c7bc7e2024-09-30 14:09:25 +020080 (sleep 5 && $(SAXON) -xsl:xslt/epub2i5.xsl $(shell find $< -name "*.opf") $(shell if cat `find $< -name originalPath.xml` | grep -iq buchpreis; then echo buchpreis=1; fi) debug=1 > $@) || (echo "WARN: ignoring invalid $@" && > $@)
Marc Kupietz1c3ebca2024-09-22 13:49:28 +020081
Marc Kupietz1a422662024-03-16 09:34:10 +010082%.zip: %.i5.xml
Marc Kupietz98937292026-03-14 17:28:05 +010083 docker run --rm -i korap/tei2korapxml:latest -l warn -s -tk - < $< > $@ 2> >(tee $(@:.zip=.log) >&2)
84 printf "%s\t%s\n" "$$(grep -c '<idsText ' $<)" "$$(unzip -l $@ | grep data.xml | wc -l)"
Marc Kupietz1a422662024-03-16 09:34:10 +010085
86%.tree_tagger.zip: %.zip
Marc Kupietz36ec6002026-03-15 17:49:54 +010087 $(KORAPXMLTOOL) -A "docker run -v ./models/:/local/models--rm -i korap/conllu-treetagger -l german -p" -t zip -f -D $(TARGET_DIR) $<
Marc Kupietz3b6edcd2025-11-02 19:57:53 +010088# $(KORAPXMLTOOL) $< | pv | docker run --rm -i korap/conllu2treetagger -l german | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +010089
90%.spacy.zip: %.zip
Marc Kupietz36ec6002026-03-15 17:49:54 +010091 $(SPACYXMLTOOL) -A "docker run -e SPACY_USE_DEPENDENCIES=True --rm -i korap/conllu2spacy:latest" -t zip -f -D $(TARGET_DIR) $<
Marc Kupietz1a422662024-03-16 09:34:10 +010092
Marc Kupietz8ea92282024-03-24 14:55:55 +010093models/de.marmot:
94 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010095 curl -sL -o $@ https://cistern.cis.lmu.de/marmot/models/CURRENT/spmrl/de.marmot
Marc Kupietz8ea92282024-03-24 14:55:55 +010096
97models/german.mco:
98 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010099 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
Marc Kupietz8ea92282024-03-24 14:55:55 +0100100
Marc Kupietza5538652024-04-21 15:49:30 +0200101models/dereko_domains_s.classifier:
102 mkdir -p models
103 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
104
Marc Kupietz36ec6002026-03-15 17:49:54 +0100105models/german-fast.tagger:
106 mkdir -p models
107 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
108
109models/germanSR.ser.gz:
110 mkdir -p models
111 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
112
Marc Kupietz8ea92282024-03-24 14:55:55 +0100113%.marmot-malt.zip: %.zip models/de.marmot models/german.mco
Marc Kupietz36ec6002026-03-15 17:49:54 +0100114 $(MARMOTMALTOOL) -T marmot -P malt -t zip -f -D $(TARGET_DIR) $<
115
116%.corenlp.zip: %.zip models/de.marmot models/german.mco
117 $(MARMOTMALTOOL) -T corenlp -P corenlp -t zip -f -D $(TARGET_DIR) $<
Marc Kupietzced34de2025-03-31 10:01:54 +0200118
119malt: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).marmot-malt.zip)
Marc Kupietz8ea92282024-03-24 14:55:55 +0100120
Marc Kupietz1a422662024-03-16 09:34:10 +0100121%.ud.zip: %.zip
Marc Kupietz133333e2025-02-20 18:08:17 +0100122 $(KORAPXMLTOOL) $< | pv | ./scripts/udpipe2 | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +0100123
Marc Kupietz36ec6002026-03-15 17:49:54 +0100124%.krill.tar: %.zip %.marmot-malt.zip %.tree_tagger.zip %.spacy.zip %.corenlp.zip
Marc Kupietz87597512024-04-15 18:31:34 +0200125 mkdir -p ${BUILD_DIR}/krill/$(basename $@)
Marc Kupietz3d82f562024-03-16 10:19:03 +0100126 mkdir -p $(basename $@)
Marc Kupietz36ec6002026-03-15 17:49:54 +0100127 #K2K_PUBLISHER_STRING=1 K2K_TRANSLATOR_TEXT=1 korapxml2krill archive -w -z -cfg krill-korap4dnb.cfg -c ${BUILD_DIR}/krill/$(basename $@)/korapxml2krill.cache -j 30 -te ${BUILD_DIR}/krill/$(basename $@) --non-word-tokens --meta I5 -i $< -i $(word 2,$^) -i $(word 3,$^) -i $(word 4,$^) -o $(basename $@)
128 K2K_PUBLISHER_STRING=1 K2K_TRANSLATOR_TEXT=1 $(KORAPXMLTOOL) --non-word-tokens -linfo -f -t krill -D $(TARGET_DIR) $(basename $<)*.zip
Marc Kupietz881c1232025-10-28 15:36:48 +0100129 $(SLACK) "$(basename $@) krill archive created"
Marc Kupietz1a422662024-03-16 09:34:10 +0100130
Marc Kupietzfc328622024-03-16 14:31:34 +0100131%.json: %.krill.tar
132 rm -rf $@
133 mkdir -p $@
134 for f in $<; do tar -C $@ -xf $$f; done
Marc Kupietz1a422662024-03-16 09:34:10 +0100135
Marc Kupietz956aa492025-10-22 14:14:42 +0200136krill: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).krill.tar)
Marc Kupietz3ccadbf2024-07-27 12:28:25 +0200137
Marc Kupietz3ccadbf2024-07-27 12:28:25 +0200138
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100139
Marc Kupietzab1f3ac2024-04-16 14:56:43 +0200140$(TARGET_DIR)/dnb.index.tar.xz: $(TARGET_DIR)/dnb.index
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100141 tar -I 'xz -T0' -C $(dir $<) -cf $@ $(notdir $<)
142
Marc Kupietzb7696992024-03-18 17:41:15 +0100143deploy: $(TARGET_DIR)/dnb.index.tar.xz korap4dnb-compose.yml
144 rsync -v $^ $(DEPLOY_USER)@$(DEPLOY_HOST):$(DEPLOY_PATH)/
145 ssh $(DEPLOY_USER)@$(DEPLOY_HOST) "mkdir -p $(DEPLOY_PATH) && cd $(DEPLOY_PATH) && docker compose -p korap4dnb --profile=lite -f $(notdir $(word 2,$^)) up -d --dry-run && docker compose -p korap4dnb stop && (mv -f dnb.index dnb.index.bak || true) && tar Jxvf $(notdir $<) && docker compose -p korap4dnb --profile=lite -f $(notdir $(word 2,$^)) up -d"
146
147show-server-log:
148 ssh $(DEPLOY_USER)@$(DEPLOY_HOST) "cd $(DEPLOY_PATH) && docker compose -p korap4dnb --profile=lite -f korap4dnb-compose.yml logs -f"
149
150show-server-status:
151 ssh $(DEPLOY_USER)@$(DEPLOY_HOST) "cd $(DEPLOY_PATH) && docker compose -p korap4dnb --profile=lite -f korap4dnb-compose.yml ps"
152
Marc Kupietz1a422662024-03-16 09:34:10 +0100153clean:
154 rm -rf $(BUILD_DIR) $(TARGET_DIR)
Marc Kupietz8d090062024-09-22 12:09:29 +0200155
Marc Kupietzcd8c0ec2025-11-02 17:36:22 +0100156$(TARGET_DIR)/dnb.index: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).krill.tar)
Marc Kupietz8d090062024-09-22 12:09:29 +0200157 rm -rf $@
Marc Kupietz6e73bdd2025-11-02 19:58:32 +0100158 java -jar lib/Krill-Indexer.jar --progress -c lib/krill.conf -i $(subst " ",;,$^) -o $@