Search in sources :

Example 31 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class NameServiceImpl method getTaggedName.

@Override
public List<TaggedText> getTaggedName(UUID uuid) {
    TaxonName taxonName = dao.load(uuid);
    List<TaggedText> taggedName = taxonName.getTaggedName();
    return taggedName;
}
Also used : TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 32 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TaxonRelationshipsDTOTest method test.

@Test
@Ignore
public void test() {
    // 2
    Reference sec2 = ReferenceFactory.newGeneric();
    sec2.setAuthorship(Person.NewInstance("Mue.", "Mueller", "I.", "Inger"));
    sec2.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
    Taxon from2 = Taxon.NewInstance(fromName, sec2);
    TaxonRelationship rel2 = toTaxon.addMisappliedName(from2, sec2, "333");
    // 3
    // same as rel1 except for sec
    TaxonRelationship rel3 = toTaxon.addMisappliedName(from2, taxonRel.getCitation(), taxonRel.getCitationMicroReference());
    Taxon taxon2 = Taxon.NewInstance(fromName, sec2);
    Taxon taxon2Dupl = Taxon.NewInstance(fromName, toSec);
    // 4
    TaxonRelationship rel4 = toTaxon.addMisappliedName(taxon2, null, null);
    TaxonRelationship rel5 = toTaxon.addMisappliedName(taxon2Dupl, null, null);
    TaxonRelationshipsDTO dto = new TaxonRelationshipsDTO();
    dto.addRelation(taxonRel, Direction.relatedFrom, languages);
    dto.addRelation(rel2, Direction.relatedFrom, languages);
    TaxonRelationDTO relToDuplicate = dto.addRelation(rel3, Direction.relatedFrom, languages);
    dto.addRelation(rel4, Direction.relatedFrom, languages);
    TaxonRelationDTO duplicateWithoutRelSec2 = dto.addRelation(rel5, Direction.relatedFrom, languages);
    dto.createMisapplicationString();
    List<List<TaggedText>> misapplications = dto.getMisapplications();
    // 2/5 were deduplicated
    Assert.assertEquals("2 of 5 misapplications must be deduplicated", 3, misapplications.size());
    List<TaggedText> deduplicated = misapplications.get(0);
    Assert.assertEquals(13, deduplicated.size());
    Assert.assertSame(relToDuplicate.getTaggedText().get(6), deduplicated.get(8));
    Assert.assertEquals(11, misapplications.get(1).size());
    deduplicated = misapplications.get(2);
    Assert.assertEquals(9, deduplicated.size());
    Assert.assertSame(duplicateWithoutRelSec2.getTaggedText().get(6), deduplicated.get(8));
}
Also used : TaxonRelationship(eu.etaxonomy.cdm.model.taxon.TaxonRelationship) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) List(java.util.List) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText) TaxonRelationDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRelationshipsDTO.TaxonRelationDTO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 33 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TypeDesignationSetFormatterTest method testNameTypeDesignationTaggedText.

@Test
public void testNameTypeDesignationTaggedText() throws RegistrationValidationException {
    @SuppressWarnings("rawtypes") List<TypeDesignationBase> tds = new ArrayList<>();
    tds.add(ntd);
    TaxonName typifiedName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    typifiedName.setTitleCache("Prionus L.", true);
    typifiedName.addTypeDesignation(ntd, false);
    TypeDesignationSetManager manager = new TypeDesignationSetManager(tds);
    TypeDesignationSetFormatter formatter = new TypeDesignationSetFormatter(true, true, true);
    String text = formatter.format(manager);
    Assert.assertEquals("Prionus L.\u202F\u2013\u202FNametype: Prionus coriatius L.", text);
    List<TaggedText> taggedText = formatter.toTaggedText(manager);
    Assert.assertEquals("first entry should be the typified name", new TaggedText(TagEnum.name, "Prionus L.", TypedEntityReference.fromEntity(typifiedName, false)), taggedText.get(0));
    Assert.assertEquals("fourth entry should be the name type nameCache", new TaggedText(TagEnum.name, "Prionus"), // maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
    taggedText.get(3));
    Assert.assertEquals("fourth entry should be the name type nameCache", new TaggedText(TagEnum.name, "coriatius"), // maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
    taggedText.get(4));
    Assert.assertEquals("fifth entry should be the name type authorship cache", new TaggedText(TagEnum.authors, "L."), taggedText.get(5));
    // protected titleCache
    ntd.getTypeName().setTitleCache("Prionus coriatius L.", true);
    taggedText = formatter.toTaggedText(manager);
    Assert.assertEquals("fourth entry should be the name type titleCache", new TaggedText(TagEnum.name, "Prionus coriatius L."), // maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
    taggedText.get(3));
    Assert.assertEquals("there should be 4 tags only", 4, taggedText.size());
}
Also used : TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) ArrayList(java.util.ArrayList) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText) Test(org.junit.Test)

Example 34 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TypeDesignationSetFormatterTest method testSpecimenTypeDesignationTaggedTextWithStatus.

@Test
public void testSpecimenTypeDesignationTaggedTextWithStatus() throws RegistrationValidationException {
    @SuppressWarnings("rawtypes") List<TypeDesignationBase> tds = new ArrayList<>();
    tds.add(std_HT);
    TaxonName typifiedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    typifiedName.setTitleCache("Prionus coriatius L.", true);
    typifiedName.addTypeDesignation(std_HT, false);
    // TODO not yet handled in cache strategy as we do not have tagged text here
    Reference statusSource = ReferenceFactory.newBook();
    statusSource.setTitle("Status test");
    std_HT.getTypeSpecimen().addStatus(OccurrenceStatus.NewInstance(DefinedTerm.getTermByUuid(DefinedTerm.uuidDestroyed), statusSource, "335"));
    TypeDesignationSetManager manager = new TypeDesignationSetManager(tds);
    TypeDesignationSetFormatter formatter = new TypeDesignationSetFormatter(true, true, true);
    String text = formatter.format(manager);
    Assert.assertEquals("Prionus coriatius L.\u202F\u2013\u202FType: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: OHA 1234, destroyed)", text);
    List<TaggedText> taggedText = formatter.toTaggedText(manager);
    Assert.assertEquals("first entry should be the typified name", new TaggedText(TagEnum.name, "Prionus coriatius L.", TypedEntityReference.fromEntity(typifiedName, false)), taggedText.get(0));
// Assert.assertEquals("fourth entry should be the name type nameCache",
// new TaggedText(TagEnum.name, "Prionus"), taggedText.get(3));  //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
// Assert.assertEquals("fourth entry should be the name type nameCache",
// new TaggedText(TagEnum.name, "coriatius"), taggedText.get(4)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
// Assert.assertEquals("fifth entry should be the name type authorship cache",
// new TaggedText(TagEnum.authors, "L."), taggedText.get(5));
// 
// //protected titleCache
// ntd.getTypeName().setTitleCache("Prionus coriatius L.", true);
// taggedText = formatter.toTaggedText(manager);
// Assert.assertEquals("fourth entry should be the name type titleCache",
// new TaggedText(TagEnum.name, "Prionus coriatius L."), taggedText.get(3)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
// Assert.assertEquals("there should be 4 tags only", 4, taggedText.size());
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) ArrayList(java.util.ArrayList) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText) Test(org.junit.Test)

Example 35 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TaxonRelationshipFormatterTest method testGetFamilyNames.

@Test
public void testGetFamilyNames() {
    // Test start condition with single person
    List<TaggedText> tags = formatter.getTaggedText(taxonRel, reverse, languages);
    String str = TaggedCacheHelper.createString(tags);
    Assert.assertFalse("Formatted text should not contain the team correctly formatted", str.contains("Macfarlane & Cheek"));
    // use team
    Team secRelTeam = Team.NewInstance();
    secRelTeam.addTeamMember(macFarlane);
    secRelTeam.addTeamMember(cheek);
    relSec.setAuthorship(secRelTeam);
    tags = formatter.getTaggedText(taxonRel, reverse, languages);
    str = TaggedCacheHelper.createString(tags);
    System.out.println(str);
    Assert.assertTrue(str.contains("rel. sec. Macfarlane & Cheek 1919"));
    // add third member
    secRelTeam.addTeamMember(toSecAuthor);
    tags = formatter.getTaggedText(taxonRel, reverse, languages);
    str = TaggedCacheHelper.createString(tags);
    System.out.println(str);
    Assert.assertTrue(str.contains("rel. sec. Macfarlane & al. 1919"));
    // add et al.
    secRelTeam.setHasMoreMembers(true);
    tags = formatter.getTaggedText(taxonRel, reverse, languages);
    str = TaggedCacheHelper.createString(tags);
    System.out.println(str);
    Assert.assertTrue(str.contains("rel. sec. Macfarlane & al. 1919"));
}
Also used : Team(eu.etaxonomy.cdm.model.agent.Team) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText) Test(org.junit.Test)

Aggregations

TaggedText (eu.etaxonomy.cdm.strategy.cache.TaggedText)36 ArrayList (java.util.ArrayList)14 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)12 Test (org.junit.Test)10 Rank (eu.etaxonomy.cdm.model.name.Rank)4 TypeDesignationBase (eu.etaxonomy.cdm.model.name.TypeDesignationBase)4 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)4 TaxonRelationshipType (eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)3 List (java.util.List)3 TypeDesignationSetManager (eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager)2 Team (eu.etaxonomy.cdm.model.agent.Team)2 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)2 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)2 HybridRelationship (eu.etaxonomy.cdm.model.name.HybridRelationship)2 SpecimenTypeDesignation (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)2 TextualTypeDesignation (eu.etaxonomy.cdm.model.name.TextualTypeDesignation)2 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)2