Class 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 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.
    • 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()  
      • 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
    • 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 interface java.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 interface java.lang.Appendable
        Throws:
        java.io.IOException
      • append

        public java.lang.Appendable append​(char c)
                                    throws java.io.IOException
        Specified by:
        append in interface java.lang.Appendable
        Throws:
        java.io.IOException
      • length

        public int length()
        Specified by:
        length in interface java.lang.CharSequence
      • charAt

        public char charAt​(int index)
        Specified by:
        charAt in interface java.lang.CharSequence
      • subSequence

        public java.lang.CharSequence subSequence​(int start,
                                                  int end)
        Specified by:
        subSequence in interface java.lang.CharSequence
      • toString

        @NotNull
        public @NotNull java.lang.String toString()
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object