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 2 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, write to the Free Software |
---|
14 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
15 | */ |
---|
16 | |
---|
17 | /* |
---|
18 | * Predicate.java |
---|
19 | * Copyright (C) 2003 Peter A. Flach, Nicolas Lachiche |
---|
20 | * |
---|
21 | * Thanks to Amelie Deltour for porting the original C code to Java |
---|
22 | * and integrating it into Weka. |
---|
23 | */ |
---|
24 | |
---|
25 | package weka.associations.tertius; |
---|
26 | |
---|
27 | import weka.core.RevisionHandler; |
---|
28 | import weka.core.RevisionUtils; |
---|
29 | |
---|
30 | import java.io.Serializable; |
---|
31 | import java.util.ArrayList; |
---|
32 | |
---|
33 | /** |
---|
34 | * @author Peter A. Flach |
---|
35 | * @author Nicolas Lachiche |
---|
36 | * @version $Revision: 1.5 $ |
---|
37 | */ |
---|
38 | public class Predicate |
---|
39 | implements Serializable, RevisionHandler { |
---|
40 | |
---|
41 | /** for serialization */ |
---|
42 | private static final long serialVersionUID = -8374702481965026640L; |
---|
43 | |
---|
44 | private ArrayList m_literals; |
---|
45 | |
---|
46 | private String m_name; |
---|
47 | |
---|
48 | private int m_index; |
---|
49 | |
---|
50 | private boolean m_isClass; |
---|
51 | |
---|
52 | public Predicate(String name, int index, boolean isClass) { |
---|
53 | |
---|
54 | m_literals = new ArrayList(); |
---|
55 | m_name = name; |
---|
56 | m_index = index; |
---|
57 | m_isClass = isClass; |
---|
58 | } |
---|
59 | |
---|
60 | public void addLiteral(Literal lit) { |
---|
61 | |
---|
62 | m_literals.add(lit); |
---|
63 | } |
---|
64 | |
---|
65 | public Literal getLiteral(int index) { |
---|
66 | |
---|
67 | return (Literal) m_literals.get(index); |
---|
68 | } |
---|
69 | |
---|
70 | public int getIndex() { |
---|
71 | |
---|
72 | return m_index; |
---|
73 | } |
---|
74 | |
---|
75 | public int indexOf(Literal lit) { |
---|
76 | |
---|
77 | int index = m_literals.indexOf(lit); |
---|
78 | return ((index != -1) |
---|
79 | ? index |
---|
80 | : m_literals.indexOf(lit.getNegation())); |
---|
81 | } |
---|
82 | |
---|
83 | public int numLiterals() { |
---|
84 | |
---|
85 | return m_literals.size(); |
---|
86 | } |
---|
87 | |
---|
88 | public boolean isClass() { |
---|
89 | |
---|
90 | return m_isClass; |
---|
91 | } |
---|
92 | |
---|
93 | public String toString() { |
---|
94 | |
---|
95 | return m_name; |
---|
96 | } |
---|
97 | |
---|
98 | public String description() { |
---|
99 | |
---|
100 | StringBuffer text = new StringBuffer(); |
---|
101 | text.append(this.toString() + "\n"); |
---|
102 | for (int i = 0; i < numLiterals(); i++) { |
---|
103 | Literal lit = getLiteral(i); |
---|
104 | Literal neg = lit.getNegation(); |
---|
105 | text.append("\t" + lit + "\t" + neg + "\n"); |
---|
106 | } |
---|
107 | return text.toString(); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * Returns the revision string. |
---|
112 | * |
---|
113 | * @return the revision |
---|
114 | */ |
---|
115 | public String getRevision() { |
---|
116 | return RevisionUtils.extract("$Revision: 1.5 $"); |
---|
117 | } |
---|
118 | } |
---|