Search in sources :

Example 61 with TaxonImpl

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());
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Test(org.junit.Test)

Example 62 with TaxonImpl

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);
}
Also used : TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 63 with TaxonImpl

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));
        }
    }
}
Also used : Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) JsonNode(org.codehaus.jackson.JsonNode)

Example 64 with TaxonImpl

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;
}
Also used : TaxonImage(org.eol.globi.domain.TaxonImage) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) EOLService(org.eol.globi.taxon.EOLService)

Example 65 with TaxonImpl

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;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) ArrayList(java.util.ArrayList)

Aggregations

TaxonImpl (org.eol.globi.domain.TaxonImpl)123 Specimen (org.eol.globi.domain.Specimen)59 Test (org.junit.Test)54 Taxon (org.eol.globi.domain.Taxon)42 StudyImpl (org.eol.globi.domain.StudyImpl)34 Study (org.eol.globi.domain.Study)32 Location (org.eol.globi.domain.Location)16 LocationImpl (org.eol.globi.domain.LocationImpl)15 TaxonNode (org.eol.globi.domain.TaxonNode)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 IOException (java.io.IOException)11 TermImpl (org.eol.globi.domain.TermImpl)11 StringWriter (java.io.StringWriter)9 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)7 Map (java.util.Map)5 Node (org.neo4j.graphdb.Node)5 File (java.io.File)4