Newer
Older
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|mappings|wikidata|text}
"
##############
# setup paths
##############
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CONFIGDIR="$ROOT/extractionConfiguration"
DIEFDIR="$ROOT/marvin-extraction/extraction-framework"
LOGDIR="$ROOT/marvin-extraction/logs/$(date +%Y-%m-%d)" && mkdir -p $LOGDIR
EXTRACTIONBASEDIR="$ROOT/marvin-extraction/wikidumps" && mkdir -p $EXTRACTIONBASEDIR
DATABUSDIR="$ROOT/marvin-extraction/databus-maven-plugin"
##############
# functions
##############
# exception for generic, 1. spark, 2. as English is big and has to be run separately
>&2 ../run sparkextraction $CONFIGDIR/extraction.generic.properties;
>&2 ../run sparkextraction $CONFIGDIR/extraction.generic.en.properties;
else
# run for all
>&2 ../run extraction $CONFIGDIR/extraction.$GROUP.properties;
fi
cd $DIEFDIR/scripts;
echo "post-processing of $GROUP"
>&2 ../run ResolveTransitiveLinks $EXTRACTIONBASEDIR redirects redirects_transitive .ttl.bz2 @downloaded;
>&2 ../run MapObjectUris $EXTRACTIONBASEDIR redirects_transitive .ttl.bz2 mappingbased-objects-uncleaned _redirected .ttl.bz2 @downloaded;
>&2 ../run TypeConsistencyCheck type.consistency.check.properties;
elif [ "$GROUP" = "wikidata" ]
then
>&2 ../run ResolveTransitiveLinks $EXTRACTIONBASEDIR redirects transitive-redirects .ttl.bz2 wikidata
>&2 ../run MapObjectUris $EXTRACTIONBASEDIR transitive-redirects .ttl.bz2 mappingbased-objects-uncleaned,raw -redirected .ttl.bz2 wikidata
>&2 ../run TypeConsistencyCheck type.consistency.check.properties;
elif [ "$GROUP" = "generic" ]
then
>&2 ../run ResolveTransitiveLinks $EXTRACTIONBASEDIR redirects redirects_transitive .ttl.bz2 @downloaded;
>&2 ../run MapObjectUris $EXTRACTIONBASEDIR redirects_transitive .ttl.bz2 disambiguations,infobox-properties,page-links,persondata,topical-concepts _redirected .ttl.bz2 @downloaded;
elif [ "$GROUP" = "test" ]
then
>&2 ../run ResolveTransitiveLinks $EXTRACTIONBASEDIR redirects redirects_transitive .ttl.bz2 @downloaded;
>&2 ../run MapObjectUris $EXTRACTIONBASEDIR redirects_transitive .ttl.bz2 mappingbased-objects-uncleaned _redirected .ttl.bz2 @downloaded;
>&2 ../run TypeConsistencyCheckManual mappingbased-objects instance-types ro;
# log files from same day get overwritten, only latest is kept
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";;
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
"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-properties-reified") echo "mappingbased-properties-reified";;
"wikidata-duplicate-iri-split") echo "debug_duplicateirisplit";;
"wikidata-r2r-mapping-errors") echo "debug_r2rmappingerrors";;
"wikidata-type-like-statements") echo "debug_typelikestatements";;
# both mappings and wikidata
"instance-types") echo "instance-types_specific";;
"instance-types-transitive") echo "instance-types_transitive";;
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%%.*}"
extension="${file#*.}"
# wikidata exception
extraction=$(echo -n $extraction | sed 's|interlanguage-links-|interlanguage-links_lang=|' )
# 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.$extension"
# TODO proper handling of "_redirected"
#concerns onlyy 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
# targetFile=$(echo -n "$targetFile" | sed 's/_redirected//g' )
# copy
echo "< $path
> $artifact/$version/$targetFile"
echo "----------------------"
# TODO enable after testing
#cp -vn "$path" "$DATABUSMVNPOMDIR/$targetArVe/$targetFile"