public void buildARFF(String filename) {
		try {
			ARFFWriter writer = new ARFFWriter(filename, "index");
			String docClasses = "{";
			boolean first = true;
			for (String className : classes) {
				if (first) {
					docClasses += className;
					first = false;
				}
				else {
					docClasses += ", " + className;
				}
			}
			writer.addAttribute("@documentClass@", docClasses + "}");
			writer.addAttribute("@documentName@", "STRING");
			writer.addAttribute("@hasStemming@", "NUMERIC");
			for (String term : index.keySet()) {
				writer.addAttribute(term, "NUMERIC");
			}
			writer.beginData();
			for (String entry : documentVectors.keySet()) {
				String[] tmp = entry.split("/");
				writer.startRow();
				writer.addConstantValue(true, 0, tmp[0]);
				writer.addStringValue(false, 1, tmp[1]);
				writer.addNumericValue(false, 2, this.useStemming ? 1 : 0);
				TreeMap<Integer, Double> list = documentVectors.get(entry);
				for (Integer idx : list.keySet()) {
					// The first tree entries are class, name and the stemming attributes, so we have
					// to add 3 to the index
					writer.addNumericValue(false, idx + 3, list.get(idx).intValue());
				}
				writer.endRow();
			}
			writer.close();
			logger.info("Wrote document vectors to " + filename);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}