<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>A. Willerval); dennis.diefenbach@the-qa-company.com
(D. Diefenbach); pierre.maret@the-qa-company.com (P. Maret)</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Easily setting up a local Wikidata SPARQL endpoint using the qEndpoint</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Antoine Willerval</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dennis Diefenbach</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Pierre Maret</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>CNRS, Laboratoire Hubert Curien UMR 5516, University of Lyon</institution>
          ,
          <country country="FR">France</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>The QA Company SAS</institution>
          ,
          <country country="FR">France</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2022</year>
      </pub-date>
      <volume>000</volume>
      <fpage>0</fpage>
      <lpage>0003</lpage>
      <abstract>
        <p>Setting up a local Wikidata SPARQL endpoint is currently technically complex and requires costly hardware resources. In this paper we propose a novel workflow to index Wikidata and setup a local SPARQL endpoint which is easy (simple a docker pull), fast (takes less then 3 hours), cheap (can be executed on a laptop with 16GB of RAM) and eficient (achieves comparable query response times to the oficial endpoint). We achieve this by exploiting a newly open source SPARQL endpoint called the qEndpoint.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Wikidata</kwd>
        <kwd>SPARQL endpoint</kwd>
        <kwd>qEndpoint</kwd>
        <kwd>scalability</kwd>
        <kwd>HDT</kwd>
        <kwd>RDF4J</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>also shown in a long standing issue4 to tackle this problem.</p>
      <p>One option, suggested also by the community5, is to ofer an easier setup to locally run a query
service over Wikidata. This would have mainly two consequences:
• the query service at https://query.wikidata.org would have to handle lower pressure
allowing a better service overall for all users;
• users querying the local setup would not be blocked due to the query limits of the public
endpoint6, and should experience less query timeouts since all the local resources would
be reserved for them.</p>
      <p>While this option seems a viable approach it is technically challenging. The instructions provided
by Wikimedia7 to setup a local SPARQL endpoint state that: "it will take about 12 days to get all
data imported (into the triple-store), and another 12 days to make the query service catching up
the lag". Additionally one needs to add the time to download the dump. Moreover considerable
computing resources are necessary8 for the setup, i.e. a server with 100GB of RAM and 16 CPUs.
This explains why this solution is not widespread.</p>
      <p>In this paper we present an alternative workflow to setup a local SPARQL endpoint over
Wikidata. In this version we restrict to a SPARQL endpoint over the truthy statements, but we
plan to extend it to the full dump. The workflow allows to setup a local SPARQL endpoint over
Wikidata in 3 hours9 that contains data that is not older then 24h and that can run on a laptop
with 16GB of RAM. This represents a huge improvement over the existing setup. As a side efect
we publish truthy dumps for Wikidata that are more up to date than the once published by
Wikidata itself. We achieve this by implementing a new indexing workflow and use a recently
created open source triple-store, the qEndpoint.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Definition</title>
      <sec id="sec-2-1">
        <title>2.1. qEndpoint</title>
        <p>
          In this article we are using tools and algorithm, in this section we are describing them.
The qEndpoint is a new triple-store that aims at making RDF datasets queriable at scale with low
hardware requirements. The qEndpoint combines two established Semantic-Web technologies
namely RDF4J[
          <xref ref-type="bibr" rid="ref2">2</xref>
          ]10 and HDT[
          <xref ref-type="bibr" rid="ref3">3</xref>
          ]11. RDF4J is a popular Java library that includes SPARQL
querying capabilities. It provides stores that are recommended only for datasets up to 200
million triples. On the other side, HDT is a compressed RDF dataset format scaling to billions of
triples, but it is read-only and it ofers only the ability to search triple patterns (without ofering
4https://phabricator.wikimedia.org/T206560
5Discussions were raised for example during the Wikidata Workshop at ISWC in 2020
6https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual#Query_limits
7https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual#Standalone_service
8https://addshore.com/2019/10/your-own-wikidata-query-service-with-no-limits/
9assuming a fast internet connection with 10Mb/s
10https://rdf4j.org
11https://www.rdfhdt.org
2.2.1. HDTCat
2.2.2. HDTDif
full SPARQL support).
        </p>
        <p>By taking inspiration on architectures developed in the relational databases world, the qEndpoint
combines the advantages of both HDT and RDF4J. It is highly scalable thanks to HDT and
supports updates and SPARQL syntax thanks to RDF4J.</p>
        <p>
          The qEndpoint is available as an open source project at https://github.com/the-qa-company/
qEndpoint. It is already used for instance as a part of the infrastructure of the EU Knowledge
Graph[
          <xref ref-type="bibr" rid="ref4">4</xref>
          ]12 and is the index used by the question answering system QAnswer[
          <xref ref-type="bibr" rid="ref5">5</xref>
          ]1314.
        </p>
      </sec>
      <sec id="sec-2-2">
        <title>2.2. HDTDif and HDTCat</title>
        <p>
          The compressed RDF dataset format HDT doesn’t supports updates by default, to fix this issue,
2 methods are available, HDTCat[
          <xref ref-type="bibr" rid="ref6">6</xref>
          ] and HDTDif 15.
        </p>
        <p>This method allows to create the UNION of 2 HDT datasets into a new HDT dataset.</p>
        <p>HDTCat(ℎ1, ℎ2) = ℎ1 ∪ ℎ2
This method allows to remove triples from an HDT dataset to create a new HDT dataset. We
need to give it an HDT ℎ and a bitmap  of the size the number of triples of ℎ if a bit 
= 1, the triple at the index  in the HDT should be removed.</p>
        <p>HDTDif (ℎ, ) = {ℎ | ℎ ∈ ℎ ∧  = 0}</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Wikidata Indexing Workflow</title>
      <p>In the following we describe the workflow that we use to index Wikidata. It makes an intensive
use of HDT and some of its related functions. The steps are depicted in Figure 1.
1. We take the truthy dump of Wikidata 16 at a given time 0 and we compress it obtaining
0 .
2. We fetch all the changes since 0 using the Wikimedia Recent Changes API17 and for each
of the changed entities we download its current turtle representation18. By concatenating
and compressing all these files we create an  .
3. We use HDTDif (2.2.2) to eliminate from 0 all triples having as a subject one of the
entities we fetched from the recent changes API to obtain 0− .
12https://linkedopendata.eu
13https://app.qanswer.ai
14https://wikidata.qanswer.ai
15https://github.com/rdfhdt/hdt-java/pull/153
16https://dumps.wikimedia.org/wikidatawiki/entities/
17https://www.mediawiki.org/wiki/API:RecentChanges
18for example for the entity Q1 https://www.wikidata.org/wiki/Special:EntityData/Q1.ttl?flavor=simple
4. Using HDTCat (2.2.1) we join 0−  with  to obtain an up-to-date HDT.</p>
      <p>Finally we compute the corresponding HDT index file.
5. We publish the newly updated Wikidata HDT.
6. We publish a docker image of the qEndpoint that downloads on demand the created</p>
      <p>Wikidata HDT.</p>
      <p>Note that the steps 1 to 5 are carried out by the publisher. The consumer, i.e. the person that
wants to set up the SPARQL endpoint, just needs to download the HDT file and its associated
index with the qEndpoint. No other loading time is required. In this case we take advantage of
HDT that highly compresses RDF datasets while ofering triple pattern query capabilities.</p>
      <p>The steps 1 to 5 are published in the Wiki-changes repository at https://github.com/the-qa-company/
wiki-changes/releases. Step 6 is a docker image that is available at https://hub.docker.com/
r/qacompany/qendpoint-wikidata. It bundles the qEndpoint and downloads at start time the
latest HDT index over Wikidata available at https://qanswer-svc4.univ-st-etienne.fr.</p>
    </sec>
    <sec id="sec-4">
      <title>4. Experiments</title>
      <p>First, we show the time that is necessary to generate a fresh index (i.e. steps 1 to 5). To run
Wiki-changes, we used a server with 32GB of RAM. The results are presented in the Table 1.
We made tests for an 1-day old HDT and a 3-day old HDT. The figures show that once we have
the  HDT we can get a new up-to-date +1 HDT in less than 18 hours (13 hours for a 1-day
old HDT), allowing a maximum diference of 1 day between our HDT and Wikidata.</p>
      <p>Next, let’s consider the setup time. On the docker image, the download time of the image of
the qEndpoint is only a few minutes and is negligible. Once the container starts, the wikidata
index is downloaded from https://qanswer-svc4.univ-st-etienne.fr. The current size of the HDT
Wikidata index is 100GB. With a download speed of 10MB/s the endpoint can be setup in less
than 3 hours. We reproduced this number. Note that this is just 3 times slower then downloading
the full truthy dump19 of wikidata in bz2 format which is 32GB. A consequence of this is also
that the space requirement for the local endpoint is as little as 100GB on disk.</p>
      <p>
        In the next step we analyze the performance of the SPARQL endpoint using the oficial query
log of Wikidata[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. For our experiments we take the interval 7 dump20 which contains more
than 82 million queries fired against the endpoint in February and March 2018. We analyzed
the first 100.000 queries in the log. 11.378 contain the http://www.bigdata.com/ prefix. Most
notably this includes the functionality to get the labels of entities21. We exclude these queries
from our experiments since they are not covered by the SPARQL 1.1 standard. By excluding
this queries we obtain 88.622 queries. From these we exclude the once containing the prefix
http://www.wikidata.org/prop/statement/ which indicates a reefied statement which is not
included in the truthy dump. We get 84.250 remaining statements. This in particular means
that a large part of the query log is answerable by querying the truthy dump only.
We choose the first 3.600 queries of the interval 7 dump which satisfy the above criteria and run
them against the oficial Wikidata SPARQL endpoint and the local docker setup of the qEndpoint
(both configured with a timeout of 60 seconds). For the qEndpoint we configured the JVM to
use at maximum 6GB of memory22. We excluded 3 queries since they were running indefinitely
on the qEndpoint even with the timeout set due to a bug23. The results are depicted in Figure
2. Each square represents a query and the time diference between the answer time over the
qEndpoint and the oficial endpoint. Squares in green indicate queries that were answered
faster on the qEndpoint, and squares in red the queries that were answered faster on the public
endpoint. The colors are proportional to the time diference. Overall we can see in the Table 2
that for 3490 cases the qEndpoint gives better results in term of speed compared to the oficial
Wikidata SPARQL endpoint.
      </p>
    </sec>
    <sec id="sec-5">
      <title>5. Conclusion</title>
      <p>We have presented an alternative option to set up a local SPARQL endpoint over Wikidata. This
solution is quick (3 hours compared to several weeks), low in hardware requirements (only 6GB
19https://dumps.wikimedia.org/wikidatawiki/entities/
20https://iccl.inf.tu-dresden.de/web/Wikidata_SPARQL_Logs/en
21https://en.wikibooks.org/wiki/SPARQL/SERVICE_-_Label
22-Xmx setting of the JVM
23https://github.com/the-qa-company/qEndpoint/issues/80, https://github.com/eclipse/rdf4j/issues/636
of RAM and 100GB of disk compared to 100GB of RAM and TBs of disk) and fast (it can handle
a large amount of real world queries faster than the existing endpoint).</p>
      <p>We hope that the easy setup of a local Wikidata endpoint will allow to ofer new types of
services around Wikidata that are not bounded by the limits imposed by the oficial Wikidata
SPARQL service. We hope also that this setup will move part of the workload away from the
public Wikidata endpoint so that it can be hosted in a more decentralized manner.</p>
      <p>In future we aim at:
• integrating the above workflow and publishing new dumps regularly;
• releasing the same setup for the full Wikidata dump;
• allow a setup that follows live the changes of Wikidata or Wikibase implementations;
• implementing the SPARQL syntax introduced by Blazegraph in order to allow a full
compatibility in the current Wikibase ecosystem;
• evaluate the endpoint on a larger part of the query log;
• take more advantage of the internals of the qEndpoint for analytic queries which is an
interesting and exciting direction to further exploit the data published in Wikidata.</p>
      <p>Acknowledgment: We would like to thank José M. Giménez-García for the discussions we
had while building this work. We would like to thank the HDT community for the amazing work
they have done, in particular the creators of HDT and more in particular Javier D. Fernández.
We would like the RDF4J community that provides a high quality library with amazing code
contributions.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>D.</given-names>
            <surname>Vrandečić</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Krötzsch</surname>
          </string-name>
          ,
          <article-title>Wikidata: a free collaborative knowledgebase</article-title>
          ,
          <source>Communications of the ACM</source>
          <volume>57</volume>
          (
          <year>2014</year>
          )
          <fpage>78</fpage>
          -
          <lpage>85</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>J.</given-names>
            <surname>Broekstra</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Kampman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F. v.</given-names>
            <surname>Harmelen</surname>
          </string-name>
          ,
          <article-title>Sesame: A generic architecture for storing and querying rdf and rdf schema</article-title>
          , in: International semantic web conference, Springer,
          <year>2002</year>
          , pp.
          <fpage>54</fpage>
          -
          <lpage>68</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J. D.</given-names>
            <surname>Fernández</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. A.</given-names>
            <surname>Martínez-Prieto</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Gutiérrez</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Polleres</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Arias</surname>
          </string-name>
          ,
          <article-title>Binary rdf representation for publication and exchange (hdt)</article-title>
          ,
          <source>Journal of Web Semantics</source>
          <volume>19</volume>
          (
          <year>2013</year>
          )
          <fpage>22</fpage>
          -
          <lpage>41</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>D.</given-names>
            <surname>Diefenbach</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. D.</given-names>
            <surname>Wilde</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Alipio</surname>
          </string-name>
          ,
          <article-title>Wikibase as an infrastructure for knowledge graphs: The eu knowledge graph</article-title>
          , in: International Semantic Web Conference, Springer,
          <year>2021</year>
          , pp.
          <fpage>631</fpage>
          -
          <lpage>647</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>D.</given-names>
            <surname>Diefenbach</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Both</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Singh</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Maret</surname>
          </string-name>
          ,
          <article-title>Towards a question answering system over the semantic web</article-title>
          ,
          <source>Semantic Web</source>
          <volume>11</volume>
          (
          <year>2020</year>
          )
          <fpage>421</fpage>
          -
          <lpage>439</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>D.</given-names>
            <surname>Diefenbach</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. M.</given-names>
            <surname>Giménez-García</surname>
          </string-name>
          ,
          <article-title>Hdtcat: let's make hdt generation scale</article-title>
          , in: International Semantic Web Conference, Springer,
          <year>2020</year>
          , pp.
          <fpage>18</fpage>
          -
          <lpage>33</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>S.</given-names>
            <surname>Malyshev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Krötzsch</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>González</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Gonsior</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Bielefeldt</surname>
          </string-name>
          ,
          <article-title>Getting the most out of wikidata: semantic technology usage in wikipedia's knowledge graph</article-title>
          , in: International Semantic Web Conference, Springer,
          <year>2018</year>
          , pp.
          <fpage>376</fpage>
          -
          <lpage>394</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>