Search in sources :

Example 1 with IZoologicalName

use of eu.etaxonomy.cdm.model.name.IZoologicalName in project cdmlib by cybertaxonomy.

the class BasionymsMustShareEpithetsAndAuthorsTest method testZoologicalReference.

@Test
public void testZoologicalReference() {
    Reference nomRef = ReferenceFactory.newBook();
    Reference nomRef2 = ReferenceFactory.newBook();
    IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
    zooName.setGenusOrUninomial("Aus");
    zooName.setSpecificEpithet("aus");
    zooName.setBasionymAuthorship(author1);
    zooName.setNomenclaturalReference(nomRef);
    IZoologicalName originalCombination = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
    originalCombination.setGenusOrUninomial("Aus");
    originalCombination.setSpecificEpithet("aus");
    originalCombination.setCombinationAuthorship(author1);
    originalCombination.setNomenclaturalReference(nomRef);
    zooName.addBasionym(TaxonName.castAndDeproxy(originalCombination));
    Assert.assertEquals(1, zooName.getNameRelations().size());
    NameRelationship basRel = zooName.getNameRelations().iterator().next();
    Set<ConstraintViolation<NameRelationship>> constraintViolations = validator.validate(basRel, Level3.class);
    assertNoConstraintOnValidator((Set) constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
    originalCombination.setNomenclaturalReference(nomRef2);
    Assert.assertEquals(1, zooName.getNameRelations().size());
    basRel = zooName.getNameRelations().iterator().next();
    constraintViolations = validator.validate(basRel, Level3.class);
    assertHasConstraintOnValidator((Set) constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
    // reset
    originalCombination.setNomenclaturalReference(nomRef);
    Assert.assertEquals(1, zooName.getNameRelations().size());
    basRel = zooName.getNameRelations().iterator().next();
    constraintViolations = validator.validate(basRel, Level3.class);
    assertNoConstraintOnValidator((Set) constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
    zooName.setNomenclaturalMicroReference("A");
    originalCombination.setNomenclaturalMicroReference("B");
    Assert.assertEquals(1, zooName.getNameRelations().size());
    basRel = zooName.getNameRelations().iterator().next();
    constraintViolations = validator.validate(basRel, Level3.class);
    assertHasConstraintOnValidator((Set) constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) NameRelationship(eu.etaxonomy.cdm.model.name.NameRelationship) ConstraintViolation(javax.validation.ConstraintViolation) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName) Test(org.junit.Test)

Example 2 with IZoologicalName

use of eu.etaxonomy.cdm.model.name.IZoologicalName in project cdmlib by cybertaxonomy.

the class TaxonComparatorTest method createTestData.

private List<TaxonBase<?>> createTestData() {
    Reference sec = ReferenceFactory.newBook();
    Reference ref1 = ReferenceFactory.newArticle();
    ref1.setAbbrevTitle("Gard. Dict. ed. 7 110, 2 1759");
    Reference ref2 = ReferenceFactory.newBook();
    Reference ref3 = ReferenceFactory.newBook();
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    Calendar cal3 = Calendar.getInstance();
    cal1.set(1759, 3, 2);
    cal2.set(1856, 3, 2);
    cal3.set(1943, 3, 2);
    ref1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(cal1));
    // ref2.setDatePublished(TimePeriod.NewInstance(cal2));
    ref3.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(cal3));
    Person author1 = Person.NewTitledInstance("Rehder");
    author1.setNomenclaturalTitle("Rehder");
    Person author4 = Person.NewTitledInstance("Mill.");
    author1.setNomenclaturalTitle("Mill.");
    Person author2 = Person.NewTitledInstance("A.Murray");
    author2.setNomenclaturalTitle("A.Murray");
    Person author3 = Person.NewTitledInstance("Lemmon");
    author3.setNomenclaturalTitle("Lemmon");
    IBotanicalName botName1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(), "Abies", null, "procera", null, author1, ref1, null, null);
    IBotanicalName botName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(), "Abies", null, "magnifica", null, author2, ref2, null, null);
    IBotanicalName botName3 = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS(), "Abies", null, null, null, author4, ref1, null, null);
    IBotanicalName botName4 = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY(), "Abies", null, "magnifica", "shastensis", author3, ref3, null, null);
    IZoologicalName zooName1 = TaxonNameFactory.NewZoologicalInstance(null);
    // botName3.setNomenclaturalReference(ref3);
    zooName1.setPublicationYear(1823);
    List<TaxonBase<?>> list = new ArrayList<TaxonBase<?>>();
    Taxon taxon1 = Taxon.NewInstance(botName1, sec);
    Taxon taxon2 = Taxon.NewInstance(botName2, sec);
    Taxon taxon3 = Taxon.NewInstance(botName3, sec);
    Taxon taxon4 = Taxon.NewInstance(botName4, sec);
    Taxon zooTaxon4 = Taxon.NewInstance(zooName1, sec);
    taxon1.setId(1);
    taxon2.setId(2);
    taxon3.setId(3);
    taxon4.setId(4);
    zooTaxon4.setId(5);
    list.add(taxon3);
    list.add(taxon2);
    list.add(taxon1);
    list.add(taxon4);
    list.add(zooTaxon4);
    return list;
}
Also used : IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) Reference(eu.etaxonomy.cdm.model.reference.Reference) Calendar(java.util.Calendar) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ArrayList(java.util.ArrayList) Person(eu.etaxonomy.cdm.model.agent.Person) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName)

Example 3 with IZoologicalName

use of eu.etaxonomy.cdm.model.name.IZoologicalName in project cdmlib by cybertaxonomy.

the class NonViralNameParserImpl method handleAuthors.

public void handleAuthors(INonViralName nameToBeFilled, String fullNameString, String authorString) {
    TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
    Integer[] years = new Integer[4];
    try {
        NomenclaturalCode code = nameToBeFilled.getNameType();
        fullAuthors(authorString, authors, years, code);
    } catch (StringNotParsableException e) {
        nameToBeFilled.addParsingProblem(ParserProblem.UnparsableAuthorPart);
        nameToBeFilled.setTitleCache(fullNameString, true);
        // FIXME Quick fix, otherwise search would not deliver results for unparsable names
        nameToBeFilled.setNameCache(fullNameString, true);
        // END
        logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");
    }
    nameToBeFilled.setCombinationAuthorship(authors[0]);
    nameToBeFilled.setExCombinationAuthorship(authors[1]);
    nameToBeFilled.setBasionymAuthorship(authors[2]);
    nameToBeFilled.setExBasionymAuthorship(authors[3]);
    if (nameToBeFilled.isZoological()) {
        IZoologicalName zooName = (IZoologicalName) nameToBeFilled;
        zooName.setPublicationYear(years[0]);
        zooName.setOriginalPublicationYear(years[2]);
    }
}
Also used : NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) TeamOrPersonBase(eu.etaxonomy.cdm.model.agent.TeamOrPersonBase) StringNotParsableException(eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName)

Example 4 with IZoologicalName

use of eu.etaxonomy.cdm.model.name.IZoologicalName in project cdmlib by cybertaxonomy.

the class NonViralNameParserImpl method parseReference.

private void parseReference(INonViralName nameToBeFilled, String strReference, boolean isInReference) {
    INomenclaturalReference ref;
    String originalStrReference = strReference;
    // End (just delete end (e.g. '.', may be ambigous for yearPhrase, but no real information gets lost
    Matcher endMatcher = getMatcher(referenceEnd + end, strReference);
    if (endMatcher.find()) {
        String endPart = endMatcher.group(0);
        strReference = strReference.substring(0, strReference.length() - endPart.length());
    }
    // String pDetailYear = ".*" + detailSeparator + detail + fWs + yearSeperator + fWs + yearPhrase + fWs + end;
    // Matcher detailYearMatcher = getMatcher(pDetailYear, strReference);
    String strReferenceWithYear = strReference;
    // year
    String yearPart = null;
    String pYearPhrase = yearSeperator + fWs + yearPhrase + fWs + end;
    Matcher yearPhraseMatcher = getMatcher(pYearPhrase, strReference);
    if (yearPhraseMatcher.find()) {
        yearPart = yearPhraseMatcher.group(0);
        strReference = strReference.substring(0, strReference.length() - yearPart.length());
        yearPart = yearPart.replaceFirst(pStart + yearSeperator, "").trim();
    } else {
        if (nameToBeFilled.isZoological()) {
            IZoologicalName zooName = (IZoologicalName) CdmBase.deproxy(nameToBeFilled);
            yearPart = String.valueOf(zooName.getPublicationYear());
        // continue
        } else {
            ref = makeDetailYearUnparsable(nameToBeFilled, strReference);
            ref.setDatePublished(TimePeriodParser.parseStringVerbatim(yearPart));
            return;
        }
    }
    // detail
    String pDetailPhrase = detailSeparator + fWs + detail + fWs + end;
    Matcher detailPhraseMatcher = getMatcher(pDetailPhrase, strReference);
    if (detailPhraseMatcher.find()) {
        String detailPart = detailPhraseMatcher.group(0);
        strReference = strReference.substring(0, strReference.length() - detailPart.length());
        detailPart = detailPart.replaceFirst(pStart + detailSeparator, "").trim();
        nameToBeFilled.setNomenclaturalMicroReference(detailPart);
    } else {
        makeDetailYearUnparsable(nameToBeFilled, strReferenceWithYear);
        return;
    }
    // parse title and author
    ref = parseReferenceTitle(strReference, yearPart, isInReference);
    if (ref.hasProblem()) {
        // we need to protect both caches otherwise the titleCache is incorrectly build from atomized parts
        ref.setTitleCache((isInReference ? "in " : "") + originalStrReference, true);
        ref.setAbbrevTitleCache((isInReference ? "in " : "") + originalStrReference, true);
    }
    nameToBeFilled.setNomenclaturalReference(ref);
    int end = Math.min(strReference.length(), ref.getProblemEnds());
    ref.setProblemEnds(end);
}
Also used : Matcher(java.util.regex.Matcher) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName)

Example 5 with IZoologicalName

use of eu.etaxonomy.cdm.model.name.IZoologicalName in project cdmlib by cybertaxonomy.

the class TaxonNameDaoHibernateImpl method findZoologicalNameByUUID.

@Override
public IZoologicalName findZoologicalNameByUUID(UUID uuid) {
    Criteria criteria = getSession().createCriteria(type);
    if (uuid != null) {
        criteria.add(Restrictions.eq("uuid", uuid));
    } else {
        logger.warn("UUID is NULL");
        return null;
    }
    @SuppressWarnings("unchecked") List<TaxonName> results = criteria.list();
    if (results.size() == 1) {
        defaultBeanInitializer.initializeAll(results, null);
        TaxonName taxonName = results.iterator().next();
        if (taxonName.isZoological()) {
            IZoologicalName zoologicalName = taxonName;
            return zoologicalName;
        } else {
            logger.warn("This UUID (" + uuid + ") does not belong to a ZoologicalName. It belongs to: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
        }
    } else if (results.size() > 1) {
        logger.error("Multiple results for UUID: " + uuid);
    } else if (results.size() == 0) {
        logger.info("No results for UUID: " + uuid);
    }
    return null;
}
Also used : TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Criteria(org.hibernate.Criteria) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName)

Aggregations

IZoologicalName (eu.etaxonomy.cdm.model.name.IZoologicalName)21 Test (org.junit.Test)10 Reference (eu.etaxonomy.cdm.model.reference.Reference)8 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)5 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)5 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)5 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)5 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)3 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)3 INomenclaturalReference (eu.etaxonomy.cdm.model.reference.INomenclaturalReference)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)3 StringNotParsableException (eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)3 Person (eu.etaxonomy.cdm.model.agent.Person)2 Team (eu.etaxonomy.cdm.model.agent.Team)2 TeamOrPersonBase (eu.etaxonomy.cdm.model.agent.TeamOrPersonBase)2 NomenclaturalCode (eu.etaxonomy.cdm.model.name.NomenclaturalCode)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 URI (eu.etaxonomy.cdm.common.URI)1