package p13_pliki.tadeusz;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class PoliczWszystkieSlowa4 {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(new File("pan_tadeusz.txt"))) {
			scanner.useDelimiter("[^\\p{L}\\d]+");
			
			Map<String, Long> slownik = scanner.tokens()
				.map(String::toLowerCase)
				.collect(Collectors.groupingBy(x -> x, Collectors.counting()));
			
			slownik.forEach((slowo, ile) -> {
				System.out.printf("%-20s → %4d%n", slowo, ile);
			});
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}		
	}

}
