Project

General

Profile

« Previous | Next » 

Revision c561f681

Added by Andreas Müller over 7 years ago

Implement notho rank recognition #3868

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java
794 794
			 //infra genus
795 795
			 else if (infraGenusPattern.matcher(fullNameString).matches()){
796 796
				Rank infraGenericRank;
797

  
798

  
799 797
				if ("[unranked]".equals(epi[1])){
800 798
					infraGenericRank = Rank.INFRAGENERICTAXON();
801 799
				}else{
802
					infraGenericRank = Rank.getRankByIdInVoc(epi[1], nameToBeFilledOrig.getNomenclaturalCode());
800
				    String infraGenericRankMarker = epi[1];
801
				    if (infraGenericRankMarker.startsWith(notho)){  //#3868
802
                        nameToBeFilled.setBinomHybrid(true);
803
                        infraGenericRankMarker = infraGenericRankMarker.substring(notho.length());
804
                    }else if(infraGenericRankMarker.startsWith("n")){
805
                        nameToBeFilled.setBinomHybrid(true);
806
                        infraGenericRankMarker = infraGenericRankMarker.substring(1);
807
                    }
808
                    infraGenericRank = Rank.getRankByIdInVoc(infraGenericRankMarker, nameToBeFilledOrig.getNomenclaturalCode());
803 809
				}
804 810
				nameToBeFilled.setRank(infraGenericRank);
805 811
				nameToBeFilled.setGenusOrUninomial(epi[0]);
......
841 847
				if ("[unranked]".equals(infraSpecRankMarker)){
842 848
					infraSpecificRank = Rank.INFRASPECIFICTAXON();
843 849
				}else{
844
					infraSpecificRank = Rank.getRankByIdInVoc(infraSpecRankMarker);
850
					String localInfraSpecRankMarker;
851
					if (infraSpecRankMarker.startsWith(notho)){  //#3868
852
	                    nameToBeFilled.setTrinomHybrid(true);
853
	                    localInfraSpecRankMarker = infraSpecRankMarker.substring(notho.length());
854
					}else if(infraSpecRankMarker.startsWith("n")){
855
	                    nameToBeFilled.setTrinomHybrid(true);
856
	                    localInfraSpecRankMarker = infraSpecRankMarker.substring(1);
857
                    }else{
858
                        localInfraSpecRankMarker = infraSpecRankMarker;
859
                    }
860
				    infraSpecificRank = Rank.getRankByIdInVoc(localInfraSpecRankMarker);
845 861
				}
846 862
				nameToBeFilled.setRank(infraSpecificRank);
847 863
				nameToBeFilled.setGenusOrUninomial(epi[0]);
......
934 950
				nameToBeFilled.addParsingProblem(ParserProblem.UnparsableNamePart);
935 951
				nameToBeFilled.setTitleCache(fullNameString,true);
936 952
				// FIXME Quick fix, otherwise search would not deilver results for unparsable names
937
				nameToBeFilled.setNameCache(fullNameString,true);
953
				nameToBeFilled.setNameCache(fullNameString, true);
938 954
				// END
939 955
				logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");
940 956
		    }
......
1071 1087
			fullAuthors(authorString, authors, years, clazz);
1072 1088
		} catch (StringNotParsableException e) {
1073 1089
			nameToBeFilled.addParsingProblem(ParserProblem.UnparsableAuthorPart);
1074
			nameToBeFilled.setTitleCache(fullNameString,true);
1090
			nameToBeFilled.setTitleCache(fullNameString, true);
1075 1091
			// FIXME Quick fix, otherwise search would not deliver results for unparsable names
1076
			nameToBeFilled.setNameCache(fullNameString,true);
1092
			nameToBeFilled.setNameCache(fullNameString, true);
1077 1093
			// END
1078 1094
			logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");;
1079 1095
		}
......
1305 1321
	}
1306 1322

  
1307 1323

  
1308
	//Parsing of the given full name that has been identified as hybrid already somewhere else.
1309
	private void parseHybrid(NonViralName nameToBeFilled, String fullNameString, Rank rank, boolean makeEmpty){
1310
	    logger.warn("parseHybrid --> function not yet implemented");
1311

  
1312
//	    String nonHybridName  = fullNameString;
1313
//	    boolean isMonomHybrid = isMonomHybrid(fullNameString);
1314
//	    if (isMonomHybrid){
1315
//	    	nonHybridName.replaceAll(hybrid, "");
1316
//	    }
1317
//
1318
//	    String[] split = nonHybridName.split("\\s");
1319
//	    parseFullName(nameToBeFilled, nonHybridName, rank, makeEmpty);
1320
//
1321
//	    nonHybridName = nonHybridName.replaceAll(hybrid, " ");
1322
//
1323
//	    boolean isBinomHybrid = isBinomHybrid(split);
1324
////	    boolean isTrinomHybrid = isTrinomHybrid(split);
1325
//
1326
//	    nonHybridName = nonHybridName.replaceAll(hybrid, " ");
1327
//
1328
//	    parseFullName(nameToBeFilled, nonHybridName, rank, makeEmpty);
1329
//	    nameToBeFilled.getTitleCache();
1330
//	    nameToBeFilled.setMonomHybrid(isMonomHybrid);
1331
//	    nameToBeFilled.setBinomHybrid(isBinomHybrid);
1332
//	    nameToBeFilled.setBinomHybrid(isTrinomHybrid);
1333

  
1334
	    nameToBeFilled.setTitleCache(fullNameString,true);
1335
	    return;
1336
    }
1337

  
1338
//	private boolean isBinomHybrid(String[] split) {
1339
//		if (){
1340
//
1341
//		}
1342
//		return false;
1343
//	}
1344

  
1345
	private boolean isMonomHybrid(String fullNameString) {
1346
		Matcher matcher = hybridPattern.matcher(fullNameString);
1347
		boolean find = matcher.find();
1348
		int start = matcher.start();
1349
		if (find == true && start == 0){
1350
			return true;
1351
		}else{
1352
			return false;
1353
		}
1354
	}
1355

  
1356 1324
//	// Parsing of the given full name that has been identified as a cultivar already somwhere else.
1357 1325
//	// The ... cv. ... syntax is not covered here as it is not according the rules for naming cultivars.
1358 1326
	public BotanicalName parseCultivar(String fullName)	throws StringNotParsableException{
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplRegExBase.java
77 77
    protected static String status = "";
78 78

  
79 79
    //marker
80
    protected static String InfraGenusMarker = "(subgen\\.|subg\\.|sect\\.|subsect\\.|ser\\.|subser\\.|t\\.infgen\\.|\\[unranked\\])";
80
    protected static String InfraGenusMarker = "(n|notho)?(subgen\\.|subg\\.|sect\\.|subsect\\.|ser\\.|subser\\.|t\\.infgen\\.|\\[unranked\\])";
81 81
    protected static String aggrOrGroupMarker = "(aggr\\.|agg\\.|group)";
82
    protected static String infraSpeciesMarker = "(subsp\\.|convar\\.|var\\.|subvar\\.|f\\.|subf\\.|f\\. sp\\.|f\\.spec\\.|f\\.sp\\.|\\[unranked\\]|tax\\." + fWs + "infrasp\\.)";
82
    protected static String infraSpeciesMarker = "(n|notho)?(subsp\\.|convar\\.|var\\.|subvar\\.|f\\.|subf\\.|f\\.\\ssp\\.|f\\.spec\\.|f\\.sp\\.|\\[unranked\\]|tax\\." + fWs + "infrasp\\.)";
83 83
    protected static String oldInfraSpeciesMarker = "(prol\\.|proles|race|taxon|sublusus)";
84 84

  
85 85

  
......
237 237
    //cultivars and hybrids
238 238
    protected static String cultivar = oWs + "'..+'"; //Achtung mit Hochkomma in AuthorNamen
239 239
    protected static String cultivarMarker = oWs + "(cv\\.|')";
240
    protected static String hybridPart = "([xX]" + oWs + "|"+hybridSign+"|notho)";
241
    protected static String hybridFull = "(" +oWs +"|"+ pStart +")" + hybridPart;
240
    protected static String notho = "notho";
241
    protected static String hybridPart = "([xX]" + oWs + "|"+hybridSign+"|"+notho+")";
242
    protected static String noNothoHybridPart = "([xX]" + oWs + "|"+hybridSign+")";
243
    protected static String hybridFull = "(" +oWs +"|"+ pStart +")" + noNothoHybridPart;  //for some reason infraspecific notho ranks do not parse if notho is allowed as uninomial prefix.
242 244
    protected static String hybridFormularSeparator = oWs + "[" + hybridSign + "xX]" + oWs;
243 245

  
244 246

  
......
269 271
    protected static Pattern finalTeamSplitterPattern = Pattern.compile(finalTeamSplitter);
270 272
    protected static Pattern cultivarPattern = Pattern.compile(cultivar);
271 273
    protected static Pattern cultivarMarkerPattern = Pattern.compile(cultivarMarker);
272
    protected static Pattern hybridPattern = Pattern.compile(hybridFull);
273 274

  
274 275
    protected static Pattern genusOrSupraGenusPattern = Pattern.compile(pStart + genusOrSupraGenus + facultFullAuthorString2 + end);
275 276
    protected static Pattern infraGenusPattern = Pattern.compile(pStart + infraGenus + facultFullAuthorString2 + end);
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplTest.java
430 430
	 */
431 431
	@Test
432 432
	public final void testHybrids() {
433
		try {
434
			Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
435
			testName_StringNomcodeRank(parseMethod);
436
		} catch (Exception e) {
437
			e.printStackTrace();
438
			assertTrue(false);
439
		}
433
		NonViralName<?> name1;
434

  
435

  
436
        //Infrageneric hybrid
437
        name1 = parser.parseFullName("Aegilops nothosubg. Insulae Scholz", botanicCode, null);
438
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
439
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
440
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
441
        assertEquals("Infrageneric epithet must be 'Insulae'", "Insulae", name1.getInfraGenericEpithet());
440 442

  
441 443
		//Species hybrid
442 444
//		NonViralName nameTeam1 = parser.parseFullName("Aegilops \u00D7insulae-cypri H. Scholz");
443
		NonViralName<?> name1 = parser.parseFullName("Aegilops \u00D7insulae Scholz", botanicCode, null);
445
		name1 = parser.parseFullName("Aegilops \u00D7insulae Scholz", botanicCode, null);
444 446
		assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
445 447
		assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
446 448
		assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
......
453 455
		assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
454 456
		assertEquals("Uninomial must be 'Aegilops'", "Aegilops", name1.getGenusOrUninomial());
455 457

  
456
		//Species hybrid
458
		//Subspecies hybrid with hybrid sign
459
		//maybe false: see http://dev.e-taxonomy.eu/trac/ticket/3868
457 460
		name1 = parser.parseFullName("Aegilops insulae subsp. X abies Scholz", botanicCode, null);
458 461
		assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
459 462
		assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
460 463
		assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
461 464
		assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
462 465

  
466
        //Subspecies hybrid with notho / n
467
        name1 = parser.parseFullName("Aegilops insulae nothosubsp. abies Scholz", botanicCode, null);
468
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
469
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
470
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
471
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
472
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
473
        name1 = parser.parseFullName("Aegilops insulae nsubsp. abies Scholz", botanicCode, null);
474
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
475
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
476
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
477
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
478
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
463 479

  
464 480
	}
465 481

  

Also available in: Unified diff