public void train(Reader aReader) throws IOException {
  BufferedReader in=new BufferedReader(aReader);
  String line=in.readLine();
  while (line != null) {
    Matcher m=WORD_PATTERN.matcher(line.toLowerCase());
    while (m.find()) {
      String word=m.group();
      AtomicInteger count=nWords.get(word);
      if (count == null) {
        count=new AtomicInteger(0);
        nWords.put(word,count);
      }
      count.incrementAndGet();
    }
    line=in.readLine();
  }
}

public void train ( Reader aReader ) throws IOException { BufferedReader in = new BufferedReader ( aReader ) ; String line = in . readLine ( ) ; while ( line != null ) { Matcher m = WORD_PATTERN . matcher ( line . toLowerCase ( ) ) ; while ( m . find ( ) ) { String word = m . group ( ) ; AtomicInteger count = nWords . get ( word ) ; if ( count == null ) { count = new AtomicInteger ( 0 ) ; nWords . put ( word , count ) ; } count . incrementAndGet ( ) ; } line = in . readLine ( ) ; } }
read words from the given reader and count their occurrences .
