use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class NonResolvingTaxonIndexTest method createNullTaxon.
@Test
public final void createNullTaxon() throws NodeFactoryException {
Taxon taxon1 = new TaxonImpl(null, "EOL:1234");
taxon1.setPath(null);
TaxonNode taxon = taxonService.getOrCreateTaxon(taxon1);
assertThat(taxon, is(notNullValue()));
assertEquals("no name", taxon.getName());
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class GlobalNamesService method noMatch.
private void noMatch(TermMatchListener termMatchListener, JsonNode data) {
String suppliedNameString = getSuppliedNameString(data);
termMatchListener.foundTaxonForName(requestId(data), suppliedNameString, new TaxonImpl(suppliedNameString), NameType.NONE);
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class GlobalNamesService method parseClassification.
protected void parseClassification(TermMatchListener termMatchListener, JsonNode data, JsonNode aResult, TaxonomyProvider provider) {
Taxon taxon = new TaxonImpl();
String classificationPath = aResult.get("classification_path").asText();
taxon.setPath(parseList(classificationPath));
if (aResult.has("classification_path_ids")) {
String classificationPathIds = aResult.get("classification_path_ids").asText();
taxon.setPathIds(parseList(classificationPathIds, provider.getIdPrefix()));
}
String pathRanks = aResult.get("classification_path_ranks").asText();
taxon.setPathNames(parseList(pathRanks));
String[] ranks = pathRanks.split("\\|");
if (ranks.length > 0) {
String rank = ranks[ranks.length - 1];
taxon.setRank(rank);
}
String[] taxonNames = classificationPath.split("\\|");
if (ranks.length > 0 && taxonNames.length > 0) {
String taxonName = taxonNames[taxonNames.length - 1];
taxon.setName(taxonName);
} else {
taxon.setName(aResult.get("canonical_form").asText());
}
String taxonIdLabel = aResult.has("current_taxon_id") ? "current_taxon_id" : "taxon_id";
String taxonIdValue = aResult.get(taxonIdLabel).asText();
// see https://github.com/GlobalNamesArchitecture/gni/issues/35
if (!StringUtils.startsWith(taxonIdValue, "gn:")) {
String externalId = provider.getIdPrefix() + taxonIdValue;
taxon.setExternalId(externalId);
String suppliedNameString = getSuppliedNameString(data);
boolean isExactMatch = aResult.has("match_type") && aResult.get("match_type").getIntValue() < 3;
NameType nameType = isExactMatch ? NameType.SAME_AS : NameType.SIMILAR_TO;
if (isExactMatch && aResult.has("current_name_string")) {
nameType = NameType.SYNONYM_OF;
}
// related to https://github.com/GlobalNamesArchitecture/gni/issues/48
if (!pathTailRepetitions(taxon)) {
termMatchListener.foundTaxonForName(requestId(data), suppliedNameString, taxon, nameType);
}
}
if (aResult.has("vernaculars")) {
List<String> commonNames = new ArrayList<String>();
JsonNode vernaculars = aResult.get("vernaculars");
for (JsonNode vernacular : vernaculars) {
if (vernacular.has("name") && vernacular.has("language")) {
String name = vernacular.get("name").asText();
String language = vernacular.get("language").asText();
if (!StringUtils.equals(name, "null") && !StringUtils.equals(language, "null")) {
commonNames.add(vernacular.get("name").asText() + " @" + language);
}
}
}
if (commonNames.size() > 0) {
taxon.setCommonNames(StringUtils.join(commonNames, CharsetConstant.SEPARATOR));
}
}
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class EOLTaxonImageService method lookupImage.
private TaxonImage lookupImage(String externalId) throws PropertyEnricherException {
TaxonImage image;
Map<String, String> enrich = new EOLService().enrich(TaxonUtil.taxonToMap(new TaxonImpl(null, externalId)));
Taxon taxon = TaxonUtil.mapToTaxon(enrich);
image = taxonToTaxonImage(taxon);
return image;
}
use of org.eol.globi.domain.TaxonImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForBlewett method addPreyForPredator.
private List<Specimen> addPreyForPredator(String[] header, String[] line, Study study) throws NodeFactoryException {
List<Specimen> preyItems = new ArrayList<Specimen>();
int preyColumn = 4;
for (int i = preyColumn; i < header.length; i++) {
if (i < line.length) {
String preyCountString = line[i];
if (preyCountString.trim().length() > 0) {
try {
int preyCount = Integer.parseInt(preyCountString);
String preyName = header[i];
for (int j = 0; j < preyCount; j++) {
Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(preyName, null));
preyItems.add(preySpecimen);
}
} catch (NumberFormatException e) {
getLogger().warn(study, "failed to parse prey count line/column:");
}
}
}
}
return preyItems;
}
Aggregations