Search in sources :

Example 1 with PropertyEnricher

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

the class ExportTaxonMapTest method exportOnePredatorTwoPrey.

@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
    final PropertyEnricher taxonEnricher = new PropertyEnricher() {

        @Override
        public Map<String, String> enrich(Map<String, String> properties) {
            Taxon taxon = new TaxonImpl();
            TaxonUtil.mapToTaxon(properties, taxon);
            if ("Homo sapiens".equals(taxon.getName())) {
                taxon.setExternalId("homoSapiensId");
                taxon.setPath("one two three");
            } else if ("Canis lupus".equals(taxon.getName())) {
                taxon.setExternalId("canisLupusId");
                taxon.setPath("four\tfive six");
            }
            return TaxonUtil.taxonToMap(taxon);
        }

        @Override
        public void shutdown() {
        }
    };
    taxonIndex = ExportTestUtil.taxonIndexWithEnricher(taxonEnricher, getGraphDb());
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("title", "source", null, "citation"));
    Taxon taxon = new TaxonImpl("Homo sapiens");
    taxon.setExternalId("homoSapiensId");
    taxon.setPath("one two three");
    taxon.setExternalUrl("http://some/thing");
    taxon.setThumbnailUrl("http://thing/some");
    nodeFactory.createSpecimen(study, taxon);
    Taxon human = taxonIndex.getOrCreateTaxon(taxon);
    TaxonImpl dog = new TaxonImpl("Canis lupus");
    dog.setExternalId("canisLupusId");
    dog.setPath("four\tfive six");
    nodeFactory.createSpecimen(study, dog);
    final TaxonImpl altTaxonWithPath = new TaxonImpl("Alternate Homo sapiens", "alt:123");
    altTaxonWithPath.setPath("some path here");
    NodeUtil.connectTaxa(altTaxonWithPath, (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
    NodeUtil.connectTaxa(new TaxonImpl("Alternate Homo sapiens no path", "alt:123"), (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
    NodeUtil.connectTaxa(new TaxonImpl("Similar Homo sapiens", "alt:456"), (TaxonNode) human, getGraphDb(), RelTypes.SIMILAR_TO);
    resolveNames();
    StringWriter writer = new StringWriter();
    new ExportTaxonMap().exportStudy(study, writer, true);
    assertThat(writer.toString(), is("providedTaxonId\tprovidedTaxonName\tresolvedTaxonId\tresolvedTaxonName" + "\nhomoSapiensId\tHomo sapiens\thomoSapiensId\tHomo sapiens" + "\nhomoSapiensId\tHomo sapiens\talt:123\tAlternate Homo sapiens" + "\ncanisLupusId\tCanis lupus\tcanisLupusId\tCanis lupus"));
}
Also used : Study(org.eol.globi.domain.Study) StringWriter(java.io.StringWriter) PropertyEnricher(org.eol.globi.service.PropertyEnricher) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Map(java.util.Map) Test(org.junit.Test)

Example 2 with PropertyEnricher

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

the class ResolvingTaxonIndexTest method synonymsAddedToIndexOnce.

@Test
public final void synonymsAddedToIndexOnce() throws NodeFactoryException {
    ResolvingTaxonIndex taxonService = createTaxonService(getGraphDb());
    taxonService.setEnricher(new PropertyEnricher() {

        private boolean firstTime = true;

        @Override
        public Map<String, String> enrich(Map<String, String> properties) throws PropertyEnricherException {
            Taxon taxon = TaxonUtil.mapToTaxon(properties);
            if ("not pref".equals(taxon.getName())) {
                if (!firstTime) {
                    fail("should already have indexed [" + taxon.getName() + "]...");
                }
                taxon.setName("preferred");
                taxon.setExternalId("bla:123");
                taxon.setPath("one | two | three");
                taxon.setPathIds("1 | 2 | 3");
                firstTime = false;
            }
            return TaxonUtil.taxonToMap(taxon);
        }

        @Override
        public void shutdown() {
        }
    });
    this.taxonService = taxonService;
    Taxon taxon2 = new TaxonImpl("not pref", null);
    taxon2.setPath(null);
    TaxonNode first = this.taxonService.getOrCreateTaxon(taxon2);
    assertThat(first.getName(), is("preferred"));
    assertThat(first.getPath(), is("one | two | three"));
    assertThat(first.getPathIds(), is("1 | 2 | 3"));
    Taxon taxon1 = new TaxonImpl("not pref", null);
    taxon1.setPath(null);
    TaxonNode second = this.taxonService.getOrCreateTaxon(taxon1);
    assertThat(second.getNodeID(), is(first.getNodeID()));
    TaxonNode third = this.taxonService.getOrCreateTaxon(new TaxonImpl("not pref"));
    assertThat(third.getNodeID(), is(first.getNodeID()));
    TaxonNode foundTaxon = this.taxonService.findTaxonByName("not pref");
    assertThat(foundTaxon.getNodeID(), is(first.getNodeID()));
    foundTaxon = this.taxonService.findTaxonByName("preferred");
    assertThat(foundTaxon.getNodeID(), is(first.getNodeID()));
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) TaxonNode(org.eol.globi.domain.TaxonNode) PropertyEnricher(org.eol.globi.service.PropertyEnricher) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with PropertyEnricher

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

the class ResolvingTaxonIndexTest method createSpeciesMatchHigherOrder.

@Test
public void createSpeciesMatchHigherOrder() throws NodeFactoryException {
    PropertyEnricher enricher = new PropertyEnricher() {

        @Override
        public Map<String, String> enrich(Map<String, String> properties) throws PropertyEnricherException {
            Taxon taxon = TaxonUtil.mapToTaxon(properties);
            if ("bla bla".equals(taxon.getName())) {
                taxon.setPath("a path");
                taxon.setExternalId("anExternalId");
                taxon.setCommonNames(EXPECTED_COMMON_NAMES);
                taxon.setExternalUrl("someInfoUrl");
                taxon.setThumbnailUrl("someThumbnailUrl");
            }
            return TaxonUtil.taxonToMap(taxon);
        }

        @Override
        public void shutdown() {
        }
    };
    ResolvingTaxonIndex taxonService = createTaxonService(getGraphDb());
    taxonService.setEnricher(enricher);
    this.taxonService = taxonService;
    TaxonNode taxon = this.taxonService.getOrCreateTaxon(new TaxonImpl("bla bla bla"));
    assertEquals("bla bla", taxon.getName());
    assertEquals("a path", taxon.getPath());
    assertEquals("anExternalId", taxon.getExternalId());
    assertEquals("someInfoUrl", taxon.getExternalUrl());
    assertEquals("someThumbnailUrl", taxon.getThumbnailUrl());
    taxon = this.taxonService.getOrCreateTaxon(new TaxonImpl("bla bla boo"));
    assertEquals("bla bla", taxon.getName());
    assertEquals("a path", taxon.getPath());
    assertEquals("anExternalId", taxon.getExternalId());
    taxon = this.taxonService.getOrCreateTaxon(new TaxonImpl("boo bla"));
    assertEquals("boo bla", taxon.getName());
    assertThat(taxon.getExternalId(), is(PropertyAndValueDictionary.NO_MATCH));
    assertNull(taxon.getPath());
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) PropertyEnricher(org.eol.globi.service.PropertyEnricher) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Map (java.util.Map)3 Taxon (org.eol.globi.domain.Taxon)3 TaxonImpl (org.eol.globi.domain.TaxonImpl)3 PropertyEnricher (org.eol.globi.service.PropertyEnricher)3 Test (org.junit.Test)3 TreeMap (java.util.TreeMap)2 TaxonNode (org.eol.globi.domain.TaxonNode)2 StringWriter (java.io.StringWriter)1 Study (org.eol.globi.domain.Study)1 StudyImpl (org.eol.globi.domain.StudyImpl)1 PropertyEnricherException (org.eol.globi.service.PropertyEnricherException)1