2

I am trying to list all properties created in on a wikibase I installed, using docker-compose, based on this install.

Now, want to list all properties that are available in this wikibase, similar to getting that list available through:

<wikibase.url>wiki/Special:ListProperties

I have also extracted that list through SPARQL with the following SPARQL query:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT DISTINCT
  ?property
  ?propertyType
  ?propertyLabel
  ?propertyAltLabel
WHERE {
  ?property a wikibase:Property ;
              rdfs:label ?propertyLabel ;
              wikibase:propertyType ?propertyType .
  OPTIONAL {?property skos:altLabel ?propertyAltLabel .}
}

Running that SPARQL query is expensive though and I need to run that query often, so I would very much like to get that list of properties to the core wikibase API.

Is that possible?

Lucas Werkmeister
  • 2,584
  • 1
  • 17
  • 31
Andra
  • 687
  • 2
  • 9
  • 20

1 Answers1

4

If you know the namespace number for properties on the target wiki (it’s usually 122 if the wiki has an Item: namespace, or 120 if, like on Wikidata, items are in the main namespace), you can use the core allpages API: https://www.wikidata.org/w/api.php?action=query&list=allpages&apnamespace=120

To also get the labels at the same time, use it as a generator and combine it with the entityterms API (new in 1.35; looks like it’s not documented yet, but see T257658): https://www.wikidata.org/w/api.php?action=query&generator=allpages&gapnamespace=120&prop=entityterms&wbetterms=label

Lucas Werkmeister
  • 2,584
  • 1
  • 17
  • 31
  • Maybe I am getting this wrong, but isn't this API call simply returning the top 10 results? What if the user don't know the upper limit to feed `aplimit` parameter, and what if the properties are more than 500 items? – lucamauri May 23 '21 at 15:59
  • If there are more results, use continuation (https://www.mediawiki.org/wiki/API:Query#Example_4:_Continuing_queries), e.g. .get(..., continuation=True) in mwapi (https://pythonhosted.org/mwapi/session.html#mwapi.Session.get). – Lucas Werkmeister May 24 '21 at 13:51