Pregunta

I'm working with dotNetRDF and was trying to execute a SPARQL query

PREFIX rdfh: <http://lod2.eu/schemas/rdfh#>

SELECT * WHERE{ ?lo_orderdate <http://lod2.eu/schemas/rdfh#d_year> ?d_year .
FILTER(?d_year = 1993) }

but got this error when trying to execute it against Sesame:

Unable to Parse a SPARQL Result Set since a <literal> element has too many Attributes, only 1 of 'xml:lang' or 'datatype' may be specified!
StackTrace:
   at VDS.RDF.Parsing.SparqlXmlParser.ParseValue(SparqlXmlParserContext context)
   at VDS.RDF.Parsing.SparqlXmlParser.Parse(SparqlXmlParserContext context)
   at VDS.RDF.Parsing.SparqlXmlParser.Load(ISparqlResultsHandler handler, TextReader input)
   at VDS.RDF.Parsing.SparqlXmlParser.Load(ISparqlResultsHandler handler, StreamReader input)
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultSet(ISparqlResultsHandler handler, String sparqlQuery)
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultSet(String sparqlQuery)
   at VDS.RDF.Query.RemoteQueryProcessor.ProcessQuery(SparqlQuery query)

The sample of the TTL file looks as follows:

@prefix xsd:  ... .
@prefix rdfh: ... .
@prefix rdfh-inst: ... . # cannot put real values - don't have enough reputation
rdfh-inst:date_19920101 a rdfh:date ;
rdfh:d_datekey 19920101 ;
rdfh:d_date "January 1, 1992" ;
rdfh:d_dayofweek "Thursday" ;
rdfh:d_month "January" ;
rdfh:d_year 1992 ;
rdfh:d_yearmonthnum 199201 ;
rdfh:d_yearmonth "Jan1992" ;
rdfh:d_daynuminweek 5 ;
rdfh:d_daynuminmonth 1 ;
rdfh:d_daynuminyear 1 ;
rdfh:d_monthnuminyear 1 ;
rdfh:d_weeknuminyear 1 ;
rdfh:d_sellingseason "Winter" ;
rdfh:d_lastdayinweekfl "0" ;
rdfh:d_lastdayinmonthfl "1" ;
rdfh:d_holidayfl "1" ;
rdfh:d_weekdayfl "1" .

rdfh-inst:date_19920102 a rdfh:date ;
rdfh:d_datekey 19920102 ;
rdfh:d_date "January 2, 1992" ;
rdfh:d_dayofweek "Friday" ;
rdfh:d_month "January" ;
rdfh:d_year 1992 ;
rdfh:d_yearmonthnum 199201 ;
rdfh:d_yearmonth "Jan1992" ;
rdfh:d_daynuminweek 6 ;
rdfh:d_daynuminmonth 2 ;
rdfh:d_daynuminyear 2 ;
rdfh:d_monthnuminyear 1 ;
rdfh:d_weeknuminyear 1 ;
rdfh:d_sellingseason "Winter" ;
rdfh:d_lastdayinweekfl "0" ;
rdfh:d_lastdayinmonthfl "1" ;
rdfh:d_holidayfl "0" ;
rdfh:d_weekdayfl "1" .

I guess i'm receiving this error because Sesame is returning two attributes and dotNetRDF expects only one

<head>
    <variable name='lo_orderdate'/>
    <variable name='d_year'/>
    <link href='info'/>
</head>
<results>
    <result>
        <binding name='d_year'>
            <literal q:qname='xsd:integer' datatype='http://www.w3.org/2001/XMLSchema#integer'>1993</literal>
        </binding>
        <binding name='lo_orderdate'>
            <uri q:qname='rdfh-inst:date_19930101'>http://lod2.eu/schemas/rdfh-inst#date_19930101</uri>
        </binding>
    </result>
    <result>
        <binding name='d_year'>
            <literal q:qname='xsd:integer' datatype='http://www.w3.org/2001/XMLSchema#integer'>1993</literal>
        </binding>
        <binding name='lo_orderdate'>
            <uri q:qname='rdfh-inst:date_19930102'>http://lod2.eu/schemas/rdfh-inst#date_19930102</uri>
        </binding>
    </result>
    </results>

I'm not receiving this error when using OpenVirtuoso

¿Fue útil?

Solución

The extra attribute q:qname is a Sesame-specific extension of the standard format. It is a configuration setting that is supported by Sesame's SPARQLXMLWriter but is not enabled by default.

It appears, however, that the Workbench client application enables this feature and adds these additional attributes when exporting query results. So I suspect that you are getting your query result by doing the query in the Workbench and then exporting the result to file. This is a bug in the Workbench application and has now been reported as such (see SES-2059).

A workaround is to instead query your Sesame server from a different tool, bypassing the Workbench's problem. You can use something like curl, or you can even do this from any web browser directly if you want.

For example, if your SPARQL query was this:

SELECT * WHERE {?S ?P ?O } LIMIT 100

and you have a Sesame server running on, for example, localhost:8080, and the repository you're querying is called myRepository, you can get the result from your Sesame server directly by entering this URL into your browser:

http://localhost:8080/openrdf-sesame/repositories/myRepository?query=SELECT * WHERE {?S ?P ?O } LIMIT 100

Another workaround would be to appeal to the dotNetRDF developers to relax their parser's strictness a bit :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top