use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.
the class TaxonNameDefaultCacheStrategy method doGetTaggedTitle.
// ************* TAGGED NAME ***************************************/
@Override
protected List<TaggedText> doGetTaggedTitle(TaxonName taxonName) {
List<TaggedText> tags = new ArrayList<>();
if (taxonName.getNameType().isViral()) {
String acronym = taxonName.getAcronym();
if (isNotBlank(taxonName.getAcronym())) {
// this is not according to the code
tags.add(new TaggedText(TagEnum.name, acronym));
}
return tags;
} else if (taxonName.isHybridFormula()) {
// hybrid formula
String hybridSeparator = NonViralNameParserImplRegExBase.hybridSign;
boolean isFirst = true;
List<HybridRelationship> rels = taxonName.getOrderedChildRelationships();
for (HybridRelationship rel : rels) {
if (!isFirst) {
tags.add(new TaggedText(TagEnum.hybridSign, hybridSeparator));
}
isFirst = false;
tags.addAll(getTaggedTitle(rel.getParentName()));
}
return tags;
} else if (taxonName.isAutonym()) {
// Autonym
tags.addAll(handleTaggedAutonym(taxonName, true));
} else {
// not Autonym
List<TaggedText> nameTags = getTaggedName(taxonName);
tags.addAll(nameTags);
String authorCache = getAuthorshipCache(taxonName);
if (isNotBlank(authorCache)) {
tags.add(new TaggedText(TagEnum.authors, authorCache));
}
}
return tags;
}
use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method handleHomotypicalGroup.
private void handleHomotypicalGroup(CdmLightExportState state, HomotypicalGroup group, Taxon acceptedTaxon, int sortIndex) {
try {
state.addHomotypicalGroupToStore(group);
CdmLightExportTable table = CdmLightExportTable.HOMOTYPIC_GROUP;
String[] csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.SORT_INDEX)] = String.valueOf(sortIndex);
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_ID)] = getId(state, group);
List<TaxonName> typifiedNames = new ArrayList<>();
if (acceptedTaxon != null) {
List<Synonym> synonymsInGroup = acceptedTaxon.getSynonymsInGroup(group);
if (group.equals(acceptedTaxon.getHomotypicGroup())) {
typifiedNames.add(acceptedTaxon.getName());
}
synonymsInGroup.stream().forEach(synonym -> typifiedNames.add(CdmBase.deproxy(synonym.getName())));
}
TaxonName firstname = null;
for (TaxonName name : typifiedNames) {
Iterator<Taxon> taxa = name.getTaxa().iterator();
while (taxa.hasNext()) {
Taxon taxon = taxa.next();
if (!(taxon.isMisapplication() || taxon.isProparteSynonym())) {
firstname = name;
break;
}
}
}
// Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(firstname, true));
String typifiedNamesString = "";
String typifiedNamesWithSecString = "";
String typifiedNamesWithoutAccepted = "";
String typifiedNamesWithoutAcceptedWithSec = "";
int index = 0;
for (TaxonName name : typifiedNames) {
// Concatenated output string for homotypic group (names and
// citations) + status + some name relations (e.g. “non”)
// TODO: nameRelations, which and how to display
Set<TaxonBase> taxonBases = name.getTaxonBases();
TaxonBase<?> taxonBase;
String sec = "";
String nameString = name.getFullTitleCache();
String doubtful = "";
if (state.getConfig().isAddHTML()) {
nameString = createNameWithItalics(name.getTaggedFullTitle());
}
Set<NameRelationship> related = name.getNameRelations();
List<NameRelationship> relatedList = new ArrayList<>(related);
Collections.sort(relatedList, new Comparator<NameRelationship>() {
@Override
public int compare(NameRelationship nr1, NameRelationship nr2) {
return nr1.getType().compareTo(nr2.getType());
}
});
List<NameRelationship> nonNames = new ArrayList<>();
List<NameRelationship> otherRelationships = new ArrayList<>();
for (NameRelationship rel : relatedList) {
// no inverse relations
if (rel.getFromName().equals(name)) {
// alle Homonyme und inverse blocking names
if (rel.getType().equals(NameRelationshipType.LATER_HOMONYM()) || rel.getType().equals(NameRelationshipType.TREATED_AS_LATER_HOMONYM()) || (rel.getType().equals(NameRelationshipType.BLOCKING_NAME_FOR())) || (rel.getType().equals(NameRelationshipType.UNSPECIFIC_NON()))) {
nonNames.add(rel);
} else if (!rel.getType().isBasionymRelation()) {
otherRelationships.add(rel);
}
}
}
String nonRelNames = "";
String relNames = "";
if (nonNames.size() > 0) {
nonRelNames += " [";
}
for (NameRelationship relName : nonNames) {
String label = "non ";
TaxonName relatedName = null;
if (relName.getFromName().equals(name)) {
relatedName = relName.getToName();
nonRelNames += label + relatedName.getTitleCache() + " ";
}
// else{
// label = relName.getType().getInverseLabel() + " ";
// relatedName = relName.getFromName();
// nonRelNames += label + relatedName.getTitleCache() + " ";
// }
}
relNames.trim();
if (nonNames.size() > 0) {
nonRelNames = StringUtils.strip(nonRelNames, null);
nonRelNames += "] ";
}
if (otherRelationships.size() > 0) {
relNames += " [";
}
for (NameRelationship rel : otherRelationships) {
String label = "";
TaxonName relatedName = null;
if (rel.getFromName().equals(name)) {
label = rel.getType().getLabel() + " ";
relatedName = rel.getToName();
if (state.getConfig().isAddHTML()) {
relNames += label + createNameWithItalics(relatedName.getTaggedName()) + " ";
} else {
relNames += label + relatedName.getTitleCache();
}
}
// else {
// label = rel.getType().getInverseLabel() + " ";
// relatedName = rel.getFromName();
// }
}
relNames.trim();
if (otherRelationships.size() > 0) {
relNames = StringUtils.stripEnd(relNames, null);
relNames += "] ";
}
String synonymSign = "";
if (index > 0) {
if (name.isInvalid()) {
synonymSign = "\u2212 ";
} else {
synonymSign = "\u2261 ";
}
} else {
if (name.isInvalid()) {
synonymSign = "\u2212 ";
} else {
synonymSign = "\u003D ";
}
}
boolean isAccepted = false;
if (taxonBases.size() == 1) {
taxonBase = HibernateProxyHelper.deproxy(taxonBases.iterator().next());
if (taxonBase.getSec() != null) {
sec = OriginalSourceFormatter.INSTANCE_WITH_YEAR_BRACKETS.format(taxonBase.getSecSource());
}
if (taxonBase.isDoubtful()) {
doubtful = "?";
} else {
doubtful = "";
}
if (taxonBase instanceof Synonym) {
if (isNotBlank(sec)) {
sec = " syn. sec. " + sec + " ";
} else {
sec = "";
}
typifiedNamesWithoutAccepted += synonymSign + doubtful + nameString + nonRelNames + relNames;
typifiedNamesWithoutAcceptedWithSec += synonymSign + doubtful + nameString + sec + nonRelNames + relNames;
} else {
// sec = "";
if (!(((Taxon) taxonBase).isProparteSynonym() || ((Taxon) taxonBase).isMisapplication())) {
isAccepted = true;
} else {
synonymSign = "\u003D ";
}
}
if (taxonBase.getAppendedPhrase() != null) {
if (state.getConfig().isAddHTML()) {
String taxonString = createNameWithItalics(taxonBase.getTaggedTitle());
taxonString = taxonString.replace("sec " + sec, "");
String nameCacheWithItalics = createNameWithItalics(name.getTaggedName());
nameString = nameString.replace(nameCacheWithItalics, taxonString);
}
}
} else {
// there are names used more than once?
for (TaxonBase<?> tb : taxonBases) {
if (tb.getSec() != null) {
sec = OriginalSourceFormatter.INSTANCE_WITH_YEAR_BRACKETS.format(tb.getSecSource());
}
if (tb.isDoubtful()) {
doubtful = "?";
} else {
doubtful = "";
}
if (tb instanceof Synonym) {
if (StringUtils.isNotBlank(sec)) {
sec = " syn. sec. " + sec + " ";
} else {
sec = "";
}
break;
} else {
sec = "";
if (!(((Taxon) tb).isProparteSynonym() || ((Taxon) tb).isMisapplication())) {
isAccepted = true;
break;
} else {
synonymSign = "\u003D ";
}
}
}
if (!isAccepted) {
typifiedNamesWithoutAccepted += synonymSign + doubtful + nameString + "; ";
typifiedNamesWithoutAcceptedWithSec += synonymSign + doubtful + nameString + sec;
typifiedNamesWithoutAcceptedWithSec = typifiedNamesWithoutAcceptedWithSec.trim() + "; ";
}
}
typifiedNamesString += synonymSign + doubtful + nameString + nonRelNames + relNames;
typifiedNamesWithSecString += synonymSign + doubtful + nameString + sec + nonRelNames + relNames;
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_STRING)] = typifiedNamesString.trim();
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITH_SEC_STRING)] = typifiedNamesWithSecString.trim();
if (typifiedNamesWithoutAccepted != null && firstname != null) {
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTED)] = typifiedNamesWithoutAccepted.trim();
} else {
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTED)] = "";
}
if (typifiedNamesWithoutAcceptedWithSec != null && firstname != null) {
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTEDWITHSEC)] = typifiedNamesWithoutAcceptedWithSec.trim();
} else {
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTEDWITHSEC)] = "";
}
index++;
}
Set<TypeDesignationBase<?>> typeDesigantionSet = group.getTypeDesignations();
List<TypeDesignationBase<?>> designationList = new ArrayList<>();
designationList.addAll(typeDesigantionSet);
Collections.sort(designationList, new TypeComparator());
List<TaggedText> list = new ArrayList<>();
if (!designationList.isEmpty()) {
TypeDesignationSetManager manager = new TypeDesignationSetManager(group);
list.addAll(new TypeDesignationSetFormatter(true, false, false).toTaggedText(manager));
}
String typeTextDesignations = "";
// The typeDesignationManager does not handle the textual typeDesignations
for (TypeDesignationBase<?> typeDes : designationList) {
if (typeDes instanceof TextualTypeDesignation) {
typeTextDesignations = typeTextDesignations + ((TextualTypeDesignation) typeDes).getText(Language.getDefaultLanguage());
String typeDesStateRefs = "";
if (typeDes.getDesignationSource() != null) {
typeDesStateRefs = "[";
NamedSource source = typeDes.getDesignationSource();
if (source.getCitation() != null) {
typeDesStateRefs += "fide " + OriginalSourceFormatter.INSTANCE.format(source.getCitation(), null);
}
typeDesStateRefs += "]";
} else if (typeDes.getSources() != null && !typeDes.getSources().isEmpty()) {
typeDesStateRefs = "[";
for (IdentifiableSource source : typeDes.getSources()) {
if (source.getCitation() != null) {
typeDesStateRefs += "fide " + OriginalSourceFormatter.INSTANCE.format(source.getCitation(), null);
}
}
typeDesStateRefs += "]";
}
typeTextDesignations = typeTextDesignations + typeDesStateRefs + "; ";
} else if (typeDes instanceof SpecimenTypeDesignation) {
DerivedUnit specimen = ((SpecimenTypeDesignation) typeDes).getTypeSpecimen();
if (specimen != null && !state.getSpecimenStore().contains(specimen.getUuid())) {
handleSpecimen(state, specimen);
}
}
}
if (typeTextDesignations.equals("; ")) {
typeTextDesignations = "";
}
if (StringUtils.isNotBlank(typeTextDesignations)) {
typeTextDesignations = typeTextDesignations.substring(0, typeTextDesignations.length() - 2);
}
String specimenTypeString = !list.isEmpty() ? createTypeDesignationString(list, true, typifiedNames.get(0).isSpecies() || typifiedNames.get(0).isInfraSpecific()) : "";
if (StringUtils.isNotBlank(specimenTypeString)) {
if (!specimenTypeString.endsWith(".")) {
specimenTypeString = specimenTypeString + ".";
}
csvLine[table.getIndex(CdmLightExportTable.TYPE_STRING)] = specimenTypeString;
} else {
csvLine[table.getIndex(CdmLightExportTable.TYPE_STRING)] = "";
}
if (StringUtils.isNotBlank(typeTextDesignations)) {
if (!typeTextDesignations.endsWith(".")) {
typeTextDesignations = typeTextDesignations + ".";
}
csvLine[table.getIndex(CdmLightExportTable.TYPE_CACHE)] = typeTextDesignations;
} else {
csvLine[table.getIndex(CdmLightExportTable.TYPE_CACHE)] = "";
}
state.getProcessor().put(table, String.valueOf(group.getId()), csvLine);
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when handling homotypic group " + cdmBaseStr(group) + ": " + e.getMessage());
}
}
use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method createTypeDesignationString.
private String createTypeDesignationString(List<TaggedText> list, boolean isHomotypicGroup, boolean isSpecimenTypeDesignation) {
StringBuffer homotypicalGroupTypeDesignationString = new StringBuffer();
for (TaggedText text : list) {
if (text == null || text.getText() == null) {
// just in case
continue;
}
if ((// should not happen anymore
text.getText().equalsIgnoreCase("Type:") || // should not happen anymore
text.getText().equalsIgnoreCase("Nametype:") || (text.getType().equals(TagEnum.name) && !isHomotypicGroup))) {
// do nothing
} else if (text.getType().equals(TagEnum.reference)) {
homotypicalGroupTypeDesignationString.append(text.getText());
} else if (text.getType().equals(TagEnum.name)) {
if (!isSpecimenTypeDesignation) {
homotypicalGroupTypeDesignationString.append("<i>" + text.getText() + "</i> ");
}
} else if (text.getType().equals(TagEnum.typeDesignation)) {
if (isSpecimenTypeDesignation) {
homotypicalGroupTypeDesignationString.append(text.getText().replace(").", "").replace("(", "").replace(")", ""));
} else {
homotypicalGroupTypeDesignationString.append(text.getText());
}
} else {
homotypicalGroupTypeDesignationString.append(text.getText());
}
}
String typeDesignations = homotypicalGroupTypeDesignationString.toString();
typeDesignations = typeDesignations.trim();
if (typeDesignations.endsWith(";")) {
typeDesignations = typeDesignations.substring(0, typeDesignations.length() - 1);
}
typeDesignations += ".";
typeDesignations = typeDesignations.replace("..", ".");
typeDesignations = typeDesignations.replace(". .", ".");
typeDesignations = typeDesignations.replace("; \u2261", " \u2261 ");
if (typeDesignations.trim().equals(".")) {
typeDesignations = null;
}
return typeDesignations;
}
use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.
the class TaxonBaseDefaultCacheStrategy method getTaggedTitle.
@Override
public List<TaggedText> getTaggedTitle(T taxonBase) {
if (taxonBase == null) {
return null;
}
List<TaggedText> tags = new ArrayList<>();
if (taxonBase.isProtectedTitleCache()) {
// protected title cache
tags.add(new TaggedText(TagEnum.name, taxonBase.getTitleCache()));
return tags;
}
if (taxonBase.isDoubtful()) {
tags.add(new TaggedText(TagEnum.separator, "?"));
}
boolean isMisapplication = isMisapplication(taxonBase);
// name
List<TaggedText> nameTags = getNameTags(taxonBase, isMisapplication);
if (nameTags.size() > 0) {
tags.addAll(nameTags);
} else {
tags.add(new TaggedText(TagEnum.fullName, "???"));
}
boolean isSynonym = taxonBase.isInstanceOf(Synonym.class);
String secSeparator = isMisapplication ? " sensu " : (isSynonym ? " syn." : "") + " sec. ";
// not used: we currently use a post-separator in the name tags
// if (nameTags.get(nameTags.size() - 1).getType().equals(TagEnum.nomStatus)){
// secSeparator = "," + secSeparator;
// }
// sec.
List<TaggedText> secTags = getSecundumTags(taxonBase, isMisapplication);
if (!secTags.isEmpty()) {
tags.add(new TaggedText(TagEnum.separator, secSeparator));
tags.addAll(secTags);
} else if (isMisapplication && isBlank(taxonBase.getAppendedPhrase())) {
tags.add(new TaggedText(TagEnum.appendedPhrase, "auct."));
}
if (isMisapplication) {
TaxonName name = CdmBase.deproxy(taxonBase.getName());
if (name != null && isNotBlank(name.getAuthorshipCache())) {
tags.add(new TaggedText(TagEnum.separator, ", non "));
tags.add(new TaggedText(TagEnum.authors, name.getAuthorshipCache()));
}
}
return tags;
}
use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.
the class TaxonBaseDefaultCacheStrategy method getSecundumTags.
private List<TaggedText> getSecundumTags(T taxonBase, boolean isMisapplication) {
List<TaggedText> tags = new ArrayList<>();
Reference sec = taxonBase.getSec();
sec = HibernateProxyHelper.deproxy(sec);
String secRef;
if (sec == null) {
// missing sec
if (isBlank(taxonBase.getAppendedPhrase()) && !isMisapplication) {
secRef = "???";
} else {
secRef = null;
}
} else {
// existing sec
if (sec.isProtectedTitleCache() == false && sec.getCacheStrategy() != null && sec.getAuthorship() != null && isNotBlank(sec.getAuthorship().getTitleCache()) && isNotBlank(sec.getYear())) {
// microRef is handled later
secRef = OriginalSourceFormatter.INSTANCE.format(sec, null);
} else if ((sec.isWebPage() || sec.isDatabase() || sec.isMap()) && titleExists(sec)) {
// maybe we should also test protected caches (but which one, the abbrev cache or the titleCache?
secRef = isNotBlank(sec.getAbbrevTitle()) ? sec.getAbbrevTitle() : sec.getTitle();
String secDate = sec.getYear();
if (isBlank(secDate) && sec.getAccessed() != null) {
secDate = String.valueOf(sec.getAccessed().getYear());
}
secRef = CdmUtils.concat(" ", secRef, secDate);
} else {
secRef = sec.getTitleCache();
// TODO maybe not always correct
if (secTitleTrailingDotShouldBeRemoved(sec)) {
secRef = CdmUtils.removeTrailingDots(secRef);
}
}
}
if (secRef != null) {
tags.add(new TaggedText(TagEnum.secReference, secRef));
}
// secMicroReference
if (isNotBlank(taxonBase.getSecMicroReference())) {
tags.add(new TaggedText(TagEnum.separator, ": "));
tags.add(new TaggedText(TagEnum.secMicroReference, taxonBase.getSecMicroReference()));
}
return tags;
}
Aggregations