blob: dd93938c7c55f2f3cd43891a8e6a7f16349ad059 [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 Kupietzdeb95462024-04-15 20:26:14 +020018KORAPXML2CONLLU_HEAP ?= $(shell echo "$$(($(MAX_THREADS) * 1625))")
Marc Kupietzd059d2d2024-04-15 18:58:39 +020019KORAPXML2CONLLU ?= java -Xmx$(KORAPXML2CONLLU_HEAP)m -jar lib/korapxml2conllu.jar
Marc Kupietzf62bc902024-04-14 15:59:44 +020020SAXON ?= java -cp lib/saxon9ee.jar:lib/xml-resolver-1.2.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 +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
35$(TARGET_DIR)/dnb%.i5.xml: $(TARGET_DIR)/dnb%.pre.i5.xml xslt/pass2.xsl xslt/pass3.xsl
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 Kupietzdeb95462024-04-15 20:26:14 +020060test: i5valid
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 Kupietz1a422662024-03-16 09:34:10 +010067$(BUILD_DIR)/%: $(SRC_DIR)/%.epub
68 mkdir -p $@
69 echo "Converting $< to $@"
70 unzip -q -o $< -d $@
Marc Kupietz51714ed2024-04-13 12:47:39 +020071 chmod -R ug+rwX $@
Marc Kupietz1a422662024-03-16 09:34:10 +010072
Marc Kupietzdfbc3f42024-03-16 11:46:41 +010073$(TARGET_DIR)/%.i5.xml: $(BUILD_DIR)/% xslt/epub2i5.xsl xslt/idsCorpus-template.xml
Marc Kupietz1a422662024-03-16 09:34:10 +010074 mkdir -p $(TARGET_DIR)
75 echo "Converting $< to $@"
Marc Kupietz74fb31d2024-04-19 11:44:49 +020076 $(SAXON) -xsl:xslt/epub2i5.xsl $(shell find $< -name "*.opf") > $@ || (echo "WARN: ignoring invalid $@" && > $@)
Marc Kupietz1a422662024-03-16 09:34:10 +010077
78%.zip: %.i5.xml
79 tei2korapxml -l warn -s -tk - < $< > $@
80
81%.tree_tagger.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +010082 $(KORAPXML2CONLLU) $< | pv | docker run --rm -i korap/conllu2treetagger -l german | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +010083
84%.spacy.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +010085 $(KORAPXML2CONLLU) $< | pv | docker run --rm -i korap/conllu2spacy | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +010086
Marc Kupietz8ea92282024-03-24 14:55:55 +010087models/de.marmot:
88 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010089 curl -sL -o $@ https://cistern.cis.lmu.de/marmot/models/CURRENT/spmrl/de.marmot
Marc Kupietz8ea92282024-03-24 14:55:55 +010090
91models/german.mco:
92 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010093 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
Marc Kupietz8ea92282024-03-24 14:55:55 +010094
95%.marmot-malt.zip: %.zip models/de.marmot models/german.mco
Marc Kupietzdeb95462024-04-15 20:26:14 +020096 $(KORAPXML2CONLLU) -T $(MAX_THREADS) -t marmot:models/de.marmot -P malt:models/german.mco $< | conllu2korapxml > $@
Marc Kupietz8ea92282024-03-24 14:55:55 +010097
Marc Kupietz1a422662024-03-16 09:34:10 +010098%.ud.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +010099 $(KORAPXML2CONLLU) $< | pv | ./scripts/udpipe2 | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +0100100
Marc Kupietz8ea92282024-03-24 14:55:55 +0100101%.krill.tar: %.zip %.marmot-malt.zip %.tree_tagger.zip %.spacy.zip
Marc Kupietz87597512024-04-15 18:31:34 +0200102 mkdir -p ${BUILD_DIR}/krill/$(basename $@)
Marc Kupietz3d82f562024-03-16 10:19:03 +0100103 mkdir -p $(basename $@)
Marc Kupietz87597512024-04-15 18:31:34 +0200104 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,$^) -i $(word 4,$^) -o $(basename $@)
Marc Kupietz1a422662024-03-16 09:34:10 +0100105
Marc Kupietzfc328622024-03-16 14:31:34 +0100106%.json: %.krill.tar
107 rm -rf $@
108 mkdir -p $@
109 for f in $<; do tar -C $@ -xf $$f; done
Marc Kupietz1a422662024-03-16 09:34:10 +0100110
Marc Kupietzab1f3ac2024-04-16 14:56:43 +0200111$(TARGET_DIR)/dnb.index: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).json)
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100112 rm -rf $@
Marc Kupietzab1f3ac2024-04-16 14:56:43 +0200113 java -jar lib/Krill-Indexer.jar -c lib/krill.conf -i $(subst " ",;,$^) -o $@
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100114
Marc Kupietzab1f3ac2024-04-16 14:56:43 +0200115$(TARGET_DIR)/dnb.index.tar.xz: $(TARGET_DIR)/dnb.index
Marc Kupietz22ad4b72024-03-17 16:24:21 +0100116 tar -I 'xz -T0' -C $(dir $<) -cf $@ $(notdir $<)
117
Marc Kupietzb7696992024-03-18 17:41:15 +0100118deploy: $(TARGET_DIR)/dnb.index.tar.xz korap4dnb-compose.yml
119 rsync -v $^ $(DEPLOY_USER)@$(DEPLOY_HOST):$(DEPLOY_PATH)/
120 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"
121
122show-server-log:
123 ssh $(DEPLOY_USER)@$(DEPLOY_HOST) "cd $(DEPLOY_PATH) && docker compose -p korap4dnb --profile=lite -f korap4dnb-compose.yml logs -f"
124
125show-server-status:
126 ssh $(DEPLOY_USER)@$(DEPLOY_HOST) "cd $(DEPLOY_PATH) && docker compose -p korap4dnb --profile=lite -f korap4dnb-compose.yml ps"
127
Marc Kupietz1a422662024-03-16 09:34:10 +0100128clean:
129 rm -rf $(BUILD_DIR) $(TARGET_DIR)