[Mulgara-general] Problem using $score with LuceneModel.

Frederic Bergeron FBergeron at rocketmail.com
Thu Nov 15 13:43:22 UTC 2012


Oops, I forgot to post the reply on the mailing-list.

I've added some additional info at the end of the message.


________________________________
 From: Paul Gearon <gearon at ieee.org>
To: Frederic Bergeron <FBergeron at rocketmail.com>; Mulgara General <mulgara-general at mulgara.org> 
Sent: Wednesday, November 14, 2012 1:23 AM
Subject: Re: [Mulgara-general] Problem using $score with LuceneModel.
 

Hi,


On Tue, Nov 13, 2012 at 10:41 AM, Frederic Bergeron <FBergeron at rocketmail.com> wrote:

Hi,
>
>I am having a hard time trying to use the special variable $score with a LuceneModel.  Hopefully someone can help me.
>

It's been a while since I've used a Lucene model, but I thought that it was a special predicate and not a special variable? If I'm wrong, then let me know, and I'll look at the source code to figure it out (I haven't looked in the Lucene code for a long time).
 
That's correct.  The old documentation 
mentions the $score variable.  But the working example that I have found rather uses a reserved predicate.


Originally, I had a SPARQL request like this: 
>
>PREFIX dct: <http://purl.org/dc/terms/>
>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>PREFIX stuff: <http://mystuff.com/reference#>
>PREFIX server: <#>
>
>select DISTINCT ?s
>where {
>    ?s rdf:type <stuff:LearningObject> .
>    {
>        graph server:mylucene {
>            ?s dct:title "myKeyword"
>        }
>    }
>    UNION
>   
 {
>        graph server:mylucene {
>            ?s dct:description "myKeyword"
>        }
>    }
>}
>
>This works fine AFAIK.
>
>Now, I would like to do the same request but sort the results according to Lucene's ranking.  To achieve this, the documentation mentions the $score special variable.  Unless I have overlooked it, the documentation doesn't explain how to use it.
>
>I found an example that works here though:
>
>http://lists.mulgara.org/pipermail/mulgara-general/2010-August/001139.html
>
>According to this exchange on the mailing-list, if I understand well, I must use TQL instead of SPARQL to use $score so I started to convert my previous SPARQL query to TQL like follow:
>

Ah, I'd forgotten about this (and no one reminded me). Yes, I need to fix this so that it's more accessible from SPARQL (I think you can still get to the Lucene graph by using a FROM clause). However, since I need to get moving and implement SPARQL 1.1 I should get it done in there.
 
select $s $score from <rmi://localhost/comete#main>
>where $s
 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://mystuff.com/reference#LearningObject> in <rmi://localhost/comete#main>
>and $s <http://mulgara.org/mulgara#search> $q in <rmi://localhost/comete#mylucene> 
>and $q <http://purl.org/dc/terms/description> 'myKeyword' in <rmi://localhost/comete#mylucene>
>and $q <http://mulgara.org/mulgara#score> $score in <rmi://localhost/comete#mylucene>
>
>This works fine.
>
>Now, I would like to add another test on another predicate (like in my original SPARQL query in the first UNION clause).
>
>I tried a few things and got the following error:
>
>Error executing command. Reason: org.mulgara.query.QueryException: Query failed: Only one predicate supported per search: pred1=http://purl.org/dc/terms/title, pred2=http://purl.org/dc/terms/description
>
>Is it possible to use $score with a test involving more than one predicate on the
 LuceneModel?  How can I do that using TQL?
>
 
I thought that it was. Did you try to re-use the $score variable? Can I see the query please? 


I've tried many things but nothing worked so far.  If I remember correctly, the following query gave the 
previously mentioned QueryException:

select $s $score from <rmi://localhost/comete#main>
where $s
 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://mystuff.com/reference#LearningObject> in 
<rmi://localhost/comete#main>
and $s <http://mulgara.org/mulgara#search> $q in <rmi://localhost/comete#mylucene> 
and $q <http://purl.org/dc/terms/title> 'myKeyword' in <rmi://localhost/comete#mylucene>
and $q <http://purl.org/dc/terms/description> 'myKeyword' in <rmi://localhost/comete#mylucene>
and $q <http://mulgara.org/mulgara#score> $score in <rmi://localhost/comete#mylucene>

I also tried request like this:

select $s $score from <rmi://localhost/comete#main>
where $s
 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://mystuff.com/reference#LearningObject> in 
<rmi://localhost/comete#main>
and $s <http://mulgara.org/mulgara#search> $q in <rmi://localhost/comete#mylucene> 
and ( $q <http://purl.org/dc/terms/title> 'myKeyword' in <rmi://localhost/comete#mylucene>
or $q <http://purl.org/dc/terms/description> 'myKeyword' in <rmi://localhost/comete#mylucene> )
and $q <http://mulgara.org/mulgara#score> $score in <rmi://localhost/comete#mylucene>

But it doesn't parse.  I wonder if the "in <clause>" are interfering or not.


Regards,
Paul
After looking at the code, I don't think that it's possible to use the score predicate with a condition involving more than predicate.  

The method find() in FullTextStringIndex takes only one set of subject, predicate, and object values and produces Lucene queries similar to: +predicate:http://purl.org/dc/terms/title^0.0 +stemmedliteral:myKeyword.  Even when using SPARQL, I can see that several queries with only one predicate are issued separately.  Using OR with TQL also produces the same thing.  

What I want would be a Lucene query that would look like: (+predicate:http://purl.org/dc/terms/title^0.0 +stemmedliteral:myKeyword) OR (+predicate:http://purl.org/dc/terms/description^0.0 +stemmedliteral:myKeyword) so that the Lucene ranking applies to both search criterias at the same time.  

I might misunderstand the code though.  What do you think?  Is what I'm saying makes sense or not?

Frederic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mulgara.org/pipermail/mulgara-general/attachments/20121115/ab4d9240/attachment.html>


More information about the Mulgara-general mailing list