1

Consider:

PREFIX rss: <http://purl.org/rss/1.0/>
PREFIX dct: <http://purl.org/dc/terms/>

CONSTRUCT {
  ?article dct:title ?title .
}

WHERE {
  ?article rss:title ?title .
}

How I get a lang value on the output?

flag
Are you trying to set a new lang value? If the literal bound to ?title has a lang then it should come out automatically. – Ian Davis Nov 4 at 19:56
Am dealing with RSS feeds that don't have either lang or datatypes on the literals, so figured I'd add them while I'm at it. – bruce Nov 4 at 20:57

3 Answers

3

You can't do what you want with SPARQL 1.0. Currently all you can do is CONSTRUCT out triples that already exist in the underlying triple store. The CONSTRUCT query just takes the matches from the patterns in the WHERE clause and creates corresponding triples. Any languages or datatypes associated with literals will get passed through automatically.

SPARQL 1.1 should help, but as it currently stands you'll have to jump through hoops. SPARQL 1.1. as currently drafted won't support use of functions in CONSTRUCT clauses, but will support sub-selects, select expressions, and, as a time-permitting feature, a function library. A combination of these features would let you assign the value of a newly generated literal (created by a custom function) in a sub-select, and then use that variable in a CONSTRUCT clause.

This can be a little verbose, and there's currently some debate about supporting a LET keyword that will allow simpler syntax for assignments. This is supported as an extension in some SPARQL engines, but is not currently part of the specification. Now is the time to comment to the working group!

link|flag
2

I don't believe there is a way to add language tags to literals in the way you want. CONSTRUCT will copy them from the source graph, but you can't add new ones. Maybe this will be addressed in SPARQL 1.1

link|flag
You are just saying that this particular function is not explicitly called out as part of the core SPARQL 1.0 specification right? Custom functions are supported by SPARQL 1.0, described here: w3.org/TR/rdf-sparql-query/#extensionFunctions – spoon16 Nov 5 at 0:13
1

If I execute your query over the following dataset:

<article> rss:title "title without lang".
<article> rss:title "title with lang"@en.

I get this output:

<article> <http://purl.org/dc/terms/title> "title with lang"@en.
<article> <http://purl.org/dc/terms/title> "title without lang".

If this is all you want to do then I think your query will work fine. If it's not working you may have to provide additional information about the query processor/triple store you are using so that we can better help you debug.

Some query processors (the one I am using is from Intellidimension) allow you to extend their SPARQL query processor with custom functions. In this case they provide one out of the box that allows you to set/change the lang declaration on a literal value.

SPARQL Construct Query:

CONSTRUCT {
    ?article dct:title ?langTitle .
}
WHERE {
    ?article rss:title ?title .
    filter( ?langTitle = langliteral(?title, "gb") ) .
}

Output:

<article> <http://purl.org/dc/terms/title> "title with lang"@gb.
<article> <http://purl.org/dc/terms/title> "title without lang"@gb.
link|flag
I'm using redland/roqet; will give it a go. Thanks. – bruce Nov 4 at 20:57

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.