SPARQL query to retrieve data with different datatype (string)

Viewed 39

I am writing a SPARQL query to retrieve answers for the competency question. I want to retrieve all persons who have level of distress "not too disturbing".

select *
where
{
  ?person ocd:hasInsight  ?insight;
  ocd:hasThought ?thought;
  ocd:hasEmotion ?emotion;
  ocd:hasDistressLevel ?severitycontrol.
  FILTER (?severitycontrol = ocd:Not too disturbing) 
}

I am new at this and could not figure out how to fix that.

1 Answers

If the value is a string (e.g., "Not too disturbing"):

FILTER (?severitycontrol = "Not too disturbing") .

If the value is language-tagged in your RDF, you have to append that same language tag:

FILTER (?severitycontrol = "Not too disturbing"@en) . 

String matching is case-sensitive. You can use ucase/lcase to make a string uppercase/lowercase.

If you only want to match a partial string, you can use strStarts/strEnds, contains, and more.

Related