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
LanguageProfiles,
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 intprivate final @NotNull StringBuilderprivate 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) charcharAt(int index) intlength()subSequence(int start, int end) @NotNull StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:
appendin interfaceAppendable- Parameters:
text- the target text to append
-
append
- Specified by:
appendin interfaceAppendable- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Throws:
IOException
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-