Project

General

Profile

« Previous | Next » 

Revision 16c76ded

Added by Patrick Plitzner over 7 years ago

#5448 Refactor hybrid name import/check

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
197 197
        long id = rs.getLong(RedListUtil.NAMNR);
198 198
        String taxNameString = rs.getString(RedListUtil.TAXNAME);
199 199
        String epi1String = rs.getString(RedListUtil.EPI1);
200
        String epi2String = rs.getString(RedListUtil.EPI2);
201
        String epi3String = rs.getString(RedListUtil.EPI3);
200 202
        String gueltString = rs.getString(RedListUtil.GUELT);
201 203
        String trivialString = rs.getString(RedListUtil.TRIVIAL);
202 204
        String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
......
239 241
        addAnnotation(RedListUtil.WISSK+": "+wisskString, taxonBase);
240 242

  
241 243
        //check taxon name consistency
242
        checkTaxonConsistency(id, taxNameString, hybString, epi1String, taxonBase, state);
244
        checkTaxonConsistency(id, taxNameString, hybString, epi1String, epi2String, epi3String, taxonBase, state);
243 245
        return taxonBase;
244 246
    }
245 247

  
......
415 417
                }
416 418
                else if(hybString.equals(RedListUtil.HYB_XF) || hybString.equals(RedListUtil.HYB_XU)){
417 419
                    name.setHybridFormula(true);
418
                    if(ep1String.contains(RedListUtil.HYB_SIGN)){
419
                        name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String, NomenclaturalCode.ICNAFP, rank);
420
                    }
421
                    else if(ep2String.contains(RedListUtil.HYB_SIGN)){
422
                        String[] split = ep2String.split(RedListUtil.HYB_SIGN);
423
                        String hybridFormula1 = ep1String+" "+split[0].trim();
424
                        String hybridFormula2 = ep1String+" "+split[1].trim();
425
                        //check if the genus is mentioned in EP2 or not
426
                        String[] secondHybrid = split[1].trim().split(" ");
427
                        //check if the genus is abbreviated like e.g. Centaurea jacea × C. decipiens
428
                        if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z]\\.")){
429
                            hybridFormula2 = ep1String+" "+split[1].trim().substring(2);
430
                        }
431
                        else if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
432
                            hybridFormula2 = split[1];
433
                        }
434
                        if(CdmUtils.isNotBlank(ep3String)){
435
                            hybridFormula1 += " "+rank.getAbbreviation()+" "+ep3String;
436
                            hybridFormula2 += " "+rank.getAbbreviation()+" "+ep3String;
437
                        }
438
                        String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
439
                        name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
440
                    }
441
                    else if(ep3String.contains(RedListUtil.HYB_SIGN)){
442
                        String[] split = ep3String.split(RedListUtil.HYB_SIGN);
443
                        String hybridFormula1 = ep1String+" "+ep2String+" "+rank.getAbbreviation()+" "+split[0];
444
                        String hybridFormula2 = ep1String+" "+ep2String+" "+rank.getAbbreviation()+" "+split[1];
445
                        //check if the genus is mentioned in EP3 or not
446
                        String[] secondHybrid = split[1].trim().split(" ");
447
                        //check if the genus is abbreviated like e.g. Centaurea jacea jacea × C. jacea subsp. decipiens
448
                        if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z]\\.")){
449
                            hybridFormula2 = ep1String+" "+split[1].trim().substring(2);
450
                        }
451
                        else if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
452
                            hybridFormula2 = split[1];
453
                        }
454
                        String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
455
                        name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
456
                    }
420
                    String fullFormula = buildHybridFormula(ep1String, ep2String, ep3String, rank);
421
                    name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
457 422
                }
458 423
                else if(hybString.equals(RedListUtil.HYB_N)){
459 424
                    name = NonViralNameParserImpl.NewInstance().parseFullName(taxNameString, NomenclaturalCode.ICNAFP, rank);
......
482 447
        return name;
483 448
    }
484 449

  
450
    private String buildHybridFormula(String ep1String, String ep2String, String ep3String, Rank rank) {
451
        String fullFormula = null;
452
        if(ep1String.contains(RedListUtil.HYB_SIGN)){
453
            fullFormula = ep1String;
454
        }
455
        else if(ep2String.contains(RedListUtil.HYB_SIGN)){
456
            String[] split = ep2String.split(RedListUtil.HYB_SIGN);
457
            String hybridFormula1 = ep1String+" "+split[0].trim();
458
            String hybridFormula2 = ep1String+" "+split[1].trim();
459
            //check if the genus is mentioned in EP2 or not
460
            String[] secondHybrid = split[1].trim().split(" ");
461
            //check if the genus is abbreviated like e.g. Centaurea jacea × C. decipiens
462
            if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z]\\.")){
463
                hybridFormula2 = ep1String+" "+split[1].trim().substring(3);
464
            }
465
            else if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
466
                hybridFormula2 = split[1].trim();
467
            }
468
            if(CdmUtils.isNotBlank(ep3String)){
469
                hybridFormula1 += " "+rank.getAbbreviation()+" "+ep3String;
470
                hybridFormula2 += " "+rank.getAbbreviation()+" "+ep3String;
471
            }
472
            fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
473
        }
474
        else if(ep3String.contains(RedListUtil.HYB_SIGN)){
475
            String[] split = ep3String.split(RedListUtil.HYB_SIGN);
476
            String hybridFormula1 = ep1String+" "+ep2String+" "+rank.getAbbreviation()+" "+split[0].trim();
477
            String hybridFormula2 = ep1String+" "+ep2String+" "+rank.getAbbreviation()+" "+split[1].trim();
478
            //check if the genus is mentioned in EP3 or not
479
            String[] secondHybrid = split[1].trim().split(" ");
480
            //check if the genus is abbreviated like e.g. Centaurea jacea jacea × C. jacea subsp. decipiens
481
            if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z]\\.")){
482
                hybridFormula2 = ep1String+" "+split[1].trim().substring(3);
483
            }
484
            else if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
485
                hybridFormula2 = split[1].trim();
486
            }
487
            fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
488
        }
489
        return fullFormula;
490
    }
491

  
485 492
    private void checkNameConsistency(long id, String nomZusatzString, String taxZusatzString,
486 493
            String zusatzString, String authorString, String hybString, NonViralName<?> name) {
487 494
        String authorshipCache = name.getAuthorshipCache();
......
518 525
        }
519 526
    }
520 527

  
521
    private void checkTaxonConsistency(long id, String taxNameString, String hybString, String epi1String, TaxonBase<?> taxonBase, RedListGefaesspflanzenImportState state) {
528
    private void checkTaxonConsistency(long id, String taxNameString, String hybString, String epi1String, String epi2String, String epi3String, TaxonBase<?> taxonBase, RedListGefaesspflanzenImportState state) {
522 529
        if(taxNameString.split(RedListUtil.HYB_SIGN).length>2){
523 530
            RedListUtil.logInfoMessage(id, "multiple hybrid signs. No name check for "+taxNameString, logger);
524 531
            return;
......
544 551
            if(nameCache.contains("sec")){
545 552
                nameCache = nameCache.substring(0, nameCache.indexOf("sec"));
546 553
            }
547
            if(taxNameString.matches((".*[A-Z]\\..*"))){
548
                taxNameString = taxNameString.replaceAll("[A-Z]\\.", epi1String);
554
            if(!STRICT_TITLE_CHECK){
555
                taxNameString = buildHybridFormula(epi1String, epi2String, epi3String, taxonBase.getName().getRank());
549 556
            }
550
            if(taxNameString.matches((".*"+RedListUtil.HYB_SIGN+"\\s[a-z].*"))){
551
                taxNameString = taxNameString.replaceAll(RedListUtil.HYB_SIGN+" ", RedListUtil.HYB_SIGN+" "+epi1String+" ");
557
            if(taxNameString.split(RedListUtil.HYB_SIGN).length==1){
558
                taxNameString = taxNameString.replace(RedListUtil.HYB_SIGN+" ", RedListUtil.HYB_SIGN);
552 559
            }
553 560
        }
554 561

  

Also available in: Unified diff