Beispiel #1
0
 public static void main(String[] args)
     throws IOException, IllegalAccessException, InstantiationException {
   HashingIndexor indexor = new HashingIndexor();
   BitSampling.readHashFunctions();
   //        BitSampling.readHashFunctions(new FileInputStream(BitSampling.hashFunctionsFileName));
   //        LocalitySensitiveHashing.readHashFunctions();
   for (int i = 0; i < args.length; i++) {
     String arg = args[i];
     if (arg.startsWith("-i") || arg.startsWith("--input-file")) {
       // infile ...
       if ((i + 1) < args.length) indexor.addInputFile(new File(args[i + 1]));
       else printHelp();
     } else if (arg.startsWith("-l") || arg.startsWith("--index")) {
       // index
       if ((i + 1) < args.length) indexor.setIndexPath(args[i + 1]);
       else printHelp();
     } else if (arg.startsWith("-f") || arg.startsWith("--feature")) {
       // index
       if ((i + 1) < args.length)
         try {
           indexor.setFeatureClass(Class.forName(args[i + 1]));
         } catch (ClassNotFoundException e) {
           System.err.println("Could not find feature class named " + args[i + 1]);
           printHelp();
         }
       else printHelp();
     } else if (arg.startsWith("-h")) {
       // help
       printHelp();
     } else if (arg.startsWith("-s")) {
       // silent ...
       verbose = false;
     } else if (arg.startsWith("-c")) {
       // list of input files within a file.
       if ((i + 1) < args.length) {
         BufferedReader br = new BufferedReader(new FileReader(new File(args[i + 1])));
         String file;
         while ((file = br.readLine()) != null) {
           if (file.trim().length() > 2) {
             File f = new File(file);
             if (f.exists()) indexor.addInputFile(f);
             else System.err.println("Did not find file " + f.getName());
           }
         }
       } else printHelp();
     }
   }
   // check if there is an infile, an outfile and some features to extract.
   if (!indexor.isConfigured()) {
     printHelp();
   } else {
     indexor.run();
   }
 }
Beispiel #2
0
 protected void addToDocument(GlobalFeature feature, Document document, String featureFieldName) {
   // This is for debugging the image features.
   //        try {
   ////            System.out.println(feature.getClass().getName() + " " +
   // document.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]);
   //            LireFeature f1 = feature.getClass().newInstance();
   //            f1.extract(ImageIO.read(new
   // File(document.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0])));
   //            float distance = feature.getDistance(f1);
   //            if (distance != 0) {
   //                System.out.println("Extracted:" +
   // java.util.Arrays.toString(f1.getFeatureVector()).replaceAll("\\.0,", "") + "\n" +
   //                        "Data     :" +
   // java.util.Arrays.toString(feature.getFeatureVector()).replaceAll("\\.0,", "") + "\n" +
   //                        "Problem with " + f1.getClass().getName() + " at file " +
   // document.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] + ", distance=" + distance
   //                );
   ////                System.out.println("Problem with " + f1.getClass().getName() + " at file " +
   // document.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] + ", distance=" + distance);
   //            }
   //        } catch (Exception e) {
   //            e.printStackTrace();
   //
   //        }
   if (feature.getClass().getCanonicalName().equals(featureClass.getCanonicalName())) {
     // generate hashes here:
     //            int[] hashes =
     // LocalitySensitiveHashing.generateHashes(feature.getFeatureVector());
     int[] hashes = BitSampling.generateHashes(feature.getFeatureVector());
     //            System.out.println(Arrays.toString(hashes));
     // store hashes in index as terms
     document.add(
         new TextField(
             featureFieldName + "_hash",
             SerializationUtils.arrayToString(hashes),
             Field.Store.YES));
     // add the specific feature
     document.add(new StoredField(featureFieldName, feature.getByteArrayRepresentation()));
   }
   // add the specific feature
   //        document.add(new StoredField(featureFieldName, feature.getByteArrayRepresentation()));
 }