use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class ExportUnmatchedTaxonNamesTest method dog.
private Taxon dog() {
Taxon dog = new TaxonImpl("Canis lupus");
dog.setExternalId("canisLupusId");
dog.setPath("four five six");
return dog;
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class TaxonLookupServiceImplTest method createIndexDoLookupBlankName.
@Test
public void createIndexDoLookupBlankName() throws IOException {
TaxonLookupServiceImpl taxonLookupServiceImpl = new TaxonLookupServiceImpl(new RAMDirectory());
taxonLookupServiceImpl.start();
taxonLookupServiceImpl.addTerm(new TaxonImpl("Homo sapiens", "1234"));
taxonLookupServiceImpl.addTerm(new TaxonImpl("Prefix Homo sapiens suffix", "12346"));
taxonLookupServiceImpl.finish();
Taxon[] ids = taxonLookupServiceImpl.lookupTermsByName(null);
assertThat(ids.length, Is.is(0));
taxonLookupServiceImpl.destroy();
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class TaxonLookupServiceImplTest method lookup.
public void lookup(RAMDirectory indexDir) throws IOException {
TaxonLookupServiceImpl service = new TaxonLookupServiceImpl(indexDir);
service.start();
TaxonImpl term = new TaxonImpl("Homo sapiens", "1234");
term.setPath("one | two | three");
term.setPathIds("1 | 2 | 3");
term.setPathNames("name1 | name2 | name3");
term.setCommonNames("Mensch");
service.addTerm(term);
TaxonImpl term1 = new TaxonImpl("Prefix Homo sapiens suffix", "12346");
term1.setPathIds("1 | 2 | 3");
service.addTerm(term1);
service.finish();
Taxon[] ids = service.lookupTermsByName("Homo sapiens");
assertThat(ids.length, Is.is(1));
assertThat(ids[0].getExternalId(), Is.is("1234"));
ids = service.lookupTermsById("1234");
assertThat(ids.length, Is.is(1));
assertThat(ids[0].getExternalId(), Is.is("1234"));
assertThat(ids[0].getName(), Is.is("Homo sapiens"));
assertThat(ids[0].getCommonNames(), Is.is("Mensch"));
assertThat(ids[0].getPathIds(), Is.is("1 | 2 | 3"));
assertThat(ids[0].getPath(), Is.is("one | two | three"));
assertThat(ids[0].getPathNames(), Is.is("name1 | name2 | name3"));
assertThat(service.lookupTermsById("12346")[0].getPathIds(), Is.is("1 | 2 | 3"));
service.destroy();
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForHurlbert method importInteraction.
protected void importInteraction(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, Study study, String preyTaxonName, String predatorName) throws StudyImporterException {
try {
Taxon predatorTaxon = new TaxonImpl(predatorName);
Specimen predatorSpecimen = nodeFactory.createSpecimen(study, predatorTaxon);
setBasisOfRecordAsLiterature(predatorSpecimen);
Taxon preyTaxon = new TaxonImpl(preyTaxonName);
String preyNameId = StringUtils.trim(columnValueOrNull(record, "Prey_Name_ITIS_ID"));
if (NumberUtils.isDigits(preyNameId)) {
preyTaxon.setExternalId(TaxonomyProvider.ITIS.getIdPrefix() + preyNameId);
}
Specimen preySpecimen = nodeFactory.createSpecimen(study, preyTaxon);
setBasisOfRecordAsLiterature(preySpecimen);
String preyStage = StringUtils.trim(columnValueOrNull(record, "Prey_Stage"));
if (StringUtils.isNotBlank(preyStage)) {
Term lifeStage = nodeFactory.getOrCreateLifeStage("HULBERT:" + StringUtils.replace(preyStage, " ", "_"), preyStage);
preySpecimen.setLifeStage(lifeStage);
}
String preyPart = StringUtils.trim(columnValueOrNull(record, "Prey_Part"));
if (StringUtils.isNotBlank(preyPart)) {
Term term = nodeFactory.getOrCreateBodyPart("HULBERT:" + StringUtils.replace(preyPart, " ", "_"), preyPart);
preySpecimen.setBodyPart(term);
}
Date date = addCollectionDate(record, study);
nodeFactory.setUnixEpochProperty(predatorSpecimen, date);
nodeFactory.setUnixEpochProperty(preySpecimen, date);
LocationImpl location = new LocationImpl(null, null, null, null);
String longitude = columnValueOrNull(record, "Longitude_dd");
String latitude = columnValueOrNull(record, "Latitude_dd");
if (NumberUtils.isNumber(latitude) && NumberUtils.isNumber(longitude)) {
try {
LatLng latLng = LocationUtil.parseLatLng(latitude, longitude);
String altitude = columnValueOrNull(record, "Altitude_mean_m");
Double altitudeD = NumberUtils.isNumber(altitude) ? Double.parseDouble(altitude) : null;
location = new LocationImpl(latLng.getLat(), latLng.getLng(), altitudeD, null);
} catch (InvalidLocationException e) {
getLogger().warn(study, "found invalid (lat,lng) pair: (" + latitude + "," + longitude + ")");
}
}
String locationRegion = columnValueOrNull(record, "Location_Region");
String locationSpecific = columnValueOrNull(record, "Location_Specific");
location.setLocality(StringUtils.join(Arrays.asList(locationRegion, locationSpecific), ":"));
Location locationNode = nodeFactory.getOrCreateLocation(location);
String habitat_type = columnValueOrNull(record, "Habitat_type");
List<Term> habitatList = Arrays.stream(StringUtils.split(StringUtils.defaultIfBlank(habitat_type, ""), ";")).map(StringUtils::trim).map(habitat -> new TermImpl(idForHabitat(habitat), habitat)).collect(Collectors.toList());
nodeFactory.addEnvironmentToLocation(locationNode, habitatList);
preySpecimen.caughtIn(locationNode);
predatorSpecimen.caughtIn(locationNode);
predatorSpecimen.ate(preySpecimen);
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create interaction between [" + predatorName + "] and [" + preyTaxonName + "]", e);
}
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForHafner method importStudy.
@Override
public void importStudy() throws StudyImporterException {
try {
LabeledCSVParser parser = parserFactory.createParser(RESOURCE, "UTF-8");
while (parser.getLine() != null) {
String sourceCitation = "Mark S. Hafner, Philip D. Sudman, Francis X. Villablanca, Theresa A. Spradling, James W. Demastes, Steven A. Nadler. (1994). Disparate Rates of Molecular Evolution in Cospeciating Hosts and Parasites. Science 265: 1087-1090. doi:10.1126/science.8066445";
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("hafner1994", "Shan Kothari, Pers. Comm. 2014.", "doi:10.1126/science.8066445", sourceCitation));
String hostName = parser.getValueByLabel("Host");
String parasiteName = parser.getValueByLabel("Parasite");
Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
Specimen parasite = nodeFactory.createSpecimen(study, new TaxonImpl(parasiteName, null));
parasite.interactsWith(host, InteractType.PARASITE_OF);
}
} catch (IOException | NodeFactoryException e) {
throw new StudyImporterException("failed to import [" + RESOURCE + "]", e);
}
}
Aggregations