[Mulgara-general] Using Lucene from SPARQL
Alex Hall
alexhall at revelytix.com
Thu Aug 12 19:55:39 UTC 2010
On 8/12/2010 1:41 PM, Paul Gearon wrote:
> On Thu, Aug 12, 2010 at 12:49 PM, Giulio Paci <g.paci at cineca.it> wrote:
>
>> Hi to all!
>> I've just started doing some experiments using Lucene with Mulgara, but I
>> only managed to get partial success. My goal is to get both the search
>> results and their score using SPARQL.
>>
>> The following TQL query is working as expected:
>> "select $uri $score from <rmi://my#lucene>
>> where
>> $uri <http://mulgara.org/mulgara#search> $q in <rmi://my#lucene>
>> and $q <http://my/my.owl#hasDescription> 'querystring' in <rmi://my#lucene>
>> and $q <http://mulgara.org/mulgara#score> $score in <rmi://my#lucene>"
>>
>> Nevertheless it is not possible to remove any of the "in <rmi://my#lucene>"
>> or the query won't give any result, even with the default graph set to
>> "<rmi://my#lucene>".
>>
> OK, this surprises me. I would have thought they'd be exactly
> equivalent. I'll have to look at the query plan to find out why
> they're different.
>
I suspect it's an issue in the Lucene symbolic transformation code
(LuceneTransformer.java) -- this only converts a Constraint to a
LuceneConstraint if its model expression is the URI of a Lucene graph.
This holds when the graph URI is set using the TQL "in" keyword, but
when the default graph or FROM graph is used then the constraint model
is the special variable "$_from". The transformer needs to be able to
recognize the case where the constraint model expression is $_from and
the FROM or default graph is a Lucene graph, and this information is not
available from the context at the moment.
>> I'm trying the following SPARQL query without success:
>> "select ?uri ?score
>> from <rmi://my#lucene>
>> where
>> {
>> graph <rmi://my#lucene>
>> {
>> ?uri <http://mulgara.org/mulgara#search> ?q
>> . ?q <http://my/my.owl#hasDescription> 'querystring'
>> . ?q <http://mulgara.org/mulgara#:score> ?score
>> }
>> }"
>>
>> Does anyone knows how can I solve this issue? Am I doing something wrong?
>>
> Despite the fact that this should work already, I think that the exact
> equivalent to the working TQL is more likely to be:
>
> select ?uri ?score
> from <rmi://my#lucene>
> where {
> graph <rmi://my#lucene> {
> ?uri <http://mulgara.org/mulgara#search> ?q } .
> graph <rmi://my#lucene> {
> ?q <http://my/my.owl#hasDescription> 'querystring' } .
> graph <rmi://my#lucene> {
> ?q <http://mulgara.org/mulgara#:score> ?score }
> }
>
> (though the FROM clause should be entirely redundant).
>
Not exactly. The SPARQL GRAPH clause is translated to a ConstraintIn,
whereas the TQL "in" keyword gets translated to a ConstraintImpl with a
constant model expression. So to fully account for this situation, the
transformer would also need to recognize and correctly handle the
ConstraintIn class.
>> The following query is working:
>> "select ?uri
>> from <rmi://my#lucene>
>> where
>> {
>> graph <rmi://my#lucene>
>> {
>> ?uri <http://my/my.owl#hasDescription> 'querystring'
>> }
>> }"
>>
>>
>> Any help is appreciated.
>>
> I'll try and figure it out soon, but it may be a couple of days. Keep
> bugging me about it. :-)
>
This is because the LuceneResolver attempts to account for the $_from
variable when resolving a single contraint (after the expression has
already been transformed). But because it only sees one constraint at a
time, it can't join together multiple constraints, as is required to
query for the score.
Regards,
Alex
More information about the Mulgara-general
mailing list