Search in sources :

Example 1 with IngestConfig

use of org.vitrivr.cineast.standalone.config.IngestConfig in project cineast by vitrivr.

the class SessionExtractionContainer method initalizeExtraction.

private static void initalizeExtraction() {
    ExtractionDispatcher dispatcher = new ExtractionDispatcher();
    try {
        JacksonJsonProvider reader = new JacksonJsonProvider();
        IngestConfig context = reader.toObject(configFile, IngestConfig.class);
        provider = new SessionContainerProvider();
        if (dispatcher.initialize(provider, context)) {
            dispatcher.registerListener(provider);
            dispatcher.start();
        } else {
            System.err.println(String.format("Could not start session with configuration file '%s'. Does the file exist?", configFile.toString()));
        }
        dispatcher.start();
    } catch (IOException e) {
        System.err.println(String.format("Could not start session with configuration file '%s' due to a IO error.", configFile.toString()));
        e.printStackTrace();
    }
}
Also used : ExtractionDispatcher(org.vitrivr.cineast.standalone.run.ExtractionDispatcher) IngestConfig(org.vitrivr.cineast.standalone.config.IngestConfig) JacksonJsonProvider(org.vitrivr.cineast.core.util.json.JacksonJsonProvider) IOException(java.io.IOException) SessionContainerProvider(org.vitrivr.cineast.standalone.run.path.SessionContainerProvider)

Example 2 with IngestConfig

use of org.vitrivr.cineast.standalone.config.IngestConfig in project cineast by vitrivr.

the class ExtractionCommand method run.

@Override
public void run() {
    final ExtractionDispatcher dispatcher = new ExtractionDispatcher();
    final File file = new File(this.extractionConfig);
    if (file.exists()) {
        try {
            final JacksonJsonProvider reader = new JacksonJsonProvider();
            final IngestConfig context = reader.toObject(file, IngestConfig.class);
            // Check if the config specifies an IIIF job
            if (context != null) {
                InputConfig inputConfig = context.getInput();
                IIIFConfig iiifConfig = inputConfig.getIiif();
                if (iiifConfig != null) {
                    String directoryPath;
                    String iiifConfigPath = inputConfig.getPath();
                    /* If the user hasn't asked to save the images once extraction is complete or if the user has not specified a download directory for the IIIF images, then save the images in a new "iiif-media-{@link System#currentTimeMillis}" subfolder.
            This folder can act as the temp directory during extraction and can either be deleted or retained post extraction based on the value set in {@link IIIFConfig#keepImagesPostExtraction} */
                    if (!iiifConfig.isKeepImagesPostExtraction() || iiifConfigPath == null || iiifConfigPath.isEmpty()) {
                        directoryPath = file.getAbsoluteFile().toPath().getParent() + "/iiif-media-" + System.currentTimeMillis();
                        inputConfig.setPath(directoryPath);
                    } else {
                        directoryPath = iiifConfigPath;
                    }
                    prepareIIIFExtractionJob(iiifConfig, directoryPath);
                }
            }
            final ExtractionContainerProvider provider = ExtractionContainerProviderFactory.tryCreatingTreeWalkPathProvider(file, context);
            if (dispatcher.initialize(provider, context)) {
                /* Only attempt to optimize Cottontail entities if we were extracting into Cottontail, otherwise an unavoidable error message would be displayed when extracting elsewhere. */
                if (!doNotFinalize && context != null && context.getDatabase().getSelector() == DataSource.COTTONTAIL && context.getDatabase().getWriter() == DataSource.COTTONTAIL) {
                    dispatcher.registerListener(new ExtractionCompleteListener() {

                        @Override
                        public void extractionComplete() {
                            OptimizeEntitiesCommand.optimizeAllCottontailEntities();
                        }
                    });
                }
                dispatcher.registerListener((ExtractionCompleteListener) provider);
                dispatcher.start();
                dispatcher.block();
            } else {
                System.err.printf("Could not start handleExtraction with configuration file '%s'. Does the file exist?%n", file);
            }
        } catch (IOException e) {
            System.err.printf("Could not start handleExtraction with configuration file '%s' due to a IO error.%n", file);
            e.printStackTrace();
        } catch (ClassCastException e) {
            System.err.println("Could not register completion listener for extraction.");
        } finally {
            if (postExtractionIIIFCleanup != null) {
                postExtractionIIIFCleanup.run();
            }
        }
    } else {
        System.err.printf("Could not start handleExtraction with configuration file '%s'; the file does not exist!%n", file);
    }
}
Also used : ExtractionDispatcher(org.vitrivr.cineast.standalone.run.ExtractionDispatcher) IngestConfig(org.vitrivr.cineast.standalone.config.IngestConfig) ExtractionCompleteListener(org.vitrivr.cineast.standalone.run.ExtractionCompleteListener) JacksonJsonProvider(org.vitrivr.cineast.core.util.json.JacksonJsonProvider) ExtractionContainerProvider(org.vitrivr.cineast.standalone.run.ExtractionContainerProvider) InputConfig(org.vitrivr.cineast.standalone.config.InputConfig) IOException(java.io.IOException) IIIFConfig(org.vitrivr.cineast.core.iiif.IIIFConfig) File(java.io.File)

Example 3 with IngestConfig

use of org.vitrivr.cineast.standalone.config.IngestConfig in project cineast by vitrivr.

the class DatabaseSetupCommand method extractionConfigPersistentOperators.

private HashSet<PersistentOperator> extractionConfigPersistentOperators(String extractionConfig) {
    final HashSet<PersistentOperator> persistentOperators = new HashSet<>();
    final File file = new File(extractionConfig);
    if (file.exists()) {
        final JacksonJsonProvider reader = new JacksonJsonProvider();
        final IngestConfig context = reader.toObject(file, IngestConfig.class);
        for (ExtractorConfig extractor : context.getExtractors()) {
            persistentOperators.add(extractor.getExtractor());
        }
    } else {
        System.err.println(String.format("Could not setup database based upon extraction config '%s'; the file does not exist!", file.toString()));
    }
    return persistentOperators;
}
Also used : IngestConfig(org.vitrivr.cineast.standalone.config.IngestConfig) ExtractorConfig(org.vitrivr.cineast.standalone.config.ExtractorConfig) JacksonJsonProvider(org.vitrivr.cineast.core.util.json.JacksonJsonProvider) PersistentOperator(org.vitrivr.cineast.core.db.PersistentOperator) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

JacksonJsonProvider (org.vitrivr.cineast.core.util.json.JacksonJsonProvider)3 IngestConfig (org.vitrivr.cineast.standalone.config.IngestConfig)3 File (java.io.File)2 IOException (java.io.IOException)2 ExtractionDispatcher (org.vitrivr.cineast.standalone.run.ExtractionDispatcher)2 HashSet (java.util.HashSet)1 PersistentOperator (org.vitrivr.cineast.core.db.PersistentOperator)1 IIIFConfig (org.vitrivr.cineast.core.iiif.IIIFConfig)1 ExtractorConfig (org.vitrivr.cineast.standalone.config.ExtractorConfig)1 InputConfig (org.vitrivr.cineast.standalone.config.InputConfig)1 ExtractionCompleteListener (org.vitrivr.cineast.standalone.run.ExtractionCompleteListener)1 ExtractionContainerProvider (org.vitrivr.cineast.standalone.run.ExtractionContainerProvider)1 SessionContainerProvider (org.vitrivr.cineast.standalone.run.path.SessionContainerProvider)1