1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.wp6;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.regex.Matcher;
|
17
|
import java.util.regex.Pattern;
|
18
|
|
19
|
import org.apache.commons.lang.StringUtils;
|
20
|
import org.apache.log4j.Logger;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
23
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
24
|
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
|
25
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
26
|
|
27
|
/**
|
28
|
* @author a.babadshanjan
|
29
|
* @created 13.01.2009
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
public class CommonNameRow {
|
33
|
private static final Logger logger = Logger.getLogger(CommonNameRow.class);
|
34
|
|
35
|
|
36
|
private String species;
|
37
|
private String reference;
|
38
|
private String area;
|
39
|
private String nameUsedInSource;
|
40
|
|
41
|
private Map<String, List<String>> commonNames = new HashMap<String, List<String>>();
|
42
|
|
43
|
|
44
|
public CommonNameRow() {
|
45
|
this.species = "";
|
46
|
this.reference = "";
|
47
|
this.area = "";
|
48
|
commonNames = new HashMap<String, List<String>>();
|
49
|
}
|
50
|
|
51
|
// **************************** GETTER / SETTER *********************************/
|
52
|
|
53
|
public void setCommonNames(String commonNamesString){
|
54
|
commonNamesString = makeNameUsedInSource(commonNamesString);
|
55
|
String[] split = commonNamesString.split(";");
|
56
|
for (String oneLanguage : split){
|
57
|
oneLanguage = oneLanguage.trim();
|
58
|
String reLangPattern = "\\((\\*|[a-z]{2,3}|.{2,},\\sno\\sISO-Code)\\)$";
|
59
|
String pattern = ".+" + reLangPattern;
|
60
|
if (! oneLanguage.matches(pattern)){
|
61
|
logger.warn("Common name does not match: " + oneLanguage);
|
62
|
}else{
|
63
|
Pattern langPattern = Pattern.compile(reLangPattern);
|
64
|
Matcher matcher = langPattern.matcher(oneLanguage);
|
65
|
if (matcher.find()){
|
66
|
String lang = matcher.group().substring(1);
|
67
|
lang = lang.substring(0, lang.length()-1);
|
68
|
String names = "";
|
69
|
try {
|
70
|
names = oneLanguage.substring(0,matcher.start()-1);
|
71
|
} catch (Exception e) {
|
72
|
e.printStackTrace();
|
73
|
}
|
74
|
String[] splitNames = names.split(",");
|
75
|
List<String> nameList = new ArrayList<String>();
|
76
|
for (String singleName : splitNames){
|
77
|
if (StringUtils.isNotBlank(singleName)){
|
78
|
nameList.add(singleName.trim());
|
79
|
}
|
80
|
}
|
81
|
if (!nameList.isEmpty()){
|
82
|
this.commonNames.put(lang, nameList);
|
83
|
}
|
84
|
}else{
|
85
|
logger.warn("Common name does not match: " + oneLanguage);
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
|
91
|
private String makeNameUsedInSource(String commonNamesString) {
|
92
|
String[] split = commonNamesString.split(":");
|
93
|
if (split.length > 1){
|
94
|
logger.debug("NameUsedInSource: " + split[0]);
|
95
|
this.nameUsedInSource = split[0].trim();
|
96
|
if (split.length > 2){
|
97
|
logger.warn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:" + commonNamesString);
|
98
|
}
|
99
|
return split[1].trim();
|
100
|
}else{
|
101
|
return split[0].trim();
|
102
|
}
|
103
|
}
|
104
|
|
105
|
public Map<String, List<String>> getCommonNames() {
|
106
|
return commonNames;
|
107
|
}
|
108
|
|
109
|
public void parseSpecies(String species){
|
110
|
INonViralNameParser parser = NonViralNameParserImpl.NewInstance();
|
111
|
BotanicalName name = (BotanicalName)parser.parseFullName(species, NomenclaturalCode.ICNAFP, null);
|
112
|
if (name.isProtectedTitleCache()){
|
113
|
logger.warn("Name could not be parsed: " + species);
|
114
|
}
|
115
|
this.species = species;
|
116
|
}
|
117
|
|
118
|
public String getSpecies() {
|
119
|
return species;
|
120
|
}
|
121
|
|
122
|
public void setSpecies(String species) {
|
123
|
this.species = species;
|
124
|
}
|
125
|
|
126
|
public void setReference(String reference) {
|
127
|
reference = reference.replace(".", "");
|
128
|
if (! reference.matches("\\d{7}")){
|
129
|
logger.warn("Unexpected reference");
|
130
|
}
|
131
|
this.reference = reference.substring(0,6);
|
132
|
}
|
133
|
|
134
|
public String getReference() {
|
135
|
return reference;
|
136
|
}
|
137
|
|
138
|
public void setArea(String area) {
|
139
|
this.area = area;
|
140
|
}
|
141
|
|
142
|
public String getArea() {
|
143
|
return area;
|
144
|
}
|
145
|
|
146
|
public void setNameUsedInSource(String nameUsedInSource) {
|
147
|
this.nameUsedInSource = nameUsedInSource;
|
148
|
}
|
149
|
|
150
|
public String getNameUsedInSource() {
|
151
|
return nameUsedInSource;
|
152
|
}
|
153
|
|
154
|
|
155
|
|
156
|
}
|