Hi!
On 7/25/17 10:26 PM, Erik Moeller wrote:
Here's an example query:
# For a list of items, exclude the ones that have "instance of" set to
# one from a given set of excluded classes
I wonder if this one won't be more efficient:
SELECT DISTINCT ?item WHERE {
FILTER NOT EXISTS {
# Excluded classes: disambiguation pages, Wikinews articles, etc.
{ ?item wdt:P31 wd:Q4167410 }
UNION { ?item wdt:P31 wd:Q17633526 }
UNION { ?item wdt:P31 wd:Q11266439 }
UNION { ?item wdt:P31 wd:Q4167836 }
UNION { ?item wdt:P31 wd:Q14204246 }
}
# Set of items to check against the above exclusion list
# wd:Q355362 is a disambiguation page and will therefore not be in
# the result set
VALUES ?item { wd:Q23548 wd:Q355362 wd:Q1824521 wd:Q309751 wd:Q6952373 }
}
Generally, patterns like '?item ?property ?value' aren't very good
performers, though in this case the query optimizer seems to handle it
ok, so it may not matter this much.
Another note is that you can call wbsearchentities from SPARQL:
https://www.mediawiki.org/wiki/Wikidata_query_service/User_Manual/MWAPI#Fin…
Not sure whether it fits your use case or not, but offering it as one
more option.
--
Stas Malyshev
smalyshev(a)wikimedia.org