How to use FILTER REGEX in RDFLib?

138 views
Skip to first unread message

Kristina

unread,
Sep 20, 2018, 5:54:12 AM9/20/18
to rdflib-dev
I wanted to use the RDFLib for SPARQL 1.1 Queries which should be supported.
I have a file in JSON-LD and simple SELECT query works fine. But when I add a FILTER REGEX, the result is zero size and also no error.
Here is my code (abstracted):

g = Graph()
g.parse("myontology.owl", format="json-ld")
result = g.query(
"""SELECT ?func
WHERE { ?func rdf:type mo:Function .
FILTER REGEX (?func, "off", "i").}""",
initNs={"mo": "http://mynamespace#"})
for row in result:
print("%s " % row)

What is wrong with the FILTER REGEX?
I didn't find a good documentation how to use SPARQL Algebra in RDFLib.
Thank you for help!

Gunnar Aastrand Grimnes

unread,
Sep 20, 2018, 6:28:57 AM9/20/18
to rdfli...@googlegroups.com
regex is not defined on URIs - you have to cast it to a string:

FILTER REGEX(str(?func), "off", "i") should work

- Gunnar
> --
> http://github.com/RDFLib
> ---
> You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
> To post to this group, send email to rdfli...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/82048b7c-d125-410c-9feb-8689a3007267%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://gromgull.net

Kristina

unread,
Sep 20, 2018, 6:54:17 AM9/20/18
to rdflib-dev
Am Donnerstag, 20. September 2018 12:28:57 UTC+2 schrieb Gunnar Aastrand Grimnes:
> regex is not defined on URIs - you have to cast it to a string:
>
> FILTER REGEX(str(?func), "off", "i") should work
>
> - Gunnar


It works. Thank you very much!

Reply all
Reply to author
Forward
0 new messages