Package com.optimaize.langdetect.text
Class TextObject
- java.lang.Object
-
- com.optimaize.langdetect.text.TextObject
-
- All Implemented Interfaces:
Appendable
,CharSequence
@Beta public class TextObject extends Object implements CharSequence, Appendable
A convenient text object implementing CharSequence and Appendable. This is an ideal object to use for learning text to createLanguageProfile
s, as well as to pass it in toLanguageDetector.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 thetextFilter
. Equals/hashCode are not implemented as of now on purpose. You may want to call toString() and compare that.- Author:
- Fabian Kessler
-
-
Constructor Summary
Constructors Constructor Description TextObject(@NotNull TextFilter textFilter, int maxTextLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Appendable
append(char c)
TextObject
append(Reader reader)
Append the target text for language detection.TextObject
append(CharSequence text)
Append the target text for language detection.Appendable
append(CharSequence csq, int start, int end)
char
charAt(int index)
int
length()
CharSequence
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
-
-
-
-
Constructor Detail
-
TextObject
public TextObject(@NotNull @NotNull TextFilter textFilter, int maxTextLength)
- Parameters:
maxTextLength
- 0 for no limit
-
-
Method Detail
-
append
public TextObject append(Reader reader) throws IOException
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
public TextObject append(CharSequence text)
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
public Appendable append(CharSequence csq, int start, int end) throws IOException
- Specified by:
append
in interfaceAppendable
- Throws:
IOException
-
append
public Appendable append(char c) throws IOException
- 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
public CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfaceCharSequence
-
toString
@NotNull public @NotNull String toString()
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
-