Increase number of results for Wikidata query with MWAPI - sparql

When including MWAPI in a Wikidata SPARQL query, the maximum number of items in a result set is always 50.
This is an example query:
SELECT ?item ?itemLabel WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "www.wikidata.org";
wikibase:api "EntitySearch";
mwapi:search "York";
mwapi:language "en".
?item wikibase:apiOutputItem mwapi:item.
}
SERVICE wikibase:label {bd:serviceParam wikibase:language "en".}
}
Setting wikibase:limit to a higher value, e.g. 100 doesn't have any effect; the limit stays at 50.
How can I obtain more than 50 items from this kind of query?

Related

How to create a SPARQL query to search Wikidata item descriptions

I'd like to be able to find an item based on words in its descriptions.
This is what I'm trying to do, but clearly I don't know what I'm doing. Any help is appreciated.
SELECT ?item ?itemLabel WHERE {
?item schema:description ?desc.
FILTER(CONTAINS(LCASE(?desc), "space telescope"))
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
LIMIT 10
Solved by UninformedUser in the comments!
WHERE { hint:Query hint:optimizer "None".
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:api "Search";
wikibase:endpoint "www.wikidata.org";
mwapi:srsearch "space telescope".
?item wikibase:apiOutputItem mwapi:title . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
limit 10

Wikidata Sparql get item descriptions

I'm following the MWAPI docs (https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/MWAPI#Find_all_entities_with_labels_%22cheese%22_and_get_their_types) and have the following query:
SELECT * WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "www.wikidata.org";
wikibase:api "EntitySearch";
mwapi:search "python";
mwapi:language "en".
?item wikibase:apiOutputItem mwapi:item.
?label wikibase:apiOutputItem mwapi:label.
?num wikibase:apiOrdinal true.
}
}
ORDER BY ASC(?num) LIMIT 10
I also want to retrieve the description of the wikidata item but don't know how to get it. I've tried adding the following line ?description wikibase:apiOutputItem mwapi:description but it seems to be an invalid property on the API. How do I retrieve it and where can I find this in the docs?
Query reproducible here: https://query.wikidata.org/#SELECT%20%2a%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Amwapi%20%7B%0A%20%20%20%20%20%20bd%3AserviceParam%20wikibase%3Aendpoint%20%22www.wikidata.org%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wikibase%3Aapi%20%22EntitySearch%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mwapi%3Asearch%20%22python%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mwapi%3Alanguage%20%22en%22.%0A%20%20%20%20%20%20%3Fitem%20wikibase%3AapiOutputItem%20mwapi%3Aitem.%0A%20%20%20%20%20%20%3Flabel%20wikibase%3AapiOutputItem%20mwapi%3Alabel.%0A%20%20%20%20%20%20%3Fdesc%20wikibase%3AapiOutputItem%20mwapi%3Adescription.%0A%20%20%20%20%20%20%3Fnum%20wikibase%3AapiOrdinal%20true.%0A%20%20%7D%0A%7D%20%0AORDER%20BY%20ASC%28%3Fnum%29%20LIMIT%2010
The wikibase:label service provides both the label and the description of an item for a specified language. Both have to be explicitly queried for in the SELECT part:
SELECT ?item ?itemLabel ?itemDescription ?num WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "www.wikidata.org";
wikibase:api "EntitySearch";
mwapi:search "python";
mwapi:language "en".
?item wikibase:apiOutputItem mwapi:item.
?num wikibase:apiOrdinal true.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?num) LIMIT 10

Find people whose name start with a particular letter with sparql Wikidata?

This is my query but I don't get any results for records starting with "n"
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31/wdt:P279* wd:Q5.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
FILTER regex (?itemLabel, "^(n)").
}

Filter skyscrapers higher than 500 meters in Wikidata

I try to construct a SPARQL query, where I get a list of skyscrapers with a height of more then 500 meters.
I realized, that the property height (P2048) is measured in different units (meter, foot, centimeter). This would not be a problem for me to calculate the different units into meters.
But my problem is to figure out, that unit is used for the property height.
So my question: how can I get the unit for the property height?
My query so far, where ?unit is just empty:
SELECT ?skyscraper ?skyscraperLabel ?height ?unit WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?skyscraper wdt:P31 wd:Q11303.
?skyscraper wdt:P2048 ?height.
FILTER(?height > 500)
OPTIONAL { ?skyscraper wdt:P2876 ?unit. }
}
LIMIT 100
Try it here
To get the unit itelf use :P2048/psv:P2048/wikibase:quantityUnit:
SELECT ?skyscraper ?skyscraperLabel ?height ?unit ?unitLabel WHERE {
?skyscraper wdt:P31 wd:Q11303.
?skyscraper p:P2048/psv:P2048 ?vn.
?vn wikibase:quantityAmount ?height.
?vn wikibase:quantityUnit ?unit.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
LIMIT 100
Try it here
However, following AKSW and Stanislav Kralin's comments above, it is better to use Normalized values using the psn: prefix: p:P2048/psn:P2048/wikibase:quantityAmount:
SELECT ?skyscraper ?skyscraperLabel ?height WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?skyscraper wdt:P31 wd:Q11303.
?skyscraper p:P2048/psn:P2048/wikibase:quantityAmount ?height.
FILTER(?height >= 500)
}
ORDER BY DESC(?height)
LIMIT 1000
Try this here
Since some buildings contains multiple height values (for example, One World Trade Center have both architectural height (Q24192182) and height to pinnacle (Q26970842) values), some aggregation is needed to retrieve one value per building in SPARQL:
SELECT ?skyscraper ?skyscraperLabel (MAX(?h) AS ?height) WHERE {
?skyscraper wdt:P31 wd:Q11303.
?skyscraper p:P2048/psn:P2048/wikibase:quantityAmount ?h.
FILTER(?h >= 500)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?skyscraper ?skyscraperLabel
ORDER BY DESC(?height)
LIMIT 1000
Try it here

Wikidata Query Service: lookup property label

How do I form the query to look up the English label of a property on a given entity.
This query provides the ID of P31:
SELECT ?item ?itemLabel ?instance_of WHERE {
?item wdt:P646 "/m/09c7w0".
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
OPTIONAL {
?item wdt:P31 ?instance_of.}
}
}
LIMIT 1
How can I get the label of P31 instead?
Also, is there a smart way to get the "best" value of P31, possibly the one with the lowest numeric ID? Some detailed entities have very noisy values. For example, for Q30, "United States" I would prefer to see "country" as my instance_of instead of "member state of the United Nations".
Thanks AKSW. label service applies to the property given a variable with the matching suffix Label:
SELECT ?item ?itemLabel ?instance_of ?instance_ofLabel WHERE {
?item wdt:P646 "/m/09c7w0".
OPTIONAL {
?item wdt:P31 ?instance_of.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 1