Jérôme wrote:
Le 29/08/11 19:00, Andy Seaborne a écrit :

Hi,


-------- Original Message --------
Subject: Re: Matching string positions
Date: Thu, 18 Aug 2011 14:54:37 +0100
From: Paolo Castagna <[email protected]>
Reply-To: [email protected]
To: [email protected]

Jérôme wrote:
> Hello,
>
> I am a new Jena/Joseki user and i would like to get matching string
> positions in order to highligth them.
> Queries are LARQ queries.
>
> Here the client side code:
>
>         Query query = QueryFactory.create(queryString) ;
>         QueryExecution qExec = QueryExecutionFactory.sparqlService(url,
> query);
>         ResultSet set = qExec.execSelect();
>         String xml = ResultSetFormatter.asXMLString(set) ;
>         qExec.close();
>
> I probably have to use an other way than the sparqlService method. I
> know that positions are available with Lucene, but how to recover this
> information with the Jena API ?

Hi Jerome,
it is currently not possible to retrieve positions via LARQ.

I do not even know how to imagine doing this (syntactically) in
a SPARQL query, but if you or someone else have an idea on how
this might be possible we can discuss it.
Do you know how jena get the score from Lucene? I think it might be very closed to get
positions...

You can get the Lucene score back using LARQ this way:

 PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>
 SELECT ?doc ?score
 {
   (?lit ?score ) pf:textMatch '+text' .
   ?doc ?p ?lit
 }

As documented on the documentation here:
http://openjena.org/ARQ/lucene-arq.html

All the low level machinery to interact with Lucene happens in:
http://svn.apache.org/repos/asf/incubator/jena/Jena2/LARQ/trunk/src/main/java/org/apache/jena/larq/LuceneSearch.java

The score is just one value, positions are multiple values.

Paolo

> What is the a simple way to do that?

One way to do it could be to use LARQ to perform a first search,
then retrieve the literal value and use Lucene, independently from
Jena, to perform the highlighting you want.

What do you think about this approach?

It's not ideal, I know... but it should be possible and easy.
Yes, it could be a solution.

Jerome


Paolo

>
> Thanks.
>
> Jerome.


Reply via email to