A set of SPARQL examples that are used in different TGX resources
License: https://www.gnu.org/licenses/gpl-3.0
Uses method in: https://github.com/WDscholia/scholia/tree/master/scholia/app/templates/chemical-class_recent-literature.sparql
Chemical-class aspect: recent literature
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX hint: <http://www.bigdata.com/queryHints#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX target: <http://www.wikidata.org/entity/Q46995757>
SELECT
?publication_date
?work ?workLabel
?type
?via
?topics
WITH {
SELECT DISTINCT
(MAX(?publication_datetime_) AS ?publication_datetime)
?work ?via
WHERE {
{
?work wdt:P921 target: .
BIND ("main topic" AS ?via)
}
UNION
{
?work wdt:P921 / wdt:P361+ target: .
BIND ("part" AS ?via)
}
UNION
{
?work wdt:P921 / wdt:P279+ target: .
BIND ("subclass" AS ?via)
FILTER (?topic != target:)
}
UNION
{
?work wdt:P921 / wdt:P1269+ target: .
BIND ("facet" AS ?via)
}
# This seems to be expensive
# UNION
# {
# target: ?propp ?statement .
# ?statement a wikibase:BestRank ;
# prov:wasDerivedFrom / pr:P248 ?work .
# BIND ("statement" AS ?via)
# }
# Force the UNION before the publication datetime
hint:Prior hint:runFirst true .
?work wdt:P577 ?publication_datetime_ .
}
GROUP BY ?work ?via
ORDER BY DESC(?publication_datetime)
LIMIT 250
} AS %works
WITH {
SELECT
?publication_date
?work
(GROUP_CONCAT(DISTINCT ?type_label; separator=", ") AS ?type)
?via
(GROUP_CONCAT(DISTINCT ?topic_label; separator=" // ") AS ?topics)
WHERE {
INCLUDE %works
?work wdt:P921 ?topic .
BIND(xsd:date(?publication_datetime) AS ?publication_date)
OPTIONAL { ?work wdt:P31 ?type_ . ?type_ rdfs:label ?type_label . FILTER (LANG(?type_label) = 'en') }
?topic rdfs:label ?topic_label . FILTER (lang(?topic_label) = 'en')
}
GROUP BY ?publication_date ?work ?via
} AS %result
WHERE {
INCLUDE %result
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }
}
ORDER BY DESC(?publication_date)
LIMIT 500
graph TD