Search in sources :

Example 1 with StudyImporterException

use of org.eol.globi.data.StudyImporterException in project eol-globi-data by jhpoelen.

the class GraphExporterImpl method exportDataOntology.

private void exportDataOntology(List<Study> studies, String baseDir) throws StudyImporterException {
    try {
        ExporterRDF studyExporter = new ExporterRDF();
        OutputStreamWriter writer = openStream(baseDir + "globi.nq.gz");
        int total = studies.size();
        int count = 1;
        for (Study study : studies) {
            studyExporter.exportStudy(study, writer, true);
            if (count % 50 == 0) {
                LOG.info("added triples for [" + count + "] of [" + total + "] studies...");
            }
            count++;
        }
        LOG.info("adding triples for [" + total + "] of [" + total + "] studies.");
        LOG.info("writing nquads archive...");
        closeStream(baseDir + "globi.nq.gz", writer);
    } catch (IOException e) {
        throw new StudyImporterException("failed to export as owl", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImporterException(org.eol.globi.data.StudyImporterException)

Example 2 with StudyImporterException

use of org.eol.globi.data.StudyImporterException in project eol-globi-data by jhpoelen.

the class GraphExporterImpl method exportNames.

private void exportNames(List<Study> studies, String baseDir, StudyExporter exporter, String filename) throws StudyImporterException {
    try {
        String filePath = baseDir + filename;
        OutputStreamWriter writer = openStream(filePath);
        for (Study study : studies) {
            boolean includeHeader = studies.indexOf(study) == 0;
            exporter.exportStudy(study, writer, includeHeader);
        }
        closeStream(filePath, writer);
    } catch (IOException e) {
        throw new StudyImporterException("failed to export unmatched source taxa", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImporterException(org.eol.globi.data.StudyImporterException)

Example 3 with StudyImporterException

use of org.eol.globi.data.StudyImporterException in project eol-globi-data by jhpoelen.

the class Normalizer method importData.

void importData(GraphDatabaseService graphService, String cacheDir) {
    NodeFactoryNeo4j factory = new NodeFactoryNeo4j(graphService);
    factory.setEcoregionFinder(getEcoregionFinder());
    factory.setDoiResolver(new DOIResolverImpl());
    try {
        CacheFactory cacheFactory = dataset -> new CacheLocalReadonly(dataset.getNamespace(), cacheDir);
        DatasetFinder finder = new DatasetFinderLocal(cacheDir, cacheFactory);
        StudyImporter importer = new StudyImporterForGitHubData(new ParserFactoryLocal(), factory, finder);
        importer.setDataset(new DatasetLocal());
        importer.setLogger(new StudyImportLogger());
        importer.importStudy();
    } catch (StudyImporterException e) {
        LOG.error("problem encountered while importing [" + StudyImporterForGitHubData.class.getName() + "]", e);
    }
    EcoregionFinder regionFinder = getEcoregionFinder();
    if (regionFinder != null) {
        regionFinder.shutdown();
    }
}
Also used : OpenTreeTaxonIndex(org.eol.globi.opentree.OpenTreeTaxonIndex) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) EcoregionFinder(org.eol.globi.geo.EcoregionFinder) DatasetFinderLocal(org.globalbioticinteractions.dataset.DatasetFinderLocal) URISyntaxException(java.net.URISyntaxException) Options(org.apache.commons.cli.Options) TaxonCacheService(org.eol.globi.taxon.TaxonCacheService) DOIResolverCache(org.eol.globi.service.DOIResolverCache) ResolvingTaxonIndex(org.eol.globi.taxon.ResolvingTaxonIndex) HelpFormatter(org.apache.commons.cli.HelpFormatter) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) StudyImporterException(org.eol.globi.data.StudyImporterException) EcoregionFinderProxy(org.eol.globi.service.EcoregionFinderProxy) ParserFactoryLocal(org.eol.globi.data.ParserFactoryLocal) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) GraphService(org.eol.globi.db.GraphService) URI(java.net.URI) EcoregionFinderFactoryImpl(org.eol.globi.geo.EcoregionFinderFactoryImpl) HttpUtil(org.eol.globi.util.HttpUtil) Option(org.apache.commons.cli.Option) Taxon(org.eol.globi.domain.Taxon) CommandLineParser(org.apache.commons.cli.CommandLineParser) MalformedURLException(java.net.MalformedURLException) CacheLocalReadonly(org.globalbioticinteractions.cache.CacheLocalReadonly) DatasetFinder(org.eol.globi.service.DatasetFinder) DatasetLocal(org.eol.globi.service.DatasetLocal) StudyImporterForGitHubData(org.eol.globi.data.StudyImporterForGitHubData) DOIResolverImpl(org.eol.globi.service.DOIResolverImpl) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) List(java.util.List) StudyImporter(org.eol.globi.data.StudyImporter) ParseException(org.apache.commons.cli.ParseException) GraphExporterImpl(org.eol.globi.export.GraphExporterImpl) Version(org.eol.globi.Version) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) CacheFactory(org.globalbioticinteractions.cache.CacheFactory) EcoregionFinder(org.eol.globi.geo.EcoregionFinder) StudyImporterForGitHubData(org.eol.globi.data.StudyImporterForGitHubData) DOIResolverImpl(org.eol.globi.service.DOIResolverImpl) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) DatasetLocal(org.eol.globi.service.DatasetLocal) StudyImporter(org.eol.globi.data.StudyImporter) CacheLocalReadonly(org.globalbioticinteractions.cache.CacheLocalReadonly) StudyImporterException(org.eol.globi.data.StudyImporterException) DatasetFinder(org.eol.globi.service.DatasetFinder) CacheFactory(org.globalbioticinteractions.cache.CacheFactory) DatasetFinderLocal(org.globalbioticinteractions.dataset.DatasetFinderLocal) ParserFactoryLocal(org.eol.globi.data.ParserFactoryLocal)

Example 4 with StudyImporterException

use of org.eol.globi.data.StudyImporterException in project eol-globi-data by jhpoelen.

the class GitHubImporterFactory method createImporter.

public StudyImporter createImporter(Dataset dataset, final NodeFactory nodeFactory) throws StudyImporterException {
    Class<? extends StudyImporter> anImporter = findImporterFor(dataset);
    try {
        Constructor<? extends StudyImporter> constructor = anImporter.getConstructor(ParserFactory.class, NodeFactory.class);
        ParserFactoryForDataset parserFactory = new ParserFactoryForDataset(dataset);
        StudyImporter studyImporter = constructor.newInstance(parserFactory, new NodeFactoryWithDatasetContext(nodeFactory, dataset));
        studyImporter.setDataset(dataset);
        return studyImporter;
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
        throw new StudyImporterException("failed to instantiate importer for [" + dataset.getNamespace() + "]", e);
    }
}
Also used : StudyImporterException(org.eol.globi.data.StudyImporterException) ParserFactoryForDataset(org.eol.globi.data.ParserFactoryForDataset) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyImporter(org.eol.globi.data.StudyImporter) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with StudyImporterException

use of org.eol.globi.data.StudyImporterException in project eol-globi-data by jhpoelen.

the class GraphExporterImpl method exportDarwinCoreArchive.

private void exportDarwinCoreArchive(List<Study> studies, String pathPrefix, Map<String, DarwinCoreExporter> exporters) throws StudyImporterException {
    try {
        FileUtils.forceMkdir(new File(pathPrefix));
        FileWriter darwinCoreMeta = writeMetaHeader(pathPrefix);
        for (Map.Entry<String, DarwinCoreExporter> exporter : exporters.entrySet()) {
            export(studies, pathPrefix, exporter.getKey(), exporter.getValue(), darwinCoreMeta);
        }
        writeMetaFooter(darwinCoreMeta);
    } catch (IOException e) {
        throw new StudyImporterException("failed to export result to csv file", e);
    }
}
Also used : StudyImporterException(org.eol.globi.data.StudyImporterException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StudyImporterException (org.eol.globi.data.StudyImporterException)9 IOException (java.io.IOException)3 Study (org.eol.globi.domain.Study)3 FileOutputStream (java.io.FileOutputStream)2 StudyImporter (org.eol.globi.data.StudyImporter)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 BasicParser (org.apache.commons.cli.BasicParser)1