1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.strategy.parser;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertFalse;
|
14
|
import static org.junit.Assert.assertNotNull;
|
15
|
import static org.junit.Assert.assertNull;
|
16
|
import static org.junit.Assert.assertTrue;
|
17
|
|
18
|
import java.lang.reflect.InvocationTargetException;
|
19
|
import java.lang.reflect.Method;
|
20
|
import java.util.List;
|
21
|
import java.util.regex.Matcher;
|
22
|
import java.util.regex.Pattern;
|
23
|
|
24
|
import junit.framework.Assert;
|
25
|
|
26
|
import org.apache.log4j.Logger;
|
27
|
import org.junit.After;
|
28
|
import org.junit.AfterClass;
|
29
|
import org.junit.Before;
|
30
|
import org.junit.BeforeClass;
|
31
|
import org.junit.Test;
|
32
|
|
33
|
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
|
34
|
import eu.etaxonomy.cdm.model.agent.Team;
|
35
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
36
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
37
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
38
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
39
|
import eu.etaxonomy.cdm.model.name.Rank;
|
40
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
41
|
//import eu.etaxonomy.cdm.model.reference.Article;
|
42
|
//import eu.etaxonomy.cdm.model.reference.Book;
|
43
|
//import eu.etaxonomy.cdm.model.reference.BookSection;
|
44
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
45
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
46
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
47
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
48
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
49
|
import eu.etaxonomy.cdm.model.reference.IVolumeReference;
|
50
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
51
|
//import eu.etaxonomy.cdm.model.reference.Journal;
|
52
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
53
|
/**
|
54
|
* @author a.mueller
|
55
|
*
|
56
|
*/
|
57
|
public class NonViralNameParserImplTest {
|
58
|
private static final Logger logger = Logger.getLogger(NonViralNameParserImplTest.class);
|
59
|
|
60
|
final private String strNameFamily = "Asteraceae";
|
61
|
final private String strNameGenus = "Abies Mueller";
|
62
|
final private String strNameGenusUnicode = "Abies M\u00FCller";
|
63
|
final private String strNameAbies1 = "Abies alba";
|
64
|
final private String strNameAbiesSub1 = "Abies alba subsp. beta";
|
65
|
final private String strNameAbiesAuthor1 = "Abies alba Mueller";
|
66
|
final private String strNameAbiesAuthor1Unicode = "Abies alba M\u00FCller";
|
67
|
final private String strNameAbiesBasionymAuthor1 = "Abies alba (Ciardelli) D'Mueller";
|
68
|
final private String strNameAbiesBasionymAuthor1Unicode = "Abies alba (Ciardelli) D'M\u00FCller";
|
69
|
final private String strNameAbiesBasionymExAuthor1 ="Abies alba (Ciardelli ex Doering) D'Mueller ex. de Greuther";
|
70
|
final private String strNameAbiesBasionymExAuthor1Unicode ="Abies alba (Ciardelli ex D\u00F6ring) D'M\u00FCller ex. de Greuther";
|
71
|
final private String strNameTeam1 = "Abies alba Mueller & L.";
|
72
|
final private String strNameZoo1 = "Abies alba Mueller & L., 1822";
|
73
|
final private String strNameZoo2 = "Abies alba (Mueller, 1822) Ciardelli, 2002";
|
74
|
|
75
|
final private String strNameEmpty = "";
|
76
|
final private String strNameNull = null;
|
77
|
|
78
|
private NonViralNameParserImpl parser ;
|
79
|
private NomenclaturalCode botanicCode;
|
80
|
|
81
|
/**
|
82
|
* @throws java.lang.Exception
|
83
|
*/
|
84
|
@BeforeClass
|
85
|
public static void setUpBeforeClass() throws Exception {
|
86
|
DefaultTermInitializer termInitializer = new DefaultTermInitializer();
|
87
|
termInitializer.initialize();
|
88
|
}
|
89
|
|
90
|
|
91
|
/**
|
92
|
* @throws java.lang.Exception
|
93
|
*/
|
94
|
@Before
|
95
|
public void setUp() throws Exception {
|
96
|
parser = NonViralNameParserImpl.NewInstance();
|
97
|
botanicCode = NomenclaturalCode.ICBN;
|
98
|
}
|
99
|
|
100
|
|
101
|
/*************** TEST *********************************************/
|
102
|
|
103
|
/**
|
104
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#NEW_INSTANCE()}.
|
105
|
*/
|
106
|
@Test
|
107
|
public final void testNewInstance() {
|
108
|
assertNotNull(parser);
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#TaxonNameParserBotanicalNameImpl()}.
|
113
|
*/
|
114
|
@Test
|
115
|
public final void testTaxonNameParserBotanicalNameImpl() {
|
116
|
logger.warn("Not yet implemented"); // TODO
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSimpleName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
|
121
|
*/
|
122
|
@Test
|
123
|
public final void testParseSimpleName() {
|
124
|
|
125
|
//Uninomials
|
126
|
ZoologicalName milichiidae = (ZoologicalName)parser.parseSimpleName("Milichiidae", NomenclaturalCode.ICZN, null);
|
127
|
assertEquals("Family rank expected", Rank.FAMILY(), milichiidae.getRank());
|
128
|
BotanicalName crepidinae = (BotanicalName)parser.parseSimpleName("Crepidinae", NomenclaturalCode.ICBN, null);
|
129
|
assertEquals("Family rank expected", Rank.SUBTRIBE(), crepidinae.getRank());
|
130
|
BotanicalName abies = (BotanicalName)parser.parseSimpleName("Abies", NomenclaturalCode.ICBN, null);
|
131
|
assertEquals("Family rank expected", Rank.GENUS(), abies.getRank());
|
132
|
|
133
|
abies.addParsingProblem(ParserProblem.CheckRank);
|
134
|
parser.parseSimpleName(abies, "Abies", abies.getRank(), true);
|
135
|
assertTrue(abies.getParsingProblems().contains(ParserProblem.CheckRank));
|
136
|
|
137
|
BotanicalName rosa = (BotanicalName)parser.parseSimpleName("Rosaceae", NomenclaturalCode.ICBN, null);
|
138
|
assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
|
139
|
assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
|
140
|
parser.parseSimpleName(rosa, "Rosaceaex", abies.getRank(), true);
|
141
|
assertEquals("Rosaceaex have rank genus", Rank.GENUS(), rosa.getRank());
|
142
|
assertTrue("Rosaceaex must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
|
143
|
|
144
|
//repeat but remove warning after first parse
|
145
|
rosa = (BotanicalName)parser.parseSimpleName("Rosaceae", NomenclaturalCode.ICBN, null);
|
146
|
assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
|
147
|
assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
|
148
|
rosa.removeParsingProblem(ParserProblem.CheckRank);
|
149
|
parser.parseSimpleName(rosa, "Rosaceaex", rosa.getRank(), true);
|
150
|
assertEquals("Rosaceaex have rank family", Rank.FAMILY(), rosa.getRank());
|
151
|
assertFalse("Rosaceaex must have no rank warning", rosa.hasProblem(ParserProblem.CheckRank));
|
152
|
|
153
|
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericFullName(java.lang.String)}.
|
158
|
*/
|
159
|
@Test
|
160
|
public final void testParseSubGenericFullName() {
|
161
|
logger.warn("Not yet implemented"); // TODO
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericSimpleName(java.lang.String)}.
|
166
|
*/
|
167
|
@Test
|
168
|
public final void testParseSubGenericSimpleName() {
|
169
|
logger.warn("Not yet implemented"); // TODO
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
|
174
|
*/
|
175
|
@Test
|
176
|
public final void testParseFullNameUnicode() {
|
177
|
|
178
|
NonViralName nameAuthor = parser.parseFullName(strNameAbiesAuthor1Unicode, null, Rank.SPECIES());
|
179
|
assertEquals("Abies", nameAuthor.getGenusOrUninomial());
|
180
|
assertEquals("alba", nameAuthor.getSpecificEpithet());
|
181
|
assertEquals("M\u00FCller", nameAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
|
182
|
|
183
|
NonViralName nameBasionymAuthor = parser.parseFullName(strNameAbiesBasionymAuthor1Unicode, null, Rank.SPECIES());
|
184
|
assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
|
185
|
assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
|
186
|
assertEquals("D'M\u00FCller", nameBasionymAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
|
187
|
INomenclaturalAuthor basionymTeam = nameBasionymAuthor.getBasionymAuthorTeam();
|
188
|
assertEquals("Ciardelli", basionymTeam.getNomenclaturalTitle());
|
189
|
|
190
|
NonViralName nameBasionymExAuthor = parser.parseFullName(strNameAbiesBasionymExAuthor1Unicode, null, Rank.SPECIES());
|
191
|
assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
|
192
|
assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
|
193
|
assertEquals("D'M\u00FCller", nameBasionymExAuthor.getExCombinationAuthorTeam().getNomenclaturalTitle());
|
194
|
assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
|
195
|
INomenclaturalAuthor basionymTeam2 = nameBasionymExAuthor.getExBasionymAuthorTeam();
|
196
|
assertEquals("Ciardelli", basionymTeam2.getNomenclaturalTitle());
|
197
|
INomenclaturalAuthor exBasionymTeam2 = nameBasionymExAuthor.getBasionymAuthorTeam();
|
198
|
assertEquals("D\u00F6ring", exBasionymTeam2.getNomenclaturalTitle());
|
199
|
|
200
|
BotanicalName nameBasionymExAuthor2 = (BotanicalName)parser.parseFullName("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", null, Rank.SPECIES());
|
201
|
assertEquals("Washingtonia", nameBasionymExAuthor2.getGenusOrUninomial());
|
202
|
assertEquals("filifera", nameBasionymExAuthor2.getSpecificEpithet());
|
203
|
assertEquals("H.Wendl.", nameBasionymExAuthor2.getExCombinationAuthorTeam().getNomenclaturalTitle());
|
204
|
assertEquals("de Bary", nameBasionymExAuthor2.getCombinationAuthorTeam().getNomenclaturalTitle());
|
205
|
INomenclaturalAuthor basionymTeam3 = nameBasionymExAuthor2.getBasionymAuthorTeam();
|
206
|
assertEquals("Andre", basionymTeam3.getNomenclaturalTitle());
|
207
|
INomenclaturalAuthor exBasionymTeam3 = nameBasionymExAuthor2.getExBasionymAuthorTeam();
|
208
|
assertEquals("Linden", exBasionymTeam3.getNomenclaturalTitle());
|
209
|
String title = nameBasionymExAuthor2.generateTitle();
|
210
|
assertEquals("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", title);
|
211
|
|
212
|
}
|
213
|
|
214
|
|
215
|
/**
|
216
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
|
217
|
*/
|
218
|
@Test
|
219
|
public final void testParseFullName() {
|
220
|
try {
|
221
|
Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
|
222
|
testName_StringNomcodeRank(parseMethod);
|
223
|
} catch (Exception e) {
|
224
|
e.printStackTrace();
|
225
|
assertTrue(false);
|
226
|
}
|
227
|
|
228
|
//Team
|
229
|
NonViralName nameTeam1 = parser.parseFullName(strNameTeam1);
|
230
|
assertEquals( "Abies", nameTeam1.getGenusOrUninomial());
|
231
|
assertEquals( "alba", nameTeam1.getSpecificEpithet());
|
232
|
assertEquals("Mueller & L.", nameTeam1.getCombinationAuthorTeam().getNomenclaturalTitle());
|
233
|
assertTrue(nameTeam1.getCombinationAuthorTeam() instanceof Team);
|
234
|
Team team = (Team)nameTeam1.getCombinationAuthorTeam();
|
235
|
assertEquals("Mueller", team.getTeamMembers().get(0).getNomenclaturalTitle());
|
236
|
assertEquals("L.", team.getTeamMembers().get(1).getNomenclaturalTitle());
|
237
|
|
238
|
//ZooName
|
239
|
ZoologicalName nameZoo1 = (ZoologicalName)parser.parseFullName(strNameZoo1);
|
240
|
assertEquals( "Abies", nameZoo1.getGenusOrUninomial());
|
241
|
assertEquals( "alba", nameZoo1.getSpecificEpithet());
|
242
|
assertEquals("Mueller & L.", nameZoo1.getCombinationAuthorTeam().getNomenclaturalTitle());
|
243
|
assertEquals(NomenclaturalCode.ICZN, nameZoo1.getNomenclaturalCode() );
|
244
|
assertEquals(Integer.valueOf(1822), nameZoo1.getPublicationYear());
|
245
|
assertTrue(nameZoo1.getCombinationAuthorTeam() instanceof Team);
|
246
|
Team teamZoo = (Team)nameZoo1.getCombinationAuthorTeam();
|
247
|
assertEquals("Mueller", teamZoo.getTeamMembers().get(0).getNomenclaturalTitle());
|
248
|
assertEquals("L.", teamZoo.getTeamMembers().get(1).getNomenclaturalTitle());
|
249
|
|
250
|
ZoologicalName nameZoo2 = (ZoologicalName)parser.parseFullName(strNameZoo2);
|
251
|
assertEquals(Integer.valueOf(2002), nameZoo2.getPublicationYear());
|
252
|
assertEquals(Integer.valueOf(1822), nameZoo2.getOriginalPublicationYear());
|
253
|
assertEquals("Mueller", nameZoo2.getBasionymAuthorTeam().getNomenclaturalTitle());
|
254
|
assertEquals("Ciardelli", nameZoo2.getCombinationAuthorTeam().getNomenclaturalTitle());
|
255
|
|
256
|
//Autonym
|
257
|
BotanicalName autonymName = (BotanicalName)parser.parseFullName("Abies alba Mill. var. alba", NomenclaturalCode.ICBN, null);
|
258
|
assertFalse("Autonym should be parsable", autonymName.hasProblem());
|
259
|
|
260
|
|
261
|
//empty
|
262
|
NonViralName nameEmpty = parser.parseFullName(strNameEmpty);
|
263
|
assertNotNull(nameEmpty);
|
264
|
assertEquals("", nameEmpty.getTitleCache());
|
265
|
|
266
|
//null
|
267
|
NonViralName nameNull = parser.parseFullName(strNameNull);
|
268
|
assertNull(nameNull);
|
269
|
|
270
|
//some authors
|
271
|
String fullNameString = "Abies alba (Greuther & L'Hiver & al. ex M\u00FCller & Schmidt)Clark ex Ciardelli";
|
272
|
BotanicalName authorname = (BotanicalName)parser.parseFullName(fullNameString);
|
273
|
assertFalse(authorname.hasProblem());
|
274
|
assertEquals("Basionym author should have 3 authors", 3, ((Team)authorname.getExBasionymAuthorTeam()).getTeamMembers().size());
|
275
|
}
|
276
|
|
277
|
/**
|
278
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
|
279
|
*/
|
280
|
@Test
|
281
|
public final void testHybrids() {
|
282
|
try {
|
283
|
Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
|
284
|
testName_StringNomcodeRank(parseMethod);
|
285
|
} catch (Exception e) {
|
286
|
e.printStackTrace();
|
287
|
assertTrue(false);
|
288
|
}
|
289
|
|
290
|
//Species hybrid
|
291
|
// NonViralName nameTeam1 = parser.parseFullName("Aegilops ?insulae-cypri H. Scholz");
|
292
|
NonViralName name1 = parser.parseFullName("Aegilops ?insulae Scholz", botanicCode, null);
|
293
|
assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
|
294
|
assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
|
295
|
assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
|
296
|
assertEquals("Species epithet must be 'insulae'", "insulae", name1.getSpecificEpithet());
|
297
|
|
298
|
//Uninomial hybrid
|
299
|
name1 = parser.parseFullName("x Aegilops Scholz", botanicCode, null);
|
300
|
assertTrue("Name must have monom hybrid bit set", name1.isMonomHybrid());
|
301
|
assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
|
302
|
assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
|
303
|
assertEquals("Uninomial must be 'Aegilops'", "Aegilops", name1.getGenusOrUninomial());
|
304
|
|
305
|
//Species hybrid
|
306
|
name1 = parser.parseFullName("Aegilops insulae subsp. X abies Scholz", botanicCode, null);
|
307
|
assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
|
308
|
assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
|
309
|
assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
|
310
|
assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
|
311
|
|
312
|
}
|
313
|
|
314
|
private void testName_StringNomcodeRank(Method parseMethod)
|
315
|
throws InvocationTargetException, IllegalAccessException {
|
316
|
NonViralName name1 = (NonViralName)parseMethod.invoke(parser, strNameAbies1, null, Rank.SPECIES());
|
317
|
//parser.parseFullName(strNameAbies1, null, Rank.SPECIES());
|
318
|
assertEquals("Abies", name1.getGenusOrUninomial());
|
319
|
assertEquals("alba", name1.getSpecificEpithet());
|
320
|
|
321
|
NonViralName nameAuthor = (NonViralName)parseMethod.invoke(parser, strNameAbiesAuthor1, null, Rank.SPECIES());
|
322
|
assertEquals("Abies", nameAuthor.getGenusOrUninomial());
|
323
|
assertEquals("alba", nameAuthor.getSpecificEpithet());
|
324
|
assertEquals("Mueller", nameAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
|
325
|
|
326
|
NonViralName nameBasionymAuthor = (NonViralName)parseMethod.invoke(parser, strNameAbiesBasionymAuthor1, null, Rank.SPECIES());
|
327
|
assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
|
328
|
assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
|
329
|
assertEquals("D'Mueller", nameBasionymAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
|
330
|
assertEquals("Ciardelli", nameBasionymAuthor.getBasionymAuthorTeam().getNomenclaturalTitle());
|
331
|
|
332
|
NonViralName nameBasionymExAuthor = (NonViralName)parseMethod.invoke(parser, strNameAbiesBasionymExAuthor1, null, Rank.SPECIES());
|
333
|
assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
|
334
|
assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
|
335
|
assertEquals("D'Mueller", nameBasionymExAuthor.getExCombinationAuthorTeam().getNomenclaturalTitle());
|
336
|
assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
|
337
|
assertEquals("Ciardelli", nameBasionymExAuthor.getExBasionymAuthorTeam().getNomenclaturalTitle());
|
338
|
assertEquals("Doering", nameBasionymExAuthor.getBasionymAuthorTeam().getNomenclaturalTitle());
|
339
|
|
340
|
NonViralName name2 = (NonViralName)parseMethod.invoke(parser, strNameAbiesSub1, null, Rank.SPECIES());
|
341
|
assertEquals("Abies", name2.getGenusOrUninomial());
|
342
|
assertEquals("alba", name2.getSpecificEpithet());
|
343
|
assertEquals("beta", name2.getInfraSpecificEpithet());
|
344
|
assertEquals(Rank.SUBSPECIES(), name2.getRank());
|
345
|
|
346
|
|
347
|
// unparseable *********
|
348
|
String problemString = "sdfjlös wer eer wer";
|
349
|
NonViralName<?> nameProblem = (NonViralName<?>)parseMethod.invoke(parser, problemString, null, Rank.SPECIES());
|
350
|
List<ParserProblem> list = nameProblem.getParsingProblems();
|
351
|
assertTrue(nameProblem.getParsingProblem()!=0);
|
352
|
assertEquals(problemString, nameProblem.getTitleCache());
|
353
|
}
|
354
|
|
355
|
/**
|
356
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
|
357
|
*/
|
358
|
@Test
|
359
|
public final void testParseReferencedName() {
|
360
|
try {
|
361
|
Method parseMethod = parser.getClass().getDeclaredMethod("parseReferencedName", String.class, NomenclaturalCode.class, Rank.class);
|
362
|
testName_StringNomcodeRank(parseMethod);
|
363
|
} catch (Exception e) {
|
364
|
e.printStackTrace();
|
365
|
assertTrue(false);
|
366
|
}
|
367
|
|
368
|
|
369
|
//null
|
370
|
String strNull = null;
|
371
|
NonViralName<?> nameNull = parser.parseReferencedName(strNull, null, Rank.SPECIES());
|
372
|
assertNull(nameNull);
|
373
|
|
374
|
//Empty
|
375
|
String strEmpty = "";
|
376
|
NonViralName<?> nameEmpty = parser.parseReferencedName(strEmpty, null, Rank.SPECIES());
|
377
|
assertFalse(nameEmpty.hasProblem());
|
378
|
assertEquals(strEmpty, nameEmpty.getFullTitleCache());
|
379
|
assertNull(nameEmpty.getNomenclaturalMicroReference());
|
380
|
|
381
|
|
382
|
//Whitespaces
|
383
|
String strFullWhiteSpcaceAndDot = "Abies alba Mill., Sp. Pl. 4: 455 . 1987 .";
|
384
|
NonViralName<?> namefullWhiteSpcaceAndDot = parser.parseReferencedName(strFullWhiteSpcaceAndDot, null, Rank.SPECIES());
|
385
|
assertFullRefStandard(namefullWhiteSpcaceAndDot);
|
386
|
assertTrue(((Reference)namefullWhiteSpcaceAndDot.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
|
387
|
assertEquals( "Abies alba Mill., Sp. Pl. 4: 455. 1987", namefullWhiteSpcaceAndDot.getFullTitleCache());
|
388
|
|
389
|
//Book
|
390
|
String fullReference = "Abies alba Mill., Sp. Pl. 4: 455. 1987";
|
391
|
NonViralName<?> name1 = parser.parseReferencedName(fullReference, null, Rank.SPECIES());
|
392
|
assertFullRefStandard(name1);
|
393
|
assertTrue(((Reference)name1.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
|
394
|
assertEquals(fullReference, name1.getFullTitleCache());
|
395
|
assertTrue("Name author and reference author should be the same", name1.getCombinationAuthorTeam() == ((Reference)name1.getNomenclaturalReference()).getAuthorTeam());
|
396
|
|
397
|
//Book Section
|
398
|
fullReference = "Abies alba Mill. in Otto, Sp. Pl. 4(6): 455. 1987";
|
399
|
NonViralName<?> name2 = parser.parseReferencedName(fullReference + ".", null, Rank.SPECIES());
|
400
|
assertFullRefNameStandard(name2);
|
401
|
assertEquals(fullReference, name2.getFullTitleCache());
|
402
|
assertFalse(name2.hasProblem());
|
403
|
INomenclaturalReference ref = name2.getNomenclaturalReference();
|
404
|
assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.BookSection, ((Reference)ref).getType());
|
405
|
IBookSection bookSection = (IBookSection) ref;
|
406
|
IBook inBook = bookSection.getInBook();
|
407
|
assertNotNull(inBook);
|
408
|
assertNotNull(inBook.getAuthorTeam());
|
409
|
assertEquals("Otto", inBook.getAuthorTeam().getTitleCache());
|
410
|
assertEquals("Otto, Sp. Pl. 4(6)", inBook.getTitleCache());
|
411
|
assertEquals("Sp. Pl.", inBook.getTitle());
|
412
|
assertEquals("4(6)", inBook.getVolume());
|
413
|
assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorTeam() == ((Reference)name2.getNomenclaturalReference()).getAuthorTeam());
|
414
|
|
415
|
//Article
|
416
|
fullReference = "Abies alba Mill. in Sp. Pl. 4(6): 455. 1987";
|
417
|
NonViralName<?> name3 = parser.parseReferencedName(fullReference, null, Rank.SPECIES());
|
418
|
assertFullRefNameStandard(name3);
|
419
|
assertEquals(fullReference, name3.getFullTitleCache());
|
420
|
assertFalse(name3.hasProblem());
|
421
|
ref = name3.getNomenclaturalReference();
|
422
|
assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
|
423
|
//Article article = (Article)ref;
|
424
|
IJournal journal = ((IArticle)ref).getInJournal();
|
425
|
assertNotNull(journal);
|
426
|
//assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
|
427
|
assertEquals("Sp. Pl.",((Reference) journal).getTitleCache());
|
428
|
assertEquals("Sp. Pl.", journal.getTitle());
|
429
|
assertEquals("4(6)",((IArticle)ref).getVolume());
|
430
|
assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorTeam() == name3.getNomenclaturalReference().getAuthorTeam());
|
431
|
|
432
|
//SoftArticle - having "," on position > 4
|
433
|
String journalTitle = "Bull. Soc. Bot.France. Louis., Roi";
|
434
|
String yearPart = " 1987 - 1989";
|
435
|
String parsedYear = "1987-1989";
|
436
|
String fullReferenceWithoutYear = "Abies alba Mill. in " + journalTitle + " 4(6): 455.";
|
437
|
fullReference = fullReferenceWithoutYear + yearPart;
|
438
|
String fullReferenceWithEnd = fullReference + ".";
|
439
|
NonViralName<?> name4 = parser.parseReferencedName(fullReferenceWithEnd, null, Rank.SPECIES());
|
440
|
assertFalse(name4.hasProblem());
|
441
|
assertFullRefNameStandard(name4);
|
442
|
assertEquals(fullReferenceWithoutYear + " " + parsedYear, name4.getFullTitleCache());
|
443
|
ref = name4.getNomenclaturalReference();
|
444
|
assertEquals(ReferenceType.Article, ref.getType());
|
445
|
//article = (Article)ref;
|
446
|
assertEquals(parsedYear, ref.getYear());
|
447
|
journal = ((IArticle)ref).getInJournal();
|
448
|
assertNotNull(journal);
|
449
|
assertEquals(journalTitle, ((Reference) journal).getTitleCache());
|
450
|
assertEquals(journalTitle, journal.getTitle());
|
451
|
assertEquals("4(6)", ((IArticle)ref).getVolume());
|
452
|
|
453
|
//Zoo name
|
454
|
String strNotParsableZoo = "Abies alba M., 1923, Sp. P. xxwer4352, nom. inval.";
|
455
|
ZoologicalName nameZooRefNotParsabel = (ZoologicalName)parser.parseReferencedName(strNotParsableZoo, null, null);
|
456
|
assertTrue(nameZooRefNotParsabel.hasProblem());
|
457
|
List<ParserProblem> list = nameZooRefNotParsabel.getParsingProblems();
|
458
|
assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
|
459
|
assertEquals(21, nameZooRefNotParsabel.getProblemStarts());
|
460
|
assertEquals(37, nameZooRefNotParsabel.getProblemEnds());
|
461
|
assertTrue(nameZooRefNotParsabel.getNomenclaturalReference().hasProblem());
|
462
|
list = nameZooRefNotParsabel.getNomenclaturalReference().getParsingProblems();
|
463
|
assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
|
464
|
|
465
|
assertEquals(NomenclaturalCode.ICZN, nameZooRefNotParsabel.getNomenclaturalCode());
|
466
|
assertEquals(Integer.valueOf(1923), nameZooRefNotParsabel.getPublicationYear());
|
467
|
assertEquals(1, nameZooRefNotParsabel.getStatus().size());
|
468
|
|
469
|
String strZooNameSineYear = "Homo sapiens L., 1758, Sp. An. 3: 345";
|
470
|
ZoologicalName nameZooNameSineYear = (ZoologicalName)parser.parseReferencedName(strZooNameSineYear);
|
471
|
assertFalse(nameZooNameSineYear.hasProblem());
|
472
|
assertEquals("Name without reference year must have year", (Integer)1758, nameZooNameSineYear.getPublicationYear());
|
473
|
assertEquals("Name without reference year must have year", "1758", nameZooNameSineYear.getNomenclaturalReference().getYear());
|
474
|
|
475
|
String strZooNameNewCombination = "Homo sapiens (L., 1758) Mill., 1830, Sp. An. 3: 345";
|
476
|
ZoologicalName nameZooNameNewCombination = (ZoologicalName)parser.parseReferencedName(strZooNameNewCombination);
|
477
|
assertTrue(nameZooNameNewCombination.hasProblem());
|
478
|
list = nameZooNameNewCombination.getParsingProblems();
|
479
|
assertTrue("List must contain new combination has publication warning ", list.contains(ParserProblem.NewCombinationHasPublication));
|
480
|
assertEquals(35, nameZooNameNewCombination.getProblemStarts());
|
481
|
assertEquals(51, nameZooNameNewCombination.getProblemEnds());
|
482
|
|
483
|
|
484
|
//Special MicroRefs
|
485
|
String strSpecDetail1 = "Abies alba Mill. in Sp. Pl. 4(6): [455]. 1987";
|
486
|
NonViralName<?> nameSpecDet1 = parser.parseReferencedName(strSpecDetail1 + ".", null, Rank.SPECIES());
|
487
|
assertFalse(nameSpecDet1.hasProblem());
|
488
|
assertEquals(strSpecDetail1, nameSpecDet1.getFullTitleCache());
|
489
|
assertEquals("[455]", nameSpecDet1.getNomenclaturalMicroReference());
|
490
|
|
491
|
//Special MicroRefs
|
492
|
String strSpecDetail2 = "Abies alba Mill. in Sp. Pl. 4(6): couv. 2. 1987";
|
493
|
NonViralName<?> nameSpecDet2 = parser.parseReferencedName(strSpecDetail2 + ".", null, Rank.SPECIES());
|
494
|
assertFalse(nameSpecDet2.hasProblem());
|
495
|
assertEquals(strSpecDetail2, nameSpecDet2.getFullTitleCache());
|
496
|
assertEquals("couv. 2", nameSpecDet2.getNomenclaturalMicroReference());
|
497
|
|
498
|
//Special MicroRefs
|
499
|
String strSpecDetail3 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455. 1987";
|
500
|
NonViralName<?> nameSpecDet3 = parser.parseReferencedName(strSpecDetail3 + ".", null, Rank.SPECIES());
|
501
|
assertFalse(nameSpecDet3.hasProblem());
|
502
|
assertEquals(strSpecDetail3, nameSpecDet3.getFullTitleCache());
|
503
|
assertEquals("fig. 455", nameSpecDet3.getNomenclaturalMicroReference());
|
504
|
|
505
|
//Special MicroRefs
|
506
|
String strSpecDetail4 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455-567. 1987";
|
507
|
fullReference = strSpecDetail4 + ".";
|
508
|
NonViralName<?> nameSpecDet4 = parser.parseReferencedName(fullReference, null, Rank.SPECIES());
|
509
|
assertFalse(nameSpecDet4.hasProblem());
|
510
|
assertEquals(strSpecDetail4, nameSpecDet4.getFullTitleCache());
|
511
|
assertEquals("fig. 455-567", nameSpecDet4.getNomenclaturalMicroReference());
|
512
|
|
513
|
|
514
|
//Special MicroRefs
|
515
|
String strSpecDetail5 = "Abies alba Mill. in Sp. Pl. 4(6): Gard n\u00B0 4. 1987";
|
516
|
fullReference = strSpecDetail5 + ".";
|
517
|
NonViralName<?> nameSpecDet5 = parser.parseReferencedName(fullReference, null, Rank.SPECIES());
|
518
|
assertFalse(nameSpecDet5.hasProblem());
|
519
|
assertEquals(strSpecDetail5, nameSpecDet5.getFullTitleCache());
|
520
|
assertEquals("Gard n\u00B0 4", nameSpecDet5.getNomenclaturalMicroReference());
|
521
|
|
522
|
//Special MicroRefs
|
523
|
String strSpecDetail6 = "Abies alba Mill. in Sp. Pl. 4(6): 455a. 1987";
|
524
|
fullReference = strSpecDetail6 + ".";
|
525
|
NonViralName<?> nameSpecDet6 = parser.parseReferencedName(fullReference, null, Rank.SPECIES());
|
526
|
assertFalse(nameSpecDet6.hasProblem());
|
527
|
assertEquals(strSpecDetail6, nameSpecDet6.getFullTitleCache());
|
528
|
assertEquals("455a", nameSpecDet6.getNomenclaturalMicroReference());
|
529
|
|
530
|
//Special MicroRefs
|
531
|
String strSpecDetail7 = "Abies alba Mill. in Sp. Pl. 4(6): pp.455-457. 1987";
|
532
|
fullReference = strSpecDetail7 + ".";
|
533
|
NonViralName<?> nameSpecDet7 = parser.parseReferencedName(fullReference, null, Rank.SPECIES());
|
534
|
assertFalse(nameSpecDet7.hasProblem());
|
535
|
assertEquals(strSpecDetail7, nameSpecDet7.getFullTitleCache());
|
536
|
assertEquals("pp.455-457", nameSpecDet7.getNomenclaturalMicroReference());
|
537
|
|
538
|
//Special MicroRefs
|
539
|
String strSpecDetail8 = "Abies alba Mill. in Sp. Pl. 4(6): ppp.455-457. 1987";
|
540
|
NonViralName<?> nameSpecDet8 = parser.parseReferencedName(strSpecDetail8, null, Rank.SPECIES());
|
541
|
assertTrue(nameSpecDet8.hasProblem());
|
542
|
assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
|
543
|
assertEquals(51, nameSpecDet8.getProblemEnds()); //TODO better stop after -457
|
544
|
|
545
|
|
546
|
//Special MicroRefs
|
547
|
String strSpecDetail9 = "Abies alba Mill. in Sp. Pl. 4(6): pp. 455 - 457. 1987";
|
548
|
NonViralName<?> nameSpecDet9 = parser.parseReferencedName(strSpecDetail9, null, Rank.SPECIES());
|
549
|
assertFalse(nameSpecDet9.hasProblem());
|
550
|
assertEquals(strSpecDetail9, nameSpecDet9.getFullTitleCache());
|
551
|
assertEquals("pp. 455 - 457", nameSpecDet9.getNomenclaturalMicroReference());
|
552
|
|
553
|
//Special MicroRefs
|
554
|
String strSpecDetail10 = "Abies alba Mill. in Sp. Pl. 4(6): p 455. 1987";
|
555
|
NonViralName<?> nameSpecDet10 = parser.parseReferencedName(strSpecDetail10, null, Rank.SPECIES());
|
556
|
assertFalse(nameSpecDet10.hasProblem());
|
557
|
assertEquals(strSpecDetail10, nameSpecDet10.getFullTitleCache());
|
558
|
assertEquals("p 455", nameSpecDet10.getNomenclaturalMicroReference());
|
559
|
|
560
|
//Special MicroRefs
|
561
|
String strSpecDetail11 = "Abies alba Mill. in Sp. Pl. 4(6): p. 455 - 457. 1987";
|
562
|
NonViralName<?> nameSpecDet11 = parser.parseReferencedName(strSpecDetail11, null, Rank.SPECIES());
|
563
|
assertTrue(nameSpecDet11.hasProblem());
|
564
|
list = nameSpecDet11.getParsingProblems();
|
565
|
assertTrue("Problem is Detail. Must be pp.", list.contains(ParserProblem.CheckDetailOrYear));
|
566
|
assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
|
567
|
assertEquals(51, nameSpecDet8.getProblemEnds()); //TODO better stop after - 457
|
568
|
|
569
|
|
570
|
//no volume, no edition
|
571
|
String strNoVolume = "Abies alba Mill., Sp. Pl.: 455. 1987";
|
572
|
NonViralName<?> nameNoVolume = parser.parseReferencedName(strNoVolume, null, Rank.SPECIES());
|
573
|
assertFalse(nameNoVolume.hasProblem());
|
574
|
assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
|
575
|
assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
|
576
|
assertEquals(null, ((IBook)nameNoVolume.getNomenclaturalReference()).getEdition());
|
577
|
|
578
|
//volume, no edition
|
579
|
strNoVolume = "Abies alba Mill., Sp. Pl. 2: 455. 1987";
|
580
|
nameNoVolume = parser.parseReferencedName(strNoVolume, null, Rank.SPECIES());
|
581
|
assertFalse(nameNoVolume.hasProblem());
|
582
|
assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
|
583
|
assertEquals("2", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
|
584
|
assertEquals(null, ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
|
585
|
|
586
|
//no volume, edition
|
587
|
strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3: 455. 1987";
|
588
|
nameNoVolume = parser.parseReferencedName(strNoVolume, null, Rank.SPECIES());
|
589
|
assertFalse(nameNoVolume.hasProblem());
|
590
|
assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
|
591
|
assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
|
592
|
assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
|
593
|
|
594
|
//volume, edition
|
595
|
strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3, 4(5): 455. 1987";
|
596
|
nameNoVolume = parser.parseReferencedName(strNoVolume, null, Rank.SPECIES());
|
597
|
assertFalse(nameNoVolume.hasProblem());
|
598
|
assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
|
599
|
assertEquals("4(5)", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
|
600
|
assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
|
601
|
|
602
|
String strUnparsableInRef = "Abies alba Mill. in -er46: 455. 1987";
|
603
|
NonViralName<?> nameUnparsableInRef = parser.parseReferencedName(strUnparsableInRef, null, Rank.SPECIES());
|
604
|
assertTrue(nameUnparsableInRef.hasProblem());
|
605
|
list = nameUnparsableInRef.getParsingProblems();
|
606
|
assertTrue("Unparsable title", list.contains(ParserProblem.UnparsableReferenceTitle));
|
607
|
assertEquals(strUnparsableInRef, nameUnparsableInRef.getFullTitleCache());
|
608
|
assertEquals(20, nameUnparsableInRef.getProblemStarts());
|
609
|
assertEquals(25, nameUnparsableInRef.getProblemEnds());
|
610
|
|
611
|
|
612
|
//volume, edition
|
613
|
String strNoSeparator = "Abies alba Mill. Sp. Pl. ed. 3, 4(5): 455. 1987";
|
614
|
NonViralName<?> nameNoSeparator = parser.parseReferencedName(strNoSeparator, NomenclaturalCode.ICBN, Rank.SPECIES());
|
615
|
assertTrue(nameNoSeparator.hasProblem());
|
616
|
list = nameNoSeparator.getParsingProblems();
|
617
|
assertTrue("Problem is missing name-reference separator", list.contains(ParserProblem.NameReferenceSeparation));
|
618
|
assertEquals(strNoSeparator, nameNoSeparator.getFullTitleCache());
|
619
|
assertEquals(10, nameNoSeparator.getProblemStarts()); //TODO better start behind Mill. (?)
|
620
|
assertEquals(47, nameNoSeparator.getProblemEnds()); //TODO better stop before :
|
621
|
|
622
|
String strUnparsableInRef2 = "Hieracium pepsicum L., My Bookkkk 1. 1903";
|
623
|
NonViralName<?> nameUnparsableInRef2 = parser.parseReferencedName(strUnparsableInRef2, null, Rank.SPECIES());
|
624
|
assertTrue(nameUnparsableInRef2.hasProblem());
|
625
|
list = nameUnparsableInRef2.getParsingProblems();
|
626
|
assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
|
627
|
assertEquals(strUnparsableInRef2, nameUnparsableInRef2.getFullTitleCache());
|
628
|
assertEquals(23, nameUnparsableInRef2.getProblemStarts());
|
629
|
assertEquals(41, nameUnparsableInRef2.getProblemEnds());
|
630
|
|
631
|
|
632
|
String strUnparsableInRef3 = "Hieracium pespcim N., My Bookkkk 1. 1902";
|
633
|
NonViralName<?> nameUnparsableInRef3 = parser.parseReferencedName(strUnparsableInRef3, null, null);
|
634
|
assertTrue(nameUnparsableInRef3.hasProblem());
|
635
|
list = nameUnparsableInRef3.getParsingProblems();
|
636
|
assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
|
637
|
assertEquals(strUnparsableInRef3, nameUnparsableInRef3.getFullTitleCache());
|
638
|
assertEquals(22, nameUnparsableInRef3.getProblemStarts());
|
639
|
assertEquals(40, nameUnparsableInRef3.getProblemEnds());
|
640
|
|
641
|
String strUnparsableInRef4 = "Hieracium pepsicum (Hsllreterto) L., My Bookkkk 1. 1903";
|
642
|
NonViralName<?> nameUnparsableInRef4 = parser.parseReferencedName(strUnparsableInRef4, null, null);
|
643
|
assertTrue(nameUnparsableInRef4.hasProblem());
|
644
|
list = nameUnparsableInRef4.getParsingProblems();
|
645
|
assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
|
646
|
assertEquals(strUnparsableInRef4, nameUnparsableInRef4.getFullTitleCache());
|
647
|
assertEquals(37, nameUnparsableInRef4.getProblemStarts());
|
648
|
assertEquals(55, nameUnparsableInRef4.getProblemEnds());
|
649
|
|
650
|
String strSameName = "Hieracium pepcum (Hsllreterto) L., My Bokkk 1. 1903";
|
651
|
NonViralName<?> nameSameName = nameUnparsableInRef4;
|
652
|
parser.parseReferencedName(nameSameName, strSameName, null, true);
|
653
|
assertTrue(nameSameName.hasProblem());
|
654
|
list = nameSameName.getParsingProblems();
|
655
|
assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
|
656
|
assertEquals(strSameName, nameSameName.getFullTitleCache());
|
657
|
assertEquals(35, nameSameName.getProblemStarts());
|
658
|
assertEquals(51, nameSameName.getProblemEnds());
|
659
|
|
660
|
String strGenusUnparse = "Hieracium L., jlklk";
|
661
|
NonViralName<?> nameGenusUnparse =
|
662
|
parser.parseReferencedName(strGenusUnparse, null, null);
|
663
|
assertTrue(nameGenusUnparse.hasProblem());
|
664
|
list = nameGenusUnparse.getParsingProblems();
|
665
|
assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
|
666
|
assertTrue("Problem uninomial", list.contains(ParserProblem.CheckRank));
|
667
|
assertEquals(strGenusUnparse, nameGenusUnparse.getFullTitleCache());
|
668
|
assertEquals(0, nameGenusUnparse.getProblemStarts());
|
669
|
assertEquals(19, nameGenusUnparse.getProblemEnds());
|
670
|
|
671
|
String strGenusUnparse2 = "Hieracium L., Per Luigi: 44. 1987";
|
672
|
NonViralName<?> nameGenusUnparse2 =
|
673
|
parser.parseReferencedName(strGenusUnparse2, null, Rank.FAMILY());
|
674
|
assertFalse(nameGenusUnparse2.hasProblem());
|
675
|
assertEquals(strGenusUnparse2, nameGenusUnparse2.getFullTitleCache());
|
676
|
assertEquals(-1, nameGenusUnparse2.getProblemStarts());
|
677
|
assertEquals(-1, nameGenusUnparse2.getProblemEnds());
|
678
|
|
679
|
String strBookSection2 = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz, ed. 2, 2: 288. 1905-1907";
|
680
|
String strBookSection2NoComma = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905-1907";
|
681
|
NonViralName<?> nameBookSection2 =
|
682
|
parser.parseReferencedName(strBookSection2, null, null);
|
683
|
assertFalse(nameBookSection2.hasProblem());
|
684
|
assertEquals(strBookSection2NoComma, nameBookSection2.getFullTitleCache());
|
685
|
assertEquals(-1, nameBookSection2.getProblemStarts());
|
686
|
assertEquals(-1, nameBookSection2.getProblemEnds());
|
687
|
assertNull((nameBookSection2.getNomenclaturalReference()).getDatePublished().getStart());
|
688
|
assertEquals("1905-1907", ((IBookSection)nameBookSection2.getNomenclaturalReference()).getInBook().getDatePublished().getYear());
|
689
|
|
690
|
|
691
|
String strBookSection = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905";
|
692
|
NonViralName<?> nameBookSection =
|
693
|
parser.parseReferencedName(strBookSection, null, null);
|
694
|
assertFalse(nameBookSection.hasProblem());
|
695
|
assertEquals(strBookSection, nameBookSection.getFullTitleCache());
|
696
|
assertEquals(-1, nameBookSection.getProblemStarts());
|
697
|
assertEquals(-1, nameBookSection.getProblemEnds());
|
698
|
assertNull(((IBookSection)nameBookSection.getNomenclaturalReference()).getInBook().getDatePublished().getStart());
|
699
|
assertEquals("1905", ((IBookSection)nameBookSection.getNomenclaturalReference()).getDatePublished().getYear());
|
700
|
|
701
|
String strXXXs = "Abies alba, Soer der 1987";
|
702
|
NonViralName<?> problemName = parser.parseReferencedName(strXXXs, null, null);
|
703
|
assertTrue(problemName.hasProblem());
|
704
|
list = problemName.getParsingProblems();
|
705
|
assertTrue("Problem must be name-reference separation", list.contains(ParserProblem.NameReferenceSeparation));
|
706
|
parser.parseReferencedName(problemName, strBookSection, null, true);
|
707
|
assertFalse(problemName.hasProblem());
|
708
|
|
709
|
problemName = parser.parseFullName(strXXXs, null, null);
|
710
|
assertTrue(problemName.hasProblem());
|
711
|
list = problemName.getParsingProblems();
|
712
|
assertTrue("Name part must be unparsable", list.contains(ParserProblem.UnparsableNamePart));
|
713
|
|
714
|
|
715
|
String testParsable = "Pithecellobium macrostachyum Benth.";
|
716
|
assertTrue(isParsable(testParsable, NomenclaturalCode.ICBN));
|
717
|
|
718
|
testParsable = "Pithecellobium macrostachyum (Benth.)";
|
719
|
assertTrue(isParsable(testParsable, NomenclaturalCode.ICBN));
|
720
|
|
721
|
testParsable = "Pithecellobium macrostachyum (Benth., 1845)";
|
722
|
assertTrue(isParsable(testParsable, NomenclaturalCode.ICZN));
|
723
|
|
724
|
testParsable = "Pithecellobium macrostachyum L., Sp. Pl. 3: n\u00B0 123. 1753."; //00B0 is degree character
|
725
|
assertTrue(isParsable(testParsable, NomenclaturalCode.ICBN));
|
726
|
|
727
|
testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur. 6: 1285. 1929";
|
728
|
assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, NomenclaturalCode.ICBN));
|
729
|
|
730
|
testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.&Eur. 6: 1285. 1929";
|
731
|
assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, NomenclaturalCode.ICBN));
|
732
|
|
733
|
testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur.& 6: 1285. 1929";
|
734
|
assertFalse("Reference title should not support special characters like - and & at the end of the title", isParsable(testParsable, NomenclaturalCode.ICBN));
|
735
|
assertTrue("Problem must be reference title", getProblems(testParsable, NomenclaturalCode.ICBN).
|
736
|
contains(ParserProblem.UnparsableReferenceTitle));
|
737
|
|
738
|
testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.:Eur. 6: 1285. 1929";
|
739
|
assertFalse("Reference title should not support detail separator", isParsable(testParsable, NomenclaturalCode.ICBN));
|
740
|
assertTrue("Problem must be reference title", getProblems(testParsable, NomenclaturalCode.ICBN).
|
741
|
contains(ParserProblem.UnparsableReferenceTitle));
|
742
|
|
743
|
testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
|
744
|
assertTrue("Reference title should support brackets", isParsable(testParsable, NomenclaturalCode.ICBN));
|
745
|
|
746
|
testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
|
747
|
assertTrue("Reference title should support brackets", isParsable(testParsable, NomenclaturalCode.ICBN));
|
748
|
|
749
|
testParsable = "Hieracium lachenalii Zahn, nom. illeg.";
|
750
|
assertTrue("Reference should not be obligatory if a nom status exist", isParsable(testParsable, NomenclaturalCode.ICBN));
|
751
|
|
752
|
testParsable = "Hieracium lachenalii, nom. illeg.";
|
753
|
assertTrue("Authorship should not be obligatory if followed by nom status", isParsable(testParsable, NomenclaturalCode.ICBN));
|
754
|
|
755
|
testParsable = "Hieracium lachenalii, Ill. Fl. (Mitt.) 6: 1285. 1929";
|
756
|
assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, NomenclaturalCode.ICBN));
|
757
|
assertTrue("Problem must be name-reference separation", getProblems(testParsable, NomenclaturalCode.ICBN).
|
758
|
contains(ParserProblem.NameReferenceSeparation));
|
759
|
|
760
|
testParsable = "Hieracium lachenalii in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
|
761
|
assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, NomenclaturalCode.ICBN));
|
762
|
assertTrue("Problem must be name-reference separation", getProblems(testParsable, NomenclaturalCode.ICBN).
|
763
|
contains(ParserProblem.NameReferenceSeparation));
|
764
|
|
765
|
testParsable = "Abies alba Mill. var. alba";
|
766
|
assertTrue("Autonym problem", isParsable(testParsable, NomenclaturalCode.ICBN));
|
767
|
|
768
|
|
769
|
testParsable = "Hieracium antarcticum d'Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
|
770
|
// testParsable = "Hieracium antarcticum Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
|
771
|
assertTrue("Name with apostrophe is not parsable", isParsable(testParsable, NomenclaturalCode.ICBN));
|
772
|
|
773
|
}
|
774
|
|
775
|
|
776
|
|
777
|
/**
|
778
|
* @param testParsable
|
779
|
* @param icbn
|
780
|
* @return
|
781
|
*/
|
782
|
private List<ParserProblem> getProblems(String string, NomenclaturalCode code) {
|
783
|
List<ParserProblem> result;
|
784
|
result = parser.parseReferencedName(string, code, null).getParsingProblems();
|
785
|
return result;
|
786
|
}
|
787
|
|
788
|
private boolean isParsable(String string, NomenclaturalCode code){
|
789
|
NonViralName<?> name = parser.parseReferencedName(string, code, null);
|
790
|
return ! name.hasProblem();
|
791
|
}
|
792
|
|
793
|
private void assertFullRefNameStandard(NonViralName<?> name){
|
794
|
assertEquals("Abies", name.getGenusOrUninomial());
|
795
|
assertEquals("alba", name.getSpecificEpithet());
|
796
|
assertEquals("Mill.", name.getAuthorshipCache());
|
797
|
assertEquals("455", name.getNomenclaturalMicroReference());
|
798
|
assertNotNull(name.getNomenclaturalReference());
|
799
|
}
|
800
|
|
801
|
private void assertFullRefStandard(NonViralName<?> name){
|
802
|
assertEquals("Abies", name.getGenusOrUninomial());
|
803
|
assertEquals("alba", name.getSpecificEpithet());
|
804
|
assertEquals("Mill.", name.getAuthorshipCache());
|
805
|
assertEquals("455", name.getNomenclaturalMicroReference());
|
806
|
assertNotNull(name.getNomenclaturalReference());
|
807
|
INomenclaturalReference ref = (INomenclaturalReference)name.getNomenclaturalReference();
|
808
|
assertEquals("1987", ref.getYear());
|
809
|
Reference refBase = (Reference)ref;
|
810
|
assertEquals("Sp. Pl.", refBase.getTitle());
|
811
|
}
|
812
|
|
813
|
|
814
|
@Test
|
815
|
public void testNeverEndingParsing(){
|
816
|
//some full titles result in never ending parsing process https://dev.e-taxonomy.eu/trac/ticket/1556
|
817
|
|
818
|
String irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
|
819
|
// irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Uiuis Iuiui Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
|
820
|
NonViralName nvn = this.parser.parseReferencedName(irinaExample, NomenclaturalCode.ICZN, null);
|
821
|
int parsingProblem = nvn.getParsingProblem();
|
822
|
Assert.assertEquals("Name should have only rank warning", 1, parsingProblem);
|
823
|
Assert.assertEquals("Titlecache", "Milichiidae Sharp, 1899", nvn.getTitleCache());
|
824
|
Assert.assertEquals("If this line reached everything should be ok", "Milichiidae", nvn.getGenusOrUninomial());
|
825
|
|
826
|
String anotherExample = "Scorzonera hispanica var. brevifolia Boiss. & Balansa in Boissier, Diagn. Pl. Orient., ser. 2 6: 119. 1859.";
|
827
|
nvn = this.parser.parseReferencedName(anotherExample, NomenclaturalCode.ICBN, null);
|
828
|
parsingProblem = nvn.getParsingProblem();
|
829
|
Assert.assertEquals("Problem should be 0", 0, parsingProblem);
|
830
|
Assert.assertEquals("Titlecache", "Scorzonera hispanica var. brevifolia Boiss. & Balansa", nvn.getTitleCache());
|
831
|
Assert.assertEquals("If this line reached everything should be ok", "Scorzonera", nvn.getGenusOrUninomial());
|
832
|
|
833
|
String unparsable = "Taraxacum nevskii L., Trudy Bot. Inst. Nauk S.S.S.R., Ser. 1, Fl. Sist. Vyssh. Rast. 4: 293. 1937.";
|
834
|
String unparsableA = "Taraxacum nevskii L. in Trudy Bot. Inst. Nauk: 293. 1937.";
|
835
|
nvn = this.parser.parseReferencedName(unparsable, NomenclaturalCode.ICBN, null);
|
836
|
Assert.assertEquals("Titlecache", "Taraxacum nevskii L.", nvn.getTitleCache());
|
837
|
Assert.assertEquals("If this line reached everything should be ok", "Taraxacum", nvn.getGenusOrUninomial());
|
838
|
parsingProblem = nvn.getParsingProblem();
|
839
|
Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
|
840
|
|
841
|
String unparsable2 = "Hieracium pxxx Dahlst., Kongl. Svenska Vetensk. Acad. Handl. ser. 2, 26(3): 255. 1894";
|
842
|
String unparsable2A = "Hieracium pxxx Dahlst., Kongl Svenska Vetensk Acad Handl, 26: 255. 1894.";
|
843
|
nvn = this.parser.parseReferencedName(unparsable2, NomenclaturalCode.ICBN, null);
|
844
|
Assert.assertEquals("Titlecache", "Hieracium pxxx Dahlst.", nvn.getTitleCache());
|
845
|
Assert.assertEquals("If this line reached everything should be ok", "Hieracium", nvn.getGenusOrUninomial());
|
846
|
parsingProblem = nvn.getParsingProblem();
|
847
|
Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
|
848
|
|
849
|
|
850
|
String again = "Adiantum emarginatum Bory ex. Willd., Species Plantarum, ed. 4,5,1: 449,450. 1810";
|
851
|
nvn = this.parser.parseReferencedName(again, NomenclaturalCode.ICBN, null);
|
852
|
Assert.assertEquals("Titlecache", "Adiantum emarginatum Bory ex Willd.", nvn.getTitleCache());
|
853
|
Assert.assertEquals("If this line reached everything should be ok", "Adiantum", nvn.getGenusOrUninomial());
|
854
|
|
855
|
}
|
856
|
|
857
|
@Test
|
858
|
public final void testSeriesPart(){
|
859
|
Pattern seriesPattern = Pattern.compile(NonViralNameParserImpl.pSeriesPart);
|
860
|
Matcher matcher = seriesPattern.matcher("ser. 2");
|
861
|
Assert.assertTrue("", matcher.matches());
|
862
|
}
|
863
|
|
864
|
/**
|
865
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#fullTeams(java.lang.String)}.
|
866
|
*/
|
867
|
@Test
|
868
|
public final void testFullTeams() {
|
869
|
logger.warn("Not yet implemented"); // TODO
|
870
|
}
|
871
|
|
872
|
/**
|
873
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#authorTeamAndEx(java.lang.String)}.
|
874
|
*/
|
875
|
@Test
|
876
|
public final void testAuthorTeamAndEx() {
|
877
|
logger.warn("Not yet implemented"); // TODO
|
878
|
}
|
879
|
|
880
|
/**
|
881
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#authorTeam(java.lang.String)}.
|
882
|
*/
|
883
|
@Test
|
884
|
public final void testAuthorTeam() {
|
885
|
logger.warn("Not yet implemented"); // TODO
|
886
|
}
|
887
|
|
888
|
/**
|
889
|
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseCultivar(java.lang.String)}.
|
890
|
*/
|
891
|
@Test
|
892
|
public final void testParseCultivar() {
|
893
|
logger.warn("Not yet implemented"); // TODO
|
894
|
}
|
895
|
|
896
|
}
|