jena-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stuart Kenny <>
Subject Re: ARQ query on DataSources
Date Mon, 07 Feb 2011 18:14:44 GMT
Hi, sorry did not see this reply until now. I'm not sure I can send an
example as such. I've switched to trying SDB in the hopes that would
fix the problem, but I'm still having the same issue. I can only query
single models, not Datasets. I create the SDB store like this:

Store images = SDBFactory.connectStore("/tmp/sdb-mysql-innodb.ttl");

Models are stored using:

Model sdbModel = SDBFactory.connectNamedModel(images, iri);

And then I try to query:
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qe = QueryExecutionFactory.create(query,
ResultSet results = qe.execSelect();

If I query a single model taken from the Dataset, results are
returned. If I try to query the Dataset, I get nothing returned.

I'm using Arq 2.8.7, Jena 2.6.4, and sdb 1.3.3.

The possible cause is that the models are being read in from a Restlet

public Representation acceptItem(Representation entity)
   ModelMaker mk = ModelFactory.createMemModelMaker();
   Model rdf = mk.createDefaultModel();, "");

Sorry, that's probably not enough to go on. Is there anything special
that needs to be done to a Dataset so that it can be queried?

Reading the models out of the Dataset and then copying into a new
still works. But I don't see why this would be necessary.



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?


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 =;
>     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.

View raw message