Categories
Ontology Pharmacovigilance toolkit SPARQL

Medical Synonyms

Example interface to the National Library of Medicine MESH SPARQL endpoint, which returns medical synonyms using the following type of query:


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 mesh2020: <http://id.nlm.nih.gov/mesh/2020/>
PREFIX mesh2019: <http://id.nlm.nih.gov/mesh/2019/>
PREFIX mesh2018: <http://id.nlm.nih.gov/mesh/2018/>
PREFIX : <urn:ex:>


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

  # Which direct triples ?s match the query string?
  ?s ?p ?n.
  # Find ancestors a few levels above. The limiting numbers {,3} mean
  # only consider 3 levels at most - this is important as the number
  # of ancestors/descendants are potentially large.
  ?possible_concepts (:|!:){,3} ?s.
  # Of these ancestors, which have a direct path to the query string?
  ?possible_concepts (:|!:){,3} ?n.
  # ..and of these, we want concepts because they contain
  #   synonyms of interest
  [] meshv:preferredConcept ?possible_concepts.
  # Find all the children of these concepts
  ?possible_concepts (:|!:){,3} ?all_descendants.
  # Finally, enumerate labels of these concepts as synonyms of the
  # input string
  ?all_descendants meshv:label|meshv:prefLabel|rdfs:label|meshv:altLabel ?synonyms.}