Search in sources :

Example 86 with BreakIterator

use of java.text.BreakIterator in project RichTextFX by FXMisc.

the class NavigationActions method wordBreaksForwards.

/**
 * Skips n number of word boundaries forward.
 */
default void wordBreaksForwards(int n, SelectionPolicy selectionPolicy) {
    if (getLength() == 0) {
        return;
    }
    BreakIterator wordBreakIterator = BreakIterator.getWordInstance();
    wordBreakIterator.setText(getText());
    wordBreakIterator.following(getCaretPosition());
    for (int i = 1; i < n; i++) {
        wordBreakIterator.next();
    }
    moveTo(wordBreakIterator.current(), selectionPolicy);
}
Also used : BreakIterator(java.text.BreakIterator)

Example 87 with BreakIterator

use of java.text.BreakIterator in project RichTextFX by FXMisc.

the class NavigationActions method wordBreaksBackwards.

/**
 * Skips n number of word boundaries backwards.
 */
default void wordBreaksBackwards(int n, SelectionPolicy selectionPolicy) {
    if (getLength() == 0) {
        return;
    }
    BreakIterator wordBreakIterator = BreakIterator.getWordInstance();
    wordBreakIterator.setText(getText());
    wordBreakIterator.preceding(getCaretPosition());
    for (int i = 1; i < n; i++) {
        wordBreakIterator.previous();
    }
    moveTo(wordBreakIterator.current(), selectionPolicy);
}
Also used : BreakIterator(java.text.BreakIterator)

Example 88 with BreakIterator

use of java.text.BreakIterator in project RichTextFX by FXMisc.

the class SelectionImpl method selectWord.

@Override
public void selectWord(int wordPositionInArea) {
    if (area.getLength() == 0) {
        return;
    }
    BreakIterator breakIterator = BreakIterator.getWordInstance();
    breakIterator.setText(area.getText());
    breakIterator.preceding(wordPositionInArea);
    breakIterator.next();
    int wordStart = breakIterator.current();
    breakIterator.following(wordPositionInArea);
    breakIterator.next();
    int wordEnd = breakIterator.current();
    selectRange(wordStart, wordEnd);
}
Also used : BreakIterator(java.text.BreakIterator)

Example 89 with BreakIterator

use of java.text.BreakIterator in project hive by apache.

the class GenericUDFSentences method evaluate.

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    assert (arguments.length >= 1 && arguments.length <= 3);
    if (arguments[0].get() == null) {
        return null;
    }
    // if there is more than 1 argument specified, a different natural language
    // locale is being specified
    Locale locale = null;
    if (arguments.length > 1 && arguments[1].get() != null) {
        Text language = (Text) converters[1].convert(arguments[1].get());
        Text country = null;
        if (arguments.length > 2 && arguments[2].get() != null) {
            country = (Text) converters[2].convert(arguments[2].get());
        }
        if (country != null) {
            locale = new Locale(language.toString().toLowerCase(), country.toString().toUpperCase());
        } else {
            locale = new Locale(language.toString().toLowerCase());
        }
    } else {
        locale = Locale.getDefault();
    }
    // get the input and prepare the output
    Text chunk = (Text) converters[0].convert(arguments[0].get());
    String text = chunk.toString();
    ArrayList<ArrayList<Text>> result = new ArrayList<ArrayList<Text>>();
    // Parse out sentences using Java's text-handling API
    BreakIterator bi = BreakIterator.getSentenceInstance(locale);
    bi.setText(text);
    int idx = 0;
    while (bi.next() != BreakIterator.DONE) {
        String sentence = text.substring(idx, bi.current());
        idx = bi.current();
        result.add(new ArrayList<Text>());
        // Parse out words in the sentence
        BreakIterator wi = BreakIterator.getWordInstance(locale);
        wi.setText(sentence);
        int widx = 0;
        ArrayList<Text> sent_array = result.get(result.size() - 1);
        while (wi.next() != BreakIterator.DONE) {
            String word = sentence.substring(widx, wi.current());
            widx = wi.current();
            if (Character.isLetterOrDigit(word.charAt(0))) {
                sent_array.add(new Text(word));
            }
        }
    }
    return result;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) BreakIterator(java.text.BreakIterator)

Example 90 with BreakIterator

use of java.text.BreakIterator in project spring-boot by spring-projects.

the class SentenceExtractor method getFirstSentence.

String getFirstSentence(String text) {
    if (text == null) {
        return null;
    }
    int dot = text.indexOf('.');
    if (dot != -1) {
        BreakIterator breakIterator = BreakIterator.getSentenceInstance(Locale.US);
        breakIterator.setText(text);
        String sentence = text.substring(breakIterator.first(), breakIterator.next());
        return removeSpaceBetweenLine(sentence.trim());
    } else {
        String[] lines = text.split(System.lineSeparator());
        return lines[0].trim();
    }
}
Also used : BreakIterator(java.text.BreakIterator)

Aggregations

BreakIterator (java.text.BreakIterator)120 ArrayList (java.util.ArrayList)17 Locale (java.util.Locale)9 Paint (android.graphics.Paint)4 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)3 BytesRef (org.apache.lucene.util.BytesRef)3 SuppressLint (android.annotation.SuppressLint)2 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)2 Collection (java.util.Collection)2 BadLocationException (javax.swing.text.BadLocationException)2 Document (javax.swing.text.Document)2 Element (javax.swing.text.Element)2 Segment (javax.swing.text.Segment)2 Snippet (org.apache.lucene.search.highlight.Snippet)2 Intent (android.content.Intent)1 RectF (android.graphics.RectF)1 TextPaint (android.text.TextPaint)1 TagElement (com.google.devtools.j2objc.ast.TagElement)1 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)1 AbstractNLPDecoder (edu.emory.mathcs.nlp.decode.AbstractNLPDecoder)1