SentenceHighlighter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SentenceHighlighter

anton feldmann
Hi

I am writing a application to find words into a sentence.
I began with the Formatter:


import org.apache.lucene.search.highlight.Formatter;
import org.apache.lucene.search.highlight.TokenGroup;


public class SimpleSentenceFormatter implements Formatter{

        String tag;

        /**
         *Use a String to mark the sentence
         */
        public SimpleSentenceFormatter(String Tag) {
                this.tag = tag;
        }

        /**
         * Default constructor uses "\\.x\\" to mark a Sentence
         */
        public SimpleSentenceFormatter() {
                this.tag = "\\.x\\"; //("\\.x\\") instead DOT
        }

        /* (non-Javadoc)
         * @see
org.apache.lucene.search.highlight.Formatter#highlightTerm(java.lang.String, org.apache.lucene.search.highlight.TokenGroup)
         */
        public String highlightTerm(String originalText, TokenGroup tokenGroup)
{
                StringBuffer returnBuffer;
                if ( tokenGroup.getTotalScore() > 0 ) {
                        returnBuffer = new StringBuffer();
                        returnBuffer.append(tag);
                        returnBuffer.append(originalText);
                        returnBuffer.append(tag);
                        return returnBuffer.toString();
                }
                return originalText;
        }
       
        public String getTag(){
                return tag;
        }

}

Now i am Writing a Highlighter. But I have know i dear how i could
display the howl sentens which includes the querry string. Do some of
you have an Idear?

cheers

anton



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: SentenceHighlighter

mark harwood
If you are wanting to select highlights from a
document where only whole sentences are the fragments
selected you will need to implement a custom
Fragmenter class.

This will need to look for sentence boundaries eg a
"." followed by whitespace only, then a word with an
uppercase first character.
I suspect it should also have a minimum and maximum
sentence length as controls to safeguard against
unusual text.

There is no such Fragmenter implementation at present
but if you create one feel free to contribute it back
:)


Cheers
Mark
p.s. Please mail all future "How do I..." questions to
the java-user list not this java-dev list.




--- Anton Feldmann <[hidden email]>
wrote:

> Hi
>
> I am writing a application to find words into a
> sentence.
> I began with the Formatter:
>
>
> import org.apache.lucene.search.highlight.Formatter;
> import
> org.apache.lucene.search.highlight.TokenGroup;
>
>
> public class SimpleSentenceFormatter implements
> Formatter{
>
> String tag;
>
> /**
> *Use a String to mark the sentence
> */
> public SimpleSentenceFormatter(String Tag) {
> this.tag = tag;
> }
>
> /**
> * Default constructor uses "\\.x\\" to mark a
> Sentence
> */
> public SimpleSentenceFormatter() {
> this.tag = "\\.x\\"; //("\\.x\\") instead DOT
> }
>
> /* (non-Javadoc)
> * @see
>
org.apache.lucene.search.highlight.Formatter#highlightTerm(java.lang.String,

> org.apache.lucene.search.highlight.TokenGroup)
> */
> public String highlightTerm(String originalText,
> TokenGroup tokenGroup)
> {
> StringBuffer returnBuffer;
> if ( tokenGroup.getTotalScore() > 0 ) {
> returnBuffer = new StringBuffer();
> returnBuffer.append(tag);
> returnBuffer.append(originalText);
> returnBuffer.append(tag);
> return returnBuffer.toString();
> }
> return originalText;
> }
>
> public String getTag(){
> return tag;
> }
>
> }
>
> Now i am Writing a Highlighter. But I have know i
> dear how i could
> display the howl sentens which includes the querry
> string. Do some of
> you have an Idear?
>
> cheers
>
> anton
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [hidden email]
> For additional commands, e-mail:
> [hidden email]
>
>



               
___________________________________________________________
NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]