Search code examples
sqlconditional-statementssparql

Sparql Select query with condition


Im doing an sparql query , I need to know how to put a condition in the where clause , suppose it returns M(Male) , F ( Female) , i want to bind the letter (M) to the word Male,(F) with Female.

Im new in sparql , i use sql and i need to find something like this in sparql:

Case when Gender  = 'M' then 'Male' when Gender = 'Female' then 'Female'

My query simplified is more less this:

SELECT DISTINCT  ?Gender count(distinct ?publication)
FROM href
WHERE {
  ?publication a href.
  ?publication href ?AuthorList.
  ?AuthorList?item ?Person.
  ?Person foaf:gender ?genero   //Need here the condition
}

Solution

  • At last i get it with this code:

    SELECT ?Sexo count(distinct ?publication) 
    FROM href
    WHERE {
      ?publication a  href.
      ?publication < href ?listaAutores.
      ?listaAutores ?item ?persona.
      ?persona foaf:gender ?gender
      BIND(
        IF(contains(?gender, "f"), "Female",
        
        "Male")
        AS ?Sexo).
       
    }