use of eu.etaxonomy.cdm.model.common.Annotation in project cdmlib by cybertaxonomy.
the class IpniService method getNameFromLine.
private IBotanicalName getNameFromLine(String line, Map<Integer, String> parameterMap, ICdmRepository repository, IpniServiceNamesConfigurator config) {
// Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
String[] splits = line.split("%");
Map<String, String> valueMap = fillValueMap(parameterMap, splits);
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null);
// epithets
name.setGenusOrUninomial(valueMap.get(GENUS));
name.setInfraGenericEpithet(valueMap.get(INFRA_GENUS));
name.setSpecificEpithet(valueMap.get(SPECIES));
name.setInfraSpecificEpithet(valueMap.get(INFRA_SPECIFIC));
// rank
try {
String rankStr = nomalizeRank(valueMap.get(RANK));
Rank rank = Rank.getRankByLatinNameOrIdInVoc(rankStr, NomenclaturalCode.ICNAFP, true);
name.setRank(rank);
} catch (UnknownCdmTypeException e) {
logger.warn("Rank was unknown");
}
// caches
String pureName = valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS);
String nameCache = name.getNameCache();
if (!Nz(pureName).equals(nameCache)) {
nvnParser.parseSimpleName(name, valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), name.getRank(), true);
// name.setNameCache(valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), true);
}
String authors = "";
// authors
if (valueMap.get(BASIONYM_AUTHOR) != null) {
authors = valueMap.get(BASIONYM_AUTHOR);
// name.setBasionymAuthorship(Team.NewTitledInstance(valueMap.get(BASIONYM_AUTHOR), valueMap.get(BASIONYM_AUTHOR)));
}
if (valueMap.get(PUBLISHING_AUTHOR) != null) {
authors += valueMap.get(PUBLISHING_AUTHOR);
// name.setCombinationAuthorship(Team.NewTitledInstance(valueMap.get(PUBLISHING_AUTHOR), valueMap.get(PUBLISHING_AUTHOR)));
}
try {
nvnParser.parseAuthors(name, authors);
} catch (StringNotParsableException e1) {
//
}
if (!Nz(valueMap.get(AUTHORS)).equals(name.getAuthorshipCache())) {
name.setAuthorshipCache(valueMap.get(AUTHORS), true);
}
if ("Y".equals(valueMap.get(HYBRID))) {
if (!name.isHybrid()) {
// Is there a concrete way to include the hybrid flag info? As it does not say which type of hybrid it seems
// to be best to handle hybrids via parsing. But there might be a better errror handling possible.
logger.warn("Name is flagged as hybrid at IPNI but CDM name has no hybrid flag set: " + name.getTitleCache());
}
}
// publication
if (valueMap.get(PUBLICATION) != null || valueMap.get(COLLATION) != null || valueMap.get(PUBLICATION_YEAR_FULL) != null) {
Reference ref = ReferenceFactory.newGeneric();
// TODO probably we can do better parsing here
String pub = CdmUtils.concat(" ", valueMap.get(PUBLICATION), valueMap.get(COLLATION));
if (isNotBlank(pub)) {
String nomRefTitle = pub;
String[] split = nomRefTitle.split(":");
if (split.length > 1) {
String detail = split[split.length - 1];
name.setNomenclaturalMicroReference(detail.trim());
nomRefTitle = nomRefTitle.substring(0, nomRefTitle.length() - detail.length() - 1).trim();
}
ref.setAbbrevTitle(nomRefTitle);
}
VerbatimTimePeriod datePublished = parsePublicationFullYear(valueMap.get(PUBLICATION_YEAR_FULL));
ref.setDatePublished(datePublished);
name.setNomenclaturalReference(ref);
}
// name status
NomenclaturalStatusType statusType = null;
String statusString = valueMap.get(NAME_STATUS);
if (isNotBlank(statusString)) {
try {
statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString, name);
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(statusType);
name.addStatus(nomStatus);
} catch (UnknownCdmTypeException e) {
logger.warn("Name status not recognized: " + statusString);
Annotation annotation = Annotation.NewInstance("Name status: " + statusString, AnnotationType.EDITORIAL(), Language.ENGLISH());
name.addAnnotation(annotation);
}
}
// remarks
String remarks = valueMap.get(REMARKS);
if (remarks != null) {
Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
name.addAnnotation(annotation);
}
// basionym
if (config.isDoBasionyms() && valueMap.get(BASIONYM) != null) {
TaxonName basionym = TaxonNameFactory.NewBotanicalInstance(null);
basionym.setTitleCache(valueMap.get(BASIONYM), true);
name.addBasionym(basionym);
}
// replaced synonym
if (config.isDoBasionyms() && valueMap.get(REPLACED_SYNONYM) != null) {
TaxonName replacedSynoynm = TaxonNameFactory.NewBotanicalInstance(null);
replacedSynoynm.setTitleCache(valueMap.get(REPLACED_SYNONYM), true);
name.addReplacedSynonym(replacedSynoynm, null, null, null, null);
}
// type information
if (config.isDoType() && valueMap.get(COLLECTION_DATE_AS_TEXT) != null || valueMap.get(COLLECTION_NUMBER) != null || valueMap.get(COLLECTION_DAY1) != null || valueMap.get(COLLECTION_DAY2) != null || valueMap.get(COLLECTION_MONTH1) != null || valueMap.get(COLLECTION_MONTH2) != null || valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null || valueMap.get(COLLECTOR_TEAM_AS_TEXT) != null || valueMap.get(LOCALITY) != null || valueMap.get(LATITUDE_DEGREES) != null || valueMap.get(LATITUDE_MINUTES) != null || valueMap.get(LATITUDE_SECONDS) != null || valueMap.get(NORTH_OR_SOUTH) != null || valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null) // TODO TBC
{
DerivedUnitFacade specimen = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
// gathering period
String collectionDateAsText = valueMap.get(COLLECTION_DATE_AS_TEXT);
TimePeriod gatheringPeriod = TimePeriodParser.parseString(collectionDateAsText);
try {
gatheringPeriod.setStartDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY1));
gatheringPeriod.setStartMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH1));
gatheringPeriod.setStartYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR1));
gatheringPeriod.setEndDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY2));
gatheringPeriod.setEndMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH2));
gatheringPeriod.setEndYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR2));
} catch (IndexOutOfBoundsException e) {
logger.info("Exception occurred when trying to fill gathering period");
}
specimen.setGatheringPeriod(gatheringPeriod);
specimen.setFieldNumber(valueMap.get(COLLECTION_NUMBER));
// collector team
String team = valueMap.get(COLLECTOR_TEAM_AS_TEXT);
if (team != null) {
Team collectorTeam = Team.NewTitledInstance(team, team);
specimen.setCollector(collectorTeam);
}
specimen.setLocality(valueMap.get(LOCALITY));
try {
String latDegrees = CdmUtils.Nz(valueMap.get(LATITUDE_DEGREES));
String latMinutes = CdmUtils.Nz(valueMap.get(LATITUDE_MINUTES));
String latSeconds = CdmUtils.Nz(valueMap.get(LATITUDE_SECONDS));
String direction = CdmUtils.Nz(valueMap.get(NORTH_OR_SOUTH));
String latitude = latDegrees + "°" + latMinutes + "'" + latSeconds + "\"" + direction;
String lonDegrees = CdmUtils.Nz(valueMap.get(LONGITUDE_DEGREES));
String lonMinutes = CdmUtils.Nz(valueMap.get(LONGITUDE_MINUTES));
String lonSeconds = CdmUtils.Nz(valueMap.get(LONGITUDE_SECONDS));
direction = CdmUtils.Nz(valueMap.get(EAST_OR_WEST));
String longitude = lonDegrees + "°" + lonMinutes + "'" + lonSeconds + "\"" + direction;
specimen.setExactLocationByParsing(longitude, latitude, null, null);
} catch (ParseException e) {
logger.info("Parsing exception occurred when trying to parse type exact location." + e.getMessage());
} catch (Exception e) {
logger.info("Exception occurred when trying to read type exact location." + e.getMessage());
}
// type annotation
if (valueMap.get(TYPE_REMARKS) != null) {
Annotation typeAnnotation = Annotation.NewInstance(valueMap.get(TYPE_REMARKS), AnnotationType.EDITORIAL(), Language.DEFAULT());
specimen.addAnnotation(typeAnnotation);
}
}
// TODO Type name
// TODO "Type locations" , eg. holotype CAT ,isotype CAT ,isotype FI
// TODO Geographic unit as text
// source
Reference citation = getIpniCitation(repository);
name.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Name", citation, valueMap.get(VERSION));
/* EXTENDED
* Species author,
* Standardised basionym author flag,
* Standardised publishing author flag
Full name
Full name without family
Full name without authors
Reference
Standardised publication flag
Publication year
publication year note
Publication year text
Volume
Start page
End page
Primary pagination
Secondary pagination
Reference remarks
Hybrid parents
Replaced synonym Author team
Other links
Same citation as
Bibliographic reference
Bibliographic type info
Original taxon name
Original taxon name author team
Original replaced synonym
Original replaced synonym author team
Original basionym
Original basionym author team
Original parent citation taxon name author team
Original taxon distribution
Original hybrid parentage
Original cited type
Original remarks
*/
return name;
}
use of eu.etaxonomy.cdm.model.common.Annotation in project cdmlib by cybertaxonomy.
the class GeoServiceAreaAnnotatedMapping method clear.
@Override
public void clear(NamedArea area) {
Set<Annotation> removeCandidates = new HashSet<>();
for (Annotation annotation : area.getAnnotations()) {
if (AnnotationType.TECHNICAL().equals(annotation.getAnnotationType())) {
if (GeoServiceArea.isAreaMapping(annotation.getText())) {
removeCandidates.add(annotation);
}
}
}
for (Annotation remove : removeCandidates) {
area.removeAnnotation(remove);
}
termService.saveOrUpdate(area);
}
use of eu.etaxonomy.cdm.model.common.Annotation in project cdmlib by cybertaxonomy.
the class DescriptionPortalController method getAnnotations.
// mapped as absolute path, see CdmAntPathMatcher
@RequestMapping(value = "//portal/descriptionElement/{descriptionelement_uuid}/annotation", method = RequestMethod.GET)
public Pager<Annotation> getAnnotations(@PathVariable("descriptionelement_uuid") UUID uuid, HttpServletRequest request, HttpServletResponse response) {
logger.info("getAnnotations() - " + requestPathAndQuery(request));
DescriptionElementBase annotatableEntity = descriptionElementService.find(uuid);
Pager<Annotation> annotations = descriptionElementService.getAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
return annotations;
}
use of eu.etaxonomy.cdm.model.common.Annotation in project cdmlib by cybertaxonomy.
the class SDDDocumentBuilder method buildRepresentation.
/**
* Builds a Representation element using a Reference
*/
public void buildRepresentation(ElementImpl element, IDatabase reference) throws ParseException {
// create <Representation> element
ElementImpl representation = new ElementImpl(document, REPRESENTATION);
element.appendChild(representation);
buildLabel(representation, reference.getTitleCache());
Set<Annotation> annotations = ((Reference) reference).getAnnotations();
Iterator<Annotation> iterator = annotations.iterator();
String detailText = null;
if (iterator.hasNext()) {
Annotation annotation = iterator.next();
detailText = annotation.getText();
}
if (detailText != null && !detailText.equals("")) {
ElementImpl detail = new ElementImpl(document, DETAIL);
detail.appendChild(document.createTextNode(detailText));
representation.appendChild(detail);
}
Set<Media> rm = ((Reference) reference).getMedia();
if (rm != null && rm.size() > 0) {
ElementImpl mediaObject;
for (int i = 0; i < rm.size(); i++) {
mediaObject = new ElementImpl(document, MEDIA_OBJECT);
mediasCount = buildReference((Media) rm.toArray()[i], medias, REF, mediaObject, "m", mediasCount);
representation.appendChild(mediaObject);
}
}
}
use of eu.etaxonomy.cdm.model.common.Annotation in project cdmlib by cybertaxonomy.
the class SDDDocumentBuilder method buildScope.
/**
* Builds Scope associated with a CodedDescription
*/
public void buildScope(ElementImpl element, TaxonDescription taxonDescription) throws ParseException {
// <Scope>
// <TaxonName ref="t1"/>
// <Citation ref="p1" location="p. 30"/>
// </Scope>
ElementImpl scope = new ElementImpl(document, SCOPE);
Taxon taxon = taxonDescription.getTaxon();
if (taxon != null) {
TaxonName taxonName = taxon.getName();
if (taxonName != null) {
String ref = taxonNames.get(taxonName);
if (!ref.equals("")) {
ElementImpl taxonNameEl = new ElementImpl(document, TAXON_NAME);
taxonNameEl.setAttribute(REF, ref);
scope.appendChild(taxonNameEl);
}
}
}
Set<Reference> descriptionSources = new HashSet<Reference>();
for (IdentifiableSource source : taxonDescription.getSources()) {
descriptionSources.add(source.getCitation());
}
for (Iterator<Reference> rb = descriptionSources.iterator(); rb.hasNext(); ) {
Reference descriptionSource = rb.next();
if (descriptionSource.getType().equals(ReferenceType.Article)) {
ElementImpl citation = new ElementImpl(document, CITATION);
articlesCount = buildReference(descriptionSource, articles, REF, citation, "p", articlesCount);
Set<Annotation> annotations = descriptionSource.getAnnotations();
for (Iterator<Annotation> a = annotations.iterator(); a.hasNext(); ) {
Annotation annotation = a.next();
AnnotationType annotationType = annotation.getAnnotationType();
if (annotationType != null) {
String type = annotationType.getLabel();
if (type.equals("location")) {
citation.setAttribute("location", annotation.getText());
}
}
}
scope.appendChild(citation);
}
}
element.appendChild(scope);
}
Aggregations