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 2 of the License, or
5
* (at your option) any later version.
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.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Copyright (C) 2003 Peter A. Flach, Nicolas Lachiche
21
* Thanks to Amelie Deltour for porting the original C code to Java
22
* and integrating it into Weka.
25
package weka.associations.tertius;
27
import weka.core.Instance;
28
import weka.core.Instances;
29
import java.util.Iterator;
32
* Class representing the head of a rule.
34
* @author <a href="mailto:adeltour@netcourrier.com">Amelie Deltour</a>
35
* @version $Revision: 1.5 $
38
public class Head extends LiteralSet {
40
/** for serialization */
41
private static final long serialVersionUID = 5068076274253706199L;
44
* Constructor without storing the counter-instances.
52
* Constructor storing the counter-instances.
54
* @param instances The dataset.
56
public Head(Instances instances) {
62
* Test if an instance can be kept as a counter-instance,
63
* if a new literal is added to this head.
65
* @param instance The instance to test.
66
* @param newLit The new literal.
67
* @return True if the instance is still a counter-instance
68
* (if the negation of the new literal satisfies the instance).
70
public boolean canKeep(Instance instance, Literal newLit) {
71
return newLit.negationSatisfies(instance);
75
* Test if this Head is included in a rule.
76
* It is the literals of this Head are contained in the head of the other rule,
77
* or if their negation is included in the body of the other rule.
78
*/ public boolean isIncludedIn(Rule otherRule) {
79
Iterator iter = this.enumerateLiterals();
80
while (iter.hasNext()) {
81
Literal current = (Literal) iter.next();
82
if (!otherRule.headContains(current)
83
&& !otherRule.bodyContains(current.getNegation())) {
91
* Gives a String representation of this set of literals as a disjunction.
93
public String toString() {
94
Iterator iter = this.enumerateLiterals();
96
if (!iter.hasNext()) {
100
StringBuffer text = new StringBuffer();
101
while (iter.hasNext()) {
102
text.append(iter.next().toString());
103
if (iter.hasNext()) {
107
return text.toString();