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
|
package eu.etaxonomy.cdm.strategy.match;
|
10
|
|
11
|
import org.apache.log4j.Logger;
|
12
|
import org.junit.Assert;
|
13
|
import org.junit.Before;
|
14
|
import org.junit.Test;
|
15
|
|
16
|
import eu.etaxonomy.cdm.common.DOI;
|
17
|
import eu.etaxonomy.cdm.common.URI;
|
18
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
19
|
import eu.etaxonomy.cdm.model.agent.Person;
|
20
|
import eu.etaxonomy.cdm.model.agent.Team;
|
21
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
22
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
23
|
import eu.etaxonomy.cdm.model.name.Rank;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
26
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
27
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
28
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
29
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
30
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
31
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
32
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
33
|
import eu.etaxonomy.cdm.test.TermTestBase;
|
34
|
|
35
|
/**
|
36
|
* Test class for {@link MatchStrategyFactory}
|
37
|
*
|
38
|
* @author a.mueller
|
39
|
* @since 03.08.2009
|
40
|
*/
|
41
|
public class MatchStrategyFactoryTest extends TermTestBase {
|
42
|
|
43
|
@SuppressWarnings("unused")
|
44
|
private static final Logger logger = Logger.getLogger(MatchStrategyFactoryTest.class);
|
45
|
|
46
|
private static boolean FAIL_ALL = true;
|
47
|
|
48
|
private IMatchStrategyEqual matchStrategy;
|
49
|
|
50
|
private Institution institution1;
|
51
|
|
52
|
@Before
|
53
|
public void setUp() throws Exception {
|
54
|
institution1 = Institution.NewNamedInstance("Institution1");
|
55
|
}
|
56
|
|
57
|
//********************* TEST *********************************************/
|
58
|
|
59
|
@Test
|
60
|
public void testNewInstance() {
|
61
|
matchStrategy = MatchStrategyFactory.NewDefaultInstance(Reference.class);
|
62
|
Assert.assertNotNull(matchStrategy);
|
63
|
// Assert.assertEquals(Reference.class, matchStrategy.getMatchClass());
|
64
|
}
|
65
|
|
66
|
@Test
|
67
|
public void testParsedPerson() throws MatchException {
|
68
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedPersonInstance();
|
69
|
Assert.assertNotNull(matchStrategy);
|
70
|
Person fullPerson;
|
71
|
Person parsedPerson;
|
72
|
MatchResult result;
|
73
|
|
74
|
fullPerson = getDefaultFullPerson();
|
75
|
|
76
|
//should match
|
77
|
parsedPerson = getDefaultParsedPerson();
|
78
|
result = matchStrategy.invoke(parsedPerson, fullPerson);
|
79
|
System.out.println(result);
|
80
|
Assert.assertTrue("Same nom.title. should match", result.isSuccessful());
|
81
|
|
82
|
//differing nom. title.
|
83
|
parsedPerson.setNomenclaturalTitle("Wrong");
|
84
|
result = matchStrategy.invoke(fullPerson, parsedPerson, FAIL_ALL);
|
85
|
System.out.println(result);
|
86
|
Assert.assertFalse("Differing nom.title. should not match",
|
87
|
matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
|
88
|
|
89
|
//differing family
|
90
|
parsedPerson = getDefaultParsedPerson();
|
91
|
parsedPerson.setFamilyName("Wrong");
|
92
|
Assert.assertFalse("Differing family name should not match",
|
93
|
matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
|
94
|
fullPerson.setFamilyName(null);
|
95
|
Assert.assertFalse("Only parsed with family name should not match. Wrong direction.",
|
96
|
matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
|
97
|
|
98
|
//
|
99
|
parsedPerson = getDefaultParsedPerson();
|
100
|
parsedPerson.setInitials("D.");
|
101
|
Assert.assertFalse("Differing nom. title should not match",
|
102
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
103
|
|
104
|
//nom. title. (2)
|
105
|
fullPerson = getDefaultFullPerson();
|
106
|
parsedPerson = getDefaultParsedPerson();
|
107
|
fullPerson.setNomenclaturalTitle("Wro.");
|
108
|
Assert.assertFalse("Differing nom. title should not match",
|
109
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
110
|
|
111
|
//fullPerson protected
|
112
|
fullPerson = getDefaultFullPerson();
|
113
|
parsedPerson = getDefaultParsedPerson();
|
114
|
fullPerson.setTitleCache(fullPerson.getTitleCache(), true);
|
115
|
Assert.assertFalse("Differing protected title should not match",
|
116
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
117
|
|
118
|
//parsedPerson protected
|
119
|
fullPerson = getDefaultFullPerson();
|
120
|
parsedPerson = getDefaultParsedPerson();
|
121
|
parsedPerson.setTitleCache(parsedPerson.getTitleCache(), true);
|
122
|
// System.out.println(fullPerson.getTitleCache());
|
123
|
// System.out.println(parsedPerson.getTitleCache());
|
124
|
Assert.assertFalse("Differing nom. title should not match",
|
125
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
126
|
}
|
127
|
|
128
|
protected Person getDefaultFullPerson() {
|
129
|
Person fullPerson = Person.NewInstance();
|
130
|
fullPerson.setInitials("F.G.");
|
131
|
fullPerson.setFamilyName("Name");
|
132
|
fullPerson.setNomenclaturalTitle("Nam.");
|
133
|
fullPerson.setGivenName("Full Given");
|
134
|
fullPerson.setPrefix("Dr.");
|
135
|
fullPerson.setSuffix("jr.");
|
136
|
// fullPerson.setCollectorTitle();
|
137
|
fullPerson.setLifespan(TimePeriodParser.parseString("1972-2015"));
|
138
|
fullPerson.addInstitutionalMembership(institution1, TimePeriodParser.parseString("2002-2004"), "Dept. X", "Developer");
|
139
|
return fullPerson;
|
140
|
}
|
141
|
|
142
|
protected Person getDefaultParsedPerson() {
|
143
|
Person parsedPerson = Person.NewInstance();
|
144
|
parsedPerson.setNomenclaturalTitle("Nam.");
|
145
|
return parsedPerson;
|
146
|
}
|
147
|
|
148
|
@Test
|
149
|
public void testParsedTeam() throws MatchException {
|
150
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedTeamInstance();
|
151
|
Assert.assertNotNull(matchStrategy);
|
152
|
Team fullTeam;
|
153
|
Team parsedTeam;
|
154
|
MatchResult matchResult;
|
155
|
|
156
|
fullTeam = getDefaultFullTeam();
|
157
|
parsedTeam = getDefaultParsedTeam();
|
158
|
|
159
|
//should match
|
160
|
Assert.assertTrue("Same nom.title. should match",
|
161
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
162
|
|
163
|
//differing nom. title.
|
164
|
parsedTeam.setNomenclaturalTitleCache("Wrong", true);
|
165
|
Assert.assertFalse("Differing nom.title. should not match",
|
166
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
167
|
|
168
|
//differing family
|
169
|
parsedTeam = getDefaultParsedTeam();
|
170
|
parsedTeam.getTeamMembers().get(0).setFamilyName("Wrong");
|
171
|
matchResult = matchStrategy.invoke(parsedTeam, fullTeam, true);
|
172
|
Assert.assertFalse("Differing family name should not match", matchResult.isSuccessful());
|
173
|
parsedTeam.getTeamMembers().get(0).setNomenclaturalTitle("Wrong.");
|
174
|
matchResult = matchStrategy.invoke(parsedTeam, fullTeam, true);
|
175
|
System.out.println(matchResult);
|
176
|
Assert.assertFalse("Differing family name should not match", matchResult.isSuccessful());
|
177
|
|
178
|
//
|
179
|
parsedTeam = getDefaultParsedTeam();
|
180
|
parsedTeam.getTeamMembers().get(0).setInitials("D.");
|
181
|
Assert.assertFalse("Differing nom. title should not match",
|
182
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
183
|
|
184
|
//nom. title. (2)
|
185
|
fullTeam = getDefaultFullTeam();
|
186
|
parsedTeam = getDefaultParsedTeam();
|
187
|
fullTeam.setNomenclaturalTitleCache("Wro.", true);
|
188
|
Assert.assertFalse("Differing nom. title should not match",
|
189
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
190
|
|
191
|
//fullPerson protected
|
192
|
fullTeam = getDefaultFullTeam();
|
193
|
parsedTeam = getDefaultParsedTeam();
|
194
|
fullTeam.setTitleCache(fullTeam.getTitleCache(), true);
|
195
|
Assert.assertFalse("Differing protected title should not match",
|
196
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
197
|
|
198
|
//parsedPerson protected
|
199
|
fullTeam = getDefaultFullTeam();
|
200
|
parsedTeam = getDefaultParsedTeam();
|
201
|
parsedTeam.setTitleCache(parsedTeam.getTitleCache(), true);
|
202
|
Assert.assertFalse("Differing nom. title should not match",
|
203
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
204
|
|
205
|
fullTeam = getDefaultFullTeam();
|
206
|
parsedTeam = getDefaultParsedTeam();
|
207
|
fullTeam.setHasMoreMembers(true);
|
208
|
Assert.assertFalse("Differing nom. title should not match",
|
209
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
210
|
}
|
211
|
|
212
|
private Team getDefaultFullTeam() {
|
213
|
Team team = Team.NewInstance();
|
214
|
team.addTeamMember(getDefaultFullPerson());
|
215
|
team.addTeamMember(getFullPerson2());
|
216
|
team.getNomenclaturalTitleCache();
|
217
|
return team;
|
218
|
}
|
219
|
|
220
|
|
221
|
protected Person getFullPerson2() {
|
222
|
Person fullPerson = Person.NewInstance();
|
223
|
fullPerson.setInitials("A.B.");
|
224
|
fullPerson.setFamilyName("Nice");
|
225
|
fullPerson.setNomenclaturalTitle("Nice");
|
226
|
fullPerson.setGivenName("John");
|
227
|
return fullPerson;
|
228
|
}
|
229
|
|
230
|
private Team getDefaultParsedTeam() {
|
231
|
Team team = Team.NewInstance();
|
232
|
team.addTeamMember(getDefaultParsedPerson());
|
233
|
team.addTeamMember(getFullPerson2());
|
234
|
//TODO should be done in cache strategy
|
235
|
team.getNomenclaturalTitleCache();
|
236
|
return team;
|
237
|
}
|
238
|
|
239
|
protected Person getParsedPerson2() {
|
240
|
Person parsedPerson = Person.NewInstance();
|
241
|
parsedPerson.setNomenclaturalTitle("Nice");
|
242
|
return parsedPerson;
|
243
|
}
|
244
|
|
245
|
@Test
|
246
|
public void testParsedBook() throws MatchException {
|
247
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedBookInstance();
|
248
|
Assert.assertNotNull(matchStrategy);
|
249
|
IBook fullBook;
|
250
|
IBook parsedBook;
|
251
|
|
252
|
fullBook = getDefaultFullBook();
|
253
|
parsedBook = getDefaultParsedBook();
|
254
|
|
255
|
//should match
|
256
|
parsedBook = getDefaultParsedBook();
|
257
|
Assert.assertTrue("Same abbrev. title should match",
|
258
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
259
|
fullBook.setDoi(DOI.fromString("10.1234/abc"));
|
260
|
Assert.assertTrue("DOI only with full book should match as abbrev title identifies the book",
|
261
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
262
|
|
263
|
//differing nom. title.
|
264
|
parsedBook.setAbbrevTitle("Wrong");
|
265
|
Assert.assertFalse("Differing abbrev. title. should not match",
|
266
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
267
|
|
268
|
//differing family
|
269
|
parsedBook = getDefaultParsedBook();
|
270
|
parsedBook.setTitle("Wrong title");
|
271
|
Assert.assertFalse("Differing title should not match",
|
272
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
273
|
fullBook.setTitle(null);
|
274
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
|
275
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
276
|
|
277
|
//change author
|
278
|
fullBook = getDefaultFullBook();
|
279
|
parsedBook = getDefaultParsedBook();
|
280
|
((Team)fullBook.getAuthorship()).getTeamMembers().get(0).setNomenclaturalTitle("Wrong");
|
281
|
Assert.assertFalse("Differing author in nomencl. title should not match",
|
282
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
283
|
|
284
|
//change author
|
285
|
fullBook = getDefaultFullBook();
|
286
|
parsedBook = getDefaultParsedBook();
|
287
|
((Team)fullBook.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
|
288
|
Assert.assertTrue("Full book family name author changed should still match",
|
289
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
290
|
}
|
291
|
|
292
|
@Test
|
293
|
public void testParsedBookSection() throws MatchException {
|
294
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedBookSectionInstance();
|
295
|
Assert.assertNotNull(matchStrategy);
|
296
|
IBookSection fullBookSection;
|
297
|
IBookSection parsedBookSection;
|
298
|
|
299
|
fullBookSection = getMatchingFullBookSection();
|
300
|
parsedBookSection = getDefaultParsedBookSection();
|
301
|
Assert.assertTrue("Only author, book and date published should match",
|
302
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful() );
|
303
|
fullBookSection.setDoi(DOI.fromString("10.1234/abc"));
|
304
|
Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
|
305
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
306
|
fullBookSection.setDoi(null);
|
307
|
fullBookSection.setReferenceAbstract("My abstract");
|
308
|
Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
|
309
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
310
|
|
311
|
//should match
|
312
|
fullBookSection = getDefaultFullBookSection();
|
313
|
Assert.assertFalse("Abbrev. title must be equal or null",
|
314
|
matchStrategy.invoke(fullBookSection, parsedBookSection).isSuccessful());
|
315
|
parsedBookSection.setAbbrevTitle(fullBookSection.getAbbrevTitle());
|
316
|
Assert.assertFalse("Still not match because pages are not equal (parsed is null)",
|
317
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
318
|
parsedBookSection.setPages(fullBookSection.getPages());
|
319
|
Assert.assertFalse("Now they should match",
|
320
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
321
|
|
322
|
//differing nom. title.
|
323
|
parsedBookSection.setAbbrevTitle("Wrong");
|
324
|
Assert.assertFalse("Differing abbrev. title. should not match",
|
325
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
326
|
|
327
|
//differing family
|
328
|
parsedBookSection = getDefaultParsedBookSection();
|
329
|
parsedBookSection.setTitle("Wrong title");
|
330
|
Assert.assertFalse("Differing title should not match",
|
331
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
332
|
fullBookSection.setTitle(null);
|
333
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
|
334
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
335
|
|
336
|
//change author
|
337
|
fullBookSection = getMatchingFullBookSection();
|
338
|
parsedBookSection = getDefaultParsedBookSection();
|
339
|
fullBookSection.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
|
340
|
Assert.assertFalse("Differing author in nomencl. title should not match",
|
341
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
342
|
|
343
|
//change author
|
344
|
fullBookSection = getMatchingFullBookSection();
|
345
|
parsedBookSection = getDefaultParsedBookSection();
|
346
|
((Person)fullBookSection.getAuthorship()).setFamilyName("Changed");
|
347
|
Assert.assertTrue("Full book family name author changed should still match",
|
348
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
349
|
}
|
350
|
|
351
|
private IBook getDefaultFullBook() {
|
352
|
IBook book = getDefaultParsedBook();
|
353
|
book.setAuthorship(getDefaultFullTeam());
|
354
|
book.setTitle("Flora Hellenica");
|
355
|
book.setUri(URI.create("https://www.flora.hellenica.gr"));
|
356
|
book.setIsbn("1234-222-222-333"); //format not yet correct
|
357
|
book.setPublisher("Greek publisher", "Athens");
|
358
|
book.getTitleCache();
|
359
|
return book;
|
360
|
}
|
361
|
|
362
|
private IBook getDefaultParsedBook() {
|
363
|
IBook book = ReferenceFactory.newBook();
|
364
|
book.setAbbrevTitle("Fl. Hell.");
|
365
|
book.setVolume("2");
|
366
|
book.setEdition("ed. 3");
|
367
|
book.setEditor("editor");
|
368
|
book.setAuthorship(getDefaultParsedTeam());
|
369
|
book.setDatePublished(TimePeriodParser.parseStringVerbatim("1982-10-06"));
|
370
|
book.getAbbrevTitleCache();
|
371
|
return book;
|
372
|
}
|
373
|
|
374
|
private IBookSection getDefaultFullBookSection() {
|
375
|
IBookSection bookSection = getMatchingFullBookSection();
|
376
|
bookSection.setTitle("Book section title");
|
377
|
bookSection.setAbbrevTitle("Bk. sct. tit.");
|
378
|
bookSection.setPages("22-33");
|
379
|
return bookSection;
|
380
|
}
|
381
|
|
382
|
private IBookSection getMatchingFullBookSection() {
|
383
|
IBookSection bookSection = ReferenceFactory.newBookSection();
|
384
|
bookSection.setAuthorship(getDefaultFullPerson());
|
385
|
bookSection.setInBook(getDefaultFullBook());
|
386
|
bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1892"));
|
387
|
return bookSection;
|
388
|
}
|
389
|
|
390
|
private IBookSection getDefaultParsedBookSection() {
|
391
|
IBookSection bookSection = ReferenceFactory.newBookSection();
|
392
|
bookSection.setAuthorship(getDefaultParsedPerson());
|
393
|
bookSection.setInBook(getDefaultParsedBook());
|
394
|
bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1892"));
|
395
|
return bookSection;
|
396
|
}
|
397
|
|
398
|
@Test
|
399
|
public void testParsedArticle() throws MatchException {
|
400
|
|
401
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedArticleInstance();
|
402
|
Assert.assertNotNull(matchStrategy);
|
403
|
IArticle fullArticle;
|
404
|
IArticle parsedArticle;
|
405
|
|
406
|
fullArticle = getMatchingFullArticle();
|
407
|
parsedArticle = getDefaultParsedArticle();
|
408
|
Assert.assertTrue("Having only paramters both have in common like author, book and date published "
|
409
|
+ "should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
410
|
fullArticle.setDoi(DOI.fromString("10.1234/abc"));
|
411
|
Assert.assertFalse("Full article having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
|
412
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
413
|
|
414
|
//no match due to missing abbrev title match
|
415
|
fullArticle = getDefaultFullArticle();
|
416
|
Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle,
|
417
|
fullArticle).isSuccessful());
|
418
|
parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
|
419
|
Assert.assertFalse("Still not match because pages are not equal (parsed is null)",
|
420
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
421
|
//FIXME in future this should not fail, but parsed articles never have really pages, they only have page or a page span in the parsed detail which is not the same as the pages of the article
|
422
|
parsedArticle.setPages(fullArticle.getPages());
|
423
|
Assert.assertFalse("Now they should match",
|
424
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
425
|
|
426
|
//differing nom. title.
|
427
|
parsedArticle.setAbbrevTitle("Wrong");
|
428
|
Assert.assertFalse("Differing abbrev. title. should not match",
|
429
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
430
|
|
431
|
//differing family
|
432
|
parsedArticle = getDefaultParsedArticle();
|
433
|
parsedArticle.setTitle("Wrong title");
|
434
|
Assert.assertFalse("Differing title should not match",
|
435
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
436
|
fullArticle.setTitle(null);
|
437
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
|
438
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
439
|
|
440
|
//change author
|
441
|
fullArticle = getMatchingFullArticle();
|
442
|
parsedArticle = getDefaultParsedArticle();
|
443
|
fullArticle.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
|
444
|
Assert.assertFalse("Differing author in nomencl. title should not match",
|
445
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
446
|
|
447
|
//change author
|
448
|
fullArticle = getMatchingFullArticle();
|
449
|
parsedArticle = getDefaultParsedArticle();
|
450
|
((Team)fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
|
451
|
Assert.assertTrue("Full book family name author changed should still match",
|
452
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
453
|
}
|
454
|
|
455
|
/**
|
456
|
* Like {@link #getMatchingFullArticle() matching full article} with additional
|
457
|
* title, abbrevTitle and pages
|
458
|
*/
|
459
|
private IArticle getDefaultFullArticle() {
|
460
|
IArticle article = getMatchingFullArticle();
|
461
|
article.setTitle("Article title");
|
462
|
article.setAbbrevTitle("Art. tit.");
|
463
|
article.setPages("22-33");
|
464
|
return article;
|
465
|
}
|
466
|
|
467
|
/**
|
468
|
* Article with {@link #getDefaultFullTeam() full team},
|
469
|
* {@link #getDefaultFullJournal() full journal} and date published
|
470
|
*/
|
471
|
private IArticle getMatchingFullArticle() {
|
472
|
IArticle article = ReferenceFactory.newArticle();
|
473
|
article.setAuthorship(getDefaultFullTeam());
|
474
|
article.setInJournal(getDefaultFullJournal());
|
475
|
article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
|
476
|
return article;
|
477
|
}
|
478
|
|
479
|
/**
|
480
|
* Article with {@link #getDefaultParsedTeam() parsed authorship},
|
481
|
* {@link #getDefaultParsedJournal() parsed journal} and date published.
|
482
|
*/
|
483
|
private IArticle getDefaultParsedArticle() {
|
484
|
IArticle article = ReferenceFactory.newArticle();
|
485
|
article.setAuthorship(getDefaultParsedTeam());
|
486
|
article.setInJournal(getDefaultParsedJournal());
|
487
|
article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
|
488
|
return article;
|
489
|
}
|
490
|
|
491
|
private IJournal getDefaultFullJournal() {
|
492
|
IJournal journal = getDefaultParsedJournal();
|
493
|
// journal.setAuthorship(getDefaultFullTeam()); //journals should not have authors
|
494
|
journal.setTitle("J. Flow. Pl.");
|
495
|
journal.setUri(URI.create("https://www.journal-flowering-plants.gr"));
|
496
|
journal.setIssn("1234-222-222-333"); //format not yet correct
|
497
|
journal.setPublisher("Botanical publisher", "Paris");
|
498
|
journal.getTitleCache();
|
499
|
return journal;
|
500
|
}
|
501
|
|
502
|
private IJournal getDefaultParsedJournal() {
|
503
|
IJournal journal = ReferenceFactory.newJournal();
|
504
|
journal.setAbbrevTitle("Fl. Hell.");
|
505
|
// journal.setAuthorship(getDefaultParsedTeam()); //journals should not have authors
|
506
|
// ((Reference)journal).setDatePublished(TimePeriodParser.parseStringVerbatim("1992-04-03")); //journals should not have date published
|
507
|
journal.getTitleCache(); //not sure if enough
|
508
|
return journal;
|
509
|
}
|
510
|
|
511
|
@Test
|
512
|
public void testParsedReference() throws MatchException {
|
513
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedReferenceInstance();
|
514
|
Assert.assertNotNull(matchStrategy);
|
515
|
IArticle fullArticle;
|
516
|
IArticle parsedArticle;
|
517
|
|
518
|
fullArticle = getMatchingFullArticle();
|
519
|
parsedArticle = getDefaultParsedArticle();
|
520
|
Assert.assertTrue("Only author, book and date published should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful() );
|
521
|
|
522
|
//should match
|
523
|
fullArticle = getDefaultFullArticle();
|
524
|
Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
525
|
parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
|
526
|
Assert.assertFalse("Still not match because pages are not equal (parsed is null)", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
527
|
parsedArticle.setPages(fullArticle.getPages());
|
528
|
Assert.assertFalse("Now they should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
529
|
|
530
|
//differing nom. title.
|
531
|
parsedArticle.setAbbrevTitle("Wrong");
|
532
|
Assert.assertFalse("Differing abbrev. title. should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
533
|
|
534
|
//differing family
|
535
|
parsedArticle = getDefaultParsedArticle();
|
536
|
parsedArticle.setTitle("Wrong title");
|
537
|
Assert.assertFalse("Differing title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
538
|
fullArticle.setTitle(null);
|
539
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
540
|
|
541
|
//change author
|
542
|
fullArticle = getMatchingFullArticle();
|
543
|
parsedArticle = getDefaultParsedArticle();
|
544
|
fullArticle.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
|
545
|
Assert.assertFalse("Differing author in nomencl. title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
546
|
|
547
|
//change author
|
548
|
fullArticle = getMatchingFullArticle();
|
549
|
parsedArticle = getDefaultParsedArticle();
|
550
|
((Team)fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
|
551
|
Assert.assertTrue("Full book family name author changed should still match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
552
|
}
|
553
|
|
554
|
/**
|
555
|
* Article with {@link #getDefaultFullTeam() full team},
|
556
|
* {@link #getDefaultFullJournal() full journal} and date published
|
557
|
*/
|
558
|
private TaxonName getDefaultFullName() {
|
559
|
TaxonName name = getDefaultParsedName();
|
560
|
name.setNameApprobation("approbation");
|
561
|
TaxonNameDescription description = TaxonNameDescription.NewInstance(name);
|
562
|
description.addElement(Distribution.NewInstance());
|
563
|
|
564
|
//TODO continue
|
565
|
return name;
|
566
|
}
|
567
|
|
568
|
private TaxonName getDefaultParsedName() {
|
569
|
TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
570
|
name.setBasionymAuthorship(getDefaultFullTeam());
|
571
|
name.setGenusOrUninomial("Abies");
|
572
|
name.setSpecificEpithet("alba");
|
573
|
return name;
|
574
|
}
|
575
|
|
576
|
@Test
|
577
|
public void testParsedOriginalSpelling() throws MatchException {
|
578
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedOriginalSpellingInstance();
|
579
|
Assert.assertNotNull(matchStrategy);
|
580
|
|
581
|
TaxonName fullName = getDefaultFullName();
|
582
|
TaxonName parsedName = getDefaultParsedName();
|
583
|
Assert.assertTrue("Only ... should match", matchStrategy.invoke(parsedName, fullName).isSuccessful() );
|
584
|
|
585
|
//TODO
|
586
|
}
|
587
|
}
|