28

I'm doing a lot of research right now on Semantic Web and complex data models that represent relationships between individuals and organizations. I knew a little semantic ontologies although I never understood what it was used if not make graphs.

I saw on university wiki that the language to question an ontology is the SPARQL (tell me if I'm wrong).

But recently I saw a company that had created a semantic ontology put it in the form of GraphQL that I did not know (https://diffuseur.datatourisme.gouv.fr/graphql/voyager/).

It seems to me that semantic ontologies are made to better find information, for example to make a chatbot (it's what I want to do), but here they transformed a semantic ontology into an API, is it right? To make a GraphQL, should I build first a semantic ontology?

Could you explain to me a little the difference between all this, honestly it's a little vague for me.

Stanislav Kralin
  • 10,115
  • 4
  • 30
  • 52
Erwan Pesle
  • 631
  • 1
  • 7
  • 12

4 Answers4

32

Context

Datatourisme is a platform that allows to publish (via the Producteur component) and to consume (via the Diffuseur component) POI-related open data.

It seems you have linked to a particular application developed over Diffuseur with a help of GraphQL Voyager. The application illustrates capabilities of the GraphQL API exposed by Diffuseur.

The API documentation is available here (in French):

Problem

  • Datatourisme stores data in the RDF format (presumably using the Blazegraph triplestore)
  • Datatourisme provides access via GraphQL (not SPARQL)

Why RDF

  • Partly due to some "schemaless", RDF is convenient in heterogeneous data integration tasks:

    Tourism national ontology structuring in a common sharing format the whole tourism data extracted from different official French data bases: entertainment and events, natural and cultural sites, leisure and sports activities, touristic products, tours, accomodations, shops, restaurants.

  • RDF is semantic: in particular, RDF is self-describing.

SPARQL

  • SPARQL is W3C-standardized language for RDF querying. There were also proposed other RDF query languages.

    BTW, it is possible to query non-RDF sources with SPARQL, e. g. defining R2RML mappings.

  • RDF self-descibeness and SPARQL standardness remove the need to create or to learn a new (shitty) API every day.

GraphQL

  • Similar to SPARQL, GraphQL allows to avoid multiple requests.

  • GraphQL allows to wrap different data sources of different kinds, but typically they are REST APIs.

    As you can see, it is possible to wrap a SPARQL endpoint (there also exists HyperGraphQL).

Why GraphQL

Why Datatourisme have preferred GraphQL?

  • GraphQL is closer to developers and technologies they use en masse. In the past, JSON-LD had the same motivation (however, see my note about JSON-LD here).

  • As it seems, Diffuseur's GraphQL layer provides API keys support and prevents too complex SPARQL queries.

Are data still semantic

  • The answer depends on what you mean by semantic. There was an opinion that even relational model is quite semantical...

  • I'd answer affirmatively, if it's possible to extract e. g. the comment to the :rcs property with GraphQL (and the answer seems to be negative).

Conclusion

Answering your direct question:

  • it is not necessary (though possible) to create a semantic ontology first in order to use GraphQL;
  • it is not necessary (though possible) to use GraphQL after creating a semantic ontology.

Answering your indirect question:

  • probably you need a semantic ontology in order to build such chatbot;
  • probably you need something else in addition.

See also: How is the knowledge represented in Siri – is it an ontology or something else?

Update

In addition to HyperGraphQL, there are other interesting convergence projects:

Stanislav Kralin
  • 10,115
  • 4
  • 30
  • 52
  • 1
    Thank you for your impressive anwser Stanislav, My goal is to help citizens to act and participate to the daily life of their city, that's why i thought about build an ontology to desribe the ecosystem of the city (individuals - organizations), and for the IHM, to build a chatbot, an AI. Would you have any advices ? – Erwan Pesle Apr 28 '18 at 11:50
  • @ErwanPesle, unfortunately, I'm not familiar with the subject... I hope, the T. Gruber's interview would be helpful. – Stanislav Kralin Apr 29 '18 at 06:10
9

GraphQL and SPARQL are different languages for different purposes. SPARQL is a language to work with Triple stores, graph datasets, and RDF nodes. GraphQL is a API language, preferably for working with JSON structures. As for your specific case, I would recommend to clarify your goal on using AI in your application. If you require to apply a graph dataset in your application, perform more advance knowledge discovery like reasoning on dataset, then you may need a Semantic Web approach to apply SPARQL on top of your dataset. As you can see in the picture below, Semantic Web presents different layers to perform knowledge discovery, perform reasoning, by ontology design and RDF-izing datasets.

diagram

see here to read more. If your AI application does not have such requirements and you can accomplish your data analysis using a JSON-based database, GraphQL is probably a good choice to create your API, as it is widely used by different Web and Mobile applications these days. In particular, it is used to share your data through different platforms and microservices. See here for more information.

GraphQL diagram

Pablo Bianchi
  • 1,039
  • 1
  • 15
  • 23
Enayat
  • 2,784
  • 23
  • 42
  • Thank you, For a chatbot, which one of this tech would you use ? – Erwan Pesle Apr 28 '18 at 11:58
  • In the first picture, why does RDF sit above XML? Does this indicate that RDF requires XML in some way and cannot be used without it? – jaco0646 Apr 29 '18 at 16:32
  • @ErwanPesle I use both technology in different projects. I mostly use Semantic Web for doing research deeply. For example, when I want to answer sophisticated queries over a graph database. On the other side, I use graphql in a company to build a API on top of relational database, instead of using REST API. – Enayat Apr 30 '18 at 17:13
  • @jaco0646 XML is primarily a serialization format, while RDF is primarily a data model. In other words, we represent data in XML format, while RDF is a more higher level and a general aspect of data structure (e.g., each object can be defined as SUBJECT, OBJECT, and PREDICATE). So RDF triples can be represented by different formats like turtle, XML , .... Hope I could explain it well! read here https://www.cambridgesemantics.com/blog/semantic-university/learn-rdf/rdf-vs-xml/ – Enayat Apr 30 '18 at 17:20
  • So in the picture, XML is only an example? It could say "Syntax: JSON-LD" and have the same meaning? – jaco0646 Apr 30 '18 at 18:53
  • 1
    @jaco0646 Yes, could be. The picture was taken from the first SW architecture. Time to time, more data representations were added to the architecture. – Enayat Apr 30 '18 at 19:27
6

Quickly, the differences are :

  • SPARQL (SPARQL Protocol and RDF Query Language) is a language dedicated to query RDF graph databases (CRUD and more). It is a standard within the Semantic Web tools and provided by W3C Recommendation.

  • GraphQL is a language created by Facebook and strongly ressembling JSON to communicate with APIs. It is a communication tool between clients and server endpoints. The request defines itself the structure of the answer. Its use is not limited to SQL or NoSQL or ... "Graph" doesnt mean "a structure made of triples" as for the RDF.

Those are two different language for different applications.

Gilles-Antoine Nys
  • 1,413
  • 13
  • 18
  • 1
    Hello, thank you for your anwser. So, should i better use sparql or graphql to build my AI ? Why did this compagny did an ontology then a graphql ? Did they used ontology to build the logic of the data model then a graphql to query it faster ? thank you – Erwan Pesle Apr 27 '18 at 14:11
5

A very important difference, which I didn't see mentioned in the previous answers, is that, while SPARQL is more powerful query language in general, it produces only tabular output, while GraphQL gives tree structures, which is important in some implementation cases.

Ivo Velitchkov
  • 2,216
  • 9
  • 17
  • 1
    Thanks @Ivo for mentioning it, [here'is](https://stackoverflow.com/questions/54785145/extract-all-parents-of-a-given-node/54791940) an implementation case where I needed to get a tree structure, I wished I knew that before trying to do it using Sparql. – Bilal Feb 20 '19 at 17:20
  • 7
    @ivo-velitchkov : a sparql [CONSTRUCT](https://www.w3.org/TR/rdf-sparql-query/#construct) request produces a graph in output – loic.jaouen Mar 11 '19 at 08:30