Date: 2010-02-24 09:43:50
From: viktor.zhivkov-at-icb.bg
Hello,
I have a question about querying literals with XSD type and language tag specified.
Let's use this sample triples data:
<http://ex.com/Bulgaria> <http://www.w3.org/2000/01/rdf-schema#label> "Bulgaria" .
<http://ex.com/England> <http://www.w3.org/2000/01/rdf-schema#label> "England"@en .
<http://ex.com/Germany> <http://www.w3.org/2000/01/rdf-schema#label> "Deutschland"@de .
<http://ex.com/USA> <http://www.w3.org/2000/01/rdf-schema#label> "USA"^^<http://www.w3.org/2001/XMLSchema#string> .
I want to be able to filter data using a query like this:
select * where
{
?s <http://www.w3.org/2000/01/rdf-schema#label> "LABEL_VALUE"
}
Where LABEL_VALUE is replaced with the user input value.
So in runtime query should look like this:
select * where
{
?s <http://www.w3.org/2000/01/rdf-schema#label> "Bulgaria"
}
1 result.
It works fine. But if I try to query for England I don't get any results since England is defined as "England"@en.
select * where
{
?s <http://www.w3.org/2000/01/rdf-schema#label> "England"
}
0 results.
Same for USA because of xsd:string type.
In order to have any results I need to specify the details (@en or ^^xsd:string respectively) which causes major inconveniences in runtime.
Is there any work around that will enable me to write a generic SPARQL query that will match string values regardless of the details like @lang and ^^xsd:type?
Thanks!
Viktor Zhivkov
Software Developer,
ICB Ltd, http://www.icb.bg/

asked 02 Apr '13, 16:06

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k133156205
accept rate: 30%

edited 17 Apr '13, 10:36

nkrustev's gravatar image

nkrustev ♦♦
66117


Date: 2010-02-24 11:26:11
From: ivan.peikov-at-ontotext.com
Hi Viktor,
As defined by the SPARQL standard, the literals "England" and "England"@en are 
indeed different nodes in the repository graph.
A possible approach to the problem is to filter literals based on their string 
label, e.g.
select * where
{
?s <http://www.w3.org/2000/01/rdf-schema#label> ?l 
filter( str(?l) = "England" )
}
This will work for all literals with string value "England" no matter the 
language tag or literal type.
However, this approach might be slightly inefficient because string comparison 
would be needed for all literals ?l so you might want to use this type of 
filters on graph patterns that are already restrictive enough.
Cheers,
Ivan
link

answered 02 Apr '13, 16:06

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k133156205
accept rate: 30%

edited 17 Apr '13, 10:36

nkrustev's gravatar image

nkrustev ♦♦
66117

Date: 2010-02-24 11:36:45
From: viktor.zhivkov-at-icb.bg
Thank you, Ivan!
I was using 
select *
where {
?s <http://www.w3.org/2000/01/rdf-schema#label> ?l .
filter regex(str(?l), "^England$", "") .      
}
So far and expect having only a cast function instead of cast and regex match will be faster.
Thanks again for the support!
Viktor Zhivkov
Software Developer,
ICB Ltd, http://www.icb.bg/
link

answered 02 Apr '13, 16:07

Discussion-Board-Archive's gravatar image

Discussion-B...
6.1k133156205
accept rate: 30%

edited 17 Apr '13, 10:36

nkrustev's gravatar image

nkrustev ♦♦
66117

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

Tags:

×261
×243
×38

Asked: 02 Apr '13, 16:06

Seen: 4,119 times

Last updated: 17 Apr '13, 10:36

powered by BitNami OSQA