public static void RetrieveTrainMatrix() { try { BufferedReader flrdr = new BufferedReader( new FileReader("D:\\IR\\Assignment7\\Pytest\\part2\\output\\train_matrix.txt")); String line = ""; int doc_count = 0; while ((line = flrdr.readLine()) != null) { SortedSet<Integer> word_ids = new TreeSet<Integer>(); int val_count = 0; String[] key_value = line.split(" :: "); key_value[1] = key_value[1].substring(1, key_value[1].length() - 2); String[] values = key_value[1].split(","); FeatureNode[] node = new FeatureNode[values.length]; for (String val : values) word_ids.add(Integer.parseInt(val.trim())); for (int val : word_ids) node[val_count++] = new FeatureNode(val, 1); if (spam_docs.contains(key_value[0].trim())) ylable[doc_count] = 1; else ylable[doc_count] = 0; train_matrix[doc_count++] = node; } flrdr.close(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } }
public static void RetrieveSpamFiles() { try { BufferedReader flrdr = new BufferedReader( new FileReader("D:\\IR\\Assignment7\\Pytest\\part2\\output\\spam_docs.txt")); String line = flrdr.readLine(); line = line.substring(1, line.length() - 1); for (String doc : line.split(",")) { spam_docs.add(doc.substring(2, doc.length() - 1).trim()); } flrdr.close(); } catch (Exception e) { e.printStackTrace(); } }