-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.sh
executable file
·203 lines (164 loc) · 6.79 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
HELP="description:
marvin_extraction_run.sh and databus-release.sh take one argument, which is the extraction group
selects download.\$GROUP.properties and extraction.\$GROUP.properties from extractionConfig dir and uses \$GROUP as a path.
usage:
./marvin_extraction_run.sh {test|generic|generic.en|mappings|wikidata|text|sparktestgeneric}
"
##############
# setup paths
##############
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CONFIGDIR="$ROOT/extractionConfiguration"
LOGDIR="$ROOT/logs/$(date +%Y-%m-%d)" && mkdir -p $LOGDIR
DATABUSDIR="$ROOT/databus-poms"
MARVINEXTRACTIONDIR="$ROOT/marvin-extraction"
DIEFDIR="$MARVINEXTRACTIONDIR/extraction-framework"
EXTRACTIONBASEDIR="$MARVINEXTRACTIONDIR/wikidumps" && mkdir -p $EXTRACTIONBASEDIR
##############
# functions
##############
# extract data
extractDumps() {
cd $DIEFDIR/dump;
>&2 ../run extraction $CONFIGDIR/extraction.$GROUP.properties;
}
# post-processing, see http://dev.dbpedia.org/Post-Processing
postProcessing() {
cd $DIEFDIR/scripts;
# ResolveTransitiveLinks for all, affects the 'redirects' dataset
# TODO ResolveTransitiveLinks can take a wikidata interlanguage link parameter, that helps to sort the redirects
echo "-- ResolveTransitiveLinks"
>&2 ../run ResolveTransitiveLinks $EXTRACTIONBASEDIR redirects redirects_transitive .ttl.bz2 @downloaded;
# Datasets for MapObjectURIs
if [ "$GROUP" = "mappings" ] || [ "$GROUP" = "test" ]
then
DATASETS="mappingbased-objects-uncleaned"
elif [ "$GROUP" = "wikidata" ]
then
DATASETS="mappingbased-objects-uncleaned,raw"
elif [ "$GROUP" = "generic" ] || [ "$GROUP" = "generic.en" ] || [ "$GROUP" = "sparktestgeneric" ]
then
DATASETS="disambiguations,infobox-properties,page-links,persondata,topical-concepts"
fi
echo "-- MapObjectURIs"
>&2 ../run MapObjectUris $EXTRACTIONBASEDIR redirects_transitive .ttl.bz2 $DATASETS _redirected .ttl.bz2 @downloaded;
# Datasets with TypeConsistencyCheck
if [ "$GROUP" = "mappings" ] || [ "$GROUP" = "test" ] || [ "$GROUP" = "wikidata" ] || [ "$GROUP" = "generic" ] || [ "$GROUP" = "generic.en" ] || [ "$GROUP" = "sparktestgeneric" ]
then
echo "-- TypeConsistencyCheck"
>&2 ../run TypeConsistencyCheck type.consistency.check.properties;
fi
# Handling of redirects, i.e. copy to log and rename old
echo "-- copying redirects"
mkdir -p $LOGDIR/unredirected/
for redirectedFile in $(find $EXTRACTIONBASEDIR -name "*_redirected.ttl.bz2") ; do
unredirectedFile=$(echo $redirectedFile | sed 's|_redirected\.ttl\.bz2$|\.ttl\.bz2|g');
[ -f $unredirectedFile ] && cp -vn "$unredirectedFile" "$LOGDIR/unredirected/";
>&2 rename -f -v 's/_redirected//' $redirectedFile;
done
}
# compress log files
# log files from same day get overwritten, only latest is kept
archiveLogFiles() {
for f in $(find $LOGDIR -type f ); do lbzip2 -f $f; done;
}
##########################
# Databus Mapping
##########################
# switch case for some language exceptions
mapLangToContVar() {
lang=$(echo "$1" | sed 's|wiki||g')
case "$lang" in
"bat_smg") echo "_lang=batsmg";;
"zh_min_nan") echo "_lang=nan";;
"zh_yue") echo "_lang=yue";;
"data") echo "";;
"commons" ) echo "_commons";;
*) echo "_lang=$lang";;
esac
}
mapNamesToDatabus() {
case "$1" in
# generic
"article-templates-nested") echo "article-templates_nested";;
"citation-data") echo "citations_data";;
"citation-links") echo "citations_links";;
"commons-page-links") echo "commons-sameas-links";;
"page-ids") echo "page_ids";;
"page-length") echo "page_length";;
"page-links") echo "wikilinks";;
"article-categories") echo "categories_articles";;
"category-labels") echo "categories_labels";;
"skos-categories") echo "categories_skos";;
"revision-ids") echo "revisions_ids";;
"revision-uris") echo "revisions_uris";;
# mappings
"mappingbased-objects-disjoint-domain") echo "mappingbased-objects_disjointDomain";;
"mappingbased-objects-disjoint-range") echo "mappingbased-objects_disjointRange";;
# wikidata
"alias-nmw") echo "alias_nmw";;
"description-nmw") echo "description_nmw";;
"labels-nmw") echo "labels_nmw";;
"mappingbased-properties-reified-qualifiers") echo "mappingbased-properties-reified_qualifiers";;
"mappingbased-objects-uncleaned-redirected") echo "mappingbased-objects";;
"revision-ids") echo "revisions_ids";;
"revision-uris") echo "revisions_uris";;
"wikidata-duplicate-iri-split") echo "debug_duplicateirisplit";;
"wikidata-r2r-mapping-errors") echo "debug_r2rmappingerrors";;
"wikidata-type-like-statements") echo "debug_typelikestatements";;
"transitive-redirects") echo "redirects_transitive";;
# both mappings and wikidata
"instance-types") echo "instance-types_specific";;
"instance-types-transitive") echo "instance-types_transitive";;
*) echo "$1";;
esac
}
# creates links in databus dir
mapAndCopy() {
# each individual file
path=$1
# split filename
# how to use ${string##/*}
# https://www.tldp.org/LDP/abs/html/string-manipulation.html#Substring%20Removal#Substring Removal
file="${path##*/}"
version="${file#*-}"
version="${version%%-*}"
version="${version:0:4}.${version:4:2}.${version:6:2}"
lang="${file%%-*}"
extraction="${file#*-*-}"
extraction="${extraction%%.*}"
extraction=$(echo -n $extraction | sed 's|interlanguage-links-|interlanguage-links_lang=|') # generic exception
extensions="${file#*.}"
# map names and languages
mapped="$(mapNamesToDatabus $extraction)"
contVars="$(mapLangToContVar $lang)"
if [[ "$mapped" == *"_"* ]]; then
contVars="${contVars}_${mapped#*_}"
fi
artifact="${mapped%%_*}"
targetFolder="$DATABUSDIR/dbpedia/$GROUP/$artifact/$version"
targetFile="$artifact$contVars.$extensions"
if [ -d "$DATABUSDIR/dbpedia/$GROUP/$artifact" ]; then
mkdir -p $targetFolder
else
echo "[DEBUG]\"$artifact\" (artifact not found, might not be in group $GROUP) $path" >&2;
fi
# TODO proper handling of "_redirected"
# TODO see above, redirected are moved to logdir and overwrite the unredirected
# concerns only generic:
# < enwiki/20191001/enwiki-20191001-disambiguations_redirected.ttl.bz2
# < enwiki/20191001/enwiki-20191001-infobox-properties_redirected.ttl.bz2
# < enwiki/20191001/enwiki-20191001-page-links_redirected.ttl.bz2
# < enwiki/20191001/enwiki-20191001-persondata_redirected.ttl.bz2
# < enwiki/20191001/enwiki-20191001-topical-concepts_redirected.ttl.bz2
# copy
# TODO comment after testing
cp -vn "$path" "$targetFolder/$targetFile"
# ln -s "$path" "$targetFolder/$targetFile"
# echo -e "< $path\n> $targetFolder/$targetFile\n----------------------"
}
diefCommitLink() {
cd $DIEFDIR
echo "https://github.com/dbpedia/extraction-framework/commit/$(git rev-parse @)"
}