Revision c80fe770
Added by Andreas Müller almost 4 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/MatchStrategyFactory.java | ||
---|---|---|
127 | 127 |
try { |
128 | 128 |
IParsedMatchStrategy parsedBookSectionMatchStrategy = (IParsedMatchStrategy)NewDefaultInstance(Reference.class); |
129 | 129 |
|
130 |
addParsedReferenceMatchModes(parsedBookSectionMatchStrategy); |
|
130 |
addParsedSectionReferenceMatchModes(parsedBookSectionMatchStrategy);
|
|
131 | 131 |
|
132 | 132 |
//author (or either title or authorship match, but usually only authorship is known for parsed instances) |
133 | 133 |
parsedBookSectionMatchStrategy.setMatchMode("authorship", MatchMode.MATCH_REQUIRED, NewParsedTeamOrPersonInstance()); |
... | ... | |
150 | 150 |
try { |
151 | 151 |
IParsedMatchStrategy articleMatchStrategy = (IParsedMatchStrategy)NewDefaultInstance(Reference.class); |
152 | 152 |
|
153 |
addParsedReferenceMatchModes(articleMatchStrategy); |
|
153 |
addParsedSectionReferenceMatchModes(articleMatchStrategy);
|
|
154 | 154 |
|
155 | 155 |
//if a title or abbrevTitle exists for the existing (first) article |
156 | 156 |
//we can not guarantee that the article is really the one that is |
... | ... | |
178 | 178 |
} |
179 | 179 |
|
180 | 180 |
/** |
181 |
* Adds all typical parsed reference match modes which are equal for journal, article,
|
|
182 |
* book section, book (and generic?).
|
|
181 |
* Adds all typical parsed reference match modes which are equal for non section references
|
|
182 |
* (journal, book, (generic(?))).
|
|
183 | 183 |
* The following fields need to be handled explicitly by each calling method:<BR> |
184 | 184 |
* |
185 | 185 |
* <LI>authorship</LI> |
... | ... | |
191 | 191 |
* <LI>protectedAbbrevTitleCache</LI> |
192 | 192 |
* <LI>inReference</LI> |
193 | 193 |
* |
194 |
* @see #addParsedSectionReferenceMatchModes(IParsedMatchStrategy) |
|
194 | 195 |
* @param referenceMatchStrategy the strategy to fill |
195 | 196 |
* @throws MatchException |
196 | 197 |
*/ |
... | ... | |
223 | 224 |
} |
224 | 225 |
} |
225 | 226 |
|
227 |
/** |
|
228 |
* Adds all typical parsed reference match modes which are equal for section references |
|
229 |
* (article, book section). |
|
230 |
* The following fields need to be handled explicitly by each calling method:<BR> |
|
231 |
* |
|
232 |
* For further information see: #9157 |
|
233 |
* |
|
234 |
* <LI>authorship</LI> |
|
235 |
* <LI>title</LI> |
|
236 |
* <LI>abbrevTitle</LI> |
|
237 |
* <LI>titleCache</LI> |
|
238 |
* <LI>abbrevTitleCache</LI> |
|
239 |
* <LI>protectedTitleCache</LI> |
|
240 |
* <LI>protectedAbbrevTitleCache</LI> |
|
241 |
* <LI>inReference</LI> |
|
242 |
* |
|
243 |
* @see #addParsedReferenceMatchModes(IParsedMatchStrategy) |
|
244 |
* @param referenceMatchStrategy the strategy to fill |
|
245 |
* @throws MatchException |
|
246 |
*/ |
|
247 |
private static void addParsedSectionReferenceMatchModes(IParsedMatchStrategy referenceMatchStrategy) throws MatchException { |
|
248 |
|
|
249 |
//"placePublished" should be MatchMode.EQUAL if parser parses place published |
|
250 |
//TODO datePublished could also be more detailed in first then in second, e.g. Apr 2008 <-> 2008, |
|
251 |
//something like MatchMode.IncludedIn is needed here |
|
252 |
//TODO pages if a page number is given the parsed reference may not be unidentified anymore |
|
253 |
|
|
254 |
//TODO externally managed |
|
255 |
|
|
256 |
addParsedIdentifiableEntityModes(referenceMatchStrategy); |
|
257 |
|
|
258 |
//here the result differs from addParsedReferenceMatchModes |
|
259 |
String[] equalOrNullParams = new String[]{"accessed","doi", |
|
260 |
"institution","isbn","issn","organization", |
|
261 |
"pages","publisher","placePublished", |
|
262 |
"referenceAbstract","school","uri"}; |
|
263 |
for(String param : equalOrNullParams){ |
|
264 |
referenceMatchStrategy.setMatchMode(param, MatchMode.EQUAL); //EQUAL !! |
|
265 |
} |
|
266 |
|
|
267 |
String[] equalParams = new String[]{"datePublished","edition", |
|
268 |
"editor","seriesPart","volume"}; |
|
269 |
for(String param : equalParams){ |
|
270 |
referenceMatchStrategy.setMatchMode(param, MatchMode.EQUAL); |
|
271 |
} |
|
272 |
String[] matchOrNullParams = new String[]{"institution"}; |
|
273 |
for(String param : matchOrNullParams){ |
|
274 |
referenceMatchStrategy.setMatchMode(param, MatchMode.MATCH); //MATCH!! |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
226 | 278 |
private static void addParsedAgentBaseMatchModes(IParsedMatchStrategy matchStrategy) throws MatchException { |
227 | 279 |
|
228 | 280 |
//FIXME adapt for inRef authors |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/match/MatchStrategyFactoryTest.java | ||
---|---|---|
16 | 16 |
import org.junit.BeforeClass; |
17 | 17 |
import org.junit.Test; |
18 | 18 |
|
19 |
import eu.etaxonomy.cdm.common.DOI; |
|
19 | 20 |
import eu.etaxonomy.cdm.model.agent.Institution; |
20 | 21 |
import eu.etaxonomy.cdm.model.agent.Person; |
21 | 22 |
import eu.etaxonomy.cdm.model.agent.Team; |
... | ... | |
260 | 261 |
parsedBook = getDefaultParsedBook(); |
261 | 262 |
Assert.assertTrue("Same abbrev. title should match", |
262 | 263 |
matchStrategy.invoke(parsedBook, fullBook).isSuccessful()); |
264 |
fullBook.setDoi(DOI.fromString("10.1234/abc")); |
|
265 |
Assert.assertTrue("DOI only with full book should match as abbrev title identifies the book", |
|
266 |
matchStrategy.invoke(parsedBook, fullBook).isSuccessful()); |
|
263 | 267 |
|
264 | 268 |
//differing nom. title. |
265 | 269 |
parsedBook.setAbbrevTitle("Wrong"); |
... | ... | |
301 | 305 |
parsedBookSection = getDefaultParsedBookSection(); |
302 | 306 |
Assert.assertTrue("Only author, book and date published should match", |
303 | 307 |
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful() ); |
308 |
fullBookSection.setDoi(DOI.fromString("10.1234/abc")); |
|
309 |
Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page", |
|
310 |
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful()); |
|
311 |
fullBookSection.setDoi(null); |
|
312 |
fullBookSection.setReferenceAbstract("My abstract"); |
|
313 |
Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page", |
|
314 |
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful()); |
|
304 | 315 |
|
305 | 316 |
//should match |
306 | 317 |
fullBookSection = getDefaultFullBookSection(); |
... | ... | |
399 | 410 |
|
400 | 411 |
fullArticle = getMatchingFullArticle(); |
401 | 412 |
parsedArticle = getDefaultParsedArticle(); |
402 |
Assert.assertTrue("Only author, book and date published should match", |
|
403 |
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful() ); |
|
413 |
Assert.assertTrue("Having only paramters both have in common like author, book and date published " |
|
414 |
+ "should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful()); |
|
415 |
fullArticle.setDoi(DOI.fromString("10.1234/abc")); |
|
416 |
Assert.assertFalse("Full article having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page", |
|
417 |
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful()); |
|
404 | 418 |
|
405 |
//should match
|
|
419 |
//no match due to missing abbrev title match
|
|
406 | 420 |
fullArticle = getDefaultFullArticle(); |
407 | 421 |
Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle, |
408 | 422 |
fullArticle).isSuccessful()); |
409 | 423 |
parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle()); |
410 | 424 |
Assert.assertFalse("Still not match because pages are not equal (parsed is null)", |
411 | 425 |
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful()); |
426 |
//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 |
|
412 | 427 |
parsedArticle.setPages(fullArticle.getPages()); |
413 | 428 |
Assert.assertFalse("Now they should match", |
414 | 429 |
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful()); |
Also available in: Unified diff
ref #9157 handle articles and book sections matching stricter