use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class MarkupImportBase method handleNonCitationSpecific.
/**
* Create reference for non nomenclatural references
* @return
*/
protected Reference handleNonCitationSpecific(MarkupImportState state, String type, String authorStr, String titleStr, String titleCache, String volume, String issue, String edition, String editors, String pubName, String appendix, String pages, XMLEvent parentEvent) {
Reference reference;
// volume / issue
if (isBlank(volume) && isNotBlank(issue)) {
String message = "Issue ('" + issue + "') exists but no volume";
fireWarningEvent(message, parentEvent, 4);
volume = issue;
} else if (isNotBlank(issue)) {
volume = volume + "(" + issue + ")";
}
// pubName / appendix
if (isNotBlank(appendix)) {
pubName = pubName == null ? appendix : (pubName + " " + appendix).replaceAll(" ", " ");
}
if (isArticleNonCitation(type, pubName, volume, editors)) {
IArticle article = ReferenceFactory.newArticle();
if (pubName != null) {
IJournal journal = ReferenceFactory.newJournal();
journal.setTitle(pubName);
article.setInJournal(journal);
} else {
fireWarningEvent("Article has no journal", parentEvent, 4);
}
reference = (Reference) article;
} else {
if (isBookSection(type, authorStr, titleStr, editors, pubName, volume)) {
IBookSection bookSection = ReferenceFactory.newBookSection();
if (pubName != null) {
IBook book = ReferenceFactory.newBook();
book.setTitle(pubName);
bookSection.setInBook(book);
}
reference = (Reference) bookSection;
} else {
// ??
Reference bookOrPartOf = ReferenceFactory.newGeneric();
if (pubName != null && titleStr != null) {
Reference inReference = ReferenceFactory.newGeneric();
inReference.setTitle(pubName);
bookOrPartOf.setInReference(inReference);
}
reference = bookOrPartOf;
}
}
// author
TeamOrPersonBase<?> author = createAuthor(state, authorStr);
reference.setAuthorship(author);
// title
reference.setTitle(titleStr);
if (StringUtils.isNotBlank(titleCache)) {
reference.setTitleCache(titleCache, true);
}
// edition
if (reference.getInReference() != null) {
reference.getInReference().setEdition(edition);
reference.getInReference().setEditor(editors);
} else {
// edition
reference.setEdition(edition);
reference.setEditor(editors);
}
// volume
reference.setVolume(volume);
// pages
reference.setPages(pages);
return reference;
}
use of eu.etaxonomy.cdm.model.reference.IArticle 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));
}
use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class CacheStrategyGeneratorTest method testOnSaveOrUpdateReferences.
@Test
@DataSet("CacheStrategyGeneratorTest.xml")
@ExpectedDataSet
public // TODO correct abbrevTitleCache for article still unclear (open question: with or without article title ?)
void testOnSaveOrUpdateReferences() {
// References
IJournal journal1 = ReferenceFactory.newJournal();
Person journalAuthor = makePerson1();
journal1.setTitle("My journal");
journal1.setUuid(UUID.fromString("a7fdf3b8-acd8-410a-afcd-1768d29d67e9"));
journal1.setAbbrevTitle("M. Journ.");
((Reference) journal1).setAuthorship(journalAuthor);
referenceDao.save((Reference) journal1);
Person articleAuthor = makePerson2();
IArticle article1 = ReferenceFactory.newArticle();
article1.setUuid(UUID.fromString("eb090fbc-5895-405c-aba5-cac287efb128"));
article1.setAbbrevTitle("M. Art.");
article1.setVolume("1");
article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1972));
article1.setInJournal(journal1);
article1.setAuthorship(articleAuthor);
article1.getAbbrevTitleCache();
referenceDao.saveOrUpdate((Reference) article1);
commit();
}
use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class MatchStrategyFactoryTest method testParsedReference.
@Test
public void testParsedReference() throws MatchException {
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedReferenceInstance();
Assert.assertNotNull(matchStrategy);
IArticle fullArticle;
IArticle parsedArticle;
fullArticle = getMatchingFullArticle();
parsedArticle = getDefaultParsedArticle();
Assert.assertTrue("Only author, book and date published should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// should match
fullArticle = getDefaultFullArticle();
Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
Assert.assertFalse("Still not match because pages are not equal (parsed is null)", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
parsedArticle.setPages(fullArticle.getPages());
Assert.assertFalse("Now they should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// differing nom. title.
parsedArticle.setAbbrevTitle("Wrong");
Assert.assertFalse("Differing abbrev. title. should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// differing family
parsedArticle = getDefaultParsedArticle();
parsedArticle.setTitle("Wrong title");
Assert.assertFalse("Differing title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
fullArticle.setTitle(null);
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// change author
fullArticle = getMatchingFullArticle();
parsedArticle = getDefaultParsedArticle();
fullArticle.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
Assert.assertFalse("Differing author in nomencl. title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// change author
fullArticle = getMatchingFullArticle();
parsedArticle = getDefaultParsedArticle();
((Team) fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
Assert.assertTrue("Full book family name author changed should still match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
}
use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class MatchStrategyFactoryTest method getDefaultParsedArticle.
/**
* Article with {@link #getDefaultParsedTeam() parsed authorship},
* {@link #getDefaultParsedJournal() parsed journal} and date published.
*/
private IArticle getDefaultParsedArticle() {
IArticle article = ReferenceFactory.newArticle();
article.setAuthorship(getDefaultParsedTeam());
article.setInJournal(getDefaultParsedJournal());
article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
((Reference) article).updateCaches();
return article;
}
Aggregations