substring rather than exact match in query

0 views
Skip to first unread message

andrew....@elucidbio.com

unread,
Jun 10, 2016, 11:54:14 AM6/10/16
to Stardog
Hello,
I successfully use queries like the following:
SELECT * WHERE {
  graph elucid:elucidbio  {
    ?reading a elucid:Reading ;
                   elucid:name elucid:CALCVol .
  }
}

I would like to also do queries where the name (or some other property, but just staying with name as an example) is not an exact match but contains a substring.  For example, all readings that have a name that contains CALC, rather than only those with an exact name of CALVol.

In googling, I did see multiple examples, but have so far not succeeded in making it work in my graph.  The best attempt I have so far is:
SELECT * WHERE {
graph elucid:elucidbio {
?reading a elucid:Reading ;
elucid:name ?name . FILTER (CONTAINS(?name, "CALC"))
}
}


which is accepted syntactically but which produces no results (even though the more specific exact match proves there is something there.)

Also, I understand that a regular expression can also be supported, which would be even more flexible presumably than the "contains"?

Thank you for your help,
Andy

Jess Balint

unread,
Jun 10, 2016, 12:02:26 PM6/10/16
to sta...@clarkparsia.com
Hi Andy,

Check out the STR() function to use an IRI with a string function such as CONTAINS() or REGEX():


Best,
Jess

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Andrew J. Buckler (Elucid Bioimaging)

unread,
Jun 10, 2016, 12:30:36 PM6/10/16
to sta...@clarkparsia.com

Very nice; I did get the two

SELECT * WHERE {

  graph elucid:elucidbio  {

    ?reading a elucid:Reading ;

                   elucid:name ?name  . FILTER contains(str(?name), "CALC")

  }

}

 

Or

 

SELECT * WHERE {

  graph elucid:elucidbio  {

    ?reading a elucid:Reading ;

                   elucid:name ?name  . FILTER regex(str(?name), "CALC*")

  }

}

 

Thank you!

Andy

---
You received this message because you are subscribed to a topic in the Google Groups "Stardog" group.
To unsubscribe from this topic, visit https://groups.google.com/a/clarkparsia.com/d/topic/stardog/MN_d5Jc38jU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stardog+u...@clarkparsia.com.

Reply all
Reply to author
Forward
0 new messages