SPARQL string functions?

1,625 views
Skip to first unread message

Roland Wingerter

unread,
Mar 14, 2018, 11:52:19 AM3/14/18
to vocbench-user
Hi all,

making my first steps with SPARQL I also tried some string functions, e.g. LCASE() or SUBSTR() which are part of Sparql 1.1. (https://www.w3.org/TR/sparql11-query/#func-substr). I could not get them to work. Am I missing something or are they not supported in VB3?

Kind regards
Roland

Manuel Fiorelli

unread,
Mar 14, 2018, 12:01:56 PM3/14/18
to Roland Wingerter, vocbench-user
Dear Roland,

the available functions depend on the triple store that powers a given project. I think that both RDF4J and GraphDB have fairly good coverage of SPARQL 1.1 functions; however, I don't know a compatibly matrix telling exactly which functions are implemented.

Nonetheless, I think that both LCASE and SUBSTR are implemented. For laziness, I have only tested LCASE:

select ?lowercased {
    BIND(LCASE("ABCD") as ?lowercased)  
}

The query above correctly  returns "abcd".

Can you share with us an example of the query you are trying to write?

Regards

Manuel



--
You received this message because you are subscribed to the Google Groups "vocbench-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vocbench-user+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vocbench-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/vocbench-user/34916fb5-d9d9-4d58-9ee3-342cc9b16dc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Manuel Fiorelli

Roland Wingerter

unread,
Mar 14, 2018, 4:39:31 PM3/14/18
to vocbench-user
Dear Manuel,

thank you for your help. My syntax was wrong, I did not know I had to use BIND(). With it my query works as expected.

Kind regards
Roland 

Am Mittwoch, 14. März 2018 17:01:56 UTC+1 schrieb Manuel Fiorelli:
Dear Roland,

the available functions depend on the triple store that powers a given project. I think that both RDF4J and GraphDB have fairly good coverage of SPARQL 1.1 functions; however, I don't know a compatibly matrix telling exactly which functions are implemented.

Nonetheless, I think that both LCASE and SUBSTR are implemented. For laziness, I have only tested LCASE:

select ?lowercased {
    BIND(LCASE("ABCD") as ?lowercased)  
}

The query above correctly  returns "abcd".

Can you share with us an example of the query you are trying to write?

Regards

Manuel


2018-03-14 16:52 GMT+01:00 Roland Wingerter <chun...@gmail.com>:
Hi all,

making my first steps with SPARQL I also tried some string functions, e.g. LCASE() or SUBSTR() which are part of Sparql 1.1. (https://www.w3.org/TR/sparql11-query/#func-substr). I could not get them to work. Am I missing something or are they not supported in VB3?

Kind regards
Roland

--
You received this message because you are subscribed to the Google Groups "vocbench-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vocbench-use...@googlegroups.com.



--
Manuel Fiorelli

Armando Stellato

unread,
Mar 15, 2018, 2:30:53 AM3/15/18
to Roland Wingerter, vocbench-user

Dear Roland,

 

BIND is indeed not (generally) necessary, Manuel made an example with it to provide you a very generic SPARQL query that is actually not a query (it doesn't look up any data and uses bind to create the returned variable), thus is not bound (pun not intended :D ) to any dataset.

 

You can actually use LCASE on any string typed variable e.g. in a FILTER expression, such as the following:

 

SELECT *

WHERE {

   ?c a skos:Concept .

   FILTER(STRSTARTS(LCASE(STR(?c)), "http://"))

}

LIMIT 10

 

Here I’m taking all concepts having their URI starting with “http://” and I use LCASE to include also those having, say, a URI starting with “HTTP://” (or, more in general, I’m making it a case-insensitive comparison). Note the use of STR to first transform ?c (which is an RDF Resource) into a string representing its URI.

 

Cheers,

 

Armando

 

 

 

 

 

Sent from my Windows 10 phone

 


Da: vocben...@googlegroups.com <vocben...@googlegroups.com> per conto di Roland Wingerter <chun...@gmail.com>
Inviato: Wednesday, March 14, 2018 9:39:30 PM
A: vocbench-user
Oggetto: Re: [vocbench-user] SPARQL string functions?
 

Roland Wingerter

unread,
Mar 15, 2018, 5:38:21 AM3/15/18
to vocbench-user
Dear Armando,

thanks for joining in. I was trying out STR(), LCASE and SUBSTR(). For example, I tried to remove the language tag from a prefLabel. The following query works for me, but it seems to need BIND(). Or is there another way? Just curious ...

SELECT ?s ?literal ?string WHERE {
   ?s rdf:type skos:Concept .
   ?s skosxl:prefLabel ?o .
   ?o skosxl:literalForm ?literal .
   FILTER (lang(?literal) = "en") .
   BIND(STR(?literal) as ?string) .
} LIMIT 10

Kind regards
Roland

Thomas Francart

unread,
Mar 15, 2018, 5:44:26 AM3/15/18
to Roland Wingerter, vocbench-user
BIND is not necessary in this case. You can assign variables in the SELECT clause of the SPARQL query :


SELECT ?s ?literal (STR(?literal) as ?string) WHERE {

   ?s rdf:type skos:Concept .
   ?s skosxl:prefLabel ?o .
   ?o skosxl:literalForm ?literal .
   FILTER (lang(?literal) = "en") .
} LIMIT 10

To unsubscribe from this group and stop receiving emails from it, send an email to vocbench-user+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Thomas Francart - SPARNA
Web de données | Architecture de l'information | Accès aux connaissances
blog :
blog.sparna.fr, site : sparna.fr, linkedin : fr.linkedin.com/in/thomasfrancart
tel : 
 +33 (0)6.71.11.25.97
, skype : francartthomas

Roland Wingerter

unread,
Mar 15, 2018, 8:17:19 AM3/15/18
to vocbench-user
Dear Thomas,

thank you very much. That's good to know.

Kind regards
Roland
Reply all
Reply to author
Forward
0 new messages