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