views:

73

answers:

1

Hey all.

Im running a sparql query on a file that contains

<User rdf:about="#RJ">
<hasName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"&gt;RJ&lt;/hasName&gt;
</User>

I want to return only the name i.e. 'RJ' but when i enter my query

SELECT ?name
FROM <example.com> 
WHERE { 
       assign:RJ assign:hasName ?name .   
}

where assign is the correct namespace i return this :

"RJ" ^^<http://www.w3.org/2001/XMLSchema#string&gt;

does anyone have any advice on how to remove the xml schema type for a sparql noob?

thanks in advance

+3  A: 

Whether you can do this depends on the SPARQL implementation you are using. Under SPARQL 1.0 (the current standard) this isn't possible, if however the SPARQL implementation supports some of the SPARQL 1.1 features (which is a W3C working draft currently) or supports vendor specific extensions you may be able to use Project Expressions as follows:

SELECT STR(?name) AS ?StringName
FROM <example.com>
WHERE {
    assign:RJ assign:hasName ?name
}

Basically if the SPARQL implementation you are using supports project expressions you can use any valid SPARQL expression which you could use in a FILTER/ORDER BY as a variable in the SELECT to calculate a value based on the values which are bound in the graph patterns.

Since this feature is still in working draft it's implementation may well be experimental/incomplete in your SPARQL implementation (if it's present at all) and the syntax may vary, for example some systems may require you to put the whole thing in brackets e.g. (STR(?name) AS ?StringName) in order for it to work.

Take a look at the documentation for whichever SPARQL implementation you are using or try asking on the relevant mailing list to find out if this feature is supported.

RobV