001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package org.openimaj.experiment.gmm.retrieval; 031 032import java.util.HashMap; 033import java.util.Map; 034import java.util.Set; 035 036import org.apache.commons.vfs2.FileObject; 037import org.apache.commons.vfs2.FileSystemException; 038import org.apache.commons.vfs2.FileSystemManager; 039import org.apache.commons.vfs2.VFS; 040import org.openimaj.data.dataset.GroupedDataset; 041import org.openimaj.data.dataset.ReadableGroupDataset; 042import org.openimaj.data.identity.Identifiable; 043import org.openimaj.io.ObjectReader; 044 045/** 046 * A {@link GroupedDataset} of {@link UKBenchListDataset}s instances each of an 047 * item in the UKBench experiment. 048 * 049 * UKBench can be provided in any form supported by {@link VFS} 050 * 051 * The UKBench files must be in one flat directory and named "ukbenchXXXXX.jpg" 052 * 053 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 054 * 055 * @param <IMAGE> 056 * The type of IMAGE in the dataset 057 */ 058public class UKBenchGroupDataset<IMAGE> 059 extends 060 ReadableGroupDataset<Integer, UKBenchListDataset<IMAGE>, IMAGE, FileObject> 061 implements 062 Identifiable 063{ 064 private static final int UKBENCH_OBJECTS = 2550; 065 private Map<Integer, UKBenchListDataset<IMAGE>> ukbenchObjects; 066 private FileObject base; 067 068 /** 069 * @param path 070 * @param reader 071 */ 072 public UKBenchGroupDataset(String path, ObjectReader<IMAGE, FileObject> reader) { 073 super(reader); 074 this.ukbenchObjects = new HashMap<Integer, UKBenchListDataset<IMAGE>>(); 075 FileSystemManager manager; 076 try { 077 manager = VFS.getManager(); 078 this.base = manager.resolveFile(path); 079 } catch (final FileSystemException e) { 080 throw new RuntimeException(e); 081 } 082 083 for (int i = 0; i < UKBENCH_OBJECTS; i++) { 084 this.ukbenchObjects.put(i, new UKBenchListDataset<IMAGE>(path, reader, i)); 085 } 086 } 087 088 @Override 089 public String toString() { 090 return String.format("%s(%d groups with a total of %d instances)", this.getClass().getName(), this.size(), 091 this.numInstances()); 092 } 093 094 @Override 095 public String getID() { 096 return base.getName().getBaseName(); 097 } 098 099 @Override 100 public Set<java.util.Map.Entry<Integer, UKBenchListDataset<IMAGE>>> entrySet() { 101 return ukbenchObjects.entrySet(); 102 } 103 104}