Package com.optimaize.langdetect.text
Class TextObject
- java.lang.Object
-
- com.optimaize.langdetect.text.TextObject
-
- All Implemented Interfaces:
java.lang.Appendable
,java.lang.CharSequence
@Beta public class TextObject extends java.lang.Object implements java.lang.CharSequence, java.lang.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.
-
-
Field Summary
Fields Modifier and Type Field Description private int
maxTextLength
private @NotNull java.lang.StringBuilder
stringBuilder
private @NotNull TextFilter
textFilter
-
Constructor Summary
Constructors Constructor Description TextObject(@NotNull TextFilter textFilter, int maxTextLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Appendable
append(char c)
TextObject
append(java.io.Reader reader)
Append the target text for language detection.TextObject
append(java.lang.CharSequence text)
Append the target text for language detection.java.lang.Appendable
append(java.lang.CharSequence csq, int start, int end)
char
charAt(int index)
int
length()
java.lang.CharSequence
subSequence(int start, int end)
@NotNull java.lang.String
toString()
-
-
-
Field Detail
-
textFilter
@NotNull private final @NotNull TextFilter textFilter
-
stringBuilder
@NotNull private final @NotNull java.lang.StringBuilder stringBuilder
-
maxTextLength
private final int maxTextLength
-
-
Constructor Detail
-
TextObject
public TextObject(@NotNull @NotNull TextFilter textFilter, int maxTextLength)
- Parameters:
maxTextLength
- 0 for no limit
-
-
Method Detail
-
append
public TextObject append(java.io.Reader reader) throws java.io.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:
java.io.IOException
- Can't read the reader.
-
append
public TextObject append(java.lang.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 interfacejava.lang.Appendable
- Parameters:
text
- the target text to append
-
append
public java.lang.Appendable append(java.lang.CharSequence csq, int start, int end) throws java.io.IOException
- Specified by:
append
in interfacejava.lang.Appendable
- Throws:
java.io.IOException
-
append
public java.lang.Appendable append(char c) throws java.io.IOException
- Specified by:
append
in interfacejava.lang.Appendable
- Throws:
java.io.IOException
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfacejava.lang.CharSequence
-
toString
@NotNull public @NotNull java.lang.String toString()
- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
-
-