Search in sources :

Example 1 with ColdpTerm

use of life.catalogue.coldp.ColdpTerm in project backend by CatalogueOfLife.

the class ColdpReader method validate.

protected void validate() throws NormalizationFailedException.SourceInvalidException {
    super.validate();
    // allow only COL row types
    filterSchemas(rowType -> rowType instanceof ColdpTerm);
    // Fail early, if missing ignore file alltogether!!!
    for (ColdpTerm t : ID_SCHEMAS) {
        require(t, ColdpTerm.ID);
    }
    for (ColdpTerm t : NAMEID_SCHEMAS) {
        require(t, ColdpTerm.nameID);
    }
    Term nameRowType = requireOneSchema(ColdpTerm.Name, ColdpTerm.NameUsage);
    require(ColdpTerm.NameRelation, ColdpTerm.relatedNameID);
    require(ColdpTerm.NameRelation, ColdpTerm.type);
    require(ColdpTerm.TaxonConceptRelation, ColdpTerm.relatedTaxonID);
    require(ColdpTerm.TaxonConceptRelation, ColdpTerm.type);
    require(ColdpTerm.SpeciesInteraction, ColdpTerm.type);
    // either require the scientificName or at least some parsed field
    if (!hasData(nameRowType, ColdpTerm.scientificName)) {
        LOG.warn("No scientificName mapped! Require parsed name fields");
        // genus & specificEpithet must exist otherwise!
        if (nameRowType.equals(ColdpTerm.NameUsage)) {
            requireOne(nameRowType, ColdpTerm.uninomial, ColdpTerm.genericName);
        } else {
            requireOne(nameRowType, ColdpTerm.uninomial, ColdpTerm.genus);
        }
    }
    // reference dependencies
    if (!hasReferences()) {
        LOG.warn("No Reference mapped! Disallow all referenceIDs");
        disallow(ColdpTerm.NameUsage, ColdpTerm.nameReferenceID);
        for (ColdpTerm rt : REFID_SCHEMAS) {
            disallow(rt, ColdpTerm.referenceID);
        }
    }
    Optional<Schema> taxonOpt = schema(ColdpTerm.Taxon).or(() -> schema(ColdpTerm.NameUsage));
    if (taxonOpt.isPresent()) {
        Schema taxon = taxonOpt.get();
        if (taxon.hasTerm(ColdpTerm.parentID)) {
            mappingFlags.setParentNameMapped(true);
        } else {
            mappingFlags.setParentNameMapped(false);
            LOG.warn("No taxon parentID mapped");
        }
        if (taxon.hasAnyTerm(ColdpTerm.DENORMALIZED_RANKS)) {
            mappingFlags.setDenormedClassificationMapped(true);
            LOG.info("Use denormalized taxon classification");
        } else {
            mappingFlags.setDenormedClassificationMapped(false);
        }
        for (ColdpTerm t : TAXID_SCHEMAS) {
            require(t, ColdpTerm.taxonID);
        }
        requireOne(ColdpTerm.Distribution, ColdpTerm.area, ColdpTerm.areaID);
        require(ColdpTerm.VernacularName, ColdpTerm.name);
        require(ColdpTerm.Media, ColdpTerm.url);
        if (hasSchema(ColdpTerm.Synonym)) {
            mappingFlags.setAcceptedNameMapped(true);
        } else {
            LOG.warn("No Synonyms mapped!");
        }
    } else {
        LOG.warn("No Taxa mapped, only inserting names!");
        for (ColdpTerm t : TAXID_SCHEMAS) {
            schemas.remove(t);
        }
    }
    reportMissingSchemas(ColdpTerm.class);
}
Also used : Schema(life.catalogue.csv.Schema) ColdpTerm(life.catalogue.coldp.ColdpTerm) ColdpTerm(life.catalogue.coldp.ColdpTerm) Term(org.gbif.dwc.terms.Term)

Example 2 with ColdpTerm

use of life.catalogue.coldp.ColdpTerm in project backend by CatalogueOfLife.

the class DataPackageBuilder method buildSchema.

private Schema buildSchema(String resource) {
    ColdpTerm rowType = ColdpTerm.find(FilenameUtils.getBaseName(resource), true);
    if (rowType == null) {
        throw new UnknownEntityException("Unknown entity " + resource);
    } else if (!rowType.isClass()) {
        throw new UnknownEntityException(resource + " is not a class term");
    }
    Schema s = new Schema();
    s.setRowType(rowType);
    for (ColdpTerm t : ColdpTerm.RESOURCES.get(rowType)) {
        String type = dataTypes.get(t.getType());
        String format = dataFormats.getOrDefault(t.getType(), Field.FORMAT_DEFAULT);
        Map<String, Object> constraints = new HashMap<>();
        if (enums.containsKey(t)) {
            constraints.put(Field.CONSTRAINT_KEY_ENUM, enumValues(rowType, t));
        }
        if (required.contains(t)) {
            constraints.put(Field.CONSTRAINT_KEY_REQUIRED, true);
        }
        if (ColdpTerm.ID == t) {
            s.setPrimaryKey(t.simpleName());
        // constraints.put(Field.CONSTRAINT_KEY_UNIQUE, true);
        }
        if (foreignKeys.containsKey(t)) {
            s.getForeignKeys().add(foreignKeys.get(t));
        }
        if (monomials.contains(t)) {
            constraints.put(Field.CONSTRAINT_KEY_PATTERN, MONOMIAL_PATTERN);
        }
        s.getFields().add(new Field(t.simpleName(), type, format, null, null, constraints));
    }
    return s;
}
Also used : ColdpTerm(life.catalogue.coldp.ColdpTerm)

Example 3 with ColdpTerm

use of life.catalogue.coldp.ColdpTerm in project backend by CatalogueOfLife.

the class InterpreterBase method interpretUsage.

public NeoUsage interpretUsage(ParsedNameUsage pnu, Term taxStatusTerm, TaxonomicStatus defaultStatus, VerbatimRecord v, Term... idTerms) {
    NeoUsage u;
    // a synonym by status?
    EnumNote<TaxonomicStatus> status = SafeParser.parse(TaxonomicStatusParser.PARSER, v.get(taxStatusTerm)).orElse(() -> new EnumNote<>(defaultStatus, null), Issue.TAXONOMIC_STATUS_INVALID, v);
    if (status.val.isBareName()) {
        u = NeoUsage.createBareName(Origin.SOURCE, pnu.getName());
    } else if (status.val.isSynonym()) {
        u = NeoUsage.createSynonym(Origin.SOURCE, pnu.getName(), status.val);
        if (pnu.isExtinct()) {
            // flag this as synonyms cannot have the extinct flag
            v.addIssue(Issue.NAME_CONTAINS_EXTINCT_SYMBOL);
        }
    } else {
        u = NeoUsage.createTaxon(Origin.SOURCE, pnu.getName(), status.val);
        if (pnu.isExtinct()) {
            ((Taxon) u.usage).setExtinct(true);
        }
    }
    // shared usage props
    u.setId(v.getFirstRaw(idTerms));
    u.setVerbatimKey(v.getId());
    setTaxonomicNote(u.usage, pnu.getTaxonomicNote(), v);
    u.homotypic = TaxonomicStatusParser.isHomotypic(status);
    // flat classification via dwc or coldp
    u.classification = new Classification();
    if (v.hasDwcTerms()) {
        for (DwcTerm t : DwcTerm.HIGHER_RANKS) {
            u.classification.setByTerm(t, v.get(t));
        }
        for (DwcUnofficialTerm t : DwcUnofficialTerm.HIGHER_RANKS) {
            u.classification.setByTerm(t, v.get(t));
        }
    }
    if (v.hasColdpTerms()) {
        for (ColdpTerm t : ColdpTerm.DENORMALIZED_RANKS) {
            u.classification.setByTerm(t, v.get(t));
        }
    }
    return u;
}
Also used : DwcUnofficialTerm(life.catalogue.coldp.DwcUnofficialTerm) NeoUsage(life.catalogue.importer.neo.model.NeoUsage) ColdpTerm(life.catalogue.coldp.ColdpTerm) DwcTerm(org.gbif.dwc.terms.DwcTerm)

Example 4 with ColdpTerm

use of life.catalogue.coldp.ColdpTerm in project backend by CatalogueOfLife.

the class ClassificationTest method higherRanks.

@Test
public void higherRanks() {
    Classification c = new Classification();
    int hash = c.hashCode();
    for (ColdpTerm t : ColdpTerm.DENORMALIZED_RANKS) {
        assertTrue(c.setByTerm(t, "xyz"));
        assertNotEquals("unused term " + t, hash, c.hashCode());
        hash = c.hashCode();
    }
    for (DwcTerm t : DwcTerm.HIGHER_RANKS) {
        assertTrue("unused term " + t, c.setByTerm(t, "foo"));
        assertNotEquals("unused term " + t, hash, c.hashCode());
        hash = c.hashCode();
    }
    for (DwcUnofficialTerm t : DwcUnofficialTerm.HIGHER_RANKS) {
        assertTrue("unused term " + t, c.setByTerm(t, "bar"));
        assertNotEquals("unused term " + t, hash, c.hashCode());
        hash = c.hashCode();
    }
    for (Rank r : Classification.RANKS) {
        assertTrue("unused rank " + r, c.setByRank(r, "grrr"));
        assertEquals("grrr", c.getByRank(r));
        assertNotEquals("unused rank " + r, hash, c.hashCode());
        hash = c.hashCode();
    }
}
Also used : DwcUnofficialTerm(life.catalogue.coldp.DwcUnofficialTerm) Rank(org.gbif.nameparser.api.Rank) ColdpTerm(life.catalogue.coldp.ColdpTerm) DwcTerm(org.gbif.dwc.terms.DwcTerm) Test(org.junit.Test)

Example 5 with ColdpTerm

use of life.catalogue.coldp.ColdpTerm in project backend by CatalogueOfLife.

the class ColdpTermTest method testNameUsage.

@Test
public void testNameUsage() {
    for (ColdpTerm t : RESOURCES.get(Name)) {
        if (t == genus)
            continue;
        assertTrue(RESOURCES.get(NameUsage).contains(t));
    }
    for (ColdpTerm t : RESOURCES.get(Taxon)) {
        if (t == provisional || t == nameID)
            continue;
        assertTrue(RESOURCES.get(NameUsage).contains(t));
    }
    for (ColdpTerm t : RESOURCES.get(Synonym)) {
        if (t == nameID || t == taxonID)
            continue;
        assertTrue(RESOURCES.get(NameUsage).contains(t));
    }
    // each term exists in at least one resource
    for (ColdpTerm t : ColdpTerm.values()) {
        if (t.isClass()) {
            assertTrue(t + " is no resource", RESOURCES.containsKey(t));
        } else {
            boolean found = false;
            for (var res : RESOURCES.values()) {
                if (res.contains(t)) {
                    found = true;
                    break;
                }
            }
            assertTrue(t + " without resource", found);
        }
    }
}
Also used : ColdpTerm(life.catalogue.coldp.ColdpTerm) Test(org.junit.Test)

Aggregations

ColdpTerm (life.catalogue.coldp.ColdpTerm)6 Test (org.junit.Test)3 DwcUnofficialTerm (life.catalogue.coldp.DwcUnofficialTerm)2 DwcTerm (org.gbif.dwc.terms.DwcTerm)2 Schema (life.catalogue.csv.Schema)1 NeoUsage (life.catalogue.importer.neo.model.NeoUsage)1 Term (org.gbif.dwc.terms.Term)1 Rank (org.gbif.nameparser.api.Rank)1