Adding Wikipedia links to WikiData extracts

Processed pipeline in Azure Data Factory

Back in August I posted a technique to create database dimensions from WikiData using Azure Data Factory to extract from the dump files in ntriples format.

We recently had a requirement to add the Wikipedia links for each entity in the dimension - both for use as a primary key (since the Wikipedia URI is unique and human friendly) as well as for quality control.

That should be pretty easy: much of the WikiData entities have links to the matching object on Wikipedia. For example, if you extracting cities, look at the RDF for Rosemount you’ll see the relationships for eack Wikipedia entry in different languages:

<,_Minnesota> a schema:Article ;
	schema:about wd:Q1986505 ;
	schema:inLanguage "en" ;
	schema:isPartOf <> ;
	schema:name "Rosemount, Minnesota"@en .

Or, in NTriples:

<,_Minnesota> <> <> .
<,_Minnesota> <> <> .
<,_Minnesota> <> "en" .
<,_Minnesota> <> <> .
<,_Minnesota> <> "Rosemount, Minnesota"@en .
<> <> "wikipedia" .

So, I thought, should be pretty easy to add to the existing split operation and match on rows with the predicate of <> and then join on the URI of the desired object. To ensure we only get the relationship to the English version of Wikipedia, either

I opted for the second option as semantically more correct, added the relevant splits and joins and ran the pipeline. Nothing came out. Huh? It took a full scan of the file to realize the the truthy file doesn’t contain the predicates (for a more detailed discussion of the difference, see WikiData).

To get those, one must turn to the full dump, a 122GB bzip2 file. Once downloaded, I amended my data flow to accept two source files, the truthy pipeline stayed as is, the Wikipedia relationships I extracted from the all file.

Adding this functionality pushed run time from ~50 minutes to ~80 (see image above). Not bad for a five fold increase in input data.