hi all, I have a disease class and a datatype property "complication" //range is string Can anyone please help me by providing me the SPARQL query to find all complications that contains some specified string like "abc". same as "like operator in sql"

asked 19 Feb '11, 12:47

ahmedsaud's gravatar image

ahmedsaud
22828
accept rate: 0%


You should use REGEX() in a FILTER but you may need to use the STR function to force the variable to be a string or REGEX() will not match non-literal values:

SELECT ?disease
WHERE {
   ?disease namespace:complication ?value.
   FILTER (REGEX(STR(?value), "abc", "i"))
}

See the specification for REGEX() which states it operates over simple literals, if the value bound to ?value is a URI then the REGEX() will not match on it unless you use STR(?value) to force ?value to a String

permanent link

answered 19 Feb '11, 14:36

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.9k1715
accept rate: 29%

It works... thanks Rob Vesse♦ for the sample code and explanation.

(19 Feb '11, 15:18) ahmedsaud ahmedsaud's gravatar image

Actually, you might not need the STR clause for a couple of reasons, 1 that the property in question is a datatype property and 2 the range of that property is a string, so if the data is being reasoned over at query time or creation time, then the reasoner will infer that the value is of type string (or it might blow up if its not). Its probably good practice to keep it in, but there might be an overhead in performance.

(19 Feb '11, 19:02) William Greenly William%20Greenly's gravatar image

Additionally, if the value is a URI and we know that property is a datatype property, then chances are the assertion is a mistake and logically you would want it ignored by the filter, not explicitly casted to a string, matched and included in a result.

(19 Feb '11, 19:08) William Greenly William%20Greenly's gravatar image

It depends whether you want to regex within a URI or not. Even if something is inferred to be a string i.e. "literal"^^xsd:string it still needs casting with STR() as REGEX operates on simple literals i.e. "literal" so we still need STR() to strip off the datatype

(20 Feb '11, 10:50) Rob Vesse ♦ Rob%20Vesse's gravatar image

According to the spec, it should operate the same as a fn:matches which in turn operates as follows:

$input as xs:string?, $pattern as xs:string

Think it might be casting anyway??? So it will probably end up being implementation specific???

(20 Feb '11, 11:35) William Greenly William%20Greenly's gravatar image

Thanks Rob!

(16 Feb '13, 02:09) altruist altruist's gravatar image

There is no automatic casting from IRIs to strings.

(17 Feb '13, 09:07) AndyS ♦ AndyS's gravatar image
showing 5 of 7 show 2 more comments
SELECT ?disease
WHERE {
   ?disease namespace:complication ?value.
   FILTER regex(?value, "abc", "i")
}

You can play around with the regex as much as you want.

permanent link

answered 19 Feb '11, 13:23

William%20Greenly's gravatar image

William Greenly
5.1k412
accept rate: 13%

regex is your friend…

permanent link

answered 19 Feb '11, 12:52

AB's gravatar image

AB
1.6k310
accept rate: 35%

It doesn't provide me the results

(19 Feb '11, 12:58) ahmedsaud ahmedsaud's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×1,301

question asked: 19 Feb '11, 12:47

question was seen: 5,481 times

last updated: 17 Feb '13, 09:07