Search in sources :

Example 1 with EcoregionFinder

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

the class NodeFactoryNeo4j method associateWithEcoRegions.

private List<Ecoregion> associateWithEcoRegions(Location location) throws NodeFactoryException {
    List<Ecoregion> associatedEcoregions = new ArrayList<Ecoregion>();
    try {
        EcoregionFinder finder = getEcoregionFinder();
        if (finder != null) {
            Collection<Ecoregion> ecoregions = finder.findEcoregion(location.getLatitude(), location.getLongitude());
            for (Ecoregion ecoregion : ecoregions) {
                associateLocationWithEcoRegion(location, ecoregion);
                associatedEcoregions.add(ecoregion);
            }
        }
    } catch (EcoregionFinderException e) {
        throw new NodeFactoryException("problem finding eco region for location (lat,lng):(" + location.getLatitude() + "," + location.getLongitude() + ")");
    }
    return associatedEcoregions;
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) ArrayList(java.util.ArrayList) EcoregionFinderException(org.eol.globi.geo.EcoregionFinderException)

Example 2 with EcoregionFinder

use of org.eol.globi.geo.EcoregionFinder 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 3 with EcoregionFinder

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

the class NormalizerTest method createNormalizer.

private Normalizer createNormalizer() {
    Normalizer dataNormalizationTool = new Normalizer();
    dataNormalizationTool.setEcoregionFinder(new EcoregionFinder() {

        @Override
        public Collection<Ecoregion> findEcoregion(double lat, double lng) throws EcoregionFinderException {
            final Ecoregion ecoregion = new Ecoregion();
            ecoregion.setName("some name");
            ecoregion.setPath("some | path");
            ecoregion.setId("someId");
            ecoregion.setGeometry("POINT(1,2)");
            return new ArrayList<Ecoregion>() {

                {
                    add(ecoregion);
                }
            };
        }

        @Override
        public void shutdown() {
        }
    });
    return dataNormalizationTool;
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) EcoregionFinderException(org.eol.globi.geo.EcoregionFinderException) Collection(java.util.Collection)

Example 4 with EcoregionFinder

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

the class GraphDBTestCase method createNodeFactory.

NodeFactory createNodeFactory() {
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j(getGraphDb());
    nodeFactoryNeo4j.setEcoregionFinder(new EcoregionFinder() {

        @Override
        public Collection<Ecoregion> findEcoregion(double lat, double lng) throws EcoregionFinderException {
            final Ecoregion ecoregion = new Ecoregion();
            ecoregion.setName("some eco region");
            ecoregion.setPath("some | eco | region | path");
            ecoregion.setId("some:id");
            ecoregion.setGeometry("POINT(0,0)");
            return new ArrayList<Ecoregion>() {

                {
                    add(ecoregion);
                }
            };
        }

        @Override
        public void shutdown() {
        }
    });
    nodeFactoryNeo4j.setEnvoLookupService(getEnvoLookupService());
    nodeFactoryNeo4j.setTermLookupService(getTermLookupService());
    return nodeFactoryNeo4j;
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) EcoregionFinderException(org.eol.globi.geo.EcoregionFinderException) Collection(java.util.Collection)

Example 5 with EcoregionFinder

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

the class EcoregionFinderProxyTest method multipleRegionsForSingleLocation.

@Test
public void multipleRegionsForSingleLocation() throws EcoregionFinderException {
    ArrayList<EcoregionFinder> finders = new ArrayList<EcoregionFinder>() {

        {
            add(new EcoregionTestFinder("one:"));
            add(new EcoregionTestFinder("two:"));
            add(new EcoregionTestFinder("two:"));
            add(new EcoregionTestFinder("three:"));
        }
    };
    Collection<Ecoregion> ecoregion = new EcoregionFinderProxy(finders).findEcoregion(9.2, -79.91667);
    Collection<String> ids = new ArrayList<String>();
    for (Ecoregion region : ecoregion) {
        ids.add(region.getId());
    }
    assertThat(ids.contains("one:123"), is(true));
    assertThat(ids.contains("two:123"), is(true));
    assertThat(ids.contains("three:123"), is(true));
    assertThat(ecoregion.size(), is(3));
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

EcoregionFinder (org.eol.globi.geo.EcoregionFinder)5 Ecoregion (org.eol.globi.geo.Ecoregion)4 ArrayList (java.util.ArrayList)3 EcoregionFinderException (org.eol.globi.geo.EcoregionFinderException)3 Collection (java.util.Collection)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 BasicParser (org.apache.commons.cli.BasicParser)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Version (org.eol.globi.Version)1