protected boolean isConfigured() { boolean isConfigured = true; // check if there are input files and if they exist. if (inputFiles.size() > 0) { for (Iterator<File> iterator = inputFiles.iterator(); iterator.hasNext(); ) { File next = iterator.next(); if (!next.exists()) { isConfigured = false; System.err.println("Input file " + next.getPath() + " does not exist."); } } } return isConfigured; }
public void run() { // do it ... try { IndexWriter indexWriter = LuceneUtils.createIndexWriter( indexPath, overwriteIndex, LuceneUtils.AnalyzerType.WhitespaceAnalyzer); for (Iterator<File> iterator = inputFiles.iterator(); iterator.hasNext(); ) { File inputFile = iterator.next(); if (verbose) System.out.println("Processing " + inputFile.getPath() + "."); if (verbose) System.out.println("Counting images."); run = 0; readFile(indexWriter, inputFile); if (verbose) System.out.printf("%d images found in the data file.\n", docCount); int numberOfRepresentatives = 1000; // TODO: clever selection. // select a number of representative "fixed stars" randomly from file if (numberOfRepresentatives > Math.sqrt(docCount)) numberOfRepresentatives = (int) Math.sqrt(docCount); if (verbose) System.out.printf( "Selecting %d representative images for hashing.\n", numberOfRepresentatives); representativesID = new HashSet<Integer>(numberOfRepresentatives); while (representativesID.size() < numberOfRepresentatives) { representativesID.add((int) Math.floor(Math.random() * (docCount - 1))); } representatives = new ArrayList<LireFeature>(numberOfRepresentatives); docCount = 0; run = 1; if (verbose) System.out.println("Now getting representatives from the data file."); readFile(indexWriter, inputFile); docCount = 0; run = 2; if (verbose) System.out.println("Finally we start the indexing process, please wait ..."); readFile(indexWriter, inputFile); if (verbose) System.out.println("Indexing finished."); } indexWriter.commit(); indexWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
private int[] getHashes(LireFeature feature) { // result = new int[maximumHits]; hashingResultScoreDocs.clear(); maxDistance = 0f; tmpScore = 0f; int rep = 0; LireFeature tmpFeature; for (Iterator<LireFeature> iterator = representatives.iterator(); iterator.hasNext(); ) { tmpFeature = iterator.next(); tmpScore = tmpFeature.getDistance(feature); if (hashingResultScoreDocs.size() < maximumHits) { hashingResultScoreDocs.add(new SimpleResult(tmpScore, null, rep)); maxDistance = Math.max(maxDistance, tmpScore); } else if (tmpScore < maxDistance) { hashingResultScoreDocs.add(new SimpleResult(tmpScore, null, rep)); } while (hashingResultScoreDocs.size() > maximumHits) { hashingResultScoreDocs.remove(hashingResultScoreDocs.last()); maxDistance = hashingResultScoreDocs.last().getDistance(); } rep++; } rep = 0; for (Iterator<SimpleResult> iterator = hashingResultScoreDocs.iterator(); iterator.hasNext(); ) { SimpleResult next = iterator.next(); result[rep] = next.getIndexNumber(); rep++; } return result; }