{{!
@param IRI exercise
}}

{{> sparql/prefixes.mustache }}

SELECT (REPLACE(STR(?prerequisite), "^.*\\/([^/]+)$", "$1") AS ?id)
       ?name
WHERE {
  ?prerequisite a sp:Query .
  FILTER (!sameTerm(<{{exercise}}>, ?prerequisite))
  FILTER NOT EXISTS {
    ?prerequisite dcterms:subject ?languageConstruct .
    FILTER NOT EXISTS {
      <{{exercise}}> dcterms:subject ?languageConstruct .
    }
  }
  # Prerequisite must have the same or easier difficulty than the selected exercise.
  <{{exercise}}> sparqlab:hasDifficulty/skos:notation ?difficulty .
  ?prerequisite sparqlab:hasDifficulty/skos:notation ?prerequisiteDifficulty .
  FILTER (?prerequisiteDifficulty <= ?difficulty)
  ?prerequisite rdfs:label ?name .
}

{{!
@param IRI exercise
}}

{{> sparql/prefixes.mustache }}

SELECT (REPLACE(STR(?prerequisite), "^.*\\/([^/]+)$", "$1") AS ?id)
       ?name
WHERE {
  ?prerequisite a sp:Query .
  FILTER (!sameTerm(<{{exercise}}>, ?prerequisite))
  FILTER NOT EXISTS {
    ?prerequisite dcterms:subject ?languageConstruct .
    FILTER NOT EXISTS {
      <{{exercise}}> dcterms:subject ?languageConstruct .
    }
  }
  # Prerequisite must have the same or easier difficulty than the selected exercise.
  <{{exercise}}> sparqlab:hasDifficulty/skos:notation ?difficulty .
  ?prerequisite sparqlab:hasDifficulty/skos:notation ?prerequisiteDifficulty .
  FILTER (?prerequisiteDifficulty <= ?difficulty)
  ?prerequisite rdfs:label ?name .
}
ORDER BY ?prerequisiteDifficulty
LIMIT 10

Order prerequisites by difficulty and limit them to 10
Order prerequisites by difficulty and limit them to 10
