[4] | 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 | * IndividualInstances.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 | |
---|
| 26 | package weka.associations.tertius; |
---|
| 27 | |
---|
| 28 | import weka.core.Attribute; |
---|
| 29 | import weka.core.Instance; |
---|
| 30 | import weka.core.Instances; |
---|
| 31 | import weka.core.RevisionUtils; |
---|
| 32 | |
---|
| 33 | import java.util.Enumeration; |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * @author Peter A. Flach |
---|
| 37 | * @author Nicolas Lachiche |
---|
| 38 | * @version $Revision: 1.6 $ |
---|
| 39 | */ |
---|
| 40 | public class IndividualInstances |
---|
| 41 | extends Instances { |
---|
| 42 | |
---|
| 43 | /** for serialization */ |
---|
| 44 | private static final long serialVersionUID = -7355054814895636733L; |
---|
| 45 | |
---|
| 46 | public IndividualInstances(Instances individuals, Instances parts) |
---|
| 47 | throws Exception { |
---|
| 48 | |
---|
| 49 | super(individuals, individuals.numInstances()); |
---|
| 50 | |
---|
| 51 | Attribute individualIdentifier = attribute("id"); |
---|
| 52 | if (individualIdentifier == null) { |
---|
| 53 | throw new Exception("No identifier found in individuals dataset."); |
---|
| 54 | } |
---|
| 55 | Attribute partIdentifier = parts.attribute("id"); |
---|
| 56 | if (partIdentifier == null) { |
---|
| 57 | throw new Exception("No identifier found in parts dataset."); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | Enumeration enumIndividuals = individuals.enumerateInstances(); |
---|
| 61 | while (enumIndividuals.hasMoreElements()) { |
---|
| 62 | Instance individual = (Instance) enumIndividuals.nextElement(); |
---|
| 63 | Instances partsOfIndividual = new Instances(parts, 0); |
---|
| 64 | Enumeration enumParts = parts.enumerateInstances(); |
---|
| 65 | while (enumParts.hasMoreElements()) { |
---|
| 66 | Instance part = (Instance) enumParts.nextElement(); |
---|
| 67 | if (individual.value(individualIdentifier) |
---|
| 68 | == part.value(partIdentifier)) { |
---|
| 69 | partsOfIndividual.add(part); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | add(new IndividualInstance(individual, partsOfIndividual)); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * Returns the revision string. |
---|
| 78 | * |
---|
| 79 | * @return the revision |
---|
| 80 | */ |
---|
| 81 | public String getRevision() { |
---|
| 82 | return RevisionUtils.extract("$Revision: 1.6 $"); |
---|
| 83 | } |
---|
| 84 | } |
---|