Project

General

Profile

Revision e7375c14

IDe7375c14bb1d62b546771cdc57cd5bde781ba55f
Parent 70f7cd1e
Child 9a3c0737

Added by Andreas Müller almost 3 years ago

fix #6577 implement sp. nov. parser

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java
772 772
		String fullNameString = fullNameStringOrig.replaceAll(oWs , " ").trim();
773 773

  
774 774
		fullNameString = removeHybridBlanks(fullNameString);
775
		fullNameString = removeSpNovBlanks(fullNameString);
775 776
		String[] epi = pattern.split(fullNameString);
776 777
		try {
777 778
	    	//cultivars //TODO 2 implement cultivars
......
827 828
			 else if (speciesPattern.matcher(fullNameString).matches()){
828 829
				nameToBeFilled.setRank(Rank.SPECIES());
829 830
				nameToBeFilled.setGenusOrUninomial(epi[0]);
830
				nameToBeFilled.setSpecificEpithet(epi[1]);
831
				nameToBeFilled.setSpecificEpithet(normalizeSpNov(epi[1]));
831 832
				authorString = fullNameString.substring(epi[0].length() + 1 + epi[1].length());
832 833
			}
833 834
		    //species with infra generic epithet
......
1001 1002
	}
1002 1003

  
1003 1004
	/**
1005
     * @param string
1006
     * @return
1007
     */
1008
    private String normalizeSpNov(String epi) {
1009
        if (spNovPattern.matcher(epi).matches()){
1010
            epi = epi.replace(".", ". ").replace("\\s+", " ").trim();
1011
        }
1012
        return epi;
1013
    }
1014

  
1015
    /**
1004 1016
     * @param firstName
1005 1017
     * @param secondNameString
1006 1018
     * @return
......
1092 1104
		return result;
1093 1105
	}
1094 1106

  
1107

  
1108
    private String removeSpNovBlanks(String fullNameString) {
1109
        Matcher spNovMatcher = spNovPattern.matcher(fullNameString);
1110
        if (spNovMatcher.find()){
1111
            String spNov = spNovMatcher.group(0);
1112
            String spNovShort = spNov.replaceAll("\\s", "");
1113
            if (spNov.length() != spNovShort.length()){
1114
                fullNameString = fullNameString.replace(spNov, spNovShort);
1115
            }
1116
        }
1117
        return fullNameString;
1118
    }
1119

  
1120

  
1095 1121
	/**
1096 1122
	 * Author parser for external use
1097 1123
	 * @param nonViralName
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplRegExBase.java
270 270
    protected static String genusOrSupraGenus = "("+hybridFull+")?" + capitalEpiWord;
271 271
    protected static String infraGenus = capitalEpiWord + oWs + InfraGenusMarker + oWs + capitalEpiWord;
272 272
    protected static String aggrOrGroup = capitalEpiWord + oWs + nonCapitalEpiWord + oWs + aggrOrGroupMarker;
273
    protected static String species = genusOrSupraGenus + oWs + "("+hybridPart+")?" + nonCapitalEpiWord;
274
    protected static String speciesWithInfraGen = genusOrSupraGenus + oWs + "\\(" + capitalEpiWord + "\\)" + oWs + nonCapitalEpiWord;
273
    protected static String spNov = "sp\\.(\\s*nov\\.)?(\\s*\\d{1,2})?";
274
    protected static String specificEpi = "(" + nonCapitalEpiWord + "|" + spNov + ")";
275
    protected static String species = genusOrSupraGenus + oWs + "("+hybridPart+")?" + specificEpi;
276
    protected static String speciesWithInfraGen = genusOrSupraGenus + oWs + "\\(" + capitalEpiWord + "\\)" + oWs + specificEpi;
275 277

  
276 278
    protected static String infraSpecies = species + oWs + infraSpeciesMarker + oWs + "("+hybridPart+")?" + nonCapitalEpiWord;
277 279
    protected static String zooInfraSpecies = species + oWs + "(" + infraSpeciesMarker + oWs +")?" + "("+hybridPart+")?" + nonCapitalEpiWord;
......
330 332
    protected static Pattern anyBotanicFullNamePattern = Pattern.compile(anyBotanicFullName);
331 333
    protected static Pattern anyZooFullNamePattern = Pattern.compile(anyZooFullName);
332 334

  
335
    protected static Pattern spNovPattern = Pattern.compile(spNov);
336

  
333 337

  
334 338
}
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplTest.java
1749 1749
        Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1750 1750
        Rank rank = sectionName.getRank();
1751 1751
        Assert.assertEquals("", Rank.SECTION_BOTANY(), rank  );
1752
    }
1753

  
1754
    //#6577
1755
    @Test
1756
    public final void testParseSpNov(){
1757
        //Canabio, issue with space
1758
        INonViralName name = parser.parseFullName("Iresine sp. nov. 1");
1759
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1760
        Assert.assertEquals("sp. nov. 1", name.getSpecificEpithet());
1761

  
1762
        name = parser.parseFullName("Gomphichis sp. 22");
1763
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1764
        Assert.assertEquals("sp. 22", name.getSpecificEpithet());
1765

  
1766
        name = parser.parseFullName("Phleum sp. nov.");
1767
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1768
        Assert.assertEquals("sp. nov.", name.getSpecificEpithet());
1769

  
1770
        name = parser.parseFullName("Phleum sp.");
1771
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1772
        Assert.assertEquals("sp.", name.getSpecificEpithet());
1752 1773

  
1753 1774
    }
1754 1775

  
1776

  
1755 1777
    @Test  //#5072
1756 1778
    public final void testLongRunningParsingCapitals(){
1757 1779
        DateTime start = DateTime.now();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)