You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Anton Feldmann <an...@uni-bielefeld.de> on 2006/04/19 15:08:11 UTC

SentenceHighlighter

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: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Re: SentenceHighlighter

Posted by mark harwood <ma...@yahoo.co.uk>.
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 <an...@uni-bielefeld.de>
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:
> java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail:
> java-dev-help@lucene.apache.org
> 
> 



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

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org