sparna-git / Sparnatural

Sparnatural : Typescript visual SPARQL query builder for knowledge graphs, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
206 stars 34 forks source link

Intégration avec Wikidata #258

Open tfrancart opened 2 years ago

tfrancart commented 2 years ago

Voici l'appel qui est fait depuis l'autocompletion dans l'interface Wikidata:

https://www.wikidata.org/w/api.php?origin=*&action=wbsearchentities&format=json&limit=50&continue=0&language=fr&uselang=fr&search=chat&type=item

On voit aussi passer ca:

https://www.wikidata.org/w/api.php?origin=*&action=wbsearchentities&format=json&limit=50&continue=0&language=fr&uselang=fr&search=P31&type=property

Doc de l'API wbsearhentities: https://www.wikidata.org/w/api.php?action=help&modules=wbsearchentities

Extrait du résultat:

{
  "searchinfo": {
    "search": "chat"
  },
  "search": [
    {
      "id": "Q146",
      "title": "Q146",
      "pageid": 282,
      "repository": "wikidata",
      "url": "//www.wikidata.org/wiki/Q146",
      "concepturi": "http://www.wikidata.org/entity/Q146",
      "label": "chat domestique",
      "description": "espèce de mammifères de la famille des félidés",
      "match": {
        "type": "label",
        "language": "fr",
        "text": "chat domestique"
      }
    },
    {
      "id": "Q58199",
      "title": "Q58199",
      "pageid": 61017,
      "repository": "wikidata",
      "url": "//www.wikidata.org/wiki/Q58199",
      "concepturi": "http://www.wikidata.org/entity/Q58199",
      "label": "messagerie instantanée",
      "description": "type d'échange instantané de messages textuels et de fichiers entre deux personnes",
      "match": {
        "type": "alias",
        "language": "fr",
        "text": "chat"
      },
      "aliases": [
        "chat"
      ]
    },
   ...
  ],
  "search-continue": 50,
  "success": 1
}
tfrancart commented 2 years ago

Voir également l'API query : https://www.mediawiki.org/wiki/API:Prefixsearch Sur la page d'accueil, voici l'API qui est envoyée:

https://www.wikidata.org/w/api.php?action=wbsearchentities&search=chat&format=json&errorformat=plaintext&language=en&uselang=en&type=item
tfrancart commented 4 months ago

The following SPARQL query against wikidata endpoint works fine with autocompletion + class criteria. The drawback is that 50 entities are returned first, and after only the filtering on the type happens. Which can lead to small number of results

SELECT DISTINCT ?person ?personLabel WHERE {
  SERVICE wikibase:mwapi {
      bd:serviceParam wikibase:api "EntitySearch" .
      bd:serviceParam wikibase:endpoint "www.wikidata.org" .
      bd:serviceParam mwapi:search "alb" .
      bd:serviceParam mwapi:language "en" .
      # The maximum limit we can set is 50.
      # bd:serviceParam mwapi:limit "50" .
      ?person wikibase:apiOutputItem mwapi:item .
  }
  ?person wdt:P31/wdt:P279* wd:Q5. 

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

} ORDER BY ?personLabel
tfrancart commented 4 months ago

There is also the OpenLink Wikidata demo SPARQL endpoint : https://wikidata.demo.openlinksw.com/sparql?default-graph-uri=&query=%0D%0Aselect+%3Fs+%3Fo+%0D%0Awhere+%0D%0A++%7B+%0D%0A++++++graph+%3Fg+%0D%0A++++++%7B+%0D%0A+++++++++%3Fs+rdfs%3Alabel+%3Fo+.%0D%0A+++++++++%3Fo+bif%3Acontains++%27%22Paris%22%27++.%0D%0A+++++++++filter+%28lang%28%3Fo%29+%3D+%22en%22%29%0D%0A++++++++%0D%0A++++++%7D%0D%0A++++%0D%0A++%7D%0D%0A%0D%0Alimit+100+&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&signal_void=on&signal_unconnected=on&run=+Run+Query+