// Path: src/com/learningmodule/association/conceptdrug/model/PredictionMatrix.java
// public class PredictionMatrix implements Serializable {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	// Prediction matrix is a hastable with key as concept_id and value as
// 	// ConceptRow
// 	Hashtable<String, ConceptRow> rows;
// 
// 	public PredictionMatrix(int noOfConcepts) {
// 		rows = new Hashtable<String, ConceptRow>();
// 	}
// 
// 	/*
// 	 * method to get the list of drugs that are associated with a drugId
// 	 */
// 	public LinkedList<Cell> getDrugs(String conceptId) {
// 		// if conceptId is present in the hash table then get the list of drugs
// 		// related to it
// 		if (rows.containsKey(conceptId)) {
// 			return rows.get(conceptId).getDrugs();
// 		}
// 		return null;
// 	}
// 
// 	/*
// 	 * method to get all the concepts which are related to some drug
// 	 */
// 	public LinkedList<String> getNonEmptyConcepts() {
// 		Enumeration<String> temp = rows.keys();
// 		LinkedList<String> result = new LinkedList<String>();
// 		while (temp.hasMoreElements()) {
// 			String key = temp.nextElement();
// 			if (!getDrugs(key).isEmpty()) {
// 				result.add(key);
// 			}
// 		}
// 		return result;
// 	}
// 
// 	/*
// 	 * method to add a new cell to Prediction matrix
// 	 */
// 	public void addCell(String concept, String drug, double conf) {
// 		// if concept is already present in hast table put a new key value pair
// 		// with key as this concept
// 		if (!rows.containsKey(concept)) {
// 			rows.put(concept, new ConceptRow(concept));
// 		}
// 		// add the drug in conceptRow
// 		rows.get(concept).addCell(drug, conf);
// 	}
// 
// 	@Override
// 	public String toString() {
// 		String result = "";
// 		int count = 0;
// 		Enumeration<String> keys = rows.keys();
// 		while (keys.hasMoreElements()) {
// 			result = result + rows.get(keys.nextElement()).toString() + "\n";
// 			count++;
// 		}
// 		return result + count;
// 	}
// 
// }


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.apache.log4j.Logger;
import com.learningmodule.association.conceptdrug.model.PredictionMatrix;
import weka.associations.ItemSet;
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instances;
package com.learningmodule.association.conceptdrug.learning;





/*
 * Class for Post Processing of the results from aproiri algorithm
 */

public class PostProcessing {

	private static Logger log = Logger.getLogger(PostProcessing.class);
	/*
	 * method to save the rules and instances in files "rules" and "instances"
	 */
	public static void save(FastVector[] allRules, Instances instances) {
		try {
			String path = PostProcessing.class.getResource("/").getFile();
			System.out.println(path);
			FileOutputStream saveFile = new FileOutputStream(path + "files/rules");
			ObjectOutputStream save = new ObjectOutputStream(saveFile);
			save.writeObject(allRules);
			save.close();
			
			saveFile = new FileOutputStream(path + "files/instances");
			save = new ObjectOutputStream(saveFile);
			save.writeObject(instances);
			save.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			log.error(e);
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e);
		}
	}

	/*
	 * Method to save the final Prediction matrix
	 */
// Path: src/com/learningmodule/association/conceptdrug/model/PredictionMatrix.java
// public class PredictionMatrix implements Serializable {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	// Prediction matrix is a hastable with key as concept_id and value as
// 	// ConceptRow
// 	Hashtable<String, ConceptRow> rows;
// 
// 	public PredictionMatrix(int noOfConcepts) {
// 		rows = new Hashtable<String, ConceptRow>();
// 	}
// 
// 	/*
// 	 * method to get the list of drugs that are associated with a drugId
// 	 */
// 	public LinkedList<Cell> getDrugs(String conceptId) {
// 		// if conceptId is present in the hash table then get the list of drugs
// 		// related to it
// 		if (rows.containsKey(conceptId)) {
// 			return rows.get(conceptId).getDrugs();
// 		}
// 		return null;
// 	}
// 
// 	/*
// 	 * method to get all the concepts which are related to some drug
// 	 */
// 	public LinkedList<String> getNonEmptyConcepts() {
// 		Enumeration<String> temp = rows.keys();
// 		LinkedList<String> result = new LinkedList<String>();
// 		while (temp.hasMoreElements()) {
// 			String key = temp.nextElement();
// 			if (!getDrugs(key).isEmpty()) {
// 				result.add(key);
// 			}
// 		}
// 		return result;
// 	}
// 
// 	/*
// 	 * method to add a new cell to Prediction matrix
// 	 */
// 	public void addCell(String concept, String drug, double conf) {
// 		// if concept is already present in hast table put a new key value pair
// 		// with key as this concept
// 		if (!rows.containsKey(concept)) {
// 			rows.put(concept, new ConceptRow(concept));
// 		}
// 		// add the drug in conceptRow
// 		rows.get(concept).addCell(drug, conf);
// 	}
// 
// 	@Override
// 	public String toString() {
// 		String result = "";
// 		int count = 0;
// 		Enumeration<String> keys = rows.keys();
// 		while (keys.hasMoreElements()) {
// 			result = result + rows.get(keys.nextElement()).toString() + "\n";
// 			count++;
// 		}
// 		return result + count;
// 	}
// 
// }


// Path: src/com/learningmodule/association/conceptdrug/learning/PostProcessing.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.apache.log4j.Logger;
import com.learningmodule.association.conceptdrug.model.PredictionMatrix;
import weka.associations.ItemSet;
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instances;

package com.learningmodule.association.conceptdrug.learning;





/*
 * Class for Post Processing of the results from aproiri algorithm
 */

public class PostProcessing {

	private static Logger log = Logger.getLogger(PostProcessing.class);
	/*
	 * method to save the rules and instances in files "rules" and "instances"
	 */
	public static void save(FastVector[] allRules, Instances instances) {
		try {
			String path = PostProcessing.class.getResource("/").getFile();
			System.out.println(path);
			FileOutputStream saveFile = new FileOutputStream(path + "files/rules");
			ObjectOutputStream save = new ObjectOutputStream(saveFile);
			save.writeObject(allRules);
			save.close();
			
			saveFile = new FileOutputStream(path + "files/instances");
			save = new ObjectOutputStream(saveFile);
			save.writeObject(instances);
			save.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			log.error(e);
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e);
		}
	}

	/*
	 * Method to save the final Prediction matrix
	 */
	public static void saveResults(PredictionMatrix matrix, String matrixFileName) {