Sample Queries


#1: Retrieve a list of descriptors that are no longer active in current MeSH and when they were last active.

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT *
FROM <http://id.nlm.nih.gov/mesh>
WHERE {
?d a meshv:Descriptor .
?d meshv:active 0 .
?d meshv:lastActiveYear ?year .
?d rdfs:label ?name

}

Run This Query

#2: Retrieve a list of predicates in MeSH RDF

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT DISTINCT ?p
FROM <http://id.nlm.nih.gov/mesh>
WHERE {

?s ?p ?o

}
ORDER BY ?p

Run This Query
return to top

#3: Retrieve all meshv classes in MeSH RDF

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT DISTINCT ?class
FROM <http://id.nlm.nih.gov/mesh>
WHERE {

?s rdf:type ?class

}
ORDER BY ?class

Run This Query
return to top

#4: Find triples with 'Ofloxacin' as the object

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT *
FROM <http://id.nlm.nih.gov/mesh>

WHERE {
?s ?p mesh:D015242 .
}

Run This Query
return to top

#5: Find the MeSH headings and labels of Pharmacological Actions for 'Ofloxacin'


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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT *
FROM <http://id.nlm.nih.gov/mesh>

WHERE {
mesh:D015242 meshv:pharmacologicalAction ?pa .
?pa rdfs:label ?paLabel
}

Run This Query
return to top

#6: Descriptors and SCRs that have the Pharmacological Action 'Anti-Bacterial Agents'

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT ?d ?dLabel
FROM <http://id.nlm.nih.gov/mesh>

WHERE {
?d meshv:pharmacologicalAction ?pa.
?d meshv:active 1 .
?d rdfs:label ?dLabel .
?pa rdfs:label "Anti-Bacterial Agents"@en
}

ORDER BY ASC (?dLabel)

Run This Query
return to top

#7: Find all active MeSH descriptors with an allowable qualifier of 'adverse effects'

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT distinct ?d ?dLabel
FROM <http://id.nlm.nih.gov/mesh>

WHERE {
?d meshv:allowableQualifier ?q .
?d meshv:active 1 .
?q rdfs:label "adverse effects"@en .
?d rdfs:label ?dLabel
}

Run This Query
return to top

#8: Find all MeSH descriptors that are ancestors of MeSH descriptor D005138 'Eyebrow'

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT ?treeNum ?ancestorTreeNum ?ancestor ?alabel
FROM <http://id.nlm.nih.gov/mesh>

WHERE {
mesh:D005138 meshv:treeNumber ?treeNum .
?treeNum meshv:parentTreeNumber+ ?ancestorTreeNum .
?ancestor meshv:treeNumber ?ancestorTreeNum .
?ancestor rdfs:label ?alabel
}

ORDER BY ?treeNum ?ancestorTreeNum

Run This Query
return to top

#9: Find all MeSH descriptors that are descendants of MeSH descriptor D009369 'Neoplasm'

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT DISTINCT ?descriptor ?label
FROM <http://id.nlm.nih.gov/mesh>

WHERE {
mesh:D009369 meshv:treeNumber ?treeNum .
?childTreeNum meshv:parentTreeNumber+ ?treeNum .
?descriptor meshv:treeNumber ?childTreeNum .
?descriptor rdfs:label ?label .
}

ORDER BY ?label

Run This Query
return to top

#10: Retrieve all MeSH descriptors or concepts with 'infection' anywhere in its name

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT ?d ?dName ?c ?cName
FROM <http://id.nlm.nih.gov/mesh>

WHERE {

?d a meshv:Descriptor .
?d meshv:active 1 .
?d meshv:concept ?c .
?d rdfs:label ?dName .
?c rdfs:label ?cName
FILTER(REGEX(?dName,"infection","i") || REGEX(?cName,"infection","i"))

}
ORDER BY ?d

Run This Query
return to top

#11: Find all MeSH Descriptors created for 2016 MeSH that are treed under diseases.

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT DISTINCT ?d ?name ?dateEstablished
FROM <http://id.nlm.nih.gov/mesh>

WHERE {

?d a meshv:Descriptor .
?d rdfs:label ?name .
?d meshv:treeNumber ?tn .
?d meshv:dateEstablished ?dateEstablished
FILTER(regex(?dateEstablished, "2017-01-01"))
FILTER(REGEX(?tn,"C"))

}

ORDER BY ?name

Run This Query
return to top

#12: Retrieve all terms that belong to Descriptor D009369 'Neoplasm'.

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT ?t ?pred ?label

FROM <http://id.nlm.nih.gov/mesh>

WHERE {
mesh:D009369 meshv:concept ?c .
?c meshv:term ?t .
?t rdfs:label ?label .
?t ?pred ?label
}

Run This Query
return to top

#13: Display MeSH Qualifiers grouped by the their descriptors' base tree numbers.

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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>

SELECT ?qualifier ?baseTreeNum (count(?baseTreeNum) AS ?count) WHERE {
SELECT ?qualifier (SUBSTR(?tnLabel,1,3) AS ?baseTreeNum)

WHERE {
?dq a meshv:AllowedDescriptorQualifierPair .
?dq meshv:hasDescriptor ?d .
?dq meshv:hasQualifier ?q .
?d meshv:treeNumber ?tn .
?tn rdfs:label ?tnLabel .
?q meshv:preferredTerm ?pt .
?pt meshv:prefLabel ?qualifier
FILTER(?qualifier = 'adverse effects'@en)
#full list of qualifiers to choose from:
#http://www.nlm.nih.gov/mesh/topsubscope.html
}
}
GROUP BY ?qualifier ?baseTreeNum
ORDER BY ?baseTreeNum

Run This Query
return to top