Search in sources :

Example 36 with BreakIterator

use of java.text.BreakIterator in project elasticsearch by elastic.

the class CustomSeparatorBreakIteratorTests 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 37 with BreakIterator

use of java.text.BreakIterator in project elasticsearch by elastic.

the class CustomSeparatorBreakIteratorTests 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 38 with BreakIterator

use of java.text.BreakIterator in project elasticsearch by elastic.

the class CustomSeparatorBreakIteratorTests 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 39 with BreakIterator

use of java.text.BreakIterator in project j2objc by google.

the class JavadocGenerator method printDocComment.

private void printDocComment(Javadoc javadoc) {
    if (javadoc != null) {
        printIndent();
        // Use HeaderDoc doc-comment start, which is compatible with Xcode Quick Help and Doxygen.
        println("/*!");
        List<TagElement> tags = javadoc.getTags();
        for (TagElement tag : tags) {
            if (tag.getTagName() == null) {
                // Description section.
                String description = printTagFragments(tag.getFragments());
                // Extract first sentence from description.
                BreakIterator iterator = BreakIterator.getSentenceInstance(Locale.US);
                iterator.setText(description.toString());
                int start = iterator.first();
                int end = iterator.next();
                if (end != BreakIterator.DONE) {
                    // Print brief tag first, since Quick Help shows it first. This makes the
                    // generated source easier to review.
                    printDocLine(String.format("@brief %s", description.substring(start, end)).trim());
                    String remainder = description.substring(end);
                    if (!remainder.isEmpty()) {
                        printDocLine(remainder);
                    }
                } else {
                    printDocLine(description);
                }
            } else {
                String doc = printTag(tag);
                if (!doc.isEmpty()) {
                    printDocLine(doc);
                }
            }
        }
        printIndent();
        println(" */");
    }
}
Also used : TagElement(com.google.devtools.j2objc.ast.TagElement) BreakIterator(java.text.BreakIterator)

Example 40 with BreakIterator

use of java.text.BreakIterator in project robovm by robovm.

the class BreakIteratorTest method testConcurrentBreakIteratorAccess.

// http://code.google.com/p/android/issues/detail?id=41143
// This code is inherently unsafe and crazy;
// we're just trying to provoke native crashes!
public void testConcurrentBreakIteratorAccess() throws Exception {
    final BreakIterator it = BreakIterator.getCharacterInstance();
    ArrayList<Thread> threads = new ArrayList<Thread>();
    for (int i = 0; i < 10; ++i) {
        Thread t = new Thread(new Runnable() {

            public void run() {
                for (int i = 0; i < 4096; ++i) {
                    it.setText("some example text");
                    for (int index = it.first(); index != BreakIterator.DONE; index = it.next()) {
                    }
                }
            }
        });
        threads.add(t);
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
}
Also used : ArrayList(java.util.ArrayList) 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