@Test public void testParseJ48() { System.out.println("parseJ48"); String treeResult = "J48 pruned tree\r\n------------------\r\n\r\n" + "GP: physician-fee-freeze = n: democrat (253.41/3.75)\r\n" + "GP: physician-fee-freeze = y\r\n" + "| GP: synfuels-corporation-cutback = n: republican (145.71/4.0)\r\n" + "| GP: synfuels-corporation-cutback = y\r\n" + "| | GP: mx-missile = n (6.03/1.03)\r\n" + "| | GP: mx-missile = y: democrat (6.03/1.03)\r\n\r\n" + "Number of Leaves : 22\r\n\r\n" + "Size of the tree : 33"; HashMap expResult = new HashMap<String, Integer>(); expResult.put("GP: physician-fee-freeze", new Integer(0)); expResult.put("GP: synfuels-corporation-cutback", new Integer(1)); expResult.put("GP: mx-missile", new Integer(2)); HashMap result = Parse.parseJ48(treeResult); assertEquals(expResult, result); System.out.println("parseJ48: Success"); }
public static HashMap<String, Integer> parseJ48(String treeResult) { HashMap<String, Integer> hm = new HashMap<String, Integer>(); String[] lines = treeResult.split("\\r\\n?|\\n"); for(String line : lines) { if(line.matches("[\\|\\ ]*GP:\\ [\\x20-\\x7E]+")) { String[] lineSplit = line.split("\\ [\\<\\=\\>]"); int level = countOccurrences(lineSplit[0], '|'); if (level == 0) { hm.put(lineSplit[0], level); } else { String[] split = lineSplit[0].split("\\|"); hm.put(split[split.length - 1].trim(), level); } } } return hm; }
Parse { public static HashMap<String, Integer> parseJ48(String treeResult) { HashMap<String, Integer> hm = new HashMap<String, Integer>(); String[] lines = treeResult.split("\\r\\n?|\\n"); for(String line : lines) { if(line.matches("[\\|\\ ]*GP:\\ [\\x20-\\x7E]+")) { String[] lineSplit = line.split("\\ [\\<\\=\\>]"); int level = countOccurrences(lineSplit[0], '|'); if (level == 0) { hm.put(lineSplit[0], level); } else { String[] split = lineSplit[0].split("\\|"); hm.put(split[split.length - 1].trim(), level); } } } return hm; } }
Parse { public static HashMap<String, Integer> parseJ48(String treeResult) { HashMap<String, Integer> hm = new HashMap<String, Integer>(); String[] lines = treeResult.split("\\r\\n?|\\n"); for(String line : lines) { if(line.matches("[\\|\\ ]*GP:\\ [\\x20-\\x7E]+")) { String[] lineSplit = line.split("\\ [\\<\\=\\>]"); int level = countOccurrences(lineSplit[0], '|'); if (level == 0) { hm.put(lineSplit[0], level); } else { String[] split = lineSplit[0].split("\\|"); hm.put(split[split.length - 1].trim(), level); } } } return hm; }  }
Parse { public static HashMap<String, Integer> parseJ48(String treeResult) { HashMap<String, Integer> hm = new HashMap<String, Integer>(); String[] lines = treeResult.split("\\r\\n?|\\n"); for(String line : lines) { if(line.matches("[\\|\\ ]*GP:\\ [\\x20-\\x7E]+")) { String[] lineSplit = line.split("\\ [\\<\\=\\>]"); int level = countOccurrences(lineSplit[0], '|'); if (level == 0) { hm.put(lineSplit[0], level); } else { String[] split = lineSplit[0].split("\\|"); hm.put(split[split.length - 1].trim(), level); } } } return hm; }  static HashMap<String, Integer> parseJ48(String treeResult); static int getTreeSize(String j48Tree); static String formatGenomeString(String genome); }
Parse { public static HashMap<String, Integer> parseJ48(String treeResult) { HashMap<String, Integer> hm = new HashMap<String, Integer>(); String[] lines = treeResult.split("\\r\\n?|\\n"); for(String line : lines) { if(line.matches("[\\|\\ ]*GP:\\ [\\x20-\\x7E]+")) { String[] lineSplit = line.split("\\ [\\<\\=\\>]"); int level = countOccurrences(lineSplit[0], '|'); if (level == 0) { hm.put(lineSplit[0], level); } else { String[] split = lineSplit[0].split("\\|"); hm.put(split[split.length - 1].trim(), level); } } } return hm; }  static HashMap<String, Integer> parseJ48(String treeResult); static int getTreeSize(String j48Tree); static String formatGenomeString(String genome);  }