Andy,

This is my method to display query results to a user that can select display 
format:



    public void print(String format, OutputStream out, ResultSet results){
        if(format==null || "".equals(format)){
            ResultSetFormatter.out(out, results);
        }else if(ARG_OUTPUT_FORMAT_JSON.equalsIgnoreCase(format)){
            ResultSetFormatter.output(out, results, ResultSetFormat.syntaxJSON);
        }else if(ARG_OUTPUT_FORMAT_XML.equalsIgnoreCase(format)){
            ResultSetFormatter.output(out, results, ResultSetFormat.syntaxXML);
        }else if(ARG_OUTPUT_FORMAT_CSV.equalsIgnoreCase(format)){
            ResultSetFormatter.output(out, results, ResultSetFormat.syntaxCSV);
        }else if(ARG_OUTPUT_FORMAT_RDF.equalsIgnoreCase(format)){
            ResultSetFormatter.output(out, results, 
ResultSetFormat.syntaxRDF_XML);
        }else if(ARG_OUTPUT_FORMAT_N3.equalsIgnoreCase(format)){
            ResultSetFormatter.output(out, results, 
ResultSetFormat.syntaxRDF_N3);
            //results.getResourceModel().write(out, "N-TRIPLE");
        }else if(ARG_OUTPUT_FORMAT_TURTLE.equalsIgnoreCase(format)){
            ResultSetFormatter.output(out, results, 
ResultSetFormat.syntaxRDF_TURTLE);
            //results.getResourceModel().write(out, "TURTLE");
        }else{
            ResultSetFormatter.output(out, results, ResultSetFormat.syntaxText);
        }
    }


It's quite simple, nothing fancy. 


Milorad


----- Original Message -----
> From: Andy Seaborne <[email protected]>
> To: [email protected]
> Cc: 
> Sent: Wednesday, February 15, 2012 2:03 PM
> Subject: Re: namespaces in sparql results
> 
> On 15/02/12 11:57, Milorad Tosic wrote:
>>  Andy,
>> 
>>  Yes, results are ResultSet. What you described about
>>  ResultSetFormatter.output is exactly what I noticed, but couldn't
>>  find it in any documentation, so I concluded that I did something
>>  wrong. Thanks for the explanation.
>> 
>>  Prefixes only matter the presentation style and are not related to
>>  resource identity IRI/URI etc. However, it would be more convenient
>>  for a human user to watch query results presented without full URI
>>  names. In fact, my personal choice would be turtle format with
>>  prefixes instead of full URI names.
>> 
>> 
>>  Are you suggesting that if I set prefixes explicitly in the Model
>>  containing results before I try to do
>>  results.getResourceModel().write(out, "TURTLE") it would print 
> turtle
>>  format with prefixes instead of full URL names?
>> 
>>  Thanks, Milorad
> 
> Hi Milorad,
> 
> Results.getResourceModel() does not contain the results of the query. 
> In some cases it's undefined, sometimes its empty, sometimes it is the 
> data queried.
> 
> If you want the results as RDF (non-standard format) you need to call 
> outputAsRDF.  That's a model and you can set it's prefixes.
> 
> If you want to process a result set, then try out the text format 
> output, you'll find it does try to use prefixes where available.  It 
> uses FmtUtils.stringForRDFNode to format the result set items.
> 
> A complete, minimal example of what you're trying to do would be helpful.
> 
>     Andy
>

Reply via email to