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);
}
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);
}
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);
}
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;
}
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();
}
}
Aggregations