Package com.optimaize.langdetect.text
Class TextObject
java.lang.Object
com.optimaize.langdetect.text.TextObject
- All Implemented Interfaces:
Appendable
,CharSequence
A convenient text object implementing CharSequence and Appendable.
This is an ideal object to use for learning text to create
LanguageProfile
s,
as well as to pass it in to LanguageDetector.detect(java.lang.CharSequence)
.
To get one, use a TextObjectFactory (through a TextObjectFactoryBuilder).
Example use:
//create the factory once:
TextObjectFactory textObjectFactory = new TextObjectFactoryBuilder()
.withTextFilter(UrlTextFilter.getInstance())
.build();
//then create as many text objects as you like:
TextObject inputText = textObjectFactory.create().append("deutsche Text").append(" ").append("blah blah");
All append() methods go through the textFilter
.
Equals/hashCode are not implemented as of now on purpose. You may want to call toString() and compare that.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
private final @NotNull StringBuilder
private final @NotNull TextFilter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) Append the target text for language detection.append
(CharSequence text) Append the target text for language detection.append
(CharSequence csq, int start, int end) char
charAt
(int index) int
length()
subSequence
(int start, int end) @NotNull String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
textFilter
-
stringBuilder
-
maxTextLength
private final int maxTextLength
-
-
Constructor Details
-
TextObject
- Parameters:
maxTextLength
- 0 for no limit
-
-
Method Details
-
append
Append the target text for language detection. This method read the text from specified input reader. If the total size of target text exceeds the limit size, the rest is ignored.- Parameters:
reader
- the input reader (BufferedReader as usual)- Throws:
IOException
- Can't read the reader.
-
append
Append the target text for language detection. If the total size of target text exceeds the limit size , the rest is cut down.- Specified by:
append
in interfaceAppendable
- Parameters:
text
- the target text to append
-
append
- Specified by:
append
in interfaceAppendable
- Throws:
IOException
-
append
- Specified by:
append
in interfaceAppendable
- Throws:
IOException
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAt
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-