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

1

5

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").
}
Midgard answered 16/3, 2016 at 13:47 Comment(0)
F
7

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). 
}
Feed answered 16/3, 2016 at 15:28 Comment(2)
Thank you so much!! Your answer is exactly what i was looking for!Midgard
I'd argue that Wikidata is broken in this case since it's storing a number as a string. The conversion shouldn't be necessary.Ginni

© 2022 - 2024 — McMap. All rights reserved.