jena-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Seaborne <andy.seabo...@epimorphics.com>
Subject Re: ARQ query on DataSources
Date Wed, 02 Feb 2011 20:03:42 GMT
Stuart,

I can't see what might be going wrong from your code - could you show 
how the DataSource was created in the first place and how data got into 
it?  Ideally, a complete, minimal example that I can run at my end. 
(and the version of software would also be good).

What is quite odd is that:

 >     images.addNamedModel(id, mk.createDefaultModel().read(new
 >        ByteArrayInputStream(bytes.toString().getBytes()),""));
 >     images.addNamedModel(id, image);

which adds the data twice once as a new model and once as the original 
data, in fact replaces the new with the original.  addNamedModel is 
replace if the name is already in use.

What is the query?

	Andy

On 02/02/11 16:31, Stuart Kenny wrote:
> Hi, I've been stuck trying to query a DataSource for the last few
> days. The DataSource is being used as a store of models. One class
> adds Models to the DataSource using addNamedModel, and a separate
> class is meant to answer queries on this DataSource. When I try to
> execute a query however I get no results:
>
>
> Query query = QueryFactory.create(queryString);
> QueryExecution qe = QueryExecutionFactory.create(query, getImages());
> ResultSet results = qe.execSelect();
>
> where getImages() returns the DataSource being used as a Model store.
>
> Crazily if I create a new DataSource and then iterate through the
> models, writing them out and then reading them back in, the query
> works on this new DataSource:
>
> ModelMaker mk = ModelFactory.createMemModelMaker();
> DataSource images = DatasetFactory.create(mk.createDefaultModel());
>
> for ( Iterator<String>  imagesIter = getImages().listNames();
> imagesIter.hasNext(); ){
>     String id = imagesIter.next();
>     Model image = getImages().getNamedModel(id);
>     ByteArrayOutputStream bytes = new ByteArrayOutputStream();
>     BufferedOutputStream out = new BufferedOutputStream(bytes);
>     image.getWriter().write(image, out, "");
>     images.addNamedModel(id, mk.createDefaultModel().read(new
>        ByteArrayInputStream(bytes.toString().getBytes()),""));
>     images.addNamedModel(id, image);
> }
>
> Query query = QueryFactory.create(queryString);
> QueryExecution qe = QueryExecutionFactory.create(query, images);
> ResultSet results = qe.execSelect();
>
> Just adding the models isn't enough, I have to write and read to new
> Models to get it to work!
>
> I can't really write all the models out and then re-read them to get a
> query to succeed. Presumably using a DataSource in this way is
> incorrect. I'm new to this so I'm obviously doing something
> fundamentally wrong.
>
> Would be very grateful for any help.
>
> Thanks.

Mime
View raw message