Project

General

Profile

Download (5.73 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.test.function.strategy;
11

    
12
import static org.junit.Assert.assertTrue;
13

    
14
import java.util.regex.Matcher;
15
import java.util.regex.Pattern;
16

    
17
import org.apache.log4j.Logger;
18
import org.junit.Test;
19

    
20
import eu.etaxonomy.cdm.model.name.IBotanicalName;
21
import eu.etaxonomy.cdm.model.name.INonViralName;
22
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
23
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
24
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
25

    
26
/**
27
 * @author a.mueller
28
 *
29
 */
30
public class TestTaxonNameParserBotanicalNameImpl {
31
	private static final Logger logger = Logger.getLogger(TestTaxonNameParserBotanicalNameImpl.class);
32

    
33
	final private String strNameFamily = "Asteraceae";
34
	final private String strNameGenus = "Abies Müller";
35
	final private String strNameAbies1 = "Abies alba";
36
	final private String strNameAbiesSub1 = "Abies alba subsp. beta";
37
	final private String strNameAbiesAuthor1 = "Abies alba Müller";
38
	final private String strNameAbiesBasionymAuthor1 = "Abies alba (Ciardelli) D'Müller";
39
	final private String strNameAbiesBasionymExAuthor1 ="Abies alba (Ciardelli ex Döhring) D'Müller ex. de Greuther";
40
	final private String strNameAbiesBasionymAuthorUe = "Abies alba (Ciardelli) D'Mueller";
41

    
42
	private INonViralNameParser<IBotanicalName> parser ;
43

    
44
/*************** TEST *********************************************/
45

    
46

    
47
	@Test
48
	public final void functionTest() {
49

    
50

    
51
		if (false){
52
			String start = "^";
53
		    String end = "$";
54
		    String oWs = "\\s+"; //obligatory whitespaces
55
		    String fWs = "\\s*"; //facultative whitespcace
56

    
57
		    String capitalWord = "\\p{javaUpperCase}\\p{javaLowerCase}*";
58
		    String nonCapitalWord = "\\p{javaLowerCase}+";
59

    
60
		    String capitalDotWord = capitalWord + "\\.?"; //capitalWord with facultativ '.' at the end
61
		    String nonCapitalDotWord = nonCapitalWord + "\\.?"; //nonCapitalWord with facultativ '.' at the end
62
		    String authorPart = "(" + "(D'|L'|'t\\s)?" + capitalDotWord + "('" + nonCapitalDotWord + ")?" + "|da|de(n|l|\\sla)?)" ;
63
		    String author = "(" + authorPart + "(" + fWs + "|-)" + ")+" + "(f.|fil.|secundus)?";
64

    
65
		    String teamSplitter = fWs + "(&|,)" + fWs;
66
		    String authorTeam = fWs + "(" + author + teamSplitter + ")*" + author + "(" + teamSplitter + "al.)?" + fWs;
67
		    String exString = "(ex.?)";
68
		    String authorAndExTeam = authorTeam + "(" + oWs + exString + oWs + authorTeam + ")?";
69

    
70

    
71
			String basStart = "\\(";
72
		    String basEnd = "\\)";
73
		    String basionym = basStart + authorAndExTeam + basEnd + "{1}.*";  // '(' and ')' is for evaluation with RE.paren(x)
74
		    //String basionym = basStart + "(" + authorAndExTeam + ")" + basEnd +  "{1}.";  // '(' and ')' is for evaluation with RE.paren(x)
75

    
76
		    Pattern pattern = Pattern.compile(basionym);
77
			Matcher matcher = pattern.matcher("(Mueller)Ciard");
78
			assertTrue(matcher.matches());
79
		}
80

    
81

    
82
	}
83

    
84

    
85
	private void testRefParser(){
86
		int result = 0;
87
		//Barkerwebbia humilis (Becc.) Becc. ex Martelli
88

    
89

    
90
		String reference1 = "Sp. P. 2: 755. 1753., nom. inval.";
91
		//String reference1 = "Sp. P.";
92
		String fullRef1;
93

    
94
		fullRef1 = strNameAbiesBasionymAuthorUe + ", " + reference1;
95
//		result += parseIt(fullRef1);
96
		//Abies alba (Ciardelli) D'Mueller
97
//		result += parseIt( "Barkerwebbia humilis (Becc.) Becc. ex Martelli");
98
//		result += parseIt( "Heterospathe elegans subsp. versteegiana M.S.Trudgen & W.J.Baker");
99
//		result += parseIt( "Barkerwebbia elegans Becc., Webbia 16(456): 283. 1905");
100
//		result += parseIt( "Barkerwebbia elegans Becc. in Bot. J. 16(456): 283. 1905");
101
//		result += parseIt( "H. elegans (Becc.) Becc., Nova Guinea 8: 205. 1907");
102
//		result += parseIt( "Heterospathe elegans subsp. versteegiana M.S.Trudgen & W.J.Baker");
103
//		result += parseIt( "Hieracium asturicum Arv.-Touv.");
104
//		result += parseIt( "Hieracium mougeotii subsp. asturicum Zahn");
105
//		result += parseIt( "Hieracium vogesiacum subsp. asturicum (Zahn) O. Bolòs & Vigo");
106
//		result += parseIt( "Hieracium cantabricum Arv.-Touv.");
107
//		result += parseIt( "Hieracium mougeotii subsp. cantabricum (Arv.-Touv.) Zahn");
108
//		result += parseIt( "Hieracium murorramondii Mateo");
109
		result += parseIt( "Micrasterias denticulata Brébisson ex Ralfs 1848");
110
//		[13:11:55] Patricia Kelbert : Micrasterias denticulata var. angulosa (Hantzsch) W. et G.S. West 1902
111
//		[13:12:04] Patricia Kelbert : Micrasterias angulosa Hantzsch in Rabenhorst 1862
112

    
113
		System.out.println(result);
114
	}
115

    
116

    
117
	private int  parseIt(String fullRef1){
118
	    INonViralName nvName = TaxonNameFactory.NewZoologicalInstance(null);
119
		NonViralNameParserImpl parser = new NonViralNameParserImpl();
120

    
121
		//parser.parseFullName(strNameAbiesBasionymAuthorUe, null);
122
		nvName = parser.parseReferencedName(fullRef1, null, null);
123

    
124
		System.out.println(nvName.hasProblem());
125
		System.out.println("  Name: " + nvName.getTitleCache());
126
		System.out.println("  Reference: " + ((nvName.getNomenclaturalReference() == null) ? "-" : nvName.getNomenclaturalReference().getTitleCache()));
127
		System.out.println("  FullReference: " + ((nvName.getNomenclaturalReference() == null) ? "-" : nvName.getNomenclaturalReference().getNomenclaturalCitation(nvName.getNomenclaturalMicroReference())));
128
		return nvName.hasProblem() ? 1: 0;
129

    
130
	}
131

    
132

    
133
	/**
134
	 * @param args
135
	 */
136
	public static void  main(String[] args) {
137
		TestTaxonNameParserBotanicalNameImpl test = new TestTaxonNameParserBotanicalNameImpl();
138
    	test.testRefParser();
139
	}
140

    
141

    
142
}
(3-3/3)