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.AbstractMap; 033import java.util.HashMap; 034import java.util.LinkedHashMap; 035import java.util.Map; 036import java.util.Set; 037 038import org.apache.commons.vfs2.FileObject; 039import org.apache.commons.vfs2.FileSystemException; 040import org.apache.commons.vfs2.FileSystemManager; 041import org.apache.commons.vfs2.VFS; 042import org.openimaj.data.dataset.GroupedDataset; 043import org.openimaj.data.dataset.ListDataset; 044import org.openimaj.data.dataset.ReadableGroupDataset; 045import org.openimaj.data.identity.Identifiable; 046import org.openimaj.image.Image; 047import org.openimaj.io.ObjectReader; 048 049/** 050 * A {@link GroupedDataset} of {@link UKBenchListDataset}s instances each of an 051 * item in the UKBench experiment. 052 * 053 * UKBench can be provided in any form supported by {@link VFS} 054 * 055 * The UKBench files must be in one flat directory and named "ukbenchXXXXX.jpg" 056 * 057 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 058 * 059 * @param <IMAGE> 060 * The type of IMAGE in the dataset 061 */ 062public class UKBenchGroupDataset<IMAGE> 063 extends 064 ReadableGroupDataset<Integer, UKBenchListDataset<IMAGE>, IMAGE, FileObject> 065 implements 066 Identifiable 067{ 068 private static final int UKBENCH_OBJECTS = 2550; 069 private Map<Integer, UKBenchListDataset<IMAGE>> ukbenchObjects; 070 private FileObject base; 071 /** 072 * @param path 073 * @param reader 074 */ 075 public UKBenchGroupDataset(String path, ObjectReader<IMAGE, FileObject> reader) { 076 super(reader); 077 this.ukbenchObjects = new HashMap<Integer, UKBenchListDataset<IMAGE>>(); 078 FileSystemManager manager; 079 try { 080 manager = VFS.getManager(); 081 this.base = manager.resolveFile(path); 082 } catch (FileSystemException e) { 083 throw new RuntimeException(e); 084 } 085 086 for(int i = 0; i < UKBENCH_OBJECTS; i++){ 087 this.ukbenchObjects.put(i, new UKBenchListDataset<IMAGE>(path, reader,i )); 088 } 089 } 090 091 092 @Override 093 public String toString() { 094 return String.format("%s(%d groups with a total of %d instances)", this.getClass().getName(), this.size(), 095 this.numInstances()); 096 } 097 098 099 @Override 100 public String getID() { 101 return base.getName().getBaseName(); 102 } 103 104 105 @Override 106 public Set<java.util.Map.Entry<Integer, UKBenchListDataset<IMAGE>>> entrySet() { 107 return ukbenchObjects.entrySet(); 108 } 109 110 111 112}