1 |
|
/**
|
2 |
|
*
|
3 |
|
*/
|
4 |
|
package eu.etaxonomy.cdm.strategy;
|
5 |
|
|
6 |
|
import java.util.Calendar;
|
7 |
|
import java.util.regex.Matcher;
|
8 |
|
import java.util.regex.Pattern;
|
9 |
|
|
10 |
|
import org.apache.log4j.Logger;
|
11 |
|
|
12 |
|
import eu.etaxonomy.cdm.model.agent.Team;
|
13 |
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
14 |
|
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
|
15 |
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
16 |
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
17 |
|
import eu.etaxonomy.cdm.model.name.Rank;
|
18 |
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
19 |
|
import eu.etaxonomy.cdm.model.reference.Article;
|
20 |
|
import eu.etaxonomy.cdm.model.reference.Book;
|
21 |
|
import eu.etaxonomy.cdm.model.reference.BookSection;
|
22 |
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
23 |
|
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
|
24 |
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
25 |
|
|
26 |
|
|
27 |
|
/**
|
28 |
|
* @author a.mueller
|
29 |
|
*
|
30 |
|
*/
|
31 |
|
public class TaxonNameParserBotanicalNameImpl implements ITaxonNameParser<BotanicalName> {
|
32 |
|
private static final Logger logger = Logger.getLogger(TaxonNameParserBotanicalNameImpl.class);
|
33 |
|
|
34 |
|
// good intro: http://java.sun.com/docs/books/tutorial/essential/regex/index.html
|
35 |
|
|
36 |
|
public static TaxonNameParserBotanicalNameImpl NEW_INSTANCE(){
|
37 |
|
return new TaxonNameParserBotanicalNameImpl();
|
38 |
|
}
|
39 |
|
|
40 |
|
|
41 |
|
/* (non-Javadoc)
|
42 |
|
* @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseSimpleName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)
|
43 |
|
*/
|
44 |
|
public BotanicalName parseSimpleName(String simpleName, Rank rank){
|
45 |
|
//TODO
|
46 |
|
logger.warn("parseSimpleName() not yet implemented. Uses parseFullName() instead");
|
47 |
|
return parseFullName(simpleName, rank);
|
48 |
|
}
|
49 |
|
|
50 |
|
|
51 |
|
/* (non-Javadoc)
|
52 |
|
* @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseSubGenericSimpleName(java.lang.String)
|
53 |
|
*/
|
54 |
|
public BotanicalName parseSimpleName(String simpleName){
|
55 |
|
return parseSimpleName(simpleName, null);
|
56 |
|
}
|
57 |
|
|
58 |
|
/* (non-Javadoc)
|
59 |
|
* @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseFullReference(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)
|
60 |
|
*/
|
61 |
|
public BotanicalName parseFullReference(String fullReference, Rank rank) {
|
62 |
|
if (fullReference == null){
|
63 |
|
return null;
|
64 |
|
}else{
|
65 |
|
BotanicalName result = new BotanicalName(null);
|
66 |
|
parseFullReference(result, fullReference, rank, false);
|
67 |
|
return result;
|
68 |
|
}
|
69 |
|
}
|
70 |
|
|
71 |
|
/* (non-Javadoc)
|
72 |
|
* @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseFullReference(eu.etaxonomy.cdm.model.name.BotanicalName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)
|
73 |
|
*/
|
74 |
|
public void parseFullReference(BotanicalName nameToBeFilled, String fullReference, Rank rank, boolean makeEmpty) {
|
75 |
|
if (fullReference == null){
|
76 |
|
//return null;
|
77 |
|
return;
|
78 |
|
}
|
79 |
|
if (makeEmpty){
|
80 |
|
makeEmpty(nameToBeFilled);
|
81 |
|
}
|
82 |
|
fullReference.replaceAll(oWs , " ");
|
83 |
|
fullReference = fullReference.trim();
|
84 |
|
|
85 |
|
//seperate name and reference part
|
86 |
|
String nameAndRefSeperator = "(^" + anyFullName + ")("+ referenceSeperator + ")";
|
87 |
|
Pattern nameAndRefSeperatorPattern = Pattern.compile(nameAndRefSeperator);
|
88 |
|
Matcher nameAndRefSeperatorMatcher = nameAndRefSeperatorPattern.matcher(fullReference);
|
89 |
|
|
90 |
|
if (nameAndRefSeperatorMatcher.find() ){
|
91 |
|
String nameAndSeperator = nameAndRefSeperatorMatcher.group(0);
|
92 |
|
String name = nameAndRefSeperatorMatcher.group(1);
|
93 |
|
String reference = fullReference.substring(nameAndRefSeperatorMatcher.end());
|
94 |
|
|
95 |
|
// inRef?
|
96 |
|
String seperator = nameAndSeperator.substring(name.length());
|
97 |
|
boolean isInReference = false;
|
98 |
|
if (seperator.matches(inReferenceSeperator)){
|
99 |
|
isInReference = true;
|
100 |
|
}
|
101 |
|
|
102 |
|
//status
|
103 |
|
reference = parseNomStatus(reference, nameToBeFilled);
|
104 |
|
|
105 |
|
//parse subparts
|
106 |
|
parseFullName(nameToBeFilled, name, rank, makeEmpty);
|
107 |
|
parseReference(nameToBeFilled, reference, isInReference);
|
108 |
|
|
109 |
|
}else{
|
110 |
|
//don't parse if name can't be seperated
|
111 |
|
nameToBeFilled.setHasProblem(true);
|
112 |
|
nameToBeFilled.setTitleCache(fullReference);
|
113 |
|
logger.info("no applicable parsing rule could be found for \"" + fullReference + "\"");
|
114 |
|
}
|
115 |
|
}
|
116 |
|
|
117 |
|
//TODO make it an Array of status
|
118 |
|
/**
|
119 |
|
* Extracts a {@link NomenclaturalStatus} from the reference String and adds it to the @link {@link TaxonNameBase}.
|
120 |
|
* The nomenclatural status part ist deleted from the reference String.
|
121 |
|
* @return String the new (shortend) reference String
|
122 |
|
*/
|
123 |
|
String parseNomStatus(String reference, BotanicalName nameToBeFilled) {
|
124 |
|
String statusString;
|
125 |
|
Pattern hasStatusPattern = Pattern.compile("(" + pNomStatusPhrase + ")");
|
126 |
|
Matcher hasStatusMatcher = hasStatusPattern.matcher(reference);
|
127 |
|
|
128 |
|
if (hasStatusMatcher.find()) {
|
129 |
|
String statusPhrase = hasStatusMatcher.group(0);
|
130 |
|
|
131 |
|
Pattern statusPattern = Pattern.compile(pNomStatus);
|
132 |
|
Matcher statusMatcher = statusPattern.matcher(statusPhrase);
|
133 |
|
statusMatcher.find();
|
134 |
|
statusString = statusMatcher.group(0);
|
135 |
|
try {
|
136 |
|
NomenclaturalStatusType nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString);
|
137 |
|
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(nomStatusType);
|
138 |
|
nameToBeFilled.addStatus(nomStatus);
|
139 |
|
|
140 |
|
reference = reference.replace(statusPhrase, "");
|
141 |
|
} catch (UnknownCdmTypeException e) {
|
142 |
|
//Do nothing
|
143 |
|
}
|
144 |
|
}
|
145 |
|
return reference;
|
146 |
|
}
|
147 |
|
|
148 |
|
|
149 |
|
private void parseReference(BotanicalName nameToBeFilled, String reference, boolean isInReference){
|
150 |
|
|
151 |
|
if (referencePattern.matcher(reference).matches() ){
|
152 |
|
//End (just delete, may be ambigous for yearPhrase, but no real information gets lost
|
153 |
|
Pattern endPattern = Pattern.compile( referenceEnd + end);
|
154 |
|
Matcher endMatcher = endPattern.matcher(reference);
|
155 |
|
if (endMatcher.find()){
|
156 |
|
String endPart = endMatcher.group(0);
|
157 |
|
reference = reference.substring(0, reference.length() - endPart.length());
|
158 |
|
}
|
159 |
|
|
160 |
|
//year
|
161 |
|
String yearPart = null;
|
162 |
|
String pYearPhrase = yearSeperator + yearPhrase + end;
|
163 |
|
Pattern yearPhrasePattern = Pattern.compile(pYearPhrase);
|
164 |
|
Matcher yearPhraseMatcher = yearPhrasePattern.matcher(reference);
|
165 |
|
if (yearPhraseMatcher.find()){
|
166 |
|
yearPart = yearPhraseMatcher.group(0);
|
167 |
|
reference = reference.substring(0, reference.length() - yearPart.length());
|
168 |
|
yearPart = yearPart.replaceFirst(start + yearSeperator, "").trim();
|
169 |
|
}
|
170 |
|
|
171 |
|
//detail
|
172 |
|
String pDetailPhrase = detailSeperator + detail + end;
|
173 |
|
Pattern detailPhrasePattern = Pattern.compile(pDetailPhrase);
|
174 |
|
Matcher detailPhraseMatcher = detailPhrasePattern.matcher(reference);
|
175 |
|
if (detailPhraseMatcher.find()){
|
176 |
|
String detailPart = detailPhraseMatcher.group(0);
|
177 |
|
reference = reference.substring(0, reference.length() - detailPart.length());
|
178 |
|
detailPart = detailPart.replaceFirst(start + detailSeperator, "").trim();
|
179 |
|
nameToBeFilled.setNomenclaturalMicroReference(detailPart);
|
180 |
|
}
|
181 |
|
//Title (and author)
|
182 |
|
parseReferenceTitle(reference, yearPart);
|
183 |
|
}
|
184 |
|
|
185 |
|
}
|
186 |
|
|
187 |
|
/**
|
188 |
|
* Parses the referenceTitlePart, including the author volume and edition.
|
189 |
|
* @param reference
|
190 |
|
* @param year
|
191 |
|
* @return
|
192 |
|
*/
|
193 |
|
private ReferenceBase parseReferenceTitle(String reference, String year){
|
194 |
|
ReferenceBase result = null;
|
195 |
|
Pattern bookPattern = Pattern.compile(bookReference);
|
196 |
|
Pattern articlePattern = Pattern.compile(articleReference);
|
197 |
|
Pattern bookSectionPattern = Pattern.compile(bookSectionReference);
|
198 |
|
|
199 |
|
|
200 |
|
Matcher articleMatcher = articlePattern.matcher(reference);
|
201 |
|
Matcher bookMatcher = bookPattern.matcher(reference);
|
202 |
|
Matcher bookSectionMatcher = bookSectionPattern.matcher(reference);
|
203 |
|
|
204 |
|
|
205 |
|
if (articleMatcher.matches()){
|
206 |
|
//if (articlePatter)
|
207 |
|
//(type, author, title, volume, editor, series;
|
208 |
|
Article article = new Article();
|
209 |
|
article.setTitleCache(reference);
|
210 |
|
result = article;
|
211 |
|
}else if(bookMatcher.matches()){
|
212 |
|
Book book = new Book();
|
213 |
|
book .setTitleCache(reference);
|
214 |
|
result = book;
|
215 |
|
}else if (bookSectionMatcher.matches()){
|
216 |
|
BookSection bookSection = new BookSection();
|
217 |
|
bookSection.setTitleCache(reference);
|
218 |
|
result = bookSection;
|
219 |
|
}else{
|
220 |
|
logger.warn("unknown reference type not yet implemented");
|
221 |
|
//ReferenceBase refBase =
|
222 |
|
}
|
223 |
|
return result;
|
224 |
|
}
|
225 |
|
|
226 |
|
|
227 |
|
/* (non-Javadoc)
|
228 |
|
* @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseSubGenericFullName(java.lang.String)
|
229 |
|
*/
|
230 |
|
public BotanicalName parseFullName(String fullName){
|
231 |
|
return parseFullName(fullName, null);
|
232 |
|
}
|
233 |
|
|
234 |
|
|
235 |
|
/* (non-Javadoc)
|
236 |
|
* @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)
|
237 |
|
*/
|
238 |
|
public BotanicalName parseFullName(String fullName, Rank rank) {
|
239 |
|
if (fullName == null){
|
240 |
|
return null;
|
241 |
|
}else{
|
242 |
|
BotanicalName result = new BotanicalName(null);
|
243 |
|
parseFullName(result, fullName, rank, false);
|
244 |
|
return result;
|
245 |
|
}
|
246 |
|
}
|
247 |
|
|
248 |
|
|
249 |
|
public void parseFullName(BotanicalName nameToBeFilled, String fullName, Rank rank, boolean makeEmpty) {
|
250 |
|
//TODO prol. etc.
|
251 |
|
|
252 |
|
String authorString = null;
|
253 |
|
|
254 |
|
if (fullName == null){
|
255 |
|
return;
|
256 |
|
}
|
257 |
|
if (makeEmpty){
|
258 |
|
makeEmpty(nameToBeFilled);
|
259 |
|
}
|
260 |
|
fullName.replaceAll(oWs , " ");
|
261 |
|
//TODO
|
262 |
|
// OLD: fullName = oWsRE.subst(fullName, " "); //substitute multiple whitespaces
|
263 |
|
fullName = fullName.trim();
|
264 |
|
|
265 |
|
String[] epi = pattern.split(fullName);
|
266 |
|
try {
|
267 |
|
//cultivars //TODO 2 implement cultivars
|
268 |
|
// if ( cultivarMarkerRE.match(fullName) ){ funktioniert noch nicht, da es z.B. auch Namen gibt, wie 't Hart
|
269 |
|
// result = parseCultivar(fullName);
|
270 |
|
// }
|
271 |
|
//hybrids //TODO 2 implement hybrids
|
272 |
|
//else
|
273 |
|
if (hybridPattern.matcher(fullName).matches() ){
|
274 |
|
nameToBeFilled = parseHybrid(fullName);
|
275 |
|
}
|
276 |
|
else if (genusOrSupraGenusPattern.matcher(fullName).matches()){
|
277 |
|
//supraGeneric
|
278 |
|
if (rank.isSupraGeneric()){
|
279 |
|
nameToBeFilled.setRank(rank);
|
280 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
281 |
|
}
|
282 |
|
//genus
|
283 |
|
else {
|
284 |
|
nameToBeFilled.setRank(Rank.GENUS());
|
285 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
286 |
|
}
|
287 |
|
authorString = fullName.substring(epi[0].length());
|
288 |
|
}
|
289 |
|
//infra genus
|
290 |
|
else if (infraGenusPattern.matcher(fullName).matches()){
|
291 |
|
nameToBeFilled.setRank(Rank.getRankByAbbreviation(epi[1]));
|
292 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
293 |
|
nameToBeFilled.setInfraGenericEpithet(epi[2]);
|
294 |
|
authorString = fullName.substring(epi[0].length() + 1 + epi[1].length()+ 1 + epi[2].length());
|
295 |
|
}
|
296 |
|
//aggr. or group
|
297 |
|
else if (aggrOrGroupPattern.matcher(fullName).matches()){
|
298 |
|
nameToBeFilled.setRank(Rank.getRankByAbbreviation(epi[2]));
|
299 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
300 |
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
301 |
|
}
|
302 |
|
//species
|
303 |
|
else if (speciesPattern.matcher(fullName).matches()){
|
304 |
|
nameToBeFilled.setRank(Rank.SPECIES());
|
305 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
306 |
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
307 |
|
authorString = fullName.substring(epi[0].length() + 1 + epi[1].length());
|
308 |
|
}
|
309 |
|
//autonym
|
310 |
|
else if (autonymPattern.matcher(fullName).matches()){
|
311 |
|
nameToBeFilled.setRank(Rank.getRankByAbbreviation(epi[epi.length - 2]));
|
312 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
313 |
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
314 |
|
nameToBeFilled.setInfraSpecificEpithet(epi[epi.length - 1]);
|
315 |
|
int lenSpecies = 2 + epi[0].length()+epi[1].length();
|
316 |
|
int lenInfraSpecies = 2 + epi[epi.length - 2].length() + epi[epi.length - 1].length();
|
317 |
|
authorString = fullName.substring(lenSpecies, fullName.length() - lenInfraSpecies);
|
318 |
|
}
|
319 |
|
//infraSpecies
|
320 |
|
else if (infraSpeciesPattern.matcher(fullName).matches()){
|
321 |
|
String infraSpecRankEpi = epi[2];
|
322 |
|
String infraSpecEpi = epi[3];
|
323 |
|
if ("tax.".equals(infraSpecRankEpi)){
|
324 |
|
infraSpecRankEpi += " " + epi[3];
|
325 |
|
infraSpecEpi = epi[4];
|
326 |
|
}
|
327 |
|
nameToBeFilled.setRank(Rank.getRankByAbbreviation(infraSpecRankEpi));
|
328 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
329 |
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
330 |
|
nameToBeFilled.setInfraSpecificEpithet(infraSpecEpi);
|
331 |
|
authorString = fullName.substring(epi[0].length()+ 1 + epi[1].length() +1 + infraSpecRankEpi.length() + 1 + infraSpecEpi.length());
|
332 |
|
}//old infraSpecies
|
333 |
|
else if (oldInfraSpeciesPattern.matcher(fullName).matches()){
|
334 |
|
boolean implemented = false;
|
335 |
|
if (implemented){
|
336 |
|
nameToBeFilled.setRank(Rank.getRankByNameOrAbbreviation(epi[2]));
|
337 |
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
338 |
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
339 |
|
//TODO result.setUnnamedNamePhrase(epi[2] + " " + epi[3]);
|
340 |
|
authorString = fullName.substring(epi[0].length()+ 1 + epi[1].length() +1 + epi[2].length() + 1 + epi[3].length());
|
341 |
|
}else{
|
342 |
|
nameToBeFilled.setHasProblem(true);
|
343 |
|
nameToBeFilled.setTitleCache(fullName);
|
344 |
|
logger.info("Name string " + fullName + " could not be parsed because UnnnamedNamePhrase is not yet implemented!");
|
345 |
|
}
|
346 |
|
}
|
347 |
|
//none
|
348 |
|
else{
|
349 |
|
nameToBeFilled.setHasProblem(true);
|
350 |
|
nameToBeFilled.setTitleCache(fullName);
|
351 |
|
logger.info("no applicable parsing rule could be found for \"" + fullName + "\"");
|
352 |
|
}
|
353 |
|
//authors
|
354 |
|
if (nameToBeFilled != null && authorString != null && authorString.trim().length() > 0 ){
|
355 |
|
Team[] authors = null;
|
356 |
|
try {
|
357 |
|
authors = fullTeams(authorString);
|
358 |
|
} catch (StringNotParsableException e) {
|
359 |
|
nameToBeFilled.setHasProblem(true);
|
360 |
|
nameToBeFilled.setTitleCache(fullName);
|
361 |
|
logger.info("no applicable parsing rule could be found for \"" + fullName + "\"");;
|
362 |
|
}
|
363 |
|
nameToBeFilled.setCombinationAuthorTeam(authors[0]);
|
364 |
|
nameToBeFilled.setExCombinationAuthorTeam(authors[1]);
|
365 |
|
nameToBeFilled.setBasionymAuthorTeam(authors[2]);
|
366 |
|
nameToBeFilled.setExBasionymAuthorTeam(authors[3]);
|
367 |
|
}
|
368 |
|
//return
|
369 |
|
if (nameToBeFilled != null){
|
370 |
|
//return(BotanicalName)result;
|
371 |
|
return;
|
372 |
|
}else{
|
373 |
|
nameToBeFilled.setHasProblem(true);
|
374 |
|
nameToBeFilled.setTitleCache(fullName);
|
375 |
|
logger.info("Name string " + fullName + " could not be parsed!");
|
376 |
|
//return result;
|
377 |
|
return;
|
378 |
|
}
|
379 |
|
} catch (UnknownCdmTypeException e) {
|
380 |
|
nameToBeFilled.setHasProblem(true);
|
381 |
|
nameToBeFilled.setTitleCache(fullName);
|
382 |
|
logger.info("unknown rank (" + (rank == null? "null":rank) + ") or abbreviation in string " + fullName);
|
383 |
|
//return result;
|
384 |
|
return;
|
385 |
|
}
|
386 |
|
}
|
387 |
|
|
388 |
|
private void makeEmpty(BotanicalName nameToBeFilled){
|
389 |
|
nameToBeFilled.setAnamorphic(false);
|
390 |
|
nameToBeFilled.setAppendedPhrase(null);
|
391 |
|
nameToBeFilled.setAuthorshipCache(null);
|
392 |
|
//TODO ??
|
393 |
|
//nameToBeFilled.setBasionym(basionym);
|
394 |
|
nameToBeFilled.setBasionymAuthorTeam(null);
|
395 |
|
nameToBeFilled.setBinomHybrid(false);
|
396 |
|
nameToBeFilled.setCombinationAuthorTeam(null);
|
397 |
|
nameToBeFilled.setExBasionymAuthorTeam(null);
|
398 |
|
|
399 |
|
|
400 |
|
nameToBeFilled.setExCombinationAuthorTeam(null);
|
401 |
|
nameToBeFilled.setGenusOrUninomial(null);
|
402 |
|
nameToBeFilled.setHasProblem(false);
|
403 |
|
// TODO ?
|
404 |
|
//nameToBeFilled.setHomotypicalGroup(newHomotypicalGroup);
|
405 |
|
nameToBeFilled.setHybridFormula(false);
|
406 |
|
nameToBeFilled.setInfraGenericEpithet(null);
|
407 |
|
nameToBeFilled.setInfraSpecificEpithet(null);
|
408 |
|
nameToBeFilled.setMonomHybrid(false);
|
409 |
|
nameToBeFilled.setNameCache(null);
|
410 |
|
nameToBeFilled.setNomenclaturalMicroReference(null);
|
411 |
|
nameToBeFilled.setNomenclaturalReference(null);
|
412 |
|
nameToBeFilled.setProtectedTitleCache(false);
|
413 |
|
nameToBeFilled.setRank(null);
|
414 |
|
nameToBeFilled.setSpecificEpithet(null);
|
415 |
|
nameToBeFilled.setTitleCache(null, false);
|
416 |
|
nameToBeFilled.setTrinomHybrid(false);
|
417 |
|
nameToBeFilled.setUpdated(Calendar.getInstance());
|
418 |
|
// TODO nameToBeFilled.setUpdatedBy(updatedBy);
|
419 |
|
|
420 |
|
}
|
421 |
|
|
422 |
|
|
423 |
|
/**
|
424 |
|
* Parses the fullAuthorString
|
425 |
|
* @param fullAuthorString
|
426 |
|
* @return array of Teams containing the Team[0],
|
427 |
|
* ExTeam[1], BasionymTeam[2], ExBasionymTeam[3]
|
428 |
|
*/
|
429 |
|
public Team[] fullTeams (String fullAuthorString)
|
430 |
|
throws StringNotParsableException{
|
431 |
|
fullAuthorString = fullAuthorString.trim();
|
432 |
|
if (! fullAuthorStringPattern.matcher(fullAuthorString).matches())
|
433 |
|
throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
|
434 |
|
return fullTeamsChecked(fullAuthorString);
|
435 |
|
}
|
436 |
|
|
437 |
|
|
438 |
|
/*
|
439 |
|
* like fullTeams but without trim and match check
|
440 |
|
*/
|
441 |
|
private Team[] fullTeamsChecked (String fullAuthorString){
|
442 |
|
Team[] result = new Team[4];
|
443 |
|
int authorTeamStart = 0;
|
444 |
|
Matcher basionymMatcher = basionymPattern.matcher(fullAuthorString);
|
445 |
|
if (basionymMatcher.find(0)){
|
446 |
|
|
447 |
|
String basString = basionymMatcher.group();
|
448 |
|
basString = basString.replaceFirst(basStart, "");
|
449 |
|
basString = basString.replaceAll(basEnd, "").trim();
|
450 |
|
authorTeamStart = basionymMatcher.end(1) + 1;
|
451 |
|
|
452 |
|
Team[] basTeam = authorTeamAndEx(basString);
|
453 |
|
result[2]= basTeam[0];
|
454 |
|
result[3]= basTeam[1];
|
455 |
|
}
|
456 |
|
Team[] aTeam = authorTeamAndEx(fullAuthorString.substring(authorTeamStart));
|
457 |
|
result[0]= aTeam[0];
|
458 |
|
result[1]= aTeam[1];
|
459 |
|
return result;
|
460 |
|
}
|
461 |
|
|
462 |
|
|
463 |
|
/**
|
464 |
|
* Parses the author and ex-author String
|
465 |
|
* @param authorTeamString String representing the author and the ex-author team
|
466 |
|
* @return array of Teams containing the Team[0] and the ExTeam[1]
|
467 |
|
*/
|
468 |
|
public Team[] authorTeamAndEx (String authorTeamString){
|
469 |
|
Team[] result = new Team[2];
|
470 |
|
//TODO noch allgemeiner am anfang durch Replace etc.
|
471 |
|
authorTeamString = authorTeamString.trim();
|
472 |
|
authorTeamString = authorTeamString.replaceFirst(oWs + "ex" + oWs, " ex. " );
|
473 |
|
int authorEnd = authorTeamString.length();
|
474 |
|
|
475 |
|
Matcher exAuthorMatcher = exAuthorPattern.matcher(authorTeamString);
|
476 |
|
if (exAuthorMatcher.find(0)){
|
477 |
|
int exAuthorBegin = exAuthorMatcher.end(0);
|
478 |
|
String exString = authorTeamString.substring(exAuthorBegin).trim();
|
479 |
|
authorEnd = exAuthorMatcher.start(0);
|
480 |
|
result [1] = authorTeam(exString);
|
481 |
|
}
|
482 |
|
result [0] = authorTeam(authorTeamString.substring(0, authorEnd));
|
483 |
|
return result;
|
484 |
|
}
|
485 |
|
|
486 |
|
|
487 |
|
/**
|
488 |
|
* Parses an authorTeam String and returns the Team
|
489 |
|
* !!! TODO (atomization not yet implemented)
|
490 |
|
* @param authorTeamString String representing the author team
|
491 |
|
* @return an Team
|
492 |
|
*/
|
493 |
|
public Team authorTeam (String authorTeamString){
|
494 |
|
if (authorTeamString == null)
|
495 |
|
return null;
|
496 |
|
else if ((authorTeamString = authorTeamString.trim()).length() == 0)
|
497 |
|
return null;
|
498 |
|
else {
|
499 |
|
Team result = Team.NewInstance();
|
500 |
|
result.setTitleCache(authorTeamString);
|
501 |
|
//TODO result = atomizedAuthor(authorTeamString);
|
502 |
|
return result;
|
503 |
|
}
|
504 |
|
|
505 |
|
}
|
506 |
|
|
507 |
|
|
508 |
|
//Parsing of the given full name that has been identified as hybrid already somewhere else.
|
509 |
|
private BotanicalName parseHybrid(String fullName){
|
510 |
|
logger.warn("parseHybrid --> function not yet implemented");
|
511 |
|
BotanicalName result = new BotanicalName(null);
|
512 |
|
result.setTitleCache(fullName);
|
513 |
|
return result;
|
514 |
|
}
|
515 |
|
|
516 |
|
// // Parsing of the given full name that has been identified as a cultivar already somwhere else.
|
517 |
|
// // The ... cv. ... syntax is not covered here as it is not according the rules for naming cultivars.
|
518 |
|
public BotanicalName parseCultivar(String fullName) throws StringNotParsableException{
|
519 |
|
CultivarPlantName result = null;
|
520 |
|
String[] words = oWsPattern.split(fullName);
|
521 |
|
|
522 |
|
/* ---------------------------------------------------------------------------------
|
523 |
|
* cultivar
|
524 |
|
* ---------------------------------------------------------------------------------*/
|
525 |
|
if (fullName.indexOf(" '") != 0){
|
526 |
|
//TODO location of 'xx' is probably not arbitrary
|
527 |
|
Matcher cultivarMatcher = cultivarPattern.matcher(fullName);
|
528 |
|
if (cultivarMatcher.find()){
|
529 |
|
String namePart = fullName.replaceFirst(cultivar, "");
|
530 |
|
|
531 |
|
String cultivarPart = cultivarMatcher.group(0).replace("'","").trim();
|
532 |
|
//OLD: String cultivarPart = cultivarRE.getParen(0).replace("'","").trim();
|
533 |
|
|
534 |
|
result = (CultivarPlantName)parseFullName(namePart);
|
535 |
|
result.setCultivarName(cultivarPart);
|
536 |
|
}
|
537 |
|
}else if (fullName.indexOf(" cv.") != 0){
|
538 |
|
// cv. is old form (not official)
|
539 |
|
throw new StringNotParsableException("Cultivars with only cv. not yet implemented in name parser!");
|
540 |
|
}
|
541 |
|
|
542 |
|
/* ---------------------------------------------------------------------------------
|
543 |
|
* cultivar group
|
544 |
|
* ---------------------------------------------------------------------------------
|
545 |
|
*/
|
546 |
|
// TODO in work
|
547 |
|
//Ann. this is not the official way of noting cultivar groups
|
548 |
|
String group = oWs + "Group" + oWs + capitalEpiWord + end;
|
549 |
|
Pattern groupRE = Pattern.compile(group);
|
550 |
|
Matcher groupMatcher = groupRE.matcher(fullName);
|
551 |
|
if (groupMatcher.find()){
|
552 |
|
if (! words[words.length - 2].equals("group")){
|
553 |
|
throw new StringNotParsableException ("fct ParseHybrid --> term before cultivar group name in " + fullName + " should be 'group'");
|
554 |
|
}else{
|
555 |
|
|
556 |
|
String namePart = fullName.substring(0, groupMatcher.start(0) - 0);
|
557 |
|
//OLD: String namePart = fullName.substring(0, groupRE.getParenStart(0) - 0);
|
558 |
|
|
559 |
|
String cultivarPart = words[words.length -1];
|
560 |
|
result = (CultivarPlantName)parseFullName(namePart);
|
561 |
|
if (result != null){
|
562 |
|
result.setCultivarName(cultivarPart);
|
563 |
|
|
564 |
|
//OLD: result.setCultivarGroupName(cultivarPart);
|
565 |
|
}
|
566 |
|
}
|
567 |
|
|
568 |
|
}
|
569 |
|
// // ---------------------------------------------------------------------------------
|
570 |
|
// if ( result = "" ){
|
571 |
|
// return "I: fct ParseCultivar: --> could not parse cultivar " + fullName;
|
572 |
|
// }else{
|
573 |
|
// return result;
|
574 |
|
// }
|
575 |
|
return result; //TODO
|
576 |
|
}
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
//splitter
|
581 |
|
static String epiSplitter = "(\\s+|\\(|\\))"; //( ' '+| '(' | ')' )
|
582 |
|
static Pattern pattern = Pattern.compile(epiSplitter);
|
583 |
|
|
584 |
|
//some useful non-terminals
|
585 |
|
static String start = "^";
|
586 |
|
static String end = "$";
|
587 |
|
static String anyEnd = ".*" + end;
|
588 |
|
static String oWs = "\\s+"; //obligatory whitespaces
|
589 |
|
static String fWs = "\\s*"; //facultative whitespcace
|
590 |
|
|
591 |
|
static String capitalWord = "\\p{javaUpperCase}\\p{javaLowerCase}*";
|
592 |
|
static String nonCapitalWord = "\\p{javaLowerCase}+";
|
593 |
|
|
594 |
|
static String capitalDotWord = capitalWord + "\\.?"; //capitalWord with facultativ '.' at the end
|
595 |
|
static String nonCapitalDotWord = nonCapitalWord + "\\.?"; //nonCapitalWord with facultativ '.' at the end
|
596 |
|
static String dotWord = "(" + capitalWord + "|" + nonCapitalWord + ")\\.?"; //word (capital or non-capital) with facultativ '.' at the end
|
597 |
|
//Words used in an epethiton for a TaxonName
|
598 |
|
static String nonCapitalEpiWord = "[a-z?\\-]+"; //TODO solve checkin Problem with Unicode character "[a-z�\\-]+";
|
599 |
|
static String capitalEpiWord = "[A-Z]"+ nonCapitalEpiWord;
|
600 |
|
|
601 |
|
|
602 |
|
//years
|
603 |
|
static String month = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
|
604 |
|
static String singleYear = "\\b" + "(?:17|18|19|20)" + "\\d{2}" + "\\b"; // word boundary followed by either 17,18,19, or 20 (not captured) followed by 2 digits
|
605 |
|
static String yearPhrase = "(" + singleYear + "(-" + singleYear + ")?" +
|
606 |
|
"(" + month + ")?)" ; // optional month
|
607 |
|
|
608 |
|
//seperator
|
609 |
|
static String yearSeperator = "." + oWs;
|
610 |
|
static String detailSeperator = ":" + oWs;
|
611 |
|
static String referenceSeperator1 = "," + oWs ;
|
612 |
|
static String inReferenceSeperator = oWs + "in" + oWs;
|
613 |
|
static String referenceSeperator = "(" + referenceSeperator1 +"|" + inReferenceSeperator + ")" ;
|
614 |
|
static String referenceAuthorSeperator = ","+ oWs;
|
615 |
|
static String volumeSeperator = "," + fWs ;
|
616 |
|
static String referenceEnd = ".";
|
617 |
|
|
618 |
|
|
619 |
|
//status
|
620 |
|
static String status = "";
|
621 |
|
|
622 |
|
//marker
|
623 |
|
static String InfraGenusMarker = "(subgen.|subg.|sect.|subsect.|ser.|subser.|t.infgen.)";
|
624 |
|
static String aggrOrGroupMarker = "(aggr.|agg.|group)";
|
625 |
|
static String infraSpeciesMarker = "(subsp.|convar.|var.|subvar.|f.|subf.|f.spec.|tax." + fWs + "infrasp.)";
|
626 |
|
static String oldInfraSpeciesMarker = "(prol.|proles|race|taxon|sublusus)";
|
627 |
|
|
628 |
|
|
629 |
|
//AuthorString
|
630 |
|
static String authorPart = "(" + "(D'|L'|'t\\s)?" + capitalDotWord + "('" + nonCapitalDotWord + ")?" + "|da|de(n|l|\\sla)?)" ;
|
631 |
|
static String author = "(" + authorPart + "(" + fWs + "|-)" + ")+" + "(f.|fil.|secundus)?";
|
632 |
|
static String teamSplitter = fWs + "(&)" + fWs;
|
633 |
|
static String authorTeam = fWs + "(" + author + teamSplitter + ")*" + author + "(" + teamSplitter + "al.)?" + fWs;
|
634 |
|
static String exString = "(ex.?)";
|
635 |
|
static String authorAndExTeam = authorTeam + "(" + oWs + exString + oWs + authorTeam + ")?";
|
636 |
|
static String basStart = "\\(";
|
637 |
|
static String basEnd = "\\)";
|
638 |
|
static String basionymAuthor = basStart + "(" + authorAndExTeam + ")" + basEnd; // '(' and ')' is for evaluation with RE.paren(x)
|
639 |
|
static String fullAuthorString = fWs + "(" + basionymAuthor +")?" + fWs + authorAndExTeam + fWs;
|
640 |
|
static String facultFullAuthorString = "(" + fullAuthorString + ")?" ;
|
641 |
|
|
642 |
|
|
643 |
|
//details
|
644 |
|
//TODO still very simple
|
645 |
|
static String pageNumber = "\\d{1,5}";
|
646 |
|
static String detail = "(" + pageNumber + ")";
|
647 |
|
|
648 |
|
//reference
|
649 |
|
static String volume = "\\d{4}" + "\\(\\d{4}\\)?";
|
650 |
|
|
651 |
|
static String referenceTitle = "(" + dotWord + fWs + ")" + "{2,}";
|
652 |
|
static String bookReference = referenceTitle + volumeSeperator + volume;
|
653 |
|
static String bookSectionReference = authorTeam + referenceAuthorSeperator;
|
654 |
|
static String articleReference = inReferenceSeperator + bookReference ;
|
655 |
|
static String reference = "(" + articleReference + "|" + bookReference +")" +
|
656 |
|
detailSeperator + detail + yearSeperator + yearPhrase +
|
657 |
|
referenceEnd;
|
658 |
|
|
659 |
|
static Pattern referencePattern = Pattern.compile(reference);
|
660 |
|
|
661 |
|
static String pNomStatusNom = "nom\\." + fWs + "(superfl\\.|nud\\.|illeg\\.|inval\\.|cons\\.|alternativ\\.|subnud.|"+
|
662 |
|
"rej\\.|rej\\."+ fWs + "prop\\.|provis\\.)";
|
663 |
|
static String pNomStatusOrthVar = "orth\\." + fWs + "var\\.";
|
664 |
|
static String pNomStatus = "(" + pNomStatusNom + "|" + pNomStatusOrthVar + ")";
|
665 |
|
static String pNomStatusPhrase1 = "," + fWs + pNomStatus;
|
666 |
|
static String pNomStatusPhrase2 = "\\[" + fWs + pNomStatus + "\\]";
|
667 |
|
|
668 |
|
static String pNomStatusPhrase = "(?:" + pNomStatusPhrase1 + "|" + pNomStatusPhrase2 + ")";
|
669 |
|
|
670 |
|
// Soraya
|
671 |
|
//opus utique oppr.
|
672 |
|
//pro syn.
|
673 |
|
//provisional synonym
|
674 |
|
//fossil name
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
//cultivars and hybrids
|
679 |
|
static String cultivar = oWs + "'..+'"; //Achtung mit Hochkomma in AuthorNamen
|
680 |
|
static String cultivarMarker = oWs + "(cv.|')";
|
681 |
|
static String hybrid = oWs + "((x|X)" + oWs + "|notho)";//= ( x )|( X )|( notho)
|
682 |
|
|
683 |
|
// Name String
|
684 |
|
static String genusOrSupraGenus = capitalEpiWord;
|
685 |
|
static String infraGenus = capitalEpiWord + oWs + InfraGenusMarker + oWs + capitalEpiWord;
|
686 |
|
static String aggrOrGroup = capitalEpiWord + oWs + nonCapitalEpiWord + oWs + aggrOrGroupMarker;
|
687 |
|
static String species = capitalEpiWord + oWs + nonCapitalEpiWord;
|
688 |
|
static String infraSpecies = capitalEpiWord + oWs + nonCapitalEpiWord + oWs + infraSpeciesMarker + oWs + nonCapitalEpiWord;
|
689 |
|
static String oldInfraSpecies = capitalEpiWord + oWs + nonCapitalEpiWord + oWs + oldInfraSpeciesMarker + oWs + nonCapitalEpiWord;
|
690 |
|
static String autonym = capitalEpiWord + oWs + "(" + nonCapitalEpiWord +")" + oWs + fullAuthorString + oWs + infraSpeciesMarker + oWs + "\\1"; //2-nd word and last word are the same
|
691 |
|
static String anyName = "(" + genusOrSupraGenus + "|" + infraGenus + "|" + aggrOrGroup + "|" + species + "|" +
|
692 |
|
infraSpecies + "|" + infraSpecies + "|" + oldInfraSpecies + "|" + autonym + ")+";
|
693 |
|
static String anyFullName = anyName + oWs + fullAuthorString;
|
694 |
|
|
695 |
|
//Pattern
|
696 |
|
static Pattern oWsPattern = Pattern.compile(oWs);
|
697 |
|
static Pattern teamSplitterPattern = Pattern.compile(teamSplitter);
|
698 |
|
static Pattern cultivarPattern = Pattern.compile(cultivar);
|
699 |
|
static Pattern cultivarMarkerPattern = Pattern.compile(cultivarMarker);
|
700 |
|
static Pattern hybridPattern = Pattern.compile(hybrid);
|
701 |
|
|
702 |
|
static Pattern genusOrSupraGenusPattern = Pattern.compile(start + genusOrSupraGenus + facultFullAuthorString + end);
|
703 |
|
static Pattern infraGenusPattern = Pattern.compile(start + infraGenus + facultFullAuthorString + end);
|
704 |
|
static Pattern aggrOrGroupPattern = Pattern.compile(start + aggrOrGroup + fWs + end); //aggr. or group has no author string
|
705 |
|
static Pattern speciesPattern = Pattern.compile(start + species + facultFullAuthorString + end);
|
706 |
|
static Pattern infraSpeciesPattern = Pattern.compile(start + infraSpecies + facultFullAuthorString + end);
|
707 |
|
static Pattern oldInfraSpeciesPattern = Pattern.compile(start + oldInfraSpecies + facultFullAuthorString + end);
|
708 |
|
static Pattern autonymPattern = Pattern.compile(start + autonym + fWs + end);
|
709 |
|
|
710 |
|
static Pattern basionymPattern = Pattern.compile(basionymAuthor);
|
711 |
|
//static Pattern startsWithBasionymRE = Pattern.compile(basionymAuthor + anyEnd);
|
712 |
|
static Pattern exAuthorPattern = Pattern.compile(oWs + exString);
|
713 |
|
|
714 |
|
static Pattern fullAuthorStringPattern = Pattern.compile(fullAuthorString);
|
715 |
|
|
716 |
|
|
717 |
|
}
|