@@ -0,0 +1,2038 @@
+import com.clarifai.api.ClarifaiClient;%0Aimport com.clarifai.api.RecognitionRequest;%0Aimport com.clarifai.api.RecognitionResult;%0Aimport com.clarifai.api.Tag;%0A%0Aimport javax.imageio.ImageIO;%0Aimport java.io.File;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException;%0Aimport java.nio.file.FileSystems;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.StandardCopyOption;%0Aimport java.util.List;%0A%0Apublic class Directifai %7B%0A%0A%09private static ClarifaiClient clarifai = new ClarifaiClient(); // create a clarifai client, get keys from the environment variables%0A%0A%09public static void main(String%5B%5D args) throws IOException %7B%0A%0A%0A%09%09if (args.length %3C 1) %7B%0A%09%09%09System.err.println(%22Usage: java -jar Directifai-1-jar-with-dependencies.jar inputDirectory%22);%0A%09%09%09return;%0A%09%09%7D%0A%0A%09%09String targetFolder = args%5B0%5D;%0A%09%09File%5B%5D files = new File(targetFolder).listFiles();%0A%0A%09%09if (files == null)%0A%09%09%09throw new FileNotFoundException(%22No files detected in the given path%22);%0A%0A%09%09for (File file : files) %7B%0A%09%09%09if (ImageIO.read(file) == null)%0A%09%09%09%09continue; // skip if current file isn't an image%0A%09%09%09System.out.println(%22Processing: %22 + file.getName());%0A%09%09%09sortIntoDirectryByTag(file);%0A%09%09%7D%0A%09%09System.out.println(%22Finished processing images%22);%0A%09%7D%0A%0A%09// move files based on their most probable tag given by Clarifai's API%0A%09private static void sortIntoDirectryByTag(File image) throws IOException %7B%0A%0A%09%09List%3CRecognitionResult%3E results =%0A%09%09%09clarifai.recognize(new RecognitionRequest(image));%0A%09%09// get the most probable%0A%09%09Tag tag = results.get(0).getTags().get(0);%0A%0A%09%09String targetDir = %22./output/%22 + tag.getName() + %22/%22;%0A%0A%09%09// create directory for each of found tags%0A%09%09if (new File(targetDir).mkdirs())%0A%09%09%09System.out.println(%22New directory created: %22 + tag.getName());%0A%0A%09%09// move from original to newly created directory%0A%09%09Path moveFrom = FileSystems.getDefault().getPath(image.getAbsolutePath());%0A%09%09Path target = FileSystems.getDefault().getPath(targetDir + image.getName());%0A%09%09Files.move(moveFrom, target, StandardCopyOption.REPLACE_EXISTING);%0A%09%7D%0A%0A%0A%7D%0A

Add Directifai