blob: 602c45c4ac803edbf5da3013549cadc80610ba7e [file] [log] [blame]
Marc Kupietz84da39d2024-07-25 20:23:50 +02001ifneq (,$(filter test,$(MAKECMDGOALS)))
2SRC_DIR = test/resources/DNB
3YEARS=13 18
4else
Marc Kupietzbadc4282024-07-26 15:45:22 +02005SRC_DIR ?= ./DeLiKo@DNB
Marc Kupietz13e28582024-04-19 11:26:01 +02006YEARS ?= $(shell seq -w 2012 2024 | sed 's/^.*\([0-9][0-9]\)/\1/')
Marc Kupietz84da39d2024-07-25 20:23:50 +02007endif
Marc Kupietzdeb95462024-04-15 20:26:14 +02008
Marc Kupietz1a422662024-03-16 09:34:10 +01009BUILD_DIR = build
10TARGET_DIR ?= target
Marc Kupietzb7696992024-03-18 17:41:15 +010011DEPLOY_HOST ?= compute.ids-mannheim.de
12DEPLOY_USER ?= korap
13DEPLOY_PATH ?= /export/netapp/korap4dnb
Marc Kupietz48c6a682024-03-24 15:27:08 +010014MAX_THREADS ?= $(shell nproc)
Marc Kupietz975996e2024-04-13 13:46:37 +020015MAKE ?= make -j $(shell nproc)
Marc Kupietz3146b632024-04-23 09:40:25 +020016KORAPXML2CONLLU_HEAP ?= $(shell echo "$$(($(MAX_THREADS) * 2500))")
Marc Kupietzd059d2d2024-04-15 18:58:39 +020017KORAPXML2CONLLU ?= java -Xmx$(KORAPXML2CONLLU_HEAP)m -jar lib/korapxml2conllu.jar
Marc Kupietzbec2ff02024-07-26 11:14:46 +020018SAXON ?= 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
Marc Kupietz1a422662024-03-16 09:34:10 +010019
Marc Kupietz84da39d2024-07-25 20:23:50 +020020
21
Marc Kupietz5652c812024-04-19 11:42:00 +020022.DELETE_ON_ERROR:
23
Marc Kupietz84da39d2024-07-25 20:23:50 +020024.PHONY: all clean test i5 i5valid krill index deploy show-server-log show-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 Kupietzfeed26a2024-03-17 19:16:23 +010028all: index
Marc Kupietz1a422662024-03-16 09:34:10 +010029
Marc Kupietzdeb95462024-04-15 20:26:14 +020030krill: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).krill.tar)
Marc Kupietz3d82f562024-03-16 10:19:03 +010031
Marc Kupietzab1f3ac2024-04-16 14:56:43 +020032index: $(TARGET_DIR)/dnb.index
Marc Kupietzdeb95462024-04-15 20:26:14 +020033
Marc Kupietz84da39d2024-07-25 20:23:50 +020034EPUBS := $(wildcard $(SRC_DIR)/**/*.epub)
35
Marc Kupietz8a1e4652024-04-21 15:55:03 +020036$(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 +020037 $(SAXON) -xsl:xslt/pass2.xsl $< | $(SAXON) -xsl:xslt/pass3.xsl - > $@
Marc Kupietzfa445da2024-03-16 10:46:22 +010038
Marc Kupietz84da39d2024-07-25 20:23:50 +020039$(TARGET_DIR)/dnb%.pre.i5.xml: $(patsubst %.epub,$(TARGET_DIR)/%.i5.xml,$(notdir $(EPUBS)))
40 echo $(EPUBS)
41 @find $(SRC_DIR) -type f -name '*.epub' | while read src; do \
42 echo $(TARGET_DIR)/$$(basename $${src%.epub}).i5.xml; \
43 done | sort -u > $(TARGET_DIR)/filelist$*.txt
Marc Kupietzdeb95462024-04-15 20:26:14 +020044 sed -i -e 's/ /\n/g; /^$$/d' $(TARGET_DIR)/filelist$*.txt
45 head -n -1 xslt/idsCorpus-template.xml | sed -e 's/{YY}/$*/' > $@
Marc Kupietzb926f252024-04-14 08:57:11 +020046 @while IFS= read -r f; do \
Marc Kupietzdeb95462024-04-15 20:26:14 +020047 if head -500 "$$f" | grep -Eq '<pubDate type="year">..$*'; then \
Marc Kupietzb926f252024-04-14 08:57:11 +020048 cat "$$f" >> $@; \
49 fi; \
Marc Kupietzdeb95462024-04-15 20:26:14 +020050 done < $(TARGET_DIR)/filelist$*.txt
Marc Kupietz1a422662024-03-16 09:34:10 +010051 tail -n 1 xslt/idsCorpus-template.xml >> $@
52
Marc Kupietz161d0112024-07-25 11:09:04 +020053
Marc Kupietz84677242024-04-27 11:46:07 +020054test: models/dereko_domains_s.classifier i5valid test/test-xml.sh
Marc Kupietz73a26bf2024-04-26 17:36:44 +020055 bash test/test-xml.sh
Marc Kupietz1a422662024-03-16 09:34:10 +010056
Marc Kupietzdeb95462024-04-15 20:26:14 +020057i5: $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).i5.xml)
Marc Kupietz157e0792024-04-13 12:46:42 +020058
Marc Kupietzdeb95462024-04-15 20:26:14 +020059i5valid: i5
60 xmllint --noout --valid $(foreach year,$(YEARS),$(TARGET_DIR)/dnb$(year).i5.xml)
Marc Kupietz157e0792024-04-13 12:46:42 +020061
Marc Kupietz84da39d2024-07-25 20:23:50 +020062
63$(BUILD_DIR)/%: $(SRC_DIR)/**/%.epub
Marc Kupietz1a422662024-03-16 09:34:10 +010064 mkdir -p $@
65 echo "Converting $< to $@"
66 unzip -q -o $< -d $@
Marc Kupietz51714ed2024-04-13 12:47:39 +020067 chmod -R ug+rwX $@
Marc Kupietz1a422662024-03-16 09:34:10 +010068
Marc Kupietzdfbc3f42024-03-16 11:46:41 +010069$(TARGET_DIR)/%.i5.xml: $(BUILD_DIR)/% xslt/epub2i5.xsl xslt/idsCorpus-template.xml
Marc Kupietz1a422662024-03-16 09:34:10 +010070 mkdir -p $(TARGET_DIR)
71 echo "Converting $< to $@"
Marc Kupietz74fb31d2024-04-19 11:44:49 +020072 $(SAXON) -xsl:xslt/epub2i5.xsl $(shell find $< -name "*.opf") > $@ || (echo "WARN: ignoring invalid $@" && > $@)
Marc Kupietz1a422662024-03-16 09:34:10 +010073
74%.zip: %.i5.xml
75 tei2korapxml -l warn -s -tk - < $< > $@
76
77%.tree_tagger.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +010078 $(KORAPXML2CONLLU) $< | pv | docker run --rm -i korap/conllu2treetagger -l german | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +010079
80%.spacy.zip: %.zip
Marc Kupietzfa445da2024-03-16 10:46:22 +010081 $(KORAPXML2CONLLU) $< | pv | docker run --rm -i korap/conllu2spacy | conllu2korapxml > $@
Marc Kupietz1a422662024-03-16 09:34:10 +010082
Marc Kupietz8ea92282024-03-24 14:55:55 +010083models/de.marmot:
84 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010085 curl -sL -o $@ https://cistern.cis.lmu.de/marmot/models/CURRENT/spmrl/de.marmot
Marc Kupietz8ea92282024-03-24 14:55:55 +010086
87models/german.mco:
88 mkdir -p models
Marc Kupietze8c80f32024-03-24 15:27:28 +010089 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
Marc Kupietz8ea92282024-03-24 14:55:55 +010090
Marc Kupietza5538652024-04-21 15:49:30 +020091models/dereko_domains_s.classifier:
92 mkdir -p models
93 curl -sL -o $@ https://corpora.ids-mannheim.de/tools/$@
94
Marc Kupietz8ea92282024-03-24 14:55:55 +010095%.marmot-malt.zip: %.zip models/de.marmot models/german.mco
Marc Kupietzccf09042024-04-21 17:19:36 +020096 $(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 +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 Kupietzd653bb82024-04-21 12:52:51 +0200101%.krill.tar: %.zip %.marmot-malt.zip %.tree_tagger.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 Kupietz5f0db262024-07-26 12:31:47 +0200104 K2K_TRANSLATOR_TEXT=1 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 +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)