public static Matrix loadARFF(String filepath)
            throws IOException {

        BufferedReader in = new BufferedReader(new FileReader(filepath));
        Matrix matrix = new Matrix();
        boolean isProcessingData = false;
        String line;

        while ((line = in.readLine()) != null) {
            line = line.replaceAll("\\s+", " ").replaceAll("\\{\\s", "{").
                    replaceAll("\\s\\}", "}").replaceAll(",\\s", ",").replaceAll("\\s,", ",");
            String lineLowercase = line.toLowerCase();

            if (lineLowercase.isEmpty() || lineLowercase.startsWith(COMMENT) || lineLowercase.startsWith(RELATION)) {
                continue;
            } else if (lineLowercase.startsWith(ATTRIBUTE)) {
                getAttributes(matrix, line);
            } else if (lineLowercase.startsWith(DATA)) {
                isProcessingData = true;
            } else if (isProcessingData) {
                getData(matrix, line);
            } else {
                throw new MLException("Unrecognized file format, line: " + line);
            }
        }
        in.close();
        return matrix;
    }