use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class TaxonUtilTest method copyTaxonPrefillExternalURL.
@Test
public void copyTaxonPrefillExternalURL() {
Taxon src = new TaxonImpl("name", "GBIF:123");
src.setStatus(new TermImpl("statusId", "statusLabel"));
Taxon target = new TaxonImpl();
TaxonUtil.copy(src, target);
assertThat(target.getStatus().getId(), is("statusId"));
assertThat(target.getStatus().getName(), is("statusLabel"));
assertThat(target.getExternalUrl(), is("http://www.gbif.org/species/123"));
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class TaxonUtilTest method homonymNull.
@Test
public void homonymNull() {
TaxonImpl otherTaxon = new TaxonImpl();
otherTaxon.setName("Lestes");
otherTaxon.setPath("Mammalia|Mesonychidae|Lestes");
otherTaxon.setPathNames("class|family|genus");
assertFalse(TaxonUtil.likelyHomonym(null, otherTaxon));
assertFalse(TaxonUtil.likelyHomonym(otherTaxon, null));
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class ImageLinkerTest method linkTaxonWithFunnyID.
@Test
public void linkTaxonWithFunnyID() throws NodeFactoryException {
Taxon taxon = taxonIndex.getOrCreateTaxon(new TaxonImpl("Donald duckus", "DUCK:123"));
assertNotNull(taxon);
new ImageLinker(getGraphDb(), System.out).link();
Taxon enrichedTaxon = taxonIndex.findTaxonById("DUCK:123");
assertThat(enrichedTaxon.getThumbnailUrl(), is(nullValue()));
assertThat(enrichedTaxon.getExternalUrl(), is(nullValue()));
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class IndexInteractionsTest method indexInteractions.
@Test
public void indexInteractions() throws NodeFactoryException {
TaxonIndex taxonIndex = getOrCreateTaxonIndex();
// see https://github.com/jhpoelen/eol-globi-data/wiki/Nanopubs
StudyImpl study = new StudyImpl("some study", "some source", "http://doi.org/123.23/222", "some study citation");
NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri")));
Study interaction = factory.getOrCreateStudy(study);
TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
TaxonImpl mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
Taxon mickeyTaxonNCBI = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonNCBI, getGraphDb(), RelTypes.SAME_AS);
Specimen mickey = factory.createSpecimen(interaction, mickeyTaxon);
mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxon));
donald.ate(mickey);
new IndexInteractions(getGraphDb()).link();
NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j(getGraphDb());
StudyImpl study1 = new StudyImpl("some study", "some source", null, "come citation");
study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri")));
StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
assertThat(interaction.getTitle(), is(someStudy.getTitle()));
Iterable<Relationship> specimens = NodeUtil.getSpecimens(someStudy);
RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
Set<Long> ids = new HashSet<>();
List<Long> idList = new ArrayList<>();
for (Relationship specimen : specimens) {
assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
Relationship singleRelationship = specimen.getEndNode().getSingleRelationship(hasParticipant, Direction.INCOMING);
long id = singleRelationship.getStartNode().getId();
ids.add(id);
idList.add(id);
}
assertThat(ids.size(), Is.is(1));
assertThat(idList.size(), Is.is(2));
Node interactionNode = getGraphDb().getNodeById(idList.get(0));
assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.DERIVED_FROM)));
assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.ACCESSED_AT)));
}
use of org.eol.globi.domain.TaxonImpl 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()));
}
Aggregations