Wikidata:ScienceSource project/Queries
(Redirected from User:Charles Matthews/ScienceSource queries)
This page is for sample ScienceSource SPARQL queries. Appearances to the contrary, these are not queries for the Wikidata Query Service. They are to be run on
Links are provided on a ScienceSource wiki page.
The data schema at
is in use, so the P- and Q-numbers do not refer to those in use on Wikidata. The queries are displayed here using {{Sparql}}
for readability.
For resources on SPARQL and homegrown queries, there are numerous examples on User:Charles Matthews/Queries and in Wikidata:WikiFactMine/Core SPARQL.
Articles by ascending length
edit- Try it!
#Articles by ascending notional length SELECT ?annotation ?title ?length ?article WHERE {?annotation wdt:P19 ?anchor. ?anchor wdt:P7 wd:Q6. ?anchor wdt:P12 ?article. ?anchor wdt:P10 ?length. ?article wdt:P20 ?title } ORDER BY ASC (?length)
Annotations for a particular term
edit- Try it!
#Find all annotations with term "toxocariasis", showing the article in which the term is found. SELECT ?item ?article ?term WHERE {?item wdt:P3 wd:Q5. ?item wdt:P15 ?term. ?item wdt:P20 ?article. FILTER (?term = "toxocariasis") }
Distinct terms found
edit- Try it!
#Show all distinct terms found (currently disease and drug terms) SELECT DISTINCT ?term WHERE {?item wdt:P3 wd:Q5. ?item wdt:P15 ?term}
Counting annotations
edit- Try it!
#Counting drug annotations #defaultView:BubbleChart SELECT ?drug ?drugLabel ?count WHERE { { SELECT ?drug (COUNT(?annotation) AS ?count) WHERE { ?annotation wdt:P15 ?drug. ?annotation wdt:P16 "infectiousdiseasesdrugs" . } GROUP BY ?drug HAVING (?count > 1) } SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } ORDER BY DESC(?count) LIMIT 500
- Try it!
#Counting disease annotations #defaultView:BubbleChart SELECT ?disease ?diseaseLabel ?count WHERE { { SELECT ?disease (COUNT(?annotation) AS ?count) WHERE { ?annotation wdt:P15 ?disease. ?annotation wdt:P16 "infectiousdiseases" . } GROUP BY ?disease HAVING (?count > 1) } SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } ORDER BY DESC(?count) LIMIT 500
Co-occurrence 1
edit- Try it!
#Co-occurrence of drug and disease terms (duplications removed) SELECT DISTINCT ?articletitle ?disease ?drug WHERE {?term1 wdt:P19 ?anchor1. ?term2 wdt:P19 ?anchor2. ?term1 wdt:P15 ?disease. ?term2 wdt:P15 ?drug. ?term1 wdt:P16 "infectiousdiseases". ?term2 wdt:P16 "infectiousdiseasesdrugs". ?anchor1 wdt:P12 ?article. ?anchor2 wdt:P12 ?article. ?article wdt:P20 ?articletitle. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
- Try it!
#Co-occurrence filtered by the condition "disease term before drug term" SELECT ?articletitle ?disease ?drug ?charnumber1 ?charnumber2 WHERE {?term1 wdt:P19 ?anchor1. ?term2 wdt:P19 ?anchor2. ?term1 wdt:P15 ?disease. ?term2 wdt:P15 ?drug. ?term1 wdt:P16 "infectiousdiseases". ?term2 wdt:P16 "infectiousdiseasesdrugs". ?anchor1 wdt:P10 ?charnumber1. ?anchor2 wdt:P10 ?charnumber2. ?anchor1 wdt:P12 ?article. ?anchor2 wdt:P12 ?article. ?article wdt:P20 ?articletitle. FILTER (?charnumber2 > ?charnumber1) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
Co-occurrence 2
edit- Try it!
#Co-occurrence filtered by the condition "disease term before drug term" and character distance apart < 100 SELECT ?articletitle ?disease ?drug ?charnumber1 ?charnumber2 WHERE {?term1 wdt:P19 ?anchor1. ?term2 wdt:P19 ?anchor2. ?term1 wdt:P15 ?disease. ?term2 wdt:P15 ?drug. ?term1 wdt:P16 "infectiousdiseases". ?term2 wdt:P16 "infectiousdiseasesdrugs". ?anchor1 wdt:P10 ?charnumber1. ?anchor2 wdt:P10 ?charnumber2. ?anchor1 wdt:P12 ?article. ?anchor2 wdt:P12 ?article. ?article wdt:P20 ?articletitle. FILTER (?charnumber2 > ?charnumber1) FILTER (?charnumber2 - ?charnumber1) < 100) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
Co-occurrence 3
edit- Try it!
#Co-occurrence (filtered) displayed for single article Q6679 #defaultView:Dimensions SELECT ?drugLabel ?charnumber2 ?charnumber1 ?diseaseLabel WHERE { ?anchor1 wdt:P12 wd:Q6679; wdt:P10 ?charnumber1. ?anchor2 wdt:P12 wd:Q6679; wdt:P10 ?charnumber2. ?term1 wdt:P19 ?anchor1. ?term2 wdt:P19 ?anchor2. ?term1 wdt:P15 ?disease. ?term2 wdt:P15 ?drug. ?term1 wdt:P16 "infectiousdiseases". ?term2 wdt:P16 "infectiousdiseasesdrugs". FILTER (?charnumber2 > ?charnumber1) FILTER (?charnumber2 - ?charnumber1 < 200) SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }
Counting annotations in a time period
edit- Try it!
#Counting annotations in a time period: publication date 2013 earliest SELECT ?annotation ?term ?title ?date1 WHERE {?annotation wdt:P19 ?anchor. ?annotation wdt:P15 ?term. ?anchor wdt:P12 ?article. ?article wdt:P17 ?date. ?article wdt:P20 ?title. BIND (YEAR(?date) AS ?date1) FILTER (?date1 > 2012) }
Annotations and quantiles
edit- Try it!
#Annotations in notional first 10% of paper, ordered by absolute distance #Good correlation with terms in title SELECT ?annotation ?title ?term ?length1 ?length WHERE {?annotationZ wdt:P19 ?anchorZ. ?anchorZ wdt:P7 wd:Q6. ?anchorZ wdt:P12 ?article. ?anchorZ wdt:P10 ?length. ?article wdt:P20 ?title. ?annotation wdt:P19 ?anchor. ?anchor wdt:P12 ?article. ?annotation wdt:P15 ?term. ?anchor wdt:P10 ?length1. FILTER(10*?length1 < ?length) } ORDER BY ASC (?length1)
LineChart by decile for given dictionary and paper
edit- Try it!
#defaultView:LineChart SELECT ?decile (COUNT(?annotation) AS ?count) WHERE { ?annotation wdt:P3 wd:Q5 ; wdt:P19 ?anchor; wdt:P16 "infectiousdiseasesdrugs". ?anchor wdt:P12 wd:Q6679. ?anchor wdt:P10 ?charnumber. ?annotationZ wdt:P19 ?anchorZ. ?anchorZ wdt:P7 wd:Q6; wdt:P12 wd:Q6679; wdt:P10 ?length. BIND (floor(10*?charnumber/?length) AS ?decile) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } GROUP BY ?decile