public void save(String filename) {
        try {
            PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(filename)));

            pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            pw.println("<ngrams prob=\"" + totalProb + "\">");

            Set<String> entries = ngrams.keySet();

            for (String entry : entries) {

                int length = (this.unit == Unit.CHAR) ? entry.length() : syl.countSyllables(entry);
                String pr = "";
                if (length > 0) {
                    prob(entry);
                }
                pw.println("\t<entry length=\"" + length + "\" string=\"" + entry + "\" count=\"" + ngrams.get(entry) + "\" prob=\"" + pr + "\" />");
            }

            pw.write("</ngrams>");

            pw.close();

        } catch (IOException ioe) {
            System.err.println("Error saving ngrams");
        }
    }