<!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 />
    <article-meta>
      <title-group>
        <article-title>Sparql2GraphServer: a Server-side Tool for Extracting Networks from Linked Data for Data Analysis</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>tri L</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>ro Hyvön</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Jouni Tuomin</string-name>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>HELDIG - Helsinki Centre for Digital Humanities, University of Helsinki</institution>
          ,
          <country country="FI">Finland</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Semantic Computing Research Group (SeCo), Aalto University</institution>
          ,
          <country country="FI">Finland</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>This paper presents a server-side tool for constructing graph representations from a Linked Data for network analysis. The main features for the tool are: 1) Support to read data from a SPARQL endpoint, 2) easy adaptation to virtually any dataset and data model, and 3) easy usage in web portals for data analysis. The tool is in use. Visualizing a network provides new insights about its structure and the underlying data [10,9]. A network can be built from Linked Data (LD) publication using SPARQL [3], where extraction patterns [1] allow a researcher to extract various types of connections (links, edges ) between the nodes. Many portals in the domain of Digital Humanities use network visualizations for data analysis, such as Six Degrees of Francis Bacon3, Linked Jazz4, and the co-citation graph and correspondent network in ePistolarium5. LodLive6 allows the user to browse individual triples of a LD database. For front-end visualizations there are libraries such as Cytoscape.js7, D3.js8, Sigma9, and 3D Force-Directed Graph10 for rendering a network in 3D using WebGL. An overview of the evolution of LD visualization is presented in [8].</p>
      </abstract>
      <kwd-group>
        <kwd>Linked Open Data</kwd>
        <kwd>Network Visualization</kwd>
        <kwd>Data Analysis Demo paper</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        This paper introduces an online service, Sparql2GraphServer, for constructing
networks based on LD knowledge graphs. The tool facilitates constructing either
1) an egocentric network [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] around ego, a specific knowledge graph URI, or 2) a
general network, e.g., a group of nodes with specified properties. The service is
used in practise in the biographical semantic portals AcademySampo11 (in use)
[
        <xref ref-type="bibr" rid="ref5 ref6">5,6</xref>
        ] and LetterSampo12 (prototype).
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Using the Tool</title>
      <p>Backend Process The queries to the SPARQL endpoint are performed in the
server side, and the process consists of three sequential steps. Firstly, a query
for the network links is performed as a sequence of breadth-first searches until a
desired amount of links is achieved. Secondly, the graph is constrained so that if
the number of links exceeds the limit, the nodes having the lowest degrees are
removed. This aims to retrieving more dense connections, e.g., a higher triadic
closure between nodes of higher centrality measures, instead of start-shaped
structures around a few central nodes. This pruning also aims to retrieving a
more clustered graph structure to ease, e.g., the visual analysis. The constraining
is optional and adjusting the query parameters allow for querying for an unfiltered
graph, too. Finally, the node metadata is queried calculating simultaneously the
predefined network statistics, e.g., the network diameter, average degree, and the
total number of edges, nodes, and connected components.</p>
      <p>The API query parameters are shown in Table 1; the queries are of the form
https://example.org/query?links=""&amp;nodes=""&amp;limit=""&amp;id="".
Example queries using Wikidata are shown in Tables 2 and 3. The link query requests
for teacher-student relationships starting from the sources nodes. In the query, the
placeholder &lt;ID&gt; is replaced with a list of source set nodes, initially containing
only the ego given with the query parameter id. The link weight is defined as
the count of common occupations, fields of work, and academic memberships
between two nodes.</p>
      <p>Server Response The JSON-formatted server response is depicted in Table 4.
The result field elements contains two arrays for edges and nodes. The API
adds the data fields defined in the result clauses in the corresponding SPARQL
queries to the result. The node data contains metrics like degree, in_degree,
pagerank, and distance, e.g., the shortest path length from ego. Finally, the
element metrics contains, e.g., network diameter, average degree, and the
numbers of nodes, edges, and connected components for the entire network.
The response format described is compatible with Cytoscape.js, a library for
network visualization in a web portal. Furthermore, the application also supports
the GraphML13 format.</p>
      <p>Visualization in a Front-End Portal The API response can directly be
an input for a Cytoscape.js component in a portal. Fig. 1 depicts a network
11 https://seco.cs.aalto.fi/projects/yo-matrikkelit/en/
12 https://seco.cs.aalto.fi/projects/rrl/
13 http://graphml.graphdrawing.org/
PARAMETER
endpoint
prefixes
links
nodes
id
limit
format
optimize
DESCRIPTION</p>
      <sec id="sec-2-1">
        <title>Server endpoint</title>
      </sec>
      <sec id="sec-2-2">
        <title>SPARQL prefixes</title>
      </sec>
      <sec id="sec-2-3">
        <title>SPARQL query for edge information</title>
      </sec>
      <sec id="sec-2-4">
        <title>SPARQL query for node details</title>
        <p>ego url for an egocentric network</p>
      </sec>
      <sec id="sec-2-5">
        <title>Limit the number of nodes</title>
        <p>TYPE
required
required
required
optional, default ""
optional, default None
optional, default 1000</p>
      </sec>
      <sec id="sec-2-6">
        <title>Response format: ’cytoscape’ or ’graphml’ default ’cytoscape’</title>
      </sec>
      <sec id="sec-2-7">
        <title>Drops out a proportion of low-degree nodes optional, default 1.0 removeMultipleLinks show only one link between nodes optional, default True customHttpHeaders Headers, e.g. ’Authorization’, of the query optional, default None</title>
        <p>}
?source ?rel ?target
# links by common occupations, fields</p>
        <p>of work, or memberships
OPTIONAL {</p>
        <p>VALUES ?prop</p>
        <p>{ wdt:P101 wdt:P463 wdt:P106 }
?source ?prop ?link . ?target ?
prop ?link
}
} GROUP BY ?source ?target ?label
{’elements’: {
’edges’: [
{’data’:
{’source’:</p>
        <p>’www.wikidata.org/entity/Q9047’,
’target’:</p>
        <p>
          ’www.wikidata.org/entity/Q76510’,
’label’: ’doctoral student’,
’weight’: 7}
}, {’data’: ... }, ... ],
’nodes’: [
{’data’: {’id’:
’www.wikidata.org/entity/Q9047’,
’name’:’Gottfried Wilhelm Leibniz’,
’distance’: 0, ’degree’: 5, ’
degree_weighted’: 22,
’in_degree’: 0, ’out_degree’:5,
’in_degree_weighted’: 0,
’out_degree_weighted’:22,
’pagerank’: 0.01214}
}, {’data’: ... }, ... ] },
’metrics’:
{’average_degree’: 2.48,
’diameter’: 10,
’number_connected_components’: 1,
’number_of_edges’: 62,
’number_of_nodes’: 50},
’directed’: True
}
visualization based on the example result in Table 4. The node and edge labels
are extracted from the query results while the visual appearance is configured
in the front-side application code. Here the node color on a red-blue palette is
based on the path distance from the center node, the node sizes are based on the
out-degree, and the edge strengths on the count of common occupations, fields
of work, and academic memberships between two nodes as defined in the query
for edges (Table 2).
The tool Sparql2GraphServer is based on Flask14, microframework application
written in Python 3.8 using modules NetworkX 2.415 [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ], NumPy16, RDFLib17,
and SparqlWrapper18. The source code is available in GitHub19. The source code
repository contains a Dockerfile recipe for running and deploying the application
as a container which allows for portability and scaling.
3
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Discussion</title>
      <p>
        Integration to Sampo-UI Framework The Sparql2Network API is integrated
to the Sampo-UI Framework [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]; the API was developed and is used in the
AcademySampo and LetterSampo portals with Sampo-UI. The Sampo-UI framework
includes functions for scaling and constraining the numeric result values into, e.g.,
edge widths, node sizes, as well as into RGB or HSL color ranges. For example,
this page20 in AcademySampo shows a connection network around the Finnish
composer Jean Sibelius, the page21 demonstrates using Sparql2Network to create
a sociocentric network, possibly filtered by using faceted search.
      </p>
      <p>Evaluation Performing several SPARQL queries to the database might
have longer request times, especially in cases of smaller extracted networks. An
alternative would be using a single query empowered with, e.g., property paths or
nested selection blocks. However, that approach is not guaranteed to perform in
feasible time in a more complex case and would require customizing the queries
for each specific database. The chosen solution to have a pair of simple and quick
queries appears to be more efficient. A custom SPARQL query can adapt to cases
14 https://flask.palletsprojects.com/en/2.0.x/
15 https://networkx.org/
16 https://numpy.org/
17 https://rdflib.readthedocs.io
18 https://rdflib.dev/sparqlwrapper/
19 https://github.com/SemanticComputing/Sparql2GraphServer
20 https://akatemiasampo.fi/en/people/page/p21762/connections
21 https://akatemiasampo.fi/en/people/faceted-search/network
where the linking property is not explicitly provided but reasoned from the data,
e.g., a connection between two people who have lived in the same location at the
same time.</p>
      <p>Acknowledgements This work was funded by the Academy of Finland
project SEMPARL, the EU project InTaVia22, and is related to the EU COST
action Nexus Linguarum23. CSC – IT Center for Science provided computational
resources for the work. Discussions with Mikko Kivelä, Javier Ureña-Carrion,
Minna Tamper, and Esko Ikkala are acknowledged.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Ghawi</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pfeffer</surname>
          </string-name>
          , J.:
          <article-title>Extraction Patterns to Derive Social Networks from Linked Open Data Using SPARQL</article-title>
          .
          <source>Information</source>
          <volume>11</volume>
          (
          <issue>7</issue>
          ),
          <volume>361</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Hagberg</surname>
            ,
            <given-names>A.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schult</surname>
            ,
            <given-names>D.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Swart</surname>
            ,
            <given-names>P.J.:</given-names>
          </string-name>
          <article-title>Exploring network structure, dynamics, and function using networkx</article-title>
          .
          <source>In: Proceedings of the 7th Python in Science Conference</source>
          . pp.
          <fpage>11</fpage>
          -
          <lpage>15</lpage>
          . Pasadena, CA, USA (
          <year>2008</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Harris</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Seaborne</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>SPARQL 1.1 Query Language</article-title>
          . https://www.w3.org/TR/ sparql11-query/, accessed:
          <fpage>2021</fpage>
          -06-28.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Ikkala</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hyvönen</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rantala</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Koho</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          :
          <string-name>
            <surname>Sampo-UI</surname>
          </string-name>
          :
          <article-title>A full stack JavaScript framework for developing semantic portal user interfaces</article-title>
          .
          <source>Semantic Web</source>
          (
          <year>2021</year>
          ), http://www.semantic
          <article-title>-web-journal</article-title>
          .net/, accepted.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Leskinen</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hyvönen</surname>
          </string-name>
          , E.:
          <article-title>Linked open data service about historical Finnish academic people in 1640-1899</article-title>
          . In:
          <article-title>DHN 2020 Digital Humanities in the Nordic Countries</article-title>
          .
          <source>Proceedings of the Digital Humanities in the Nordic Countries 5th Conference</source>
          . pp.
          <fpage>284</fpage>
          -
          <lpage>292</lpage>
          . CEUR Workshop Proceedings, Vol.
          <volume>2612</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Leskinen</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hyvönen</surname>
          </string-name>
          , E.:
          <article-title>Reconciling and using historical person registers as linked open data in the AcademySampo knowledge graph</article-title>
          .
          <source>In: Proceedings of the 20th International Semantic Web Conference (ISWC</source>
          <year>2021</year>
          ). Springer-Verlag (
          <year>2021</year>
          ), https://seco.cs.aalto.fi/publications/2021/leskinen-hyvonen-reconciling-
          <year>2021</year>
          .pdf.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Marsden</surname>
            ,
            <given-names>P.V.</given-names>
          </string-name>
          :
          <article-title>Egocentric and sociocentric measures of network centrality</article-title>
          .
          <source>Social networks 24(4)</source>
          ,
          <fpage>407</fpage>
          -
          <lpage>422</lpage>
          (
          <year>2002</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Po</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bikakis</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Desimoni</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Papastefanatos</surname>
          </string-name>
          , G.:
          <article-title>Linked Data Visualization: Techniques, Tools, and Big Data</article-title>
          . Morgan &amp; Claypool, Palo Alto, CA (
          <year>2020</year>
          ). https://doi.org/10.2200/S00967ED1V01Y201911WBE019.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Schlögl</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lejtovicz</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          :
          <string-name>
            <given-names>A Prosopographical</given-names>
            <surname>Information</surname>
          </string-name>
          <article-title>System (APIS)</article-title>
          .
          <source>In: BD</source>
          . pp.
          <fpage>53</fpage>
          -
          <lpage>58</lpage>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Warren</surname>
            ,
            <given-names>C.N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shore</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Otis</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wang</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Finegold</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shalizi</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          :
          <article-title>Six Degrees of Francis Bacon: A Statistical Method for Reconstructing Large Historical Social Networks</article-title>
          .
          <source>DHQ: Digital Humanities Quarterly</source>
          <volume>10</volume>
          (
          <issue>3</issue>
          ) (
          <year>2016</year>
          ).
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>