blob: 84722c5e34364b1891bde09644ef45955b9465fc [file] [log] [blame]
Marc Kupietzdeb95462024-04-15 20:26:14 +02001# Change the SRC_DIR to the directory containing the DNB EPUB files, e.g. with
2# make -j 96 target/dnb13.index.tar.xz SRC_DIR=../sample.10000
3
Marc Kupietz13e28582024-04-19 11:26:01 +02004SRC_DIR ?= /mnt/data/KorAP@DNB/Random-10-12-23.epub
Marc Kupietzdeb95462024-04-15 20:26:14 +02005
Marc Kupietz13e28582024-04-19 11:26:01 +02006# Change YEARS to the years you want to process, e.g. with
Marc Kupietzdeb95462024-04-15 20:26:14 +02007# make -j12 i5valid YEARS="18 19"
8
Marc Kupietz13e28582024-04-19 11:26:01 +02009YEARS ?= $(shell seq -w 2012 2024 | sed 's/^.*\([0-9][0-9]\)/\1/')
Marc Kupietzdeb95462024-04-15 20:26:14 +020010
Marc Kupietz1a422662024-03-16 09:34:10 +010011BUILD_DIR = build
12TARGET_DIR ?= target
Marc Kupietzb7696992024-03-18 17:41:15 +010013DEPLOY_HOST ?= compute.ids-mannheim.de
14DEPLOY_USER ?= korap
15DEPLOY_PATH ?= /export/netapp/korap4dnb
Marc Kupietz48c6a682024-03-24 15:27:08 +010016MAX_THREADS ?= $(shell nproc)
Marc Kupietz975996e2024-04-13 13:46:37 +020017MAKE ?= make -j $(shell nproc)
Marc Kupietz3146b632024-04-23 09:40:25 +020018KORAPXML2CONLLU_HEAP ?= $(shell echo "$$(($(MAX_THREADS) * 2500))")
Marc Kupietzd059d2d2024-04-15 18:58:39 +020019KORAPXML2CONLLU ?= java -Xmx$(KORAPXML2CONLLU_HEAP)m -jar lib/korapxml2conllu.jar
Marc Kupietz68b4f8a2024-05-26 18:27:40 +020020SAXON ?= java -Djava.util.logging.config.file=/logging.properties -cp lib/saxon-ee-12.4.jar:lib/xmlresolver-5.2.2.jar:lib/textclassifier.jar:lib/xmlresolver-5.2.2-data.jar net.sf.saxon.Transform -expand:off
Marc Kupietz1a422662024-03-16 09:34:10 +010021
Marc Kupietz5652c812024-04-19 11:42:00 +020022.DELETE_ON_ERROR:
23
Marc Kupietz157e0792024-04-13 12:46:42 +020024.PHONY: all clean test i5 i5valid krill index deploy server-log server-status
Marc Kupietz1a422662024-03-16 09:34:10 +010025
Marc Kupietz5652c812024-04-19 11:42:00 +020026.PRECIOUS: $(TARGET_DIR)/%.i5.xml $(TARGET_DIR)/dnb%.pre.i5.xml %.zip %.tree_tagger.zip %.ud.zip %.marmot-malt.zip %.spacy.zip %.i5.xml %.tar
Marc Kupietz1a422662024-03-16 09:34:10 +010027
Marc Kupietzb7696992024-03-18 17:41:15 +010028
Marc Kupietzfeed26a2024-03-17 19:16:23 +010029all: index
Marc Kupietz1a422662024-03-16 09:34:10 +010030
Marc Kupietzdeb95462024-04-15 20:26:14 +020031krill: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).krill.tar)
Marc Kupietz3d82f562024-03-16 10:19:03 +010032
Marc Kupietzab1f3ac2024-04-16 14:56:43 +020033index: $(TARGET_DIR)/dnb.index
Marc Kupietzdeb95462024-04-15 20:26:14 +020034
Marc Kupietz8a1e4652024-04-21 15:55:03 +020035$(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 +020036 $(SAXON) -xsl:xslt/pass2.xsl $< | $(SAXON) -xsl:xslt/pass3.xsl - > $@
Marc Kupietzfa445da2024-03-16 10:46:22 +010037
Marc Kupietz28f48e12024-04-14 16:17:05 +020038
Marc Kupietzdeb95462024-04-15 20:26:14 +020039$(TARGET_DIR)/dnb%.pre.i5.xml: $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*.epub))
40 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*0.epub)) > $(TARGET_DIR)/filelist$*.txt
41 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*1.epub)) >> $(TARGET_DIR)/filelist$*.txt
42 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*2.epub)) >> $(TARGET_DIR)/filelist$*.txt
43 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*3.epub)) >> $(TARGET_DIR)/filelist$*.txt
44 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*4.epub)) >> $(TARGET_DIR)/filelist$*.txt
45 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*5.epub)) >> $(TARGET_DIR)/filelist$*.txt
46 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*6.epub)) >> $(TARGET_DIR)/filelist$*.txt
47 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*7.epub)) >> $(TARGET_DIR)/filelist$*.txt
48 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*8.epub)) >> $(TARGET_DIR)/filelist$*.txt
49 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*9.epub)) >> $(TARGET_DIR)/filelist$*.txt
Marc Kupietz8e4e23e2024-04-19 11:16:10 +020050 @echo $(patsubst $(SRC_DIR)/%.epub,$(TARGET_DIR)/%.i5.xml,$(wildcard $(SRC_DIR)/*X.epub)) >> $(TARGET_DIR)/filelist$*.txt
Marc Kupietzdeb95462024-04-15 20:26:14 +020051 sed -i -e 's/ /\n/g; /^$$/d' $(TARGET_DIR)/filelist$*.txt
52 head -n -1 xslt/idsCorpus-template.xml | sed -e 's/{YY}/$*/' > $@
Marc Kupietzb926f252024-04-14 08:57:11 +020053 @while IFS= read -r f; do \
Marc Kupietzdeb95462024-04-15 20:26:14 +020054 if head -500 "$$f" | grep -Eq '<pubDate type="year">..$*'; then \
Marc Kupietzb926f252024-04-14 08:57:11 +020055 cat "$$f" >> $@; \
56 fi; \
Marc Kupietzdeb95462024-04-15 20:26:14 +020057 done < $(TARGET_DIR)/filelist$*.txt
Marc Kupietz1a422662024-03-16 09:34:10 +010058 tail -n 1 xslt/idsCorpus-template.xml >> $@
59
Marc Kupietz161d0112024-07-25 11:09:04 +020060test: YEARS := 13 18
61test: SRC_DIR=test/resources/DNB
62
Marc Kupietz84677242024-04-27 11:46:07 +020063test: models/dereko_domains_s.classifier i5valid test/test-xml.sh
Marc Kupietz73a26bf2024-04-26 17:36:44 +020064 bash test/test-xml.sh
Marc Kupietz1a422662024-03-16 09:34:10 +010065
Marc Kupietzdeb95462024-04-15 20:26:14 +020066i5: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).i5.xml)
Marc Kupietz157e0792024-04-13 12:46:42 +020067
Marc Kupietzdeb95462024-04-15 20:26:14 +020068i5valid: i5
69 xmllint --noout --valid $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).i5.xml)
Marc Kupietz157e0792024-04-13 12:46:42 +020070
Marc Kupietz1a422662024-03-16 09:34:10 +010071$(BUILD_DIR)/%: $(SRC_DIR)/%.epub
72 mkdir -p $@
73 echo "Converting $< to $@"
74 unzip -q -o $< -d $@
Marc Kupietz51714ed2024-04-13 12:47:39 +020075 chmod -R ug+rwX $@
Marc Kupietz1a422662024-03-16 09:34:10 +010076
Marc Kupietzdfbc3f42024-03-16 11:46:41 +010077$(TARGET_DIR)/%.i5.xml: $(BUILD_DIR)/% xslt/epub2i5.xsl xslt/idsCorpus-template.xml
Marc Kupietz1a422662024-03-16 09:34:10 +010078 mkdir -p $(TARGET_DIR)
79 echo "Converting $< to $@"
Marc Kupietz74fb31d2024-04-19 11:44:49 +020080 $(SAXON) -xsl:xslt/epub2i5.xsl $(shell find $< -name "*.opf") > $@ || (echo "WARN: ignoring invalid $@" && > $@)
Marc Kupietz1a422662024-03-16 09:34:10 +010081
82%.zip: %.i5.xml
83 tei2korapxml -l warn -s -tk - < $< > $@
84
85%.tree_tagger.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +010086 $(KORAPXML2CONLLU) $< | pv | docker run --rm -i korap/conllu2treetagger -l german | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +010087
88%.spacy.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +010089 $(KORAPXML2CONLLU) $< | pv | docker run --rm -i korap/conllu2spacy | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +010090
Marc Kupietz8ea92282024-03-24 14:55:55 +010091models/de.marmot:
92 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010093 curl -sL -o $@ https://cistern.cis.lmu.de/marmot/models/CURRENT/spmrl/de.marmot
Marc Kupietz8ea92282024-03-24 14:55:55 +010094
95models/german.mco:
96 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010097 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
Marc Kupietz8ea92282024-03-24 14:55:55 +010098
Marc Kupietza5538652024-04-21 15:49:30 +020099models/dereko_domains_s.classifier:
100 mkdir -p models
101 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
102
Marc Kupietz8ea92282024-03-24 14:55:55 +0100103%.marmot-malt.zip: %.zip models/de.marmot models/german.mco
Marc Kupietzccf09042024-04-21 17:19:36 +0200104 $(KORAPXML2CONLLU) -T $(MAX_THREADS) -t marmot:models/de.marmot -P malt:models/german.mco $< | conllu2korapxml -f "marmot dependency:malt" > $@
Marc Kupietz8ea92282024-03-24 14:55:55 +0100105
Marc Kupietz1a422662024-03-16 09:34:10 +0100106%.ud.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +0100107 $(KORAPXML2CONLLU) $< | pv | ./scripts/udpipe2 | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +0100108
Marc Kupietzd653bb82024-04-21 12:52:51 +0200109%.krill.tar: %.zip %.marmot-malt.zip %.tree_tagger.zip
Marc Kupietz87597512024-04-15 18:31:34 +0200110 mkdir -p ${BUILD_DIR}/krill/$(basename $@)
Marc Kupietz3d82f562024-03-16 10:19:03 +0100111 mkdir -p $(basename $@)
Marc Kupietzd653bb82024-04-21 12:52:51 +0200112 korapxml2krill archive --quiet -w -z -cfg krill-korap4dnb.cfg -c ${BUILD_DIR}/krill/$(basename $@)/korapxml2krill.cache -j $(MAX_THREADS) -te ${BUILD_DIR}/krill/$(basename $@) --non-word-tokens --meta I5 -i $< -i $(word 2,$^) -i $(word 3,$^) -o $(basename $@)
Marc Kupietz1a422662024-03-16 09:34:10 +0100113
Marc Kupietzfc328622024-03-16 14:31:34 +0100114%.json: %.krill.tar
115 rm -rf $@
116 mkdir -p $@
117 for f in $<; do tar -C $@ -xf $$f; done
Marc Kupietz1a422662024-03-16 09:34:10 +0100118
Marc Kupietzab1f3ac2024-04-16 14:56:43 +0200119$(TARGET_DIR)/dnb.index: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).json)
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100120 rm -rf $@
Marc Kupietzab1f3ac2024-04-16 14:56:43 +0200121 java -jar lib/Krill-Indexer.jar -c lib/krill.conf -i $(subst " ",;,$^) -o $@
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100122
Marc Kupietzab1f3ac2024-04-16 14:56:43 +0200123$(TARGET_DIR)/dnb.index.tar.xz: $(TARGET_DIR)/dnb.index
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100124 tar -I 'xz -T0' -C $(dir $<) -cf $@ $(notdir $<)
125
Marc Kupietzb7696992024-03-18 17:41:15 +0100126deploy: $(TARGET_DIR)/dnb.index.tar.xz korap4dnb-compose.yml
127 rsync -v $^ $(DEPLOY_USER)@$(DEPLOY_HOST):$(DEPLOY_PATH)/
128 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"
129
130show-server-log:
131 ssh $(DEPLOY_USER)@$(DEPLOY_HOST) "cd $(DEPLOY_PATH) && docker compose -p korap4dnb --profile=lite -f korap4dnb-compose.yml logs -f"
132
133show-server-status:
134 ssh $(DEPLOY_USER)@$(DEPLOY_HOST) "cd $(DEPLOY_PATH) && docker compose -p korap4dnb --profile=lite -f korap4dnb-compose.yml ps"
135
Marc Kupietz1a422662024-03-16 09:34:10 +0100136clean:
137 rm -rf $(BUILD_DIR) $(TARGET_DIR)