// Path: src/com/learningmodule/association/conceptdrug/model/EncounterIdConceptDrug.java
// public class EncounterIdConceptDrug {
// 	private int id;
// 	private String drug, conceptId;
// 	
// 	public EncounterIdConceptDrug(int id, String drug, String conceptId) {
// 		super();
// 		this.id = id;
// 		this.drug = drug;
// 		this.conceptId = conceptId;
// 	}
// 	
// 	public int getEncounterId() {
// 		return id;
// 	}
// 	public void setEncounterId(int id) {
// 		this.id = id;
// 	}
// 	
// 	public String getDrug() {
// 		return drug;
// 	}
// 	public void setDrug(String drug) {
// 		this.drug = drug;
// 	}
// 	public String getConceptId() {
// 		return conceptId;
// 	}
// 	public void setConceptId(String conceptId) {
// 		this.conceptId = conceptId;
// 	}
// }
// 
// 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.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import com.learningmodule.association.conceptdrug.model.EncounterIdConceptDrug;
import com.learningmodule.association.conceptdrug.model.PredictionMatrix;
package com.learningmodule.association.conceptdrug.learning;



/*
 * Class for Apriori Algorithm designed specifically to find Diesease to Drug Association Rules.
 */

public class CustomApriori {

	// min support for association rules
	private double minSupport;
	private int minSupp;

	// minConfidence for association rules
	private double minConfidence;

	// associations rules generated by apriori algorithm
	private Hashtable<String, Row> rules;

	// constructor for this class
	public CustomApriori() {
		rules = new Hashtable<String, Row>();
	}

	// constructor for this class given minSupport and minConfidence
	public CustomApriori(int minSupport, double minConfidence) {
		this.minSupport = minSupport;
		this.minConfidence = minConfidence;
		rules = new Hashtable<String, Row>();
	}

	// function to increment count of a concept whenever a concepts is found
	// records
	private void incrementConceptCounts(HashSet<String> ids) {
		for (String id : ids) {
			rules.get(id).conceptCount++;
		}
	}

	public PredictionMatrix buildAssociations(LinkedList<EncounterIdConceptDrug> data) {

		// number of instances/records/unique encounterIds
		int noOfInstance = 0;

		// previous encounterId/recordId
		int preEncounterId = 0;

		// set of disgnosis/observations in current EncounterId
		HashSet<String> currentInstanceConcepts = new HashSet<String>();

		// for every row of records
// Path: src/com/learningmodule/association/conceptdrug/model/EncounterIdConceptDrug.java
// public class EncounterIdConceptDrug {
// 	private int id;
// 	private String drug, conceptId;
// 	
// 	public EncounterIdConceptDrug(int id, String drug, String conceptId) {
// 		super();
// 		this.id = id;
// 		this.drug = drug;
// 		this.conceptId = conceptId;
// 	}
// 	
// 	public int getEncounterId() {
// 		return id;
// 	}
// 	public void setEncounterId(int id) {
// 		this.id = id;
// 	}
// 	
// 	public String getDrug() {
// 		return drug;
// 	}
// 	public void setDrug(String drug) {
// 		this.drug = drug;
// 	}
// 	public String getConceptId() {
// 		return conceptId;
// 	}
// 	public void setConceptId(String conceptId) {
// 		this.conceptId = conceptId;
// 	}
// }
// 
// 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/CustomApriori.java
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import com.learningmodule.association.conceptdrug.model.EncounterIdConceptDrug;
import com.learningmodule.association.conceptdrug.model.PredictionMatrix;

package com.learningmodule.association.conceptdrug.learning;



/*
 * Class for Apriori Algorithm designed specifically to find Diesease to Drug Association Rules.
 */

public class CustomApriori {

	// min support for association rules
	private double minSupport;
	private int minSupp;

	// minConfidence for association rules
	private double minConfidence;

	// associations rules generated by apriori algorithm
	private Hashtable<String, Row> rules;

	// constructor for this class
	public CustomApriori() {
		rules = new Hashtable<String, Row>();
	}

	// constructor for this class given minSupport and minConfidence
	public CustomApriori(int minSupport, double minConfidence) {
		this.minSupport = minSupport;
		this.minConfidence = minConfidence;
		rules = new Hashtable<String, Row>();
	}

	// function to increment count of a concept whenever a concepts is found
	// records
	private void incrementConceptCounts(HashSet<String> ids) {
		for (String id : ids) {
			rules.get(id).conceptCount++;
		}
	}

	public PredictionMatrix buildAssociations(LinkedList<EncounterIdConceptDrug> data) {

		// number of instances/records/unique encounterIds
		int noOfInstance = 0;

		// previous encounterId/recordId
		int preEncounterId = 0;

		// set of disgnosis/observations in current EncounterId
		HashSet<String> currentInstanceConcepts = new HashSet<String>();

		// for every row of records
		for (EncounterIdConceptDrug item : data) {