You could use the SPARQL API to extract any or all of the statements on an item in one go, plus the labels in any language you wanted, depending on what you put in the query.

The JSON won't be formatted exactly as below -- you'd get back a structure corresponding to a row for each statement, each row containing the various fields you've asked for -- but the information would be there.

One thing to watch out for in general if you're looking up property labels is that you might need to turn off the normal query optimiser, and instead hand-order the lines in your SPARQL query, because the optimiser often finds that irresistably tempting as a place to start. However, it may not be a problem if you're looking up the statements on a specific item, because there should usually be fewer of those.

But if you do want to get the information in one call, SPARQL may be as good a way as any to do it.

  -- James.


On 22/11/2015 14:54, ja...@j1w.xyz wrote:
I would like to create a REST service in my application that has
request/response behavior shown in the following two scenarios:


http://example/claims?id=Q170790&lang=en

{
   “id”: “Q170790”,
   “label”: “mathematician”,
   “claims”: [
     {
       “property”: {
         “id”: “P279”,
         “label”: “subclass of”
       },
       “value”: [
         {
           “id”: “Q816264”,
           “label”: “formal science”
         }
       ]
     },
     {
       “property”: {
         “id”: “P425”,
         “label”: “field of this profession”
       },
       “value”: [
         {
           “id”: “Q395”,
           “label”: “mathematics”
         }
       ]
     }
   ]
}


http://example/claims?id=Q170790&lang=fr

{
   “id”: “Q170790”,
   “label”: “math\u00e9maticien”,
   “claims”: [
     {
       “property”: {
         “id”: “P279”,
         “label”: “sous-classe de”
       },
       “value”: [
         {
           “id”: “Q816264”,
           “label”: “science formelle”
         }
       ]
     },
     {
       “property”: {
         “id”: “P425”,
         “label”: “domaine d'occupation”
       },
       “value”: [
         {
           “id”: “Q395”,
           “label”: “math\u00e9matiques”
         }
       ]
     }
   ]
}


I'm trying to identify the best Wikidata API queries to support this
functionality, ideally only requiring one invocation.  The closest one
I've found is something like the following, but it seems that I'd have
to make an additional query to get the label for each Q item returned:
https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q170790&languages=fr

Is there a way to somehow include the desired information in one query?

Regards,
James Weaver

_______________________________________________
Wikidata mailing list
Wikidata@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata



_______________________________________________
Wikidata mailing list
Wikidata@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata

Reply via email to