Revision 49ca570b
Added by Andreas Müller over 12 years ago
.gitattributes | ||
---|---|---|
838 | 838 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/merge/MergeException.java -text |
839 | 839 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/merge/MergeMode.java -text |
840 | 840 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/INonViralNameParser.java -text |
841 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NameTypeParser.java -text |
|
841 | 842 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java -text |
842 | 843 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplRegExBase.java -text |
843 | 844 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/ParserProblem.java -text |
... | ... | |
993 | 994 |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/taxon/TaxonBaseDefaultCacheStrategyTest.java -text |
994 | 995 |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/match/DefaultMatchStrategyTest.java -text |
995 | 996 |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/merge/DefaultMergeStrategyTest.java -text |
997 |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NameTypeParserTest.java -text |
|
996 | 998 |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplTest.java -text |
997 | 999 |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/ParserProblemTest.java -text |
998 | 1000 |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/location/CoordinateConverterTest.java -text |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NameTypeParser.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2009 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.cdm.strategy.parser; |
|
11 |
|
|
12 |
import org.apache.commons.lang.StringUtils; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus; |
|
15 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
|
16 |
|
|
17 |
/** |
|
18 |
* @author a.mueller |
|
19 |
* @date 02.08.2011 |
|
20 |
* |
|
21 |
*/ |
|
22 |
public class NameTypeParser { |
|
23 |
|
|
24 |
private static final String desigPattern = "\\sdesig(\\.|nation)?"; |
|
25 |
|
|
26 |
/** |
|
27 |
* see also CentralAfricaFernsTaxonParser#handleTypeLocationPart |
|
28 |
*/ |
|
29 |
public static final String typeTypePattern = "("+ |
|
30 |
"lecto(\\.|type)?+" + |
|
31 |
"(original|present|subsequent)"+ desigPattern + |
|
32 |
"(subsequent monotypy|tautonomy)" + |
|
33 |
")"; |
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
public static NameTypeDesignationStatus parseNameTypeStatus(String type) throws UnknownCdmTypeException { |
|
38 |
if (StringUtils.isBlank(type)){ |
|
39 |
return null; |
|
40 |
} |
|
41 |
if (type.matches("(?i).*" + desigPattern)){ |
|
42 |
if (type.matches("(?i)original" + desigPattern)){ |
|
43 |
return NameTypeDesignationStatus.ORIGINAL_DESIGNATION(); |
|
44 |
}else if (type.matches("(?i)present" + desigPattern)){ |
|
45 |
return NameTypeDesignationStatus.PRESENT_DESIGNATION(); |
|
46 |
}else if (type.matches("(?i)subsequent" + desigPattern)){ |
|
47 |
return NameTypeDesignationStatus.SUBSEQUENT_DESIGNATION(); |
|
48 |
} |
|
49 |
|
|
50 |
}else if(type.matches("(?i)subsequent monotypy")){ |
|
51 |
return NameTypeDesignationStatus.SUBSEQUENT_MONOTYPY(); |
|
52 |
}else if(type.matches("(?i)monotypy")){ |
|
53 |
return NameTypeDesignationStatus.MONOTYPY(); |
|
54 |
}else if(type.matches("(?i)tautonomy")){ |
|
55 |
return NameTypeDesignationStatus.TAUTONYMY(); |
|
56 |
}else if(type.matches("(?i)lectotype")){ |
|
57 |
return NameTypeDesignationStatus.LECTOTYPE(); |
|
58 |
}else if(type.matches("(?i)automatic")){ |
|
59 |
return NameTypeDesignationStatus.AUTOMATIC(); |
|
60 |
}else if(type.matches("(?i)not applicable")){ |
|
61 |
return NameTypeDesignationStatus.NOT_APPLICABLE(); |
|
62 |
} |
|
63 |
String message = "Type Status not supported: " + type; |
|
64 |
throw new UnknownCdmTypeException(message); |
|
65 |
|
|
66 |
} |
|
67 |
} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NameTypeParserTest.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2009 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.cdm.strategy.parser; |
|
11 |
|
|
12 |
import static org.junit.Assert.*; |
|
13 |
import junit.framework.Assert; |
|
14 |
|
|
15 |
import org.junit.Before; |
|
16 |
import org.junit.BeforeClass; |
|
17 |
import org.junit.Test; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer; |
|
20 |
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus; |
|
21 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author a.mueller |
|
25 |
* @date 02.08.2011 |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class NameTypeParserTest { |
|
29 |
|
|
30 |
/** |
|
31 |
* @throws java.lang.Exception |
|
32 |
*/ |
|
33 |
@BeforeClass |
|
34 |
public static void setUpBeforeClass() throws Exception { |
|
35 |
DefaultTermInitializer initializer = new DefaultTermInitializer(); |
|
36 |
initializer.initialize(); |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* @throws java.lang.Exception |
|
41 |
*/ |
|
42 |
@Before |
|
43 |
public void setUp() throws Exception { |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.NameTypeParser#makeNameTypeStatus(java.lang.String)}. |
|
48 |
*/ |
|
49 |
@Test |
|
50 |
public void testMakeNameTypeStatus() { |
|
51 |
//orig dest |
|
52 |
String typeString = "original designation"; |
|
53 |
NameTypeDesignationStatus type; |
|
54 |
try { |
|
55 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
56 |
Assert.assertEquals("Type should be original designation", NameTypeDesignationStatus.ORIGINAL_DESIGNATION(), type); |
|
57 |
} catch (UnknownCdmTypeException e) { |
|
58 |
Assert.fail(typeString + " not recognized"); |
|
59 |
} |
|
60 |
typeString = "original desig."; |
|
61 |
try { |
|
62 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
63 |
Assert.assertEquals("Type should be original designation", NameTypeDesignationStatus.ORIGINAL_DESIGNATION(), type); |
|
64 |
} catch (UnknownCdmTypeException e) { |
|
65 |
Assert.fail(typeString + " not recognized"); |
|
66 |
} |
|
67 |
typeString = "ORIginAL DESig."; |
|
68 |
try { |
|
69 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
70 |
Assert.assertEquals("Type should be original designation", NameTypeDesignationStatus.ORIGINAL_DESIGNATION(), type); |
|
71 |
} catch (UnknownCdmTypeException e) { |
|
72 |
Assert.fail(typeString + " not recognized"); |
|
73 |
} |
|
74 |
|
|
75 |
//present desig |
|
76 |
typeString = "present designation"; |
|
77 |
try { |
|
78 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
79 |
Assert.assertEquals("Type should be present designation", NameTypeDesignationStatus.PRESENT_DESIGNATION(), type); |
|
80 |
} catch (UnknownCdmTypeException e) { |
|
81 |
Assert.fail(typeString + " not recognized"); |
|
82 |
} |
|
83 |
//subsequent desig |
|
84 |
typeString = "subsequent designation"; |
|
85 |
try { |
|
86 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
87 |
Assert.assertEquals("Type should be subsequent designation", NameTypeDesignationStatus.SUBSEQUENT_DESIGNATION(), type); |
|
88 |
} catch (UnknownCdmTypeException e) { |
|
89 |
Assert.fail(typeString + " not recognized"); |
|
90 |
} |
|
91 |
//monotypy |
|
92 |
typeString = "monotypy"; |
|
93 |
try { |
|
94 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
95 |
Assert.assertEquals("Type should be 'monotypy'", NameTypeDesignationStatus.MONOTYPY(), type); |
|
96 |
} catch (UnknownCdmTypeException e) { |
|
97 |
Assert.fail(typeString + " not recognized"); |
|
98 |
} |
|
99 |
//subs. monotypy |
|
100 |
typeString = "subsequent monotypy"; |
|
101 |
try { |
|
102 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
103 |
Assert.assertEquals("Type should be 'subsequent monotypy'", NameTypeDesignationStatus.SUBSEQUENT_MONOTYPY(), type); |
|
104 |
} catch (UnknownCdmTypeException e) { |
|
105 |
Assert.fail(typeString + " not recognized"); |
|
106 |
} |
|
107 |
|
|
108 |
//tautonomy |
|
109 |
typeString = "tautonomy"; |
|
110 |
try { |
|
111 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
112 |
Assert.assertEquals("Type should be tautonomy", NameTypeDesignationStatus.TAUTONYMY(), type); |
|
113 |
} catch (UnknownCdmTypeException e) { |
|
114 |
Assert.fail(typeString + " not recognized"); |
|
115 |
} |
|
116 |
//lectotype |
|
117 |
typeString = "lectotype"; |
|
118 |
try { |
|
119 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
120 |
Assert.assertEquals("Type should be lectotype", NameTypeDesignationStatus.LECTOTYPE(), type); |
|
121 |
} catch (UnknownCdmTypeException e) { |
|
122 |
Assert.fail(typeString + " not recognized"); |
|
123 |
} |
|
124 |
//automatic |
|
125 |
typeString = "automatic"; |
|
126 |
try { |
|
127 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
128 |
Assert.assertEquals("Type should be automatic", NameTypeDesignationStatus.AUTOMATIC(), type); |
|
129 |
} catch (UnknownCdmTypeException e) { |
|
130 |
Assert.fail(typeString + " not recognized"); |
|
131 |
} |
|
132 |
//automatic |
|
133 |
typeString = "not applicable"; |
|
134 |
try { |
|
135 |
type = NameTypeParser.parseNameTypeStatus(typeString); |
|
136 |
Assert.assertEquals("Type should be 'not applicable'", NameTypeDesignationStatus.NOT_APPLICABLE(), type); |
|
137 |
} catch (UnknownCdmTypeException e) { |
|
138 |
Assert.fail(typeString + " not recognized"); |
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
} |
|
144 |
} |
Also available in: Unified diff
added NameTypeParser (with test)