[sparql related] how to get the language of a label

615 views
Skip to first unread message

jbrekle

unread,
Apr 29, 2009, 10:24:00 AM4/29/09
to OntoWiki User Discussion
hi,

i know its not directly ontowiki related, but maybe you can help me at
that:

i can get the labels of all classes:

SELECT ?class ?label WHERE {
?class rdf:type rdfs:Class .
?class rdfs:label ?label
}

but as there are are english and german labels - i get both.

to get only the german labels, i tried:

PREFIX xml: <http://www.w3.org/XML/1998/namespace>
SELECT ?class ?label WHERE {
?class rdf:type rdfs:Class .
?class rdfs:label ?label .
?label xml:lang de}

but it results in an error:
SPARQL Error: [unixODBC][OpenLink][Virtuoso iODBC Driver][Virtuoso
Server]SQ074: Line 17: SP030: SPARQL compiler, line 16: syntax error
at 'de' before '}' (37000)
Query: PREFIX sioc: PREFIX skos: PREFIX vcard: PREFIX foaf: PREFIX dc:
PREFIX owl: PREFIX rdfs: PREFIX rdf: PREFIX xml: SELECT ?class ?label
FROM FROM WHERE { ?class rdf:type rdfs:Class . ?class rdfs:label ?
label . ?label xml:lang de}

i also tried with "de" (in quotes). but this gives me "no result"

any idea?

jbrekle

unread,
Apr 29, 2009, 1:15:11 PM4/29/09
to OntoWiki User Discussion
alright, the above query is not the sparql-way :)
and i was suggested that i need to do it somehow with a filter...

it thought of:
PREFIX xml: <http://www.w3.org/XML/1998/namespace>
SELECT ?class ?label WHERE {
?class rdf:type rdfs:Class .
?class rdfs:label ?label .
?label xml:lang ?lang .
FILTER (?lang = "de")
}

but it looks like i am wrong there too because the label is not a
triple or am i mistaken there? because when i do

SELECT ?p
WHERE {
?class rdf:type rdfs:Class .
?class rdfs:label ?label .
?label ?p ?o
}

i get no results...

thanks
jonas

jbrekle

unread,
Apr 30, 2009, 3:55:44 AM4/30/09
to OntoWiki User Discussion
i got it :)

PREFIX xml: <http://www.w3.org/XML/1998/namespace>
SELECT ?class ?label WHERE {
?class rdf:type rdfs:Class .
?class rdfs:label ?label
FILTER (LANG(?label) = "de")
}

thanks

Sebastian Dietzold

unread,
Apr 30, 2009, 5:39:00 AM4/30/09
to OntoWiki User Discussion
quote jbrekle (29.4.2009):

> to get only the german labels, i tried:

> PREFIX xml: <http://www.w3.org/XML/1998/namespace>
> SELECT ?class ?label WHERE {
> ?class rdf:type rdfs:Class .
> ?class rdfs:label ?label .
> ?label xml:lang de}

please use

FILTER (lang(?label) = "de" )

regards

SD


--
Sebastian Dietzold - Department of Computer Science; University of Leipzig
Tel/Fax: +49 341 97 323-66/-29 http://bis.uni-leipzig.de/SebastianDietzold

Reply all
Reply to author
Forward
0 new messages