Search in sources :

Example 56 with BreakIterator

use of java.text.BreakIterator in project lucene-solr by apache.

the class TestCustomSeparatorBreakIterator method testSliceEnd.

public void testSliceEnd() throws Exception {
    BreakIterator expected = BreakIterator.getSentenceInstance(Locale.ROOT);
    BreakIterator actual = new CustomSeparatorBreakIterator(randomSeparator());
    assertSameBreaks("a000", 0, 1, expected, actual);
    assertSameBreaks("ab000", 0, 1, expected, actual);
    assertSameBreaks("abc000", 0, 1, expected, actual);
    assertSameBreaks("000", 0, 0, expected, actual);
}
Also used : BreakIterator(java.text.BreakIterator)

Example 57 with BreakIterator

use of java.text.BreakIterator in project lucene-solr by apache.

the class TestCustomSeparatorBreakIterator method testSliceStart.

public void testSliceStart() throws Exception {
    BreakIterator expected = BreakIterator.getSentenceInstance(Locale.ROOT);
    BreakIterator actual = new CustomSeparatorBreakIterator(randomSeparator());
    assertSameBreaks("000a", 3, 1, expected, actual);
    assertSameBreaks("000ab", 3, 2, expected, actual);
    assertSameBreaks("000abc", 3, 3, expected, actual);
    assertSameBreaks("000", 3, 0, expected, actual);
}
Also used : BreakIterator(java.text.BreakIterator)

Example 58 with BreakIterator

use of java.text.BreakIterator in project lucene-solr by apache.

the class TestCustomSeparatorBreakIterator method testFirstPosition.

/** the current position must be ignored, initial position is always first() */
public void testFirstPosition() throws Exception {
    BreakIterator expected = BreakIterator.getSentenceInstance(Locale.ROOT);
    BreakIterator actual = new CustomSeparatorBreakIterator(randomSeparator());
    assertSameBreaks("000ab000", 3, 2, 4, expected, actual);
}
Also used : BreakIterator(java.text.BreakIterator)

Example 59 with BreakIterator

use of java.text.BreakIterator in project beast-mcmc by beast-dev.

the class TextUtil method wrapText.

// auto wrap string by given a JComp and the length limit 
public static String wrapText(String someText, JComponent jComp, int lenLimit) {
    BreakIterator iterator = BreakIterator.getWordInstance(Locale.getDefault());
    iterator.setText(someText);
    int start = iterator.first();
    int end = iterator.next();
    FontMetrics fm = jComp.getFontMetrics(jComp.getFont());
    String s = "<html>";
    int len = 0;
    while (end != BreakIterator.DONE) {
        String word = someText.substring(start, end);
        if (len + fm.stringWidth(word) > lenLimit) {
            s += "<br> ";
            len = fm.stringWidth(word);
        } else {
            len += fm.stringWidth(word);
        }
        s += word;
        start = end;
        end = iterator.next();
    }
    s += "</html>";
    return s;
}
Also used : BreakIterator(java.text.BreakIterator)

Aggregations

BreakIterator (java.text.BreakIterator)59 ArrayList (java.util.ArrayList)10 Locale (java.util.Locale)6 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)3 BytesRef (org.apache.lucene.util.BytesRef)3 Snippet (org.apache.lucene.search.highlight.Snippet)2 Intent (android.content.Intent)1 TagElement (com.google.devtools.j2objc.ast.TagElement)1 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)1 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 PriorityQueue (java.util.PriorityQueue)1 JComponent (javax.swing.JComponent)1 Text (org.apache.hadoop.io.Text)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Encoder (org.apache.lucene.search.highlight.Encoder)1 CustomSeparatorBreakIterator (org.apache.lucene.search.postingshighlight.CustomSeparatorBreakIterator)1 CustomPassageFormatter (org.apache.lucene.search.uhighlight.CustomPassageFormatter)1