Search code examples
sparqlrdfwikidata-query-service

Wikidata Query Service, filtering for values/string that lay above/below a certain value


I made a query, that shows all items that are 'found in taxon' 'Chlamydia trachomatis D/UW-3/CX'. These items must have the Properties P644 (genomic start) and P645 (genomic end). So far this works. But then I wanted to filter these items depending on the values of 'genomic start' and 'genomic end'. In my example I wanted to recieve all items, where 'genomic start' is higher than '100' and 'genomic end' is lower than '3000'. But it did not work. Am I not using FILTER the right way?

Here is my code directly in the Wikidata Query Service Page: Wikidata Query Service

SELECT ?item ?genomic_start ?genomic_end
Where{
?item wdt:P703 wd:Q20800373. #P703:found in taxon
?item wdt:P644 ?genomic_start.
?item wdt:P645 ?genomic_end.
FILTER (?genomic_start > "100").
FILTER (?genomic_end < "3000").
}

Solution

  • You need to first convert the value to int in order to be able to use > or <:

    SELECT ?item ?genomic_start ?genomic_end
    Where{
    ?item wdt:P703 wd:Q20800373. #P703:found in taxon
    ?item wdt:P644 ?genomic_start.
    ?item wdt:P645 ?genomic_end.
    FILTER (xsd:integer(?genomic_start) > 100).
    FILTER (xsd:integer(?genomic_end) < 3000). 
    }