Search in sources :

Example 6 with INomenclaturalReference

use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.

the class NormalExplicitImport method createTaxon.

/**
 * @param state
 * @param rank
 * @param taxonNameStr
 * @param authorStr
 * @param nameStatus
 * @param nameStatus2
 * @param nc
 * @return
 */
private TaxonBase<?> createTaxon(TaxonExcelImportState state, Rank rank, String taxonNameStr, String authorStr, String publishingAutorStr, String basionymAuthor, String reference, String date, String nameStatus, String taxonomicStatus, NomenclaturalCode nc) {
    TaxonBase<?> taxonBase;
    INonViralName taxonName = null;
    if (nc == NomenclaturalCode.ICVCN) {
        logger.warn("ICVCN not yet supported");
    } else {
        // String taxonNameStr = titleCache.substring(0, titleCache.indexOf(authorStr));
        taxonName = nc.getNewTaxonNameInstance(rank);
        NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
        taxonName = parser.parseFullName(taxonNameStr, nc, rank);
        if (!taxonName.getNameCache().equals(taxonNameStr)) {
            taxonName.setNameCache(taxonNameStr, true);
        }
        // Create the author
        if (StringUtils.isNotBlank(authorStr)) {
            try {
                parser.parseAuthors(taxonName, authorStr);
            } catch (StringNotParsableException e) {
                taxonName.setAuthorshipCache(authorStr);
            }
        }
        if (StringUtils.isNotBlank(reference)) {
            String pub = CdmUtils.concat(" ", reference, ((NormalExplicitRow) state.getCurrentRow()).getCollation());
            String[] split = pub.split(":");
            pub = split[0];
            INomenclaturalReference ref = state.getReference(pub);
            if (ref == null) {
                ref = parser.parseReferenceTitle(pub, date, true);
                state.putReference(pub, (Reference) ref);
            }
            if (split.length > 1) {
                String detail = split[split.length - 1];
                taxonName.setNomenclaturalMicroReference(detail.trim());
            }
            if (ref.getAuthorship() == null) {
                ref.setAuthorship(taxonName.getCombinationAuthorship());
            }
            if (ref.getAbbrevTitle() == null && !ref.isOfType(ReferenceType.Article)) {
                ref.setAbbrevTitle(reference);
                ref.setProtectedAbbrevTitleCache(false);
            }
            ref.setProtectedTitleCache(false);
            taxonName.setNomenclaturalReference(ref);
        // taxonName.setNomenclaturalMicroReference(state.getCurrentRow().getCollation());
        }
    }
    // Create the taxon
    // Reference sec = state.getConfig().getSourceReference();
    // Create the status
    nameStatus = CdmUtils.Nz(nameStatus).trim().toLowerCase();
    taxonomicStatus = CdmUtils.Nz(taxonomicStatus).trim().toLowerCase();
    if (synonymMarkers.contains(nameStatus) || synonymMarkers.contains(taxonomicStatus)) {
        taxonBase = Synonym.NewInstance(taxonName, null);
    } else if (validMarkers.contains(nameStatus)) {
        taxonBase = Taxon.NewInstance(taxonName, null);
    } else {
        Taxon taxon = Taxon.NewInstance(taxonName, null);
        if (nameStatusMarkers.contains(nameStatus)) {
            if (nameStatus.equals(NOM_ILLEG)) {
                taxonName.addStatus(NomenclaturalStatusType.ILLEGITIMATE(), null, null);
            } else if (nameStatus.equals(NOM_REJ)) {
                taxonName.addStatus(NomenclaturalStatusType.REJECTED(), null, null);
            } else if (nameStatus.equals(NOM_CONS)) {
                taxonName.addStatus(NomenclaturalStatusType.CONSERVED(), null, null);
            }
        } else {
            taxon.setTaxonStatusUnknown(true);
        }
        taxonBase = taxon;
    }
    taxonBase.getName().addSource(OriginalSourceType.Import, null, "TaxonName", state.getConfig().getSourceReference(), null);
    taxonBase.addSource(OriginalSourceType.Import, null, "TaxonName", state.getConfig().getSourceReference(), null);
    return taxonBase;
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) NonViralNameParserImpl(eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) StringNotParsableException(eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)

Example 7 with INomenclaturalReference

use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.

the class NonViralNameParserImpl method makeNameWithReference.

private void makeNameWithReference(INonViralName nameToBeFilled, String fullReferenceString, Matcher nameAndRefSeparatorMatcher, Rank rank, boolean makeEmpty) {
    String nameAndSeparator = nameAndRefSeparatorMatcher.group(0);
    String name = nameAndRefSeparatorMatcher.group(1);
    String referenceString = fullReferenceString.substring(nameAndRefSeparatorMatcher.end());
    // is reference an in ref?
    String separator = nameAndSeparator.substring(name.length());
    boolean isInReference = separator.matches(inReferenceSeparator);
    // parse subparts
    int oldProblemEnds = nameToBeFilled.getProblemEnds();
    parseFullName(nameToBeFilled, name, rank, makeEmpty);
    nameToBeFilled.setProblemEnds(oldProblemEnds);
    // original spelling
    handleOriginalSpelling(nameToBeFilled);
    // zoological new combinations should not have a nom. reference to be parsed
    if (nameToBeFilled.isZoological()) {
        IZoologicalName zooName = (IZoologicalName) CdmBase.deproxy(nameToBeFilled);
        // is name new combination?
        if (zooName.getBasionymAuthorship() != null || zooName.getOriginalPublicationYear() != null) {
            ParserProblem parserProblem = ParserProblem.NewCombinationHasPublication;
            zooName.addParsingProblem(parserProblem);
            nameToBeFilled.setProblemStarts((nameToBeFilled.getProblemStarts() > -1) ? nameToBeFilled.getProblemStarts() : name.length());
            nameToBeFilled.setProblemEnds(Math.max(fullReferenceString.length(), nameToBeFilled.getProblemEnds()));
        }
    }
    parseReference(nameToBeFilled, referenceString, isInReference);
    INomenclaturalReference ref = nameToBeFilled.getNomenclaturalReference();
    // problem start
    int start = nameToBeFilled.getProblemStarts();
    int nameAndSeparatorLength = nameAndSeparator.length();
    if (nameToBeFilled.isProtectedTitleCache() || nameToBeFilled.getParsingProblems().contains(ParserProblem.CheckRank)) {
        start = Math.max(0, start);
    } else {
        if (ref != null && ref.getParsingProblem() != 0) {
            start = Math.max(nameAndSeparatorLength, start);
        // TODO search within ref
        }
    }
    // end
    int end = nameToBeFilled.getProblemEnds();
    if (ref != null && ref.getParsingProblem() != 0) {
        end = Math.min(nameAndSeparatorLength + ref.getProblemEnds(), end);
    } else {
        if (nameToBeFilled.isProtectedTitleCache()) {
            end = Math.min(end, nameAndSeparatorLength);
        // TODO search within name
        }
    }
    nameToBeFilled.setProblemStarts(start);
    nameToBeFilled.setProblemEnds(end);
    // delegate has problem to name
    if (ref != null && ref.getParsingProblem() != 0) {
        nameToBeFilled.addParsingProblems(ref.getParsingProblem());
    }
    Reference nomRef;
    if ((nomRef = nameToBeFilled.getNomenclaturalReference()) != null) {
        nomRef.setAuthorship(nameToBeFilled.getCombinationAuthorship());
    }
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) IVolumeReference(eu.etaxonomy.cdm.model.reference.IVolumeReference) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName)

Example 8 with INomenclaturalReference

use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.

the class NonViralNameParserImplTest method testParseReferencedName.

/**
 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
 */
@Test
public final void testParseReferencedName() {
    try {
        Method parseMethod = parser.getClass().getDeclaredMethod("parseReferencedName", String.class, NomenclaturalCode.class, Rank.class);
        testName_StringNomcodeRank(parseMethod);
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
    // null
    String strNull = null;
    Rank rankSpecies = Rank.SPECIES();
    INonViralName nameNull = parser.parseReferencedName(strNull, null, rankSpecies);
    assertNull(nameNull);
    // Empty
    String strEmpty = "";
    INonViralName nameEmpty = parser.parseReferencedName(strEmpty, null, rankSpecies);
    assertFalse(nameEmpty.hasProblem());
    assertEquals(strEmpty, nameEmpty.getFullTitleCache());
    assertNull(nameEmpty.getNomenclaturalMicroReference());
    // Whitespaces
    String strFullWhiteSpcaceAndDot = "Abies alba Mill.,  Sp.   Pl.  4:  455 .  1987 .";
    INonViralName namefullWhiteSpcaceAndDot = parser.parseReferencedName(strFullWhiteSpcaceAndDot, null, rankSpecies);
    assertFullRefStandard(namefullWhiteSpcaceAndDot);
    assertTrue(namefullWhiteSpcaceAndDot.getNomenclaturalReference().getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
    assertEquals("Abies alba Mill., Sp. Pl. 4: 455. 1987", namefullWhiteSpcaceAndDot.getFullTitleCache());
    // Book
    String fullReference = "Abies alba Mill., Sp. Pl. 4: 455. 1987";
    INonViralName name1 = parser.parseReferencedName(fullReference, null, rankSpecies);
    assertFullRefStandard(name1);
    assertTrue(name1.getNomenclaturalReference().getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
    assertEquals(fullReference, name1.getFullTitleCache());
    assertTrue("Name author and reference author should be the same", name1.getCombinationAuthorship() == name1.getNomenclaturalReference().getAuthorship());
    // Book Section
    fullReference = "Abies alba Mill. in Otto, Sp. Pl. 4(6): 455. 1987";
    INonViralName name2 = parser.parseReferencedName(fullReference + ".", null, rankSpecies);
    assertFullRefNameStandard(name2);
    assertEquals(fullReference, name2.getFullTitleCache());
    assertFalse(name2.hasProblem());
    INomenclaturalReference ref = name2.getNomenclaturalReference();
    assertEquals(ReferenceType.BookSection, ((Reference) ref).getType());
    IBookSection bookSection = (IBookSection) ref;
    IBook inBook = bookSection.getInBook();
    assertNotNull(inBook);
    assertNotNull(inBook.getAuthorship());
    assertEquals("Otto", inBook.getAuthorship().getTitleCache());
    assertEquals("Otto: Sp. Pl. 4(6)", inBook.getTitleCache());
    assertEquals("Sp. Pl.", inBook.getAbbrevTitle());
    assertEquals("4(6)", inBook.getVolume());
    assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorship() == name2.getNomenclaturalReference().getAuthorship());
    // Article
    fullReference = "Abies alba Mill. in Sp. Pl. 4(6): 455. 1987";
    INonViralName name3 = parser.parseReferencedName(fullReference, null, rankSpecies);
    assertFullRefNameStandard(name3);
    name3.setTitleCache(null);
    assertEquals(fullReference, name3.getFullTitleCache());
    assertFalse(name3.hasProblem());
    ref = name3.getNomenclaturalReference();
    assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
    // Article article = (Article)ref;
    IJournal journal = ((IArticle) ref).getInJournal();
    assertNotNull(journal);
    // assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
    assertEquals("Sp. Pl.", ((Reference) journal).getTitleCache());
    assertEquals("Sp. Pl.", journal.getAbbrevTitle());
    assertEquals("4(6)", ((IArticle) ref).getVolume());
    assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorship() == name3.getNomenclaturalReference().getAuthorship());
    // Article with volume range
    fullReference = "Abies alba Mill. in Sp. Pl. 4(1-2): 455. 1987";
    INonViralName name3a = parser.parseReferencedName(fullReference, null, rankSpecies);
    name3a.setTitleCache(null);
    assertEquals(fullReference, name3a.getFullTitleCache());
    assertFalse(name3a.hasProblem());
    ref = name3a.getNomenclaturalReference();
    assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
    assertEquals("4(1-2)", ((IArticle) ref).getVolume());
    // SoftArticle - having "," on position > 4
    String journalTitle = "Bull. Soc. Bot.France. Louis., Roi";
    String yearPart = " 1987 - 1989";
    String parsedYearFormatted = "1987" + SEP + "1989";
    String fullReferenceWithoutYear = "Abies alba Mill. in " + journalTitle + " 4(6): 455.";
    fullReference = fullReferenceWithoutYear + yearPart;
    String fullReferenceWithEnd = fullReference + ".";
    INonViralName name4 = parser.parseReferencedName(fullReferenceWithEnd, null, rankSpecies);
    assertFalse(name4.hasProblem());
    assertFullRefNameStandard(name4);
    assertEquals(fullReferenceWithoutYear + " " + parsedYearFormatted, name4.getFullTitleCache());
    ref = name4.getNomenclaturalReference();
    assertEquals(ReferenceType.Article, ref.getType());
    // article = (Article)ref;
    assertEquals(parsedYearFormatted, ref.getYear());
    journal = ((IArticle) ref).getInJournal();
    assertNotNull(journal);
    assertEquals(journalTitle, ((Reference) journal).getTitleCache());
    assertEquals(journalTitle, journal.getAbbrevTitle());
    assertEquals("4(6)", ((IArticle) ref).getVolume());
    // Zoo name
    String strNotParsableZoo = "Abies alba M., 1923, Sp. P. xxwer4352, nom. inval.";
    IZoologicalName nameZooRefNotParsabel = parser.parseReferencedName(strNotParsableZoo, null, null);
    assertTrue(nameZooRefNotParsabel.hasProblem());
    List<ParserProblem> list = nameZooRefNotParsabel.getParsingProblems();
    assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
    assertEquals(21, nameZooRefNotParsabel.getProblemStarts());
    assertEquals(37, nameZooRefNotParsabel.getProblemEnds());
    assertTrue(nameZooRefNotParsabel.getNomenclaturalReference().hasProblem());
    list = nameZooRefNotParsabel.getNomenclaturalReference().getParsingProblems();
    assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
    assertEquals(NomenclaturalCode.ICZN, nameZooRefNotParsabel.getNameType());
    assertEquals(Integer.valueOf(1923), nameZooRefNotParsabel.getPublicationYear());
    assertEquals(1, nameZooRefNotParsabel.getStatus().size());
    String strZooNameSineYear = "Homo sapiens L., 1758, Sp. An. 3: 345";
    IZoologicalName nameZooNameSineYear = parser.parseReferencedName(strZooNameSineYear);
    assertFalse(nameZooNameSineYear.hasProblem());
    assertEquals("Name without reference year must have year", (Integer) 1758, nameZooNameSineYear.getPublicationYear());
    assertEquals("Name without reference year must have year", "1758", nameZooNameSineYear.getNomenclaturalReference().getYear());
    String strZooNameNewCombination = "Homo sapiens (L., 1758) Mill., 1830, Sp. An. 3: 345";
    IZoologicalName nameZooNameNewCombination = parser.parseReferencedName(strZooNameNewCombination);
    assertTrue(nameZooNameNewCombination.hasProblem());
    list = nameZooNameNewCombination.getParsingProblems();
    assertTrue("List must contain new combination has publication warning ", list.contains(ParserProblem.NewCombinationHasPublication));
    assertEquals(35, nameZooNameNewCombination.getProblemStarts());
    assertEquals(51, nameZooNameNewCombination.getProblemEnds());
    // Special MicroRefs
    String strSpecDetail1 = "Abies alba Mill. in Sp. Pl. 4(6): [455]. 1987";
    INonViralName nameSpecDet1 = parser.parseReferencedName(strSpecDetail1 + ".", null, rankSpecies);
    assertFalse(nameSpecDet1.hasProblem());
    assertEquals(strSpecDetail1, nameSpecDet1.getFullTitleCache());
    assertEquals("[455]", nameSpecDet1.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail2 = "Abies alba Mill. in Sp. Pl. 4(6): couv. 2. 1987";
    INonViralName nameSpecDet2 = parser.parseReferencedName(strSpecDetail2 + ".", null, rankSpecies);
    assertFalse(nameSpecDet2.hasProblem());
    assertEquals(strSpecDetail2, nameSpecDet2.getFullTitleCache());
    assertEquals("couv. 2", nameSpecDet2.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail3 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455. 1987";
    INonViralName nameSpecDet3 = parser.parseReferencedName(strSpecDetail3 + ".", null, rankSpecies);
    assertFalse(nameSpecDet3.hasProblem());
    assertEquals(strSpecDetail3, nameSpecDet3.getFullTitleCache());
    assertEquals("fig. 455", nameSpecDet3.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail4 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455-567. 1987";
    fullReference = strSpecDetail4 + ".";
    INonViralName nameSpecDet4 = parser.parseReferencedName(fullReference, null, rankSpecies);
    assertFalse(nameSpecDet4.hasProblem());
    assertEquals(strSpecDetail4, nameSpecDet4.getFullTitleCache());
    assertEquals("fig. 455-567", nameSpecDet4.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail5 = "Abies alba Mill. in Sp. Pl. 4(6): Gard n\u00B0 4. 1987";
    fullReference = strSpecDetail5 + ".";
    INonViralName nameSpecDet5 = parser.parseReferencedName(fullReference, null, rankSpecies);
    assertFalse(nameSpecDet5.hasProblem());
    assertEquals(strSpecDetail5, nameSpecDet5.getFullTitleCache());
    assertEquals("Gard n\u00B0 4", nameSpecDet5.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail6 = "Abies alba Mill. in Sp. Pl. 4(6): 455a. 1987";
    fullReference = strSpecDetail6 + ".";
    INonViralName nameSpecDet6 = parser.parseReferencedName(fullReference, null, rankSpecies);
    assertFalse(nameSpecDet6.hasProblem());
    assertEquals(strSpecDetail6, nameSpecDet6.getFullTitleCache());
    assertEquals("455a", nameSpecDet6.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail7 = "Abies alba Mill. in Sp. Pl. 4(6): pp.455-457. 1987";
    fullReference = strSpecDetail7 + ".";
    INonViralName nameSpecDet7 = parser.parseReferencedName(fullReference, null, rankSpecies);
    assertFalse(nameSpecDet7.hasProblem());
    assertEquals(strSpecDetail7, nameSpecDet7.getFullTitleCache());
    assertEquals("pp.455-457", nameSpecDet7.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail8 = "Abies alba Mill. in Sp. Pl. 4(6): ppp.455-457. 1987";
    INonViralName nameSpecDet8 = parser.parseReferencedName(strSpecDetail8, null, rankSpecies);
    assertTrue(nameSpecDet8.hasProblem());
    // TODO better start behind :
    assertEquals(20, nameSpecDet8.getProblemStarts());
    // TODO better stop after -457
    assertEquals(51, nameSpecDet8.getProblemEnds());
    // Special MicroRefs
    String strSpecDetail9 = "Abies alba Mill. in Sp. Pl. 4(6): pp. 455 - 457. 1987";
    INonViralName nameSpecDet9 = parser.parseReferencedName(strSpecDetail9, null, rankSpecies);
    assertFalse(nameSpecDet9.hasProblem());
    assertEquals(strSpecDetail9, nameSpecDet9.getFullTitleCache());
    assertEquals("pp. 455 - 457", nameSpecDet9.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail10 = "Abies alba Mill. in Sp. Pl. 4(6): p 455. 1987";
    INonViralName nameSpecDet10 = parser.parseReferencedName(strSpecDetail10, null, rankSpecies);
    assertFalse(nameSpecDet10.hasProblem());
    assertEquals(strSpecDetail10, nameSpecDet10.getFullTitleCache());
    assertEquals("p 455", nameSpecDet10.getNomenclaturalMicroReference());
    // Special MicroRefs
    String strSpecDetail11 = "Abies alba Mill. in Sp. Pl. 4(6): p. 455 - 457. 1987";
    INonViralName nameSpecDet11 = parser.parseReferencedName(strSpecDetail11, null, rankSpecies);
    assertTrue(nameSpecDet11.hasProblem());
    list = nameSpecDet11.getParsingProblems();
    assertTrue("Problem is Detail. Must be pp.", list.contains(ParserProblem.CheckDetailOrYear));
    // TODO better start behind :
    assertEquals(20, nameSpecDet8.getProblemStarts());
    // TODO better stop after - 457
    assertEquals(51, nameSpecDet8.getProblemEnds());
    // no volume, no edition
    String strNoVolume = "Abies alba Mill., Sp. Pl.: 455. 1987";
    INonViralName nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
    assertFalse(nameNoVolume.hasProblem());
    assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
    assertEquals(null, ((IVolumeReference) (nameNoVolume.getNomenclaturalReference())).getVolume());
    assertEquals(null, ((IBook) nameNoVolume.getNomenclaturalReference()).getEdition());
    // volume, no edition
    strNoVolume = "Abies alba Mill., Sp. Pl. 2: 455. 1987";
    nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
    assertFalse(nameNoVolume.hasProblem());
    assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
    assertEquals("2", ((IVolumeReference) (nameNoVolume.getNomenclaturalReference())).getVolume());
    assertEquals(null, ((IBook) (nameNoVolume.getNomenclaturalReference())).getEdition());
    // no volume, edition
    strNoVolume = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
    nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
    assertFalse(nameNoVolume.hasProblem());
    assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
    assertEquals(null, ((IVolumeReference) (nameNoVolume.getNomenclaturalReference())).getVolume());
    assertEquals("3", ((IBook) (nameNoVolume.getNomenclaturalReference())).getEdition());
    // volume, edition
    strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3, 4(5): 455. 1987";
    nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
    assertFalse(nameNoVolume.hasProblem());
    assertEquals(strNoVolume.replace(" ed.", ", ed."), nameNoVolume.getFullTitleCache());
    assertEquals("4(5)", ((IVolumeReference) (nameNoVolume.getNomenclaturalReference())).getVolume());
    assertEquals("3", ((IBook) (nameNoVolume.getNomenclaturalReference())).getEdition());
    String strUnparsableInRef = "Abies alba Mill. in -er46: 455. 1987";
    INonViralName nameUnparsableInRef = parser.parseReferencedName(strUnparsableInRef, null, rankSpecies);
    assertTrue(nameUnparsableInRef.hasProblem());
    list = nameUnparsableInRef.getParsingProblems();
    assertTrue("Unparsable title", list.contains(ParserProblem.UnparsableReferenceTitle));
    assertEquals(strUnparsableInRef, nameUnparsableInRef.getFullTitleCache());
    assertEquals(20, nameUnparsableInRef.getProblemStarts());
    assertEquals(25, nameUnparsableInRef.getProblemEnds());
    // volume, edition
    String strNoSeparator = "Abies alba Mill. Sp. Pl. ed. 3, 4(5): 455. 1987";
    INonViralName nameNoSeparator = parser.parseReferencedName(strNoSeparator, ICNAFP, rankSpecies);
    assertTrue(nameNoSeparator.hasProblem());
    list = nameNoSeparator.getParsingProblems();
    assertTrue("Problem is missing name-reference separator", list.contains(ParserProblem.NameReferenceSeparation));
    assertEquals(strNoSeparator, nameNoSeparator.getFullTitleCache());
    // TODO better start behind Mill. (?)
    assertEquals(10, nameNoSeparator.getProblemStarts());
    // TODO better stop before :
    assertEquals(47, nameNoSeparator.getProblemEnds());
    String strUnparsableInRef2 = "Hieracium pepsicum L., My Bookkkk 1. 1903";
    INonViralName nameUnparsableInRef2 = parser.parseReferencedName(strUnparsableInRef2, null, rankSpecies);
    assertTrue(nameUnparsableInRef2.hasProblem());
    list = nameUnparsableInRef2.getParsingProblems();
    assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
    assertEquals(strUnparsableInRef2, nameUnparsableInRef2.getFullTitleCache());
    assertEquals(23, nameUnparsableInRef2.getProblemStarts());
    assertEquals(41, nameUnparsableInRef2.getProblemEnds());
    String strUnparsableInRef3 = "Hieracium pespcim N., My Bookkkk 1. 1902";
    INonViralName nameUnparsableInRef3 = parser.parseReferencedName(strUnparsableInRef3, null, null);
    assertTrue(nameUnparsableInRef3.hasProblem());
    list = nameUnparsableInRef3.getParsingProblems();
    assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
    assertEquals(strUnparsableInRef3, nameUnparsableInRef3.getFullTitleCache());
    assertEquals(22, nameUnparsableInRef3.getProblemStarts());
    assertEquals(40, nameUnparsableInRef3.getProblemEnds());
    String strUnparsableInRef4 = "Hieracium pepsicum (Hsllreterto) L., My Bookkkk 1. 1903";
    INonViralName nameUnparsableInRef4 = parser.parseReferencedName(strUnparsableInRef4, null, null);
    assertTrue(nameUnparsableInRef4.hasProblem());
    list = nameUnparsableInRef4.getParsingProblems();
    assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
    assertEquals(strUnparsableInRef4, nameUnparsableInRef4.getFullTitleCache());
    assertEquals(37, nameUnparsableInRef4.getProblemStarts());
    assertEquals(55, nameUnparsableInRef4.getProblemEnds());
    String strSameName = "Hieracium pepcum (Hsllreterto) L., My Bokkk 1. 1903";
    INonViralName nameSameName = nameUnparsableInRef4;
    parser.parseReferencedName(nameSameName, strSameName, null, true);
    assertTrue(nameSameName.hasProblem());
    list = nameSameName.getParsingProblems();
    assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
    assertEquals(strSameName, nameSameName.getFullTitleCache());
    assertEquals(35, nameSameName.getProblemStarts());
    assertEquals(51, nameSameName.getProblemEnds());
    String strGenusUnparse = "Hieracium L., jlklk";
    INonViralName nameGenusUnparse = parser.parseReferencedName(strGenusUnparse, null, null);
    assertTrue(nameGenusUnparse.hasProblem());
    list = nameGenusUnparse.getParsingProblems();
    assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
    assertTrue("Problem uninomial", list.contains(ParserProblem.CheckRank));
    assertEquals(strGenusUnparse, nameGenusUnparse.getFullTitleCache());
    assertEquals(0, nameGenusUnparse.getProblemStarts());
    assertEquals(19, nameGenusUnparse.getProblemEnds());
    String strGenusUnparse2 = "Hieracium L., Per Luigi: 44. 1987";
    INonViralName nameGenusUnparse2 = parser.parseReferencedName(strGenusUnparse2, null, Rank.FAMILY());
    assertFalse(nameGenusUnparse2.hasProblem());
    assertEquals(strGenusUnparse2, nameGenusUnparse2.getFullTitleCache());
    assertEquals(-1, nameGenusUnparse2.getProblemStarts());
    assertEquals(-1, nameGenusUnparse2.getProblemEnds());
    String strBookSection2 = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz, ed. 2, 2: 288. 1905-1907";
    String strBookSection2NoComma = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905-1907";
    INonViralName nameBookSection2 = parser.parseReferencedName(strBookSection2, null, null);
    assertFalse(nameBookSection2.hasProblem());
    nameBookSection2.setFullTitleCache(null, false);
    assertEquals(strBookSection2NoComma.replace(" ed.", ", ed.").replace("-", SEP), nameBookSection2.getFullTitleCache());
    assertEquals(-1, nameBookSection2.getProblemStarts());
    assertEquals(-1, nameBookSection2.getProblemEnds());
    assertNull((nameBookSection2.getNomenclaturalReference()).getDatePublished().getStart());
    assertEquals("1905" + SEP + "1907", ((IBookSection) nameBookSection2.getNomenclaturalReference()).getInBook().getDatePublished().getYear());
    String strBookSection = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905";
    INonViralName nameBookSection = parser.parseReferencedName(strBookSection, null, null);
    assertFalse(nameBookSection.hasProblem());
    assertEquals(strBookSection.replace(" ed.", ", ed."), nameBookSection.getFullTitleCache());
    assertEquals(-1, nameBookSection.getProblemStarts());
    assertEquals(-1, nameBookSection.getProblemEnds());
    assertNull(((IBookSection) nameBookSection.getNomenclaturalReference()).getInBook().getDatePublished().getStart());
    assertEquals("1905", ((IBookSection) nameBookSection.getNomenclaturalReference()).getDatePublished().getYear());
    String strXXXs = "Abies alba, Soer der 1987";
    INonViralName problemName = parser.parseReferencedName(strXXXs, null, null);
    assertTrue(problemName.hasProblem());
    list = problemName.getParsingProblems();
    assertTrue("Problem must be name-reference separation", list.contains(ParserProblem.NameReferenceSeparation));
    parser.parseReferencedName(problemName, strBookSection, null, true);
    assertFalse(problemName.hasProblem());
    problemName = parser.parseFullName(strXXXs, null, null);
    assertTrue(problemName.hasProblem());
    list = problemName.getParsingProblems();
    assertTrue("Name part must be unparsable", list.contains(ParserProblem.UnparsableNamePart));
    String testParsable = "Pithecellobium macrostachyum Benth.";
    assertTrue(isParsable(testParsable, ICNAFP));
    testParsable = "Pithecellobium macrostachyum (Benth.)";
    assertTrue(isParsable(testParsable, ICNAFP));
    testParsable = "Pithecellobium macrostachyum (Benth., 1845)";
    assertTrue(isParsable(testParsable, NomenclaturalCode.ICZN));
    // 00B0 is degree character
    testParsable = "Pithecellobium macrostachyum L., Sp. Pl. 3: n\u00B0 123. 1753.";
    assertTrue(isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur. 6: 1285. 1929";
    assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.&Eur. 6: 1285. 1929";
    assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur.& 6: 1285. 1929";
    assertFalse("Reference title should not support special characters like - and & at the end of the title", isParsable(testParsable, ICNAFP));
    assertTrue("Problem must be reference title", getProblems(testParsable, ICNAFP).contains(ParserProblem.UnparsableReferenceTitle));
    testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.:Eur. 6: 1285. 1929";
    assertFalse("Reference title should not support detail separator", isParsable(testParsable, ICNAFP));
    assertTrue("Problem must be reference title", getProblems(testParsable, ICNAFP).contains(ParserProblem.UnparsableReferenceTitle));
    testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
    assertTrue("Reference title should support brackets", isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
    assertTrue("Reference title should support brackets", isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium lachenalii Zahn, nom. illeg.";
    assertTrue("Reference should not be obligatory if a nom status exist", isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium lachenalii, nom. illeg.";
    assertTrue("Authorship should not be obligatory if followed by nom status", isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium lachenalii, Ill. Fl. (Mitt.) 6: 1285. 1929";
    assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICNAFP));
    assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICNAFP).contains(ParserProblem.NameReferenceSeparation));
    testParsable = "Hieracium lachenalii in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
    assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICNAFP));
    assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICNAFP).contains(ParserProblem.NameReferenceSeparation));
    testParsable = "Abies alba Mill. var. alba";
    assertTrue("Autonym problem", isParsable(testParsable, ICNAFP));
    testParsable = "Scleroblitum abc Ulbr. in Engler & Prantl, Nat. Pflanzenfam., ed. 2, 16c: 495. 1934.";
    assertTrue("Volume with subdivision", isParsable(testParsable, ICNAFP));
    testParsable = "Hieracium antarcticum d'Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
    // testParsable = "Hieracium antarcticum Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
    assertTrue("Name with apostrophe is not parsable", isParsable(testParsable, ICNAFP));
    testParsable = "Cichorium intybus subsp. glaucum (Hoffmanns. & Link) Tzvelev in Komarov, Fl. SSSR 29: 17. 1964";
    assertTrue("Reference containing a word in uppercase is not parsable", isParsable(testParsable, ICNAFP));
    testParsable = "Silene broussonetiana Schott ex Webb & Berthel., Hist. Nat. Iles Canaries 3(2,1): 141. 1840";
    assertTrue("Reference with volume with 2 number in brackets is not parsable", isParsable(testParsable, ICNAFP));
    testParsable = "Silene broussonetiana Schott ex Webb & Berthel., Hist. Nat. Iles Canaries 3(2, 1): 141. 1840";
    assertTrue("Reference with volume with 2 number in brackets is not parsable", isParsable(testParsable, ICNAFP));
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) Rank(eu.etaxonomy.cdm.model.name.Rank) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) IArticle(eu.etaxonomy.cdm.model.reference.IArticle) Method(java.lang.reflect.Method) StringNotParsableException(eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IBook(eu.etaxonomy.cdm.model.reference.IBook) IBookSection(eu.etaxonomy.cdm.model.reference.IBookSection) IJournal(eu.etaxonomy.cdm.model.reference.IJournal) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName) Test(org.junit.Test)

Example 9 with INomenclaturalReference

use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.

the class AssemblerTest method setUp.

@Before
public void setUp() throws Exception {
    lsid = new LSID("urn:lsid:example.org:taxonconcepts:1");
    authorship = Person.NewInstance();
    authorship.setTitleCache("authorship.titleCache", true);
    authorship.setLsid(new LSID("urn:lsid:dagg.org:agents:2"));
    name = TaxonNameFactory.NewBotanicalInstance(null);
    name.setNameCache("nameCache");
    INomenclaturalReference nomenclaturalReference = ReferenceFactory.newArticle();
    nomenclaturalReference.setTitleCache("nomenclaturalReference", true);
    name.setNomenclaturalReference(nomenclaturalReference);
    name.setNomenclaturalMicroReference("1");
    name.setAuthorshipCache("authorshipCache");
    name.setRank(Rank.SPECIES());
    sec = ReferenceFactory.newBook();
    sec.setAuthorship(authorship);
    sec.setTitleCache("sec.titleCache", true);
    sec.setLsid(new LSID("urn:lsid:example.org:references:1"));
    taxon = Taxon.NewInstance(name, (Reference) sec);
    taxon.setCreated(new DateTime(2004, 12, 25, 12, 0, 0, 0));
    taxon.setUpdated(new DateTime(2005, 12, 25, 12, 0, 0, 0));
    taxon.setTitleCache("titleCache", true);
    taxon.setLsid(lsid);
    for (int i = 2; i < 2 + 1; i++) {
        Taxon child = Taxon.NewInstance(name, (Reference) sec);
        child.setLsid(new LSID("urn:lsid:example.org:taxonconcepts:r0" + i));
        child.addTaxonRelation(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null);
    }
    taxonDescription = TaxonDescription.NewInstance();
    taxon.addDescription(taxonDescription);
    TextData textData = TextData.NewInstance();
    Language english = Language.NewInstance();
    english.setIso639_1("en");
    Language french = Language.NewInstance();
    french.setIso639_1("fr");
    textData.getMultilanguageText().put(english, LanguageString.NewInstance("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce justo leo, tempus ultricies bibendum eu, interdum sit amet ipsum. Suspendisse eu odio in sem iaculis euismod. Suspendisse sed metus ante, in sodales risus. In sit amet magna sit amet risus elementum dapibus. Nullam in magna at mauris placerat sagittis. Proin urna nisl, porta at venenatis in, tristique tempus nisl. Proin vel arcu blandit velit vestibulum blandit. In at diam libero, vel malesuada mauris. Duis a enim diam. Donec urna dui, dictum at suscipit vel, consectetur quis est. In venenatis bibendum diam nec laoreet. ", english));
    textData.getMultilanguageText().put(french, LanguageString.NewInstance("Mauris elementum malesuada orci, non eleifend metus placerat ut. Aenean ornare felis sed lectus cursus id cursus nulla consectetur. Mauris magna justo, placerat id pretium posuere, ultrices et libero. Aliquam erat volutpat. Ut libero diam, interdum commodo fringilla sollicitudin, faucibus vel nisl. Fusce mattis justo interdum enim rhoncus eget sollicitudin dolor lobortis. Morbi mauris odio, tempus eget egestas eu, ornare vel ante. In quis placerat mi. Aliquam blandit tristique dictum. Donec pretium dui lacinia magna ornare eu venenatis ante dignissim. Integer ullamcorper tempus nisl et tincidunt. Curabitur vel nulla eu dolor faucibus porta. Mauris pulvinar est at est porta molestie. Nam varius nunc nec ipsum lacinia non egestas turpis congue. In at ipsum augue. Nulla mollis lobortis mauris ac sagittis. Nullam et facilisis lacus. Nam euismod sapien pellentesque lacus hendrerit dapibus. Aenean blandit rhoncus feugiat.", french));
    taxonDescription.addElement(textData);
    Distribution distribution = Distribution.NewInstance();
    NamedArea namedArea = NamedArea.NewInstance("Africa", "Africa", "Africa");
    namedArea.setTitleCache("Africa", true);
    distribution.setArea(namedArea);
    distribution.setStatus(PresenceAbsenceTerm.NATIVE());
    taxonDescription.addElement(distribution);
    // ------------------------------------------------------
    book = ReferenceFactory.newBook();
    book.setTitle("Book.title");
    book.setAuthorship(authorship);
    book.setCreated(new DateTime(2004, 12, 25, 12, 0, 0, 0));
    book.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(new Partial(DateTimeFieldType.year(), 1800)));
    book.setEdition("1st Edition");
    book.setEditor("Editor");
    book.setIsbn("isbn");
    book.setPlacePublished("placePublished");
    book.setPublisher("publisher");
    book.setReferenceAbstract("referenceAbstract");
    book.setUri(new URI("http://persitent.books.foo/myBook"));
    book.setUuid(UUID.randomUUID());
    book.setVolume("Volume 1");
    book.addSource(IdentifiableSource.NewDataImportInstance("http://persitent.IdentifiableSources.foo/1"));
    bookSection = ReferenceFactory.newBookSection();
    bookSection.setInReference((Reference) book);
    bookSection.setPages("999 ff.");
    bookSection.setTitle("BookSection.title");
    bookSection.setAuthorship(authorship);
    bookSection.setCreated(new DateTime(2004, 12, 25, 12, 0, 0, 0));
    bookSection.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(new Partial(DateTimeFieldType.year(), 1800)));
    bookSection.setReferenceAbstract("referenceAbstract");
    bookSection.setUri(new URI("http://persitent.books.foo/myBookSection"));
    bookSection.setUuid(UUID.randomUUID());
    bookSection.addCredit(Credit.NewInstance(authorship, "Credits to the authorship"));
    bookSection.addSource(IdentifiableSource.NewDataImportInstance("http://persitent.IdentifiableSources.foo/2"));
}
Also used : LSID(eu.etaxonomy.cdm.model.common.LSID) Language(eu.etaxonomy.cdm.model.common.Language) Partial(org.joda.time.Partial) Reference(eu.etaxonomy.cdm.model.reference.Reference) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TextData(eu.etaxonomy.cdm.model.description.TextData) Distribution(eu.etaxonomy.cdm.model.description.Distribution) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) URI(eu.etaxonomy.cdm.common.URI) DateTime(org.joda.time.DateTime) Before(org.junit.Before)

Example 10 with INomenclaturalReference

use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.

the class TaxonNameTest method testGetSetNomenclaturalReference.

@Test
public void testGetSetNomenclaturalReference() {
    INomenclaturalReference nr = nameBase1.getNomenclaturalReference();
    assertNull("Nomenclatural Reference shall be null", nr);
    nameBase1.setNomenclaturalReference(ReferenceFactory.newGeneric());
    nr = nameBase1.getNomenclaturalReference();
    assertNotNull("Nomenclatural Reference shall not be null", nr);
}
Also used : INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) Test(org.junit.Test)

Aggregations

INomenclaturalReference (eu.etaxonomy.cdm.model.reference.INomenclaturalReference)10 Reference (eu.etaxonomy.cdm.model.reference.Reference)5 IZoologicalName (eu.etaxonomy.cdm.model.name.IZoologicalName)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)3 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)2 IVolumeReference (eu.etaxonomy.cdm.model.reference.IVolumeReference)2 StringNotParsableException (eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)2 Test (org.junit.Test)2 URI (eu.etaxonomy.cdm.common.URI)1 LSID (eu.etaxonomy.cdm.model.common.LSID)1 Language (eu.etaxonomy.cdm.model.common.Language)1 VerbatimTimePeriod (eu.etaxonomy.cdm.model.common.VerbatimTimePeriod)1 Distribution (eu.etaxonomy.cdm.model.description.Distribution)1 TextData (eu.etaxonomy.cdm.model.description.TextData)1 NamedArea (eu.etaxonomy.cdm.model.location.NamedArea)1 Rank (eu.etaxonomy.cdm.model.name.Rank)1 IArticle (eu.etaxonomy.cdm.model.reference.IArticle)1 IBook (eu.etaxonomy.cdm.model.reference.IBook)1 IBookSection (eu.etaxonomy.cdm.model.reference.IBookSection)1 IJournal (eu.etaxonomy.cdm.model.reference.IJournal)1