| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AssociationRules |
|
| 1.25;1.25 |
| 1 | /* | |
| 2 | * This program is free software: you can redistribute it and/or modify | |
| 3 | * it under the terms of the GNU General Public License as published by | |
| 4 | * the Free Software Foundation, either version 3 of the License, or | |
| 5 | * (at your option) any later version. | |
| 6 | * | |
| 7 | * This program is distributed in the hope that it will be useful, | |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 | * GNU General Public License for more details. | |
| 11 | * | |
| 12 | * You should have received a copy of the GNU General Public License | |
| 13 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 14 | */ | |
| 15 | ||
| 16 | /* | |
| 17 | * AssociationRules.java | |
| 18 | * Copyright (C) 2010-2012 University of Waikato, Hamilton, New Zealand | |
| 19 | * | |
| 20 | */ | |
| 21 | package weka.associations; | |
| 22 | ||
| 23 | import java.io.Serializable; | |
| 24 | import java.util.List; | |
| 25 | ||
| 26 | import weka.core.OptionHandler; | |
| 27 | import weka.core.Utils; | |
| 28 | ||
| 29 | /** | |
| 30 | * Class encapsulating a list of association rules. | |
| 31 | * | |
| 32 | * @author Mark Hall (mhall{[at]}pentaho{[dot]}com) | |
| 33 | * @version $Revision: 8034 $ | |
| 34 | */ | |
| 35 | public class AssociationRules implements Serializable { | |
| 36 | ||
| 37 | /** For serialization */ | |
| 38 | private static final long serialVersionUID = 8889198755948056749L; | |
| 39 | ||
| 40 | /** The scheme that produced these rules */ | |
| 41 | 0 | protected String m_producer = "Unknown"; |
| 42 | ||
| 43 | /** The list of rules */ | |
| 44 | protected List<AssociationRule> m_rules; | |
| 45 | ||
| 46 | /** | |
| 47 | * Constructs a new AssociationRules. | |
| 48 | * | |
| 49 | * @param rules the list of rules. | |
| 50 | * @param producer a string describing the scheme that produced these rules. | |
| 51 | */ | |
| 52 | 0 | public AssociationRules(List<AssociationRule> rules, String producer) { |
| 53 | 0 | m_rules = rules; |
| 54 | 0 | m_producer = producer; |
| 55 | 0 | } |
| 56 | ||
| 57 | /** | |
| 58 | * Constructs a new AssociationRules. | |
| 59 | * | |
| 60 | * @param rules the list of rules. | |
| 61 | * @param producer the scheme that produced the rules. | |
| 62 | */ | |
| 63 | 0 | public AssociationRules(List<AssociationRule> rules, Object producer) { |
| 64 | 0 | String producerString = producer.getClass().getName(); |
| 65 | 0 | if (producerString.startsWith("weka.associations.")) { |
| 66 | 0 | producerString = producerString.substring("weka.associations.".length()); |
| 67 | } | |
| 68 | ||
| 69 | 0 | if (producer instanceof OptionHandler) { |
| 70 | 0 | String [] o = ((OptionHandler) producer).getOptions(); |
| 71 | 0 | producerString += " " + Utils.joinOptions(o); |
| 72 | } | |
| 73 | ||
| 74 | 0 | m_rules = rules; |
| 75 | 0 | m_producer = producerString; |
| 76 | 0 | } |
| 77 | ||
| 78 | /** | |
| 79 | * Constructs a new AssociationRules. | |
| 80 | * | |
| 81 | * @param rules the list of rules. | |
| 82 | */ | |
| 83 | public AssociationRules(List<AssociationRule> rules) { | |
| 84 | 0 | this(rules, "Unknown"); |
| 85 | 0 | } |
| 86 | ||
| 87 | /** | |
| 88 | * Set the rules to use. | |
| 89 | * | |
| 90 | * @param rules the rules to use. | |
| 91 | */ | |
| 92 | public void setRules(List<AssociationRule> rules) { | |
| 93 | 0 | m_rules = rules; |
| 94 | 0 | } |
| 95 | ||
| 96 | /** | |
| 97 | * Get the rules. | |
| 98 | * | |
| 99 | * @return the rules. | |
| 100 | */ | |
| 101 | public List<AssociationRule> getRules() { | |
| 102 | 0 | return m_rules; |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Get the number of rules. | |
| 107 | * | |
| 108 | * @return the number of rules. | |
| 109 | */ | |
| 110 | public int getNumRules() { | |
| 111 | 0 | return m_rules.size(); |
| 112 | } | |
| 113 | ||
| 114 | ||
| 115 | /** | |
| 116 | * Set a textual description of the scheme that produced | |
| 117 | * these rules. | |
| 118 | * | |
| 119 | * @param producer a textual description of the scheme that produced | |
| 120 | * these rules. | |
| 121 | */ | |
| 122 | public void setProducer(String producer) { | |
| 123 | 0 | m_producer = producer; |
| 124 | 0 | } |
| 125 | ||
| 126 | /** | |
| 127 | * Get a string describing the scheme that produced these rules. | |
| 128 | * | |
| 129 | * @return producer | |
| 130 | */ | |
| 131 | public String getProducer() { | |
| 132 | 0 | return m_producer; |
| 133 | } | |
| 134 | } |