<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sparna Blog &#187; api</title>
	<atom:link href="https://blog.sparna.fr/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.sparna.fr</link>
	<description>Web de données &#124; Architecture de l&#039;information &#124; Accès aux connaissances</description>
	<lastBuildDate>Tue, 03 Jun 2025 10:30:27 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>European Parliament Open Data Portal : a SHACL-powered knowledge graph</title>
		<link>https://blog.sparna.fr/2025/04/09/european-parliament-open-data-portal-a-shacl-powered-knowledge-graph/</link>
		<comments>https://blog.sparna.fr/2025/04/09/european-parliament-open-data-portal-a-shacl-powered-knowledge-graph/#comments</comments>
		<pubDate>Wed, 09 Apr 2025 14:10:12 +0000</pubDate>
		<dc:creator><![CDATA[Marie Muller]]></dc:creator>
				<category><![CDATA[Editeurs]]></category>
		<category><![CDATA[FAIR]]></category>
		<category><![CDATA[Linked Data]]></category>
		<category><![CDATA[Non classé]]></category>
		<category><![CDATA[Ontologies]]></category>
		<category><![CDATA[Open Data]]></category>
		<category><![CDATA[SHACL]]></category>
		<category><![CDATA[SHACL Play]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[DCAT]]></category>
		<category><![CDATA[ELI]]></category>
		<category><![CDATA[google spreadsheets]]></category>
		<category><![CDATA[json-ld]]></category>
		<category><![CDATA[knowledge graph]]></category>
		<category><![CDATA[SKOS]]></category>
		<category><![CDATA[SPARQL]]></category>

		<guid isPermaLink="false">https://blog.sparna.fr/?p=1959</guid>
		<description><![CDATA[<p>A second usecase Thomas wrote for Veronika Heimsbakk’s SHACL for the Practitioner upcoming book is about Sparna&#8217;s work for the European Parliament. From validation of the data in the knowledge graph to further projects of data integration and dissemination, many different usages of SHACL specifications were explored&#8230; &#8230; and more exploratory usages of SHACL are foreseen ! “&#8230;</p>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2025/04/09/european-parliament-open-data-portal-a-shacl-powered-knowledge-graph/">European Parliament Open Data Portal : a SHACL-powered knowledge graph</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>A second usecase Thomas wrote for Veronika Heimsbakk’s <em><a href="https://veronahe.wordpress.com/shacl-for-the-practitioner/">SHACL for the Practitioner</a></em> upcoming book is about Sparna&rsquo;s work for the European Parliament.</p>
<p>From validation of the data in the knowledge graph to further projects of data integration and dissemination, many different usages of SHACL specifications were explored&#8230;</p>
<p>&#8230; and more exploratory usages of SHACL are foreseen !</p>
<h1>“</h1>
<h2><strong>A knowledge-graph powered open data portal</strong></h2>
<p><a href="https://data.europarl.europa.eu/">The European Parliament Open Data Portal (EPODP)</a> went live in January 2023. Its particularity is that it is not a mere aggregation of documents or dump files from business applications in custom formats; but rather a <strong>collection of datasets each extracted from a central semantic knowledge graph</strong>, itself aggregating data migrated from approximately <strong>twenty business applications</strong>. The result is a semantically interoperable open data portal : the semantic of its data model is clearly defined and documented, and reuses widely deployed existing ontologies. It already provides its data to different consumers (most notably <a href="https://www.europarl.europa.eu/">the europarl website</a> and <a href="https://law-tracker.europa.eu/">the EU law tracker</a>) in a context of cross-institutions interoperability. The data captures the activity of the parliament : as co-legislator together with the Council of the EU, the European Parliament (EP) holds plenary sittings, in which reports originating from committees, as well as motion for resolutions, are amended and voted; after the vote, the final adopted texts are published.</p>
<p>The focus on semantic interoperability of EPODP maximizes the potential of reuse and linkage of its datasets, and <strong>maximizes the quality</strong> of the offered data. It comes however at a cost when building the portal : deep analysis and understanding of the existing data and documents structure is required to capture the business semantic. SHACL is the way to formally encode this business semantic &#8211; but how is it deployed in practice ? how is it maintained ? what are the different types of SHACL specifications used ?</p>
<h2><strong>SHACL at the center of a model-driven approach</strong></h2>
<p>SHACL in the EPODP is at the basis of multiple model-driven usages depicted in the following diagram:</p>
<p><a href="https://blog.sparna.fr/wp-content/uploads/2025/04/spec-SHACL.png"><img class="aligncenter size-large wp-image-1961" src="https://blog.sparna.fr/wp-content/uploads/2025/04/spec-SHACL-1024x508.png" alt="spec-SHACL" width="650" height="322" /></a></p>
<p>There was two key drivers for introducing the use of SHACL in the EPODP project : <strong>validation of the data</strong> in the knowledge graph, and <strong>generation of public documentations</strong> of the models. The same SHACL specification that captures the business semantic is directly actionable to be published as a documentation and to validate the data. The produced documentation is a set of public files, such as <a href="https://data.europarl.europa.eu/def/eli-ep">the ELI-EP application profile documentation</a> and others accessible from <a href="https://data.europarl.europa.eu/en/developer-corner">the EPODP developer&rsquo;s corner</a>. <a href="https://shacl-play.sparna.fr/play/doc">The SHACL Play documentation generator</a> is used to produce the documentation pages. Data validation happens at earlier stages, after data transformation steps.</p>
<p>Two additional usages of SHACL specifications were explored : one was to generate SPARQL queries to extract the content of datasets from the larger knowledge graph. The SHACL specification of a dataset content is interpreted to generate SPARQL CONSTRUCT queries, executed against the entire knowledge graph, to return a subset of data corresponding to the specification. The query generation was implemented <a href="https://shacl-play.sparna.fr/play/sparql">in SHACL Play</a>, however the EPODP chose to continue using manually crafted SPARQL queries to generate the datasets. The other usage was to complement the SHACL specifications with the mapping rules used to feed the corresponding properties or classes in the graph. This has the advantage that the mapping rules are documented and maintained alongside the specification and not in a separate document. This work is ongoing.</p>
<p>More exploratory usages of SHACL are foreseen : generating a query user interface based on the SHACL specification, <a href="https://docs.sparnatural.eu/how-to-configure-shacl/How-to-configure-Sparnatural-shacl.html">using the <strong>Sparnatural</strong> query builder</a>, and also input forms to facilitate the creation of DCAT datasets descriptions. Additionally, automated generation of the JSON-LD context and the JSON schema of the API are foreseen.</p>
<h2><strong>Not &laquo;&nbsp;1 SHACL to rule them all&nbsp;&raquo;, but application profiles, dataset definitions, and migration specifications</strong></h2>
<p>The definition of the EPODP knowledge graph is not captured in a single SHACL specification, but rather in three different application profiles, each being a selection of classes and properties of one sub-domain : <strong><a href="https://data.europarl.europa.eu/def/eli-ep">ELI-EP</a></strong> covers the description of documents and activities, <strong><a href="https://data.europarl.europa.eu/def/org-ep">ORG-EP</a></strong> covers the definitions of EP organisations (such as committees, political groups, etc.) and members of the parliament, and <strong><a href="https://europarl.github.io/skos-ep">SKOS-EP</a></strong> covers how controlled vocabularies are structured. In addition, <a href="https://data.europarl.europa.eu/def/dcat-ep">DCAT-EP</a> is the specification for how dataset records are described in the EPODP catalog &#8211; but this is not part of the knowledge graph <em>per se</em>.</p>
<p>Together, ELI-EP, ORG-EP and SKOS-EP specify the structure of the entire knowledge graph from which the datasets are extracted. In addition, the structure of each dataset family available in the EPODP (such as adopted texts, plenary documents, parliamentary questions, etc.) is also described in SHACL, referred to as <strong>&laquo;&nbsp;DSD&nbsp;&raquo; for &laquo;&nbsp;Dataset Definition&nbsp;&raquo;</strong>. While the application profiles describe every possible properties on generic shapes, the DSDs will specify only the subset of properties used in a dataset, with possibly different cardinalities or range. For example, ELI-EP specifies that <em>&laquo;&nbsp;a Work may have the property</em><em> </em><em>eli:adopts</em><em>&laquo;&nbsp;</em> (with no minimum cardinality (eli:adopts is defined as <em>&laquo;&nbsp;Indicates that the work represents the adopted work of one or several related works&nbsp;&raquo;</em>). The DSD for adopted texts datasets specifies the shape of &laquo;&nbsp;Adopted texts&nbsp;&raquo; as a subset of the Works, and indicates that the minimum cardinality of eli:adopts is 1 for this particular subset. Besides, some properties, such as eli:amends are not available for adopted texts, thus not declared in the DSD.</p>
<p>In addition, specifications of the conversion of some data sources are also specified in independent SHACL files. The articulations of these 3 kinds of SHACL files and the reused ontologies is depicted in the following diagram:</p>
<p><a href="https://blog.sparna.fr/wp-content/uploads/2025/04/3-SHACL-shapes.png"><img class="aligncenter size-large wp-image-1962" src="https://blog.sparna.fr/wp-content/uploads/2025/04/3-SHACL-shapes-1024x603.png" alt="3-SHACL-shapes" width="650" height="383" /></a></p>
<p>There is currently no reuse or reference of shapes across the different specifications. Each is independent. A nice improvement would be to study how SHACL DSDs could be derived from the application profile SHACL, without redeclaring the identical constraints.</p>
<h2><strong>Editing SHACL in spreadsheets</strong></h2>
<p>In total 16 SHACL specifications are currently published in the EPODP, and around 80 are used to validate data migrated from each individual sources. The first step in the specification of each model is the design in a diagram such as the ones visible in the public documentations of the models. The EPODP team is then using spreadsheets to encode the specifications, adapted from the one provided <a href="https://shacl-play.sparna.fr/play/shaclexcel">in the SHACL Play suite</a>. The spreadsheet is converted to SHACL using <a href="https://xls2rdf.sparna.fr/rest/">the xls2rdf converter</a>. <strong>Spreadsheets provide a simple editing solution</strong>, with an easy learning curve, made even easier with a few formulas to compute cell values automatically. It even provides ways for editing advanced patterns (such as the ability to directly turtle lists for sh:or, or blank nodes for property paths), but of course still limits the expressivity. The following screenshot shows how property shapes look like in the spreadsheet:</p>
<p><a href="https://blog.sparna.fr/wp-content/uploads/2025/04/properties-ELI.png"><img class="aligncenter size-large wp-image-1963" src="https://blog.sparna.fr/wp-content/uploads/2025/04/properties-ELI-1024x442.png" alt="properties-ELI" width="650" height="281" /></a></p>
<h2></h2>
<h2><strong>Results and future perspectives</strong></h2>
<p>The EPODP use-case shows how SHACL can be applied in a systematic way in a data integration and dissemination project : at the data transformation step, at the knowledge graph level, and at the data dissemination. <strong>Public documentation, data validation, data extraction are tasks that can be be automated based on a SHACL specification</strong>. While the context is one of a large public institution, the same approach can be applied in industrial contexts. The SHACL specifications are a cornerstone of such projects, enabling semantic interoperability at large and a mutual understanding between business experts, data analysts, developers, and data consumers.</p>
<p>&nbsp;</p>
<h1>”</h1>
<p>Veronika&rsquo;s book will be divided into three parts :<br class="html-br" /><br class="html-br" />1. Back to Basics<br class="html-br" />Introduction to logic and RDF, brief skimming of the topics. Also covering various world assumptions.</p>
<p>2. Getting to know the stuff<br class="html-br" />Introduction to SHACL, including core, sh-sparql, advanced features.</p>
<p>3. Working with the stuff<br class="html-br" />SHACL Stories. Use cases, user stories and implementations.</p>
<p><em>Image : © European Union, [2024] &#8211; EP</em></p>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2025/04/09/european-parliament-open-data-portal-a-shacl-powered-knowledge-graph/">European Parliament Open Data Portal : a SHACL-powered knowledge graph</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sparna.fr/2025/04/09/european-parliament-open-data-portal-a-shacl-powered-knowledge-graph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Data versus API</title>
		<link>https://blog.sparna.fr/2012/09/26/opendataversusapi/</link>
		<comments>https://blog.sparna.fr/2012/09/26/opendataversusapi/#comments</comments>
		<pubDate>Wed, 26 Sep 2012 09:35:10 +0000</pubDate>
		<dc:creator><![CDATA[Thomas Francart]]></dc:creator>
				<category><![CDATA[Open Data]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[dataware]]></category>
		<category><![CDATA[RDF]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[temporalité]]></category>

		<guid isPermaLink="false">http://blog.sparna.fr/?p=188</guid>
		<description><![CDATA[<p>Un billet publié récemment par Christian Fauré comparant les approches d&#8217;ouverture des données par rapport à la mise à disposition d&#8217;une API [1] m&#8217;inspire quelques marques d&#8217;accord et de désaccord : Principal hochement de tête approbateur : le concept de dataware et d&#8217;autonomisation des données, les données en elles-même et pour elles-mêmes, comme dans mon&#8230;</p>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2012/09/26/opendataversusapi/">Open Data versus API</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Un billet publié récemment par Christian Fauré comparant les approches d&rsquo;ouverture des données par rapport à la mise à disposition d&rsquo;une API [1] m&rsquo;inspire quelques marques d&rsquo;accord et de désaccord :</p>
<ul>
<li>Principal hochement de tête approbateur : <strong>le concept de dataware</strong> et d&rsquo;autonomisation des données, les données en elles-même et pour elles-mêmes, comme dans mon <a title="Le dataware" href="http://blog.sparna.fr/le-dataware/">précédent billet</a>. Avec ce que cela implique de bouleversement dans la façon de concevoir les systèmes et les interactions au sein du SI.</li>
</ul>
<ul>
<li>Principale grimace de désaccord : la notion de &laquo;&nbsp;vérité éternelle des données&nbsp;&raquo;. Je crois que c&rsquo;est une vue de l&rsquo;esprit qui n&rsquo;a pas cours dans la réalité. <strong>Tous les projets de gestion d&rsquo;ontologies, de thesaurus, de catalogues, demandent et requièrent maintenant des fonctions de versionnement et de prise en compte des évolutions des données dans le temps</strong>. <span class="pullquote">Toutes les données changent dans le temps. Toutes.</span> Même le classement d&rsquo;un catalogue d&rsquo;archives évolue dans le temps. On s&rsquo;étonnera que cette notion d&rsquo;évolution dans le temps des données (&laquo;&nbsp;diachronicité des données&nbsp;&raquo;) n&rsquo;ait pas été prise en compte au niveau le plus bas des standards du web, RDF, ou même les URI (et on consultera le projet memento [2] avec intérêt si on est titillé par le sujet). Quel orgeuil, quand on y pense, de croire que les éléments d&rsquo;information que l&rsquo;on encode à un certain instant sont obligatoirement les bons, ou qu&rsquo;ils resteront valides éternellement.</li>
</ul>
<ul>
<li>Bref. Pour passer à un autre point, effectivement, le principe de base du Linked Data est que <strong>la connaissance de l&rsquo;identifiant d&rsquo;une chose suffit pour accéder à une représentation de cette chose</strong>; inutile de connaitre une API, ou de passer par le biais d&rsquo;une interface pour accéder à cette représentation.</li>
</ul>
<ul>
<li>Ce n&rsquo;est pas étonnant que l&rsquo;ouverture des systèmes à travers des API soit plus populaire que l&rsquo;ouverture des données &laquo;&nbsp;tout court&nbsp;&raquo; : l&rsquo;API est pensée pour le développeur, elle prend en compte ses cas d&rsquo;usage pour les simplifier, là où le Linked Data se garde bien de lui faciliter la tâche car justement, cette approche se concentre sur les données en elles-mêmes, sans préjuger de leur mode de réutilisation. <strong>Pour un développeur, il est bien plus facile de développer des applications à partir d&rsquo;une API qu&rsquo;à partir de données brutes</strong>; comment faire pour implémenter un simple écran de liste (de lieux, de bâtiments, de n&rsquo;importe quoi) uniquement à partir des URIs des données ? cela nécessite plusieurs appels et un parsing du résultat non trivial. Là où une API fournira un seul appel, renvoyant uniquement les données utiles, dans un format simple.</li>
</ul>
<ul>
<li>On en arrive donc à dire que <strong>publier des données sous forme de Linked Data ne permet pas leur réutilisation simple</strong>. C&rsquo;est paradoxal, puisque c&rsquo;est l&rsquo;objectif affiché. <span class="pullquote">Il faut que l&rsquo;ouverture des données fasse un pas de plus vers le développeur</span>. Des outils comme Elda [3] et la proposition du Linked Data API [4] sont exactement là pour franchir ce pas :&nbsp;&raquo;For some web developers the need to understand the RDF data model and associated serializations and query language (SPARQL) has proved a barrier to adoption of linked data. [The Linked Data API project] seeks to develop APIs, data formats and supporting tools to overcome this barrier. Including, but not limited to, accessing linked data via a developer-friendly JSON format.&nbsp;&raquo;</li>
</ul>
<p>&#8212;</p>
[1] DataCulture et APICulture : <a href="http://www.christian-faure.net/2012/09/20/dataculture-et-apiculture">http://www.christian-faure.net/2012/09/20/dataculture-et-apiculture</a><br />
[2] Memento project : <a href="http://mementoweb.org/">http://mementoweb.org/</a><br />
[3] Elda : <a href="http://code.google.com/p/elda/">http://code.google.com/p/elda/</a><br />
[4] Linked Data API : <a href="http://code.google.com/p/linked-data-api/">http://code.google.com/p/linked-data-api/</a></p>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2012/09/26/opendataversusapi/">Open Data versus API</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sparna.fr/2012/09/26/opendataversusapi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tutoriel : exemple de query SPARQL avec l&#8217;API Sesame</title>
		<link>https://blog.sparna.fr/2012/05/23/tutoriel-exemple-de-query-sparql-avec-lapi-sesame/</link>
		<comments>https://blog.sparna.fr/2012/05/23/tutoriel-exemple-de-query-sparql-avec-lapi-sesame/#comments</comments>
		<pubDate>Wed, 23 May 2012 11:23:45 +0000</pubDate>
		<dc:creator><![CDATA[Thomas Francart]]></dc:creator>
				<category><![CDATA[RDF]]></category>
		<category><![CDATA[SPARQL]]></category>
		<category><![CDATA[Triplestores]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[construct]]></category>
		<category><![CDATA[Resource Description Framework]]></category>
		<category><![CDATA[Triplestore]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.sparna.fr/?p=125</guid>
		<description><![CDATA[<p>On a vu précédemment comment utiliser l&#8217;API Sesame depuis un programme Java, quelles dépendances étaient nécessaires, et comment faire les opérations de base avec un Repository : initialiser, charger des données, écrire des données. Voilà maintenant comment effectuer des query SPARQL SELECT et CONSTRUCT sur un Repository, et traiter les résultats. Les deux types de&#8230;</p>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2012/05/23/tutoriel-exemple-de-query-sparql-avec-lapi-sesame/">Tutoriel : exemple de query SPARQL avec l&rsquo;API Sesame</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>On a vu précédemment <a title="Tutoriel : exemple avec l’API Sesame RDF" href="http://blog.sparna.fr/tutoriel-demarrage-avec-lapi-sesame-rdf/" target="_blank">comment utiliser l&rsquo;API Sesame</a> depuis un programme Java, quelles dépendances étaient nécessaires, et comment faire les opérations de base avec un Repository : initialiser, charger des données, écrire des données.</p>
<p>Voilà maintenant comment effectuer des query <a class="zem_slink" title="SPARQL" href="http://en.wikipedia.org/wiki/SPARQL" target="_blank" rel="wikipedia">SPARQL</a> SELECT et CONSTRUCT sur un Repository, et traiter les résultats. Les deux types de query utilisent des objets différents : <a href="http://www.openrdf.org/doc/sesame2/api/org/openrdf/query/TupleQuery.html" target="_blank">TupleQuery</a> et <a href="http://www.openrdf.org/doc/sesame2/api/org/openrdf/query/TupleQueryResult.html" target="_blank">TupleQueryResult</a> pour les SELECT, <a href="http://www.openrdf.org/doc/sesame2/api/org/openrdf/query/GraphQuery.html" target="_blank">GraphQuery</a> et <a href="http://www.openrdf.org/doc/sesame2/api/org/openrdf/query/GraphQueryResult.html" target="_blank">GraphQueryResult</a> pour les CONSTRUCT. Les commentaires dans le code ci-dessous parlent d&rsquo;eux-même, et n&rsquo;hésitez-pas à vous reporter à la <a href="http://www.openrdf.org/doc/sesame2/users/ch08.html#d0e879" target="_blank">documentation des API Sesame</a> pour d&rsquo;autres exemples.</p>
<p><span id="more-125"></span><br />
[java]		// création du Repository en mémoire.<br />
		Repository repository = new SailRepository(new MemoryStore());<br />
		// initialisation du Repository : cet appel est obligatoire une fois et une seule<br />
		repository.initialize();</p>
<p>		// on ouvre une connection au repository<br />
		// comme en JDBC, c&rsquo;est à travers cette connexion que sont envoyées toute les querys<br />
		RepositoryConnection connection = repository.getConnection();</p>
<p>		// I. exemple de Query SELECT</p>
<p>		// on initialise la query.<br />
		TupleQuery selectQuery = connection.prepareTupleQuery(<br />
				QueryLanguage.SPARQL,<br />
				&quot;SELECT ?x ?foafName WHERE { ?x &amp;lt;http://xmlns.com/foaf/0.1/name&amp;gt; ?foafName }&quot;<br />
		);</p>
<p>		// on l&rsquo;execute<br />
		TupleQueryResult selectQueryResult = selectQuery.evaluate();</p>
<p>		// on itère sur les résultats<br />
		while(selectQueryResult.hasNext()) {<br />
			// chaque ligne du résultat est un BindingSet<br />
			BindingSet aBinding = selectQueryResult.next();</p>
<p>			// on print les valeurs de cette ligne<br />
			System.out.println(&quot;Personne &quot;+aBinding.getValue(&quot;x&quot;)+&quot; a pour nom &quot;+aBinding.getValue(&quot;foafName&quot;));</p>
<p>			// si on ne connait pas les noms de variables de la query, on peut les récupérer dynamiquement<br />
			for (String aBindingName : selectQueryResult.getBindingNames()) {<br />
				System.out.println(&quot;La valeur de &quot;+aBindingName+&quot; est &quot;+aBinding.getValue(aBindingName));<br />
			}<br />
		}</p>
<p>		// II. Exemple de Query CONSTRUCT</p>
<p>		// on initialise la query<br />
		GraphQuery constructQuery = connection.prepareGraphQuery(<br />
				QueryLanguage.SPARQL,<br />
				&quot;PREFIX foaf: &amp;lt;http://xmlns.com/foaf/0.1/&amp;gt; &quot; +<br />
				&quot;PREFIX vcard: &amp;lt;http://www.w3.org/2006/vcard/ns#&amp;gt;&quot; +<br />
				&quot;CONSTRUCT {?x vcard:n _:n . _:n vcard:given-name ?name .} WHERE { ?x foaf:name ?name }&quot;<br />
		);</p>
<p>		// on l&rsquo;execute<br />
		GraphQueryResult constructQueryResult = constructQuery.evaluate();</p>
<p>		// on itère sur les résultats, qui sont des Statement RDF, pas des binding<br />
		while(constructQueryResult.hasNext()) {<br />
			Statement anRDFStatement = constructQueryResult.next();<br />
			// ici on se contente d&rsquo;afficher le Statement<br />
			// typiquement on devrait en faire quelque chose : écrire dans un fichier, ou<br />
			// l&rsquo;insérer dans un autre Repository, etc.<br />
			System.out.println(anRDFStatement);<br />
		}</p>
<p>		// quand on n&rsquo;a plus besoin de la connexion, on la ferme<br />
		connection.close();[/java]
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="float: right;" alt="" src="http://img.zemanta.com/pixy.gif?x-id=5dce1730-f9fa-45c9-9b5a-c5c26b36ade2" /></div>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2012/05/23/tutoriel-exemple-de-query-sparql-avec-lapi-sesame/">Tutoriel : exemple de query SPARQL avec l&rsquo;API Sesame</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sparna.fr/2012/05/23/tutoriel-exemple-de-query-sparql-avec-lapi-sesame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutoriel : exemple avec l&#8217;API Sesame RDF</title>
		<link>https://blog.sparna.fr/2012/05/20/tutoriel-demarrage-avec-lapi-sesame-rdf/</link>
		<comments>https://blog.sparna.fr/2012/05/20/tutoriel-demarrage-avec-lapi-sesame-rdf/#comments</comments>
		<pubDate>Sun, 20 May 2012 19:35:38 +0000</pubDate>
		<dc:creator><![CDATA[Thomas Francart]]></dc:creator>
				<category><![CDATA[RDF]]></category>
		<category><![CDATA[SPARQL]]></category>
		<category><![CDATA[Triplestores]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[exemple]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://blog.sparna.fr/?p=65</guid>
		<description><![CDATA[<p>Sesame dispose d&#8217;une API Java permettant de manipuler du RDF en mémoire, d&#8217;interroger un serveur Sesame (voir la procédure d&#8217;installation d&#8217;un serveur Sesame), ou d&#8217;interroger un endpoint SPARQL distant. Voici un &#171;&#160;quickstart&#160;&#187; permettant de commencer à travailler avec l&#8217;API en quelques minutes, en ajoutant les dépendances adéquates et avec un exemple de code complet. Vous&#8230;</p>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2012/05/20/tutoriel-demarrage-avec-lapi-sesame-rdf/">Tutoriel : exemple avec l&rsquo;API Sesame RDF</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Sesame dispose d&rsquo;une API Java permettant de manipuler du RDF en mémoire, d&rsquo;interroger un serveur Sesame (voir la <a title="Tutoriel : comment installer un serveur RDF Sesame ?" href="http://blog.sparna.fr/2012/05/tutoriel-comment-installer-un-serveur-rdf-sesame/">procédure d&rsquo;installation d&rsquo;un serveur Sesame</a>), ou d&rsquo;interroger un endpoint SPARQL distant. Voici un &laquo;&nbsp;quickstart&nbsp;&raquo; permettant de commencer à travailler avec l&rsquo;API en quelques minutes, en ajoutant les dépendances adéquates et avec un exemple de code complet. Vous pouvez également vous référer à la <a href="http://www.openrdf.org/doc/sesame2/users/ch08.html" target="_blank">documentation de l&rsquo;API Sesame</a>.</p>
<p><span id="more-65"></span></p>
<h2>Jars nécessaires</h2>
<p>Pour utiliser l&rsquo;API Sesame de manipulation de RDF dans votre programme Java, récupérer les jars suivants :</p>
<ul>
<li>Depuis <a href="http://openrdf.org" target="_blank">openrdf.org</a>, suivez « Download &gt; Sesame 2.x releases &gt; here &gt; <em>[numéro de version de Sesame] »</em> et téléchargez le fichier openrdf-sesame-x.y.z-onejar.jar. Attention de bien prendre le « onejar », <span style="text-decoration: underline;">pas</span> le sdk ;</li>
<li>Téléchargez <a href="http://www.slf4j.org" target="_blank">SLF4J</a>, dézippez-le, et extrayez slf4j-api-a.b.c.jar et slf4j-jdk14-a.b.c.jar ;</li>
<li>Ajoutez à votre classpath openrdf-sesame-x.y.z-onejar.jar, slf4j-api-a.b.c.jar et slf4j-jdk14-a.b.c.jar ;</li>
</ul>
<p>Optionnellement, seulement si vous voulez vous connecter à un serveur Sesame distant, ou un endpoint SPARQL (en utilisant la classe HTTPRepository), ajoutez les étapes suivantes :</p>
<ul>
<li>Téléchargez <a href="http://archive.apache.org/dist/httpcomponents/commons-httpclient/3.0/binary/" target="_blank">httpclient</a>, en prenant le fichier commons-httpclient-3.0.zip. (Attention de ne pas confondre avec httpcomponents-client), et dézippez commons-httpclient-3.0.jar ;</li>
<li>Téléchargez <a href="http://commons.apache.org/logging/download_logging.cgi" target="_blank">commons-logging</a> et dézippez commons-logging-1.1.1.jar</li>
<li>Téléchargez <a href="http://commons.apache.org/codec/download_codec.cgi" target="_blank">commons-codec</a> et dézippez commons-codec-1.6.jar ;</li>
<li>ajoutez à votre classpath commons-httpclient-3.0.jar, commons-logging-1.1.1.jar et commons-codec-1.6.jar ;</li>
</ul>
<h2>Démarrage rapide</h2>
<p>L&rsquo;exemple de code Java ci-dessous illustre l&rsquo;initialisation d&rsquo;un Repository, le chargement de données RDF, l&rsquo;écriture de RDF dans un fichier, et l&rsquo;interrogation d&rsquo;un serveur Sesame distant ou d&rsquo;un endpoint SPARQL public. Les commentaires dans le code parlent d&rsquo;eux-mêmes.</p>
<pre>
<span style="font-size: 8pt;">// I : création du Repository
// création du Repository en mémoire.</span>
<span style="font-size: 8pt;">Repository repository = new SailRepository(new MemoryStore());</span>
<span style="font-size: 8pt;">// initialisation du Repository : cet appel est obligatoire une fois et une seule</span>
<span style="font-size: 8pt;">repository.initialize();</span></pre>
<pre><span style="font-size: 8pt;">// II : chargement de fichier RDF
// le fichier RDF contenant les données à charger</span>
<span style="font-size: 8pt;">File fileToAdd = new File("/fichier/à/charger.rdf");</span>
<span style="font-size: 8pt;">// charger les données dans le Repository</span>
<span style="font-size: 8pt;">repository.getConnection().add(</span>
 <span style="font-size: 8pt;">// référence au fichier à charger</span>
 <span style="font-size: 8pt;">fileToAdd,</span>
<span style="font-size: 8pt;"> // namespace par défaut à utiliser pour les URIs relatives contenues dans le RDF</span>
<span style="font-size: 8pt;"> RDF.NAMESPACE,</span>
<span style="font-size: 8pt;"> // format du fichier RDF à charger (RDF/XML, N3, TRIG, etc.)</span>
<span style="font-size: 8pt;"> // le format est déterminé dynamiquement à partir de l'extension du fichier</span>
<span style="font-size: 8pt;"> // (.rdf, .n3, .trig, etc.)</span>
<span style="font-size: 8pt;"> RDFFormat.forFileName(fileToAdd.getName())</span>
<span style="font-size: 8pt;">);</span></pre>
<pre><span style="font-size: 8pt;">// III : écriture de fichier RDF
// on utilise RDFXMLWriter qui génère du RDF/XML</span>
<span style="font-size: 8pt;">repository.getConnection().export(new RDFXMLWriter(new FileOutputStream("/fichier.rdf")));
// on peut remplacer par N3Writer pour sortir du N3</span>
<span style="font-size: 8pt;">// dans ce cas, bien mettre l'extension du fichier à .n3</span>
<span style="font-size: 8pt;">// repository.getConnection().export(new N3Writer(new FileOutputStream("/fichier.n3")));</span></pre>
<pre><span style="font-size: 8pt;">// IV. connection à un serveur Sesame ou un endpoint SPARQL distant
// pour se connecter à un serveur Sesame : utiliser le constructeur avec 2 String</span>
<span style="font-size: 8pt;">// en donnant l'adresse du serveur et le nom du repository</span>
<span style="font-size: 8pt;">Repository sesameServer = new HTTPRepository("http://localhost:8080/openrdf-sesame","Test");</span>
<span style="font-size: 8pt;">sesameServer.initialize();
// pour se connecter à un endpoint SPARQL public : utiliser le constructeur avec 1 String</span>
<span style="font-size: 8pt;">// en donnant l'adresse du endpoint</span>
<span style="font-size: 8pt;">Repository dbpedia = new HTTPRepository("http://dbpedia.org/sparql");</span>
<span style="font-size: 8pt;">dbpedia.initialize();</span></pre>
<p>Cet article <a rel="nofollow" href="https://blog.sparna.fr/2012/05/20/tutoriel-demarrage-avec-lapi-sesame-rdf/">Tutoriel : exemple avec l&rsquo;API Sesame RDF</a> est apparu en premier sur <a rel="nofollow" href="https://blog.sparna.fr">Sparna Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.sparna.fr/2012/05/20/tutoriel-demarrage-avec-lapi-sesame-rdf/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
