import java.util.List;
import java.util.Map;
import java.util.Set;

/** Contar palabras con un Map y armar un índice con un Map de conjuntos. */
public class WordDemo {

    public static void main(String[] args) {
        String text = "La garúa cae en Lima. En Lima la garúa no moja, pero la garúa cae.";
        Map<String, Integer> counts = WordCount.count(text);
        IO.println(counts);
        IO.println("garúa: " + counts.get("garúa") + ", sol: " + counts.get("sol")
                + ", sol con getOrDefault: " + counts.getOrDefault("sol", 0));

        for (Map.Entry<String, Integer> e : counts.entrySet()) {
            if (e.getValue() >= 2) {
                IO.println("  " + e.getKey() + " x" + e.getValue());
            }
        }

        List<String> lines = List.of(
                "el puente y el río",
                "el río baja al mar",
                "un puente de piedra");
        Map<String, Set<Integer>> index = WordIndex.index(lines);
        IO.println("río -> " + index.get("río") + ", puente -> " + index.get("puente")
                + ", el -> " + index.get("el"));
        IO.println(index.size() + " palabras distintas: " + index.keySet());
    }
}
