View Javadoc
1   package com.gisgraphy.street;
2   
3   import java.util.regex.Matcher;
4   import java.util.regex.Pattern;
5   /**
6    * 
7    *  * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
8    * 
9    */
10  public class HouseNumberUtil {
11  	
12  	private static Pattern DEFAULT_PATTERN = Pattern.compile("[\\-\\–\\一]?(\\d+)[^\\d]*",Pattern.CASE_INSENSITIVE);
13  	
14  	private static Pattern CZ_SK_PATTERN = Pattern.compile("(?:(?:\\d+[/\\-\\–\\一])|(?:[^\\d]?))(\\d+)",Pattern.CASE_INSENSITIVE);
15  	
16  	public static String normalizeNumber(String numberAsString){
17  		if (numberAsString ==null){
18  			return null;
19  		}
20  		Matcher matcher = DEFAULT_PATTERN.matcher(numberAsString);
21  		if (matcher.find()){
22  			return matcher.group(1);
23  		}
24  		return null;
25  	}
26  	
27  	/**
28  	 * specific case for slovakia and czech
29  	 * see http://www.pitt.edu/~votruba/qsonhist/housenumbersslovakia.html
30  	 */
31  	public static String normalizeSkCzNumber(String numberAsString){
32  		if (numberAsString ==null){
33  			return null;
34  		}
35  		Matcher matcher = CZ_SK_PATTERN.matcher(numberAsString);
36  		if (matcher.find()){
37  			return matcher.group(1);
38  		}
39  		return null;
40  	}
41  
42  }