use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.
the class RisReferenceImport method makeDate.
private VerbatimTimePeriod makeDate(RisReferenceImportState state, RisValue da) {
if (da == null) {
return null;
}
if (!da.value.matches("([0-9]{4})?(\\/([0-9]{2})?(\\/([0-9]{2})?(\\/.*)?)?)?")) {
String message = "Tag '%s' has incorrect format. Only exactly 'dddd/dd/dd/any text' is allowed (where d is a digit), but was '%s'";
message = String.format(message, da.tag.name(), da.value);
state.getResult().addWarning(message, null, da.location);
return null;
}
String[] split = da.value.split("/");
VerbatimTimePeriod tp = VerbatimTimePeriod.NewVerbatimInstance();
if (split.length > 0 && isNotBlank(split[0])) {
tp.setStartYear(Integer.valueOf(split[0]));
}
if (split.length > 1 && isNotBlank(split[1])) {
tp.setStartMonth(Integer.valueOf(split[1]));
}
if (split.length > 2 && isNotBlank(split[2])) {
tp.setStartDay(Integer.valueOf(split[2]));
}
if (split.length > 3 && isNotBlank(split[3])) {
List<String> other = Arrays.asList(split).subList(3, split.length);
String otherStr = CdmUtils.concat("/", other.toArray(new String[other.size()]));
tp.setFreeText(tp.toString() + " " + otherStr);
}
return tp;
}
use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.
the class RisReferenceImportTest method testShort.
// ***************************** TESTS *************************************//
@Test
@DataSet(value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy = CleanSweepInsertLoadStrategy.class)
public // @Ignore
void testShort() {
RisReferenceImportConfigurator configurator = getConfigurator("RisReferenceImportTest-input.ris");
ImportResult result = defaultImport.invoke(configurator);
String report = result.createReport().toString();
Assert.assertTrue(report.length() > 0);
// System.out.println(report);
Integer expected = 2;
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
Assert.assertEquals("There should be 3 references, the article and the journal and the source reference", 3, list.size());
for (Reference ref : list) {
if (ref.equals(configurator.getSourceReference())) {
continue;
}
Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
if (ref.getType() == ReferenceType.Article) {
// title
Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea", ref.getTitle());
// author
TeamOrPersonBase<?> author = ref.getAuthorship();
Assert.assertNotNull(author);
Assert.assertTrue(author.isInstanceOf(Person.class));
Person person = CdmBase.deproxy(author, Person.class);
// this may change in future depending on the correct formatting strategy
Assert.assertEquals("Jongkind, C.C.H.", person.getTitleCache());
Assert.assertEquals("Jongkind", person.getFamilyName());
Assert.assertEquals("Carel C. H.", person.getGivenName());
// date
VerbatimTimePeriod date = ref.getDatePublished();
Assert.assertEquals(Integer.valueOf(2017), date.getStartYear());
// vol
Assert.assertEquals("47(1)", ref.getVolume());
Assert.assertEquals("43-47", ref.getPages());
// doi
// Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"), ref.getDoi());
// Abstract
Assert.assertEquals("Abstract: A new species of Violaceae, Decorsella arborea Jongkind, is described and illustrated. The new species differs from the only other species in the genus, D. paradoxa A. Chev., by the larger size of the plants, smaller leaves, more slender flowers, and stamen filaments that are free for a much larger part. Both species are from the Guineo-Congolian forest of tropical Africa. The differences between Decorsella and Rinorea are discussed. Confirming recent reports, some species of Rinorea can have zygomorphic flowers and some of these can be almost equal in shape to Decorsella flowers. Citation: Jongkind C. C. H. 2017: Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea. ? Willdenowia 47: 43?47. doi: https://doi.org/10.3372/wi.47.47105 Version of record first published online on 13 February 2017 ahead of inclusion in April 2017 issue.", ref.getReferenceAbstract());
// TODO still missing Y1, Y2, M3, UR
} else if (ref.getType() == ReferenceType.Journal) {
Assert.assertEquals("Willdenowia", ref.getTitle());
// or is this part of article?
Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
// ISSN
Assert.assertEquals("0511-9618", ref.getIssn());
} else {
Assert.fail("Only an article and a journal should exist");
}
}
}
use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.
the class Reference method setDatePublished.
@Override
@Transient
@Deprecated
public VerbatimTimePeriod setDatePublished(TimePeriod datePublished) {
VerbatimTimePeriod newTimePeriod = VerbatimTimePeriod.toVerbatim(datePublished);
setDatePublished(newTimePeriod);
return newTimePeriod;
}
use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.
the class IpniService method getPublicationFromLine.
private Reference getPublicationFromLine(String line, Map<Integer, String> parameterMap, ICdmRepository repository, IpniServicePublicationConfigurator config) {
// fill value map
String[] splits = line.split("%");
Map<String, String> valueMap = fillValueMap(parameterMap, splits);
// create reference object
Reference ref = ReferenceFactory.newGeneric();
// reference
if (config.isUseAbbreviationAsTitle() == true) {
ref.setTitle(valueMap.get(ABBREVIATION));
// TODO handle title as extension
} else {
ref.setTitle(valueMap.get(TITLE));
// TODO handle abbreviation as extension
}
ref.setIsbn(valueMap.get(ISBN));
ref.setIssn(valueMap.get(ISSN));
ref.setEdition(valueMap.get(EDITION));
ref.setPlacePublished(valueMap.get(PLACE));
String author = valueMap.get(PUBLICATION_AUTHOR_TEAM);
if (isNotBlank(author)) {
Team team = Team.NewTitledInstance(author, author);
ref.setAuthorship(team);
}
// remarks
String remarks = valueMap.get(REMARKS);
if (remarks != null) {
Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
ref.addAnnotation(annotation);
}
String tl2AuthorString = valueMap.get(TL2_AUTHOR);
if (ref.getAuthorship() == null) {
Team tl2Author = Team.NewTitledInstance(tl2AuthorString, null);
ref.setAuthorship(tl2Author);
} else {
// TODO parse name,
ref.getAuthorship().setTitleCache(tl2AuthorString, true);
ref.addAnnotation(Annotation.NewInstance(tl2AuthorString, AnnotationType.EDITORIAL(), Language.ENGLISH()));
}
// dates
VerbatimTimePeriod date = TimePeriodParser.parseStringVerbatim(valueMap.get(DATE));
ref.setDatePublished(date);
// source
Reference citation = getIpniCitation(repository);
ref.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Publication", citation, valueMap.get(VERSION));
return ref;
}
use of eu.etaxonomy.cdm.model.common.VerbatimTimePeriod in project cdmlib by cybertaxonomy.
the class TcsRdfTaxonNameImport method handleNameResource.
private TaxonName handleNameResource(Resource nameAbout, TcsRdfImportConfigurator config) {
String idNamespace = "TaxonName";
// StmtIterator stmts = nameAbout.listProperties();
// while(stmts.hasNext()){
// System.out.println(stmts.next().getPredicate().toString());
// }
Property prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "nomenclaturalCode");
Statement stateNomenclaturalCode = nameAbout.getProperty(prop);
String strNomenclaturalCode = stateNomenclaturalCode.getObject().toString();
// Rank
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "rankString");
String strRank = nameAbout.getProperty(prop).getString();
try {
Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
NomenclaturalCode nomCode;
if (strNomenclaturalCode != null) {
nomCode = TcsRdfTransformer.nomCodeString2NomCode(strNomenclaturalCode);
} else {
nomCode = NomenclaturalCode.ICNAFP;
}
TaxonName nameBase = nomCode.getNewTaxonNameInstance(rank);
// Set<String> omitAttributes = null;
// makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers);
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "nameComplete");
String strNameComplete = nameAbout.getProperty(prop).getString();
nameBase.setTitleCache(strNameComplete, true);
prop = nameAbout.getModel().getProperty(config.getCommonNamespaceURIString() + "publishedIn");
String strPublishedIn = nameAbout.getProperty(prop).getString();
if (strPublishedIn != null && strPublishedIn != "") {
// TODO
IGeneric nomRef = ReferenceFactory.newGeneric();
nomRef.setTitleCache(strPublishedIn, true);
nameBase.setNomenclaturalReference(nomRef);
try {
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "year");
String strYear = nameAbout.getProperty(prop).getString();
Integer year = null;
if (strYear != null) {
try {
year = Integer.valueOf(strYear);
VerbatimTimePeriod timeP = VerbatimTimePeriod.NewVerbatimInstance(year);
nomRef.setDatePublished(timeP);
} catch (RuntimeException e) {
logger.warn("year could not be parsed");
}
}
} catch (NullPointerException e) {
}
if (config.isPublishReferences()) {
((Reference) nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
}
}
if (nameBase.isNonViral()) {
INonViralName nonViralName = nameBase;
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "genusPart");
String strGenusPart;
try {
strGenusPart = nameAbout.getProperty(prop).getString();
} catch (NullPointerException e) {
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "uninomial");
strGenusPart = nameAbout.getProperty(prop).getString();
}
nonViralName.setGenusOrUninomial(strGenusPart);
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "infragenericEpithet");
try {
String strInfragenericEpithet = nameAbout.getProperty(prop).getString();
nonViralName.setInfraGenericEpithet(strInfragenericEpithet);
} catch (NullPointerException e) {
}
try {
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "specificEpithet");
String strSpecificEpithet = nameAbout.getProperty(prop).getString();
nonViralName.setSpecificEpithet(strSpecificEpithet);
} catch (NullPointerException e) {
}
try {
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "infraspecificEpithet");
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
} catch (NullPointerException e) {
}
// Authorships
// TODO
/*
* <tn:authorteam>
<tm:Team>
<tm:name>(Raf.) Fernald</tm:name>
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:2691-1"
tm:index="1"
tm:role="Combination Author"/>
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1"
tm:index="1"
tm:role="Basionym Author"/>
</tm:Team>
</tn:authorteam>
*/
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "authorship");
Statement stateAuthorship = nameAbout.getProperty(prop);
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString() + "authorteam");
Statement stateAuthorTeam = nameAbout.getProperty(prop);
Team authorTeam = new Team();
authorTeam.setTitleCache(stateAuthorship.getObject().toString(), true);
Statement stateAutorTeamTeam = null;
Statement stateAutorTeamName = null;
StmtIterator stateTeamMember = null;
if (stateAuthorTeam != null) {
prop = stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString() + "Team");
try {
stateAutorTeamTeam = stateAuthorTeam.getProperty(prop);
} catch (Exception e) {
}
try {
prop = stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString() + "name");
stateAutorTeamName = stateAuthorTeam.getProperty(prop);
} catch (Exception e) {
}
try {
prop = nameAbout.getModel().getProperty(config.getTeamNamespaceURIString() + "hasMember");
stateTeamMember = ((Resource) stateAuthorTeam.getObject()).listProperties(prop);
String memberString = null;
Person person;
for (Statement statement : stateTeamMember.toList()) {
memberString = statement.getObject().toString();
if (memberString != null) {
person = Person.NewTitledInstance(memberString);
authorTeam.addTeamMember(person);
}
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
nonViralName.setCombinationAuthorship(authorTeam);
// Annotations:
/*
* <tn:hasAnnotation>
<tn:NomenclaturalNote>
<tn:noteType rdf:resource="http://rs.tdwg.org/ontology/voc/TaxonName#replacementNameFor"/>
<tn:objectTaxonName rdf:resource="urn:lsid:ipni.org:names:151538-1"/>
</tn:NomenclaturalNote>
</tn:hasAnnotation>
*/
/*
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
tcsElementName = "basionymAuthorship";
String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
if (basionymAuthorValue != null){
TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
nonViralName.setBasionymAuthorship(basionymAuthor);
}
//TODO
tcsElementName = "combinationAuthorship";
String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
if (combinationAuthorValue != null){
TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
nonViralName.setCombinationAuthorship(combinationAuthor);
}
//set the authorshipCache
tcsElementName = "authorship";
String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
String cache = nonViralName.getAuthorshipCache();
if ( authorValue != null){
//compare existing authorship cache with new one and check if it is necessary to
//make cache protected //TODO refinement
if (cache == null){
nonViralName.setAuthorshipCache(authorValue);
}else{
cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
cache = cache.replace("\\(|\\)", "");
cache = cache.trim();
if (! cache.equals("")){
nonViralName.setAuthorshipCache(authorValue);
}
}
}*/
}
return nameBase;
} catch (Exception e) {
e.printStackTrace();
return null;
}
/*
//name
String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
nameBase.setTitleCache(strNameComplete, true);
//Reference
//TODO
String tcsElementName = "publishedIn";
Namespace tcsNamespace = config.getCommonNamespaceURIString();
String value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
if (value != null && value != ""){
IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
nomRef.setTitleCache(value, true);
nameBase.setNomenclaturalReference(nomRef);
//TODO
tcsElementName = "year";
tcsNamespace = taxonNameNamespace;
Integer year = null;
value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
if (value != null){
try {
year = Integer.valueOf(value);
TimePeriod timeP = TimePeriod.NewInstance(year);
nomRef.setDatePublished(timeP);
} catch (RuntimeException e) {
logger.warn("year could not be parsed");
}
}
if (config.isPublishReferences()){
((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
}
}
//Status
tcsNamespace = taxonNameNamespace;
Element elAnnotation = elTaxonName.getChild("hasAnnotation", tcsNamespace);
if (elAnnotation != null){
Element elNomenclaturalNote = elAnnotation.getChild("NomenclaturalNote", tcsNamespace);
if (elNomenclaturalNote != null){
String statusValue = (String)ImportHelper.getXmlInputValue(elNomenclaturalNote, "note", tcsNamespace);
String type = XmlHelp.getChildAttributeValue(elNomenclaturalNote, "type", tcsNamespace, "resource", rdfNamespace);
String tdwgType = "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
if (tdwgType.equalsIgnoreCase(type)){
try {
NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
//NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
if (statusType != null){
nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
}
} catch (UnknownCdmTypeException e) {
if (! statusValue.equals("valid")){
logger.warn("Unknown NomenclaturalStatusType: " + statusValue);
}
}
}
}
}
if (nameBase instanceof NonViralName){
INonViralName nonViralName = nameBase;
String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
//for names of rank genus the uninomial property should be used
if (strGenusPart == null){
strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
}
nonViralName.setGenusOrUninomial(strGenusPart);
String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
nonViralName.setGenusOrUninomial(strInfragenericEpithet);
String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
nonViralName.setSpecificEpithet(strSpecificEpithet);
String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
//AuthorTeams
//TODO
tcsElementName = "basionymAuthorship";
String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
if (basionymAuthorValue != null){
TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
nonViralName.setBasionymAuthorship(basionymAuthor);
}
//TODO
tcsElementName = "combinationAuthorship";
String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
if (combinationAuthorValue != null){
TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
nonViralName.setCombinationAuthorship(combinationAuthor);
}
//set the authorshipCache
tcsElementName = "authorship";
String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
String cache = nonViralName.getAuthorshipCache();
if ( authorValue != null){
//compare existing authorship cache with new one and check if it is necessary to
//make cache protected //TODO refinement
if (cache == null){
nonViralName.setAuthorshipCache(authorValue);
}else{
cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
cache = cache.replace("\\(|\\)", "");
cache = cache.trim();
if (! cache.equals("")){
nonViralName.setAuthorshipCache(authorValue);
}
}
}
}
ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
//nameId
//TODO
//ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
//taxonNameMap.put(nameAbout, nameBase);
return nameBase;
}catch(UnknownCdmTypeException e){
e.printStackTrace();
}
return null;*/
}
Aggregations