src/main/java/eu/digitisation/ngram/NgramModel.java
public void addText(InputStream is) {
        try {
            BufferedReader reader
                    = new BufferedReader(new InputStreamReader(is));
            String context = String.valueOf(BOS);

            while (reader.ready()) {
                String line = StringNormalizer.reduceWS(reader.readLine());
                if (!line.isEmpty()) {
                    String input
                            = (context.charAt(0) == BOS)
                            ? line
                            : " " + line;
                    addSubstrings(context, input);
                    if (input.length() >= order) {
                        context = input.substring(input.length() - order + 1);
                    } else {
                        String s = context + input;
                        context = s.substring(Math.max(0, s.length() - order + 1));
                    }
                }
            }
            addSubstrings(context, String.valueOf(EOS));
        } catch (FileNotFoundException ex) {
            Messages.severe(NgramModel.class.getName() + ": " + ex);
        } catch (IOException ex) {
            Messages.severe(NgramModel.class.getName() + ": " + ex);
        }
    }
/**
     * Add all the content in a text file
     *
     * @param is the input stream with text content
     */
Add all the content in a text file
@param is the input stream with text content
Add all the content in a text file @param is the input stream with text content
public void addText(InputStream is) {
        try {
            BufferedReader reader
                    = new BufferedReader(new InputStreamReader(is));
            String context = String.valueOf(BOS);
            while (reader.ready()) {
                String line = StringNormalizer.reduceWS(reader.readLine());
                if (!line.isEmpty()) {
                    String input
                            = (context.charAt(0) == BOS)
                            ? line
                            : " " + line;
                    addSubstrings(context, input);
                    if (input.length() >= order) {
                        context = input.substring(input.length() - order + 1);
                    } else {
                        String s = context + input;
                        context = s.substring(Math.max(0, s.length() - order + 1));
                    }
                }
            }
            addSubstrings(context, String.valueOf(EOS));
        } catch (FileNotFoundException ex) {
            Messages.severe(NgramModel.class.getName() + ": " + ex);
        } catch (IOException ex) {
            Messages.severe(NgramModel.class.getName() + ": " + ex);
        }
    }
public void addText ( InputStream is ) { try { BufferedReader reader = new BufferedReader ( new InputStreamReader ( is ) ) ; String context = String . valueOf ( BOS ) ; while ( reader . ready ( ) ) { String line = StringNormalizer . reduceWS ( reader . readLine ( ) ) ; if ( ! line . isEmpty ( ) ) { String input = ( context . charAt ( 0 ) == BOS ) ? line : " " + line ; addSubstrings ( context , input ) ; if ( input . length ( ) >= order ) { context = input . substring ( input . length ( ) - order + 1 ) ; } else { String s = context + input ; context = s . substring ( Math . max ( 0 , s . length ( ) - order + 1 ) ) ; } } } addSubstrings ( context , String . valueOf ( EOS ) ) ; } catch ( FileNotFoundException ex ) { Messages . severe ( NgramModel . class . getName ( ) + ": " + ex ) ; } catch ( IOException ex ) { Messages . severe ( NgramModel . class . getName ( ) + ": " + ex ) ; } }
Add all the content in a text file
 @param is the input stream with text content
Add all the content in a text file @param is the input stream with text content