How do I check and filter out empty strings using sparql.
How to check if a string is null or empty in a SPARQL query?
Try this:
BIND(BOUND(?abc) && strlen(?abc)>0 as ?check)
If you want to check if a string is empty or NULL, you can create a new variable
SELECT ?s ?o ?len_o
WHERE {?s prefix:predicate ?o
BIND(STRLEN(?o) AS len_o)
}
Then you can filter on the variable value
SELECT ?s ?o ?len_o
WHERE {?s prefix:predicate ?o
BIND(STRLEN(?o) AS ?len_o)
FILTER (?len_o = 0)
}
Or you can directly create a filter
SELECT ?s ?o
WHERE {?s prefix:predicate ?o
FILTER (STRLEN(?o) != 0)
}
© 2022 - 2024 — McMap. All rights reserved.
""
, or values that aren't bound? Also, what does this have to do with swrl? It doesn't appear to have anything to do with swrl, so I'm removing the tag, at least for now. – Wroughtfoaf:name
that's""
is a simple patternselect * where { ?x foaf:name "" }
, but checking whether someone has no foaf:name requiresselect * where { ?x <>* ?x filter not exists { ?x foaf:name [] } }
. if you've already got results and they include some bindings with undefined values, then you'd need something likefilter bound(?name)
orfilter !bound(?name)
, depending on whether you want – Wrought