jena-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stuart Kenny <kenny...@gmail.com>
Subject ARQ query on DataSources
Date Wed, 02 Feb 2011 16:31:28 GMT
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