ref #9157 handle articles and book sections matching stricter
authorAndreas Müller <a.mueller@bgbm.org>
Fri, 17 Jul 2020 07:33:28 +0000 (09:33 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Fri, 17 Jul 2020 07:33:28 +0000 (09:33 +0200)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/MatchStrategyFactory.java
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/match/MatchStrategyFactoryTest.java

index 4bf0b201f2a27c3d52115506d5b36bb3c1ad5171..23cb52333fb6c96f3518f9d6cb547aa19b87d743 100644 (file)
@@ -127,7 +127,7 @@ public class MatchStrategyFactory {
         try {
             IParsedMatchStrategy parsedBookSectionMatchStrategy = (IParsedMatchStrategy)NewDefaultInstance(Reference.class);
 
-            addParsedReferenceMatchModes(parsedBookSectionMatchStrategy);
+            addParsedSectionReferenceMatchModes(parsedBookSectionMatchStrategy);
 
             //author (or either title or authorship match, but usually only authorship is known for parsed instances)
             parsedBookSectionMatchStrategy.setMatchMode("authorship", MatchMode.MATCH_REQUIRED, NewParsedTeamOrPersonInstance());
@@ -150,7 +150,7 @@ public class MatchStrategyFactory {
         try {
             IParsedMatchStrategy articleMatchStrategy = (IParsedMatchStrategy)NewDefaultInstance(Reference.class);
 
-            addParsedReferenceMatchModes(articleMatchStrategy);
+            addParsedSectionReferenceMatchModes(articleMatchStrategy);
 
             //if a title or abbrevTitle exists for the existing (first) article
             //we can not guarantee that the article is really the one that is
@@ -178,8 +178,8 @@ public class MatchStrategyFactory {
     }
 
     /**
-     * Adds all typical parsed reference match modes which are equal for journal, article,
-     * book section, book (and generic?).
+     * Adds all typical parsed reference match modes which are equal for non section references
+     * (journal, book, (generic(?))).
      * The following fields need to be handled explicitly by each calling method:<BR>
      *
      * <LI>authorship</LI>
@@ -191,6 +191,7 @@ public class MatchStrategyFactory {
      * <LI>protectedAbbrevTitleCache</LI>
      * <LI>inReference</LI>
      *
+     * @see #addParsedSectionReferenceMatchModes(IParsedMatchStrategy)
      * @param referenceMatchStrategy the strategy to fill
      * @throws MatchException
      */
@@ -223,6 +224,57 @@ public class MatchStrategyFactory {
         }
     }
 
+    /**
+     * Adds all typical parsed reference match modes which are equal for section references
+     * (article, book section).
+     * The following fields need to be handled explicitly by each calling method:<BR>
+     *
+     * For further information see: #9157
+     *
+     * <LI>authorship</LI>
+     * <LI>title</LI>
+     * <LI>abbrevTitle</LI>
+     * <LI>titleCache</LI>
+     * <LI>abbrevTitleCache</LI>
+     * <LI>protectedTitleCache</LI>
+     * <LI>protectedAbbrevTitleCache</LI>
+     * <LI>inReference</LI>
+     *
+     * @see #addParsedReferenceMatchModes(IParsedMatchStrategy)
+     * @param referenceMatchStrategy the strategy to fill
+     * @throws MatchException
+     */
+    private static void addParsedSectionReferenceMatchModes(IParsedMatchStrategy referenceMatchStrategy) throws MatchException {
+
+        //"placePublished" should be MatchMode.EQUAL if parser parses place published
+        //TODO datePublished could also be more detailed in first then in second, e.g. Apr 2008 <-> 2008,
+        //something like MatchMode.IncludedIn is needed here
+        //TODO pages if a page number is given the parsed reference may not be unidentified anymore
+
+        //TODO externally managed
+
+        addParsedIdentifiableEntityModes(referenceMatchStrategy);
+
+        //here the result differs from addParsedReferenceMatchModes
+        String[] equalOrNullParams = new String[]{"accessed","doi",
+                "institution","isbn","issn","organization",
+                "pages","publisher","placePublished",
+                "referenceAbstract","school","uri"};
+        for(String param : equalOrNullParams){
+            referenceMatchStrategy.setMatchMode(param, MatchMode.EQUAL); //EQUAL !!
+        }
+
+        String[] equalParams = new String[]{"datePublished","edition",
+                "editor","seriesPart","volume"};
+        for(String param : equalParams){
+            referenceMatchStrategy.setMatchMode(param, MatchMode.EQUAL);
+        }
+        String[] matchOrNullParams = new String[]{"institution"};
+        for(String param : matchOrNullParams){
+            referenceMatchStrategy.setMatchMode(param, MatchMode.MATCH); //MATCH!!
+        }
+    }
+
     private static void addParsedAgentBaseMatchModes(IParsedMatchStrategy matchStrategy) throws MatchException {
 
         //FIXME adapt for inRef authors
index cdbd614aef57151ab92bf188ee30216a4b61d4c5..cab87f2475a6813dd0c345c79ab56ab6f404bf0d 100644 (file)
@@ -16,6 +16,7 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import eu.etaxonomy.cdm.common.DOI;
 import eu.etaxonomy.cdm.model.agent.Institution;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.agent.Team;
@@ -260,6 +261,9 @@ public class MatchStrategyFactoryTest {
         parsedBook = getDefaultParsedBook();
         Assert.assertTrue("Same abbrev. title should match",
                 matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
+        fullBook.setDoi(DOI.fromString("10.1234/abc"));
+        Assert.assertTrue("DOI only with full book should match as abbrev title identifies the book",
+                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
 
         //differing nom. title.
         parsedBook.setAbbrevTitle("Wrong");
@@ -301,6 +305,13 @@ public class MatchStrategyFactoryTest {
         parsedBookSection = getDefaultParsedBookSection();
         Assert.assertTrue("Only author, book and date published should match",
                 matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful() );
+        fullBookSection.setDoi(DOI.fromString("10.1234/abc"));
+        Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
+                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
+        fullBookSection.setDoi(null);
+        fullBookSection.setReferenceAbstract("My abstract");
+        Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
+                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
 
         //should match
         fullBookSection = getDefaultFullBookSection();
@@ -399,16 +410,20 @@ public class MatchStrategyFactoryTest {
 
         fullArticle = getMatchingFullArticle();
         parsedArticle = getDefaultParsedArticle();
-        Assert.assertTrue("Only author, book and date published should match",
-                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful() );
+        Assert.assertTrue("Having only paramters both have in common like author, book and date published "
+                + "should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
+        fullArticle.setDoi(DOI.fromString("10.1234/abc"));
+        Assert.assertFalse("Full article having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
+                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
 
-        //should match
+        //no match due to missing abbrev title match
         fullArticle = getDefaultFullArticle();
         Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle,
                 fullArticle).isSuccessful());
         parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
         Assert.assertFalse("Still not match because pages are not equal (parsed is null)",
                 matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
+        //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
         parsedArticle.setPages(fullArticle.getPages());
         Assert.assertFalse("Now they should match",
                 matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());