[Schmitzm-commits] r1895 - in trunk/schmitzm-adresses/src: main/java/de/schmitzm/adresses test/java/de/schmitzm/adresses

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sun Mar 11 14:55:44 CET 2012


Author: alfonx
Date: 2012-03-11 14:55:44 +0100 (Sun, 11 Mar 2012)
New Revision: 1895

Modified:
   trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java
   trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java
Log:


Modified: trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java
===================================================================
--- trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java	2012-03-11 13:27:01 UTC (rev 1894)
+++ trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java	2012-03-11 13:55:44 UTC (rev 1895)
@@ -549,13 +549,39 @@
 	static public String saeubereStrassenname(String orginal) {
 		String strasse = LangUtil.removeTags(orginal);
 		strasse = strasse.replaceAll("\\s\\s+", " ");
+		strasse = strasse.replaceAll("(\\d)\\s", "$1");
 		strasse = strasse.replaceAll("\\s+-\\s+", "-");
 		strasse = strasse.replaceAll("tra(ss|ß)e\\b", "tr.");
 		strasse = strasse.replaceAll("str[^\\.]", "str.");
 		strasse = strasse.replaceAll("([^\\d^\\s])(\\d)", "$1 $2");
 		strasse = strasse.replaceAll("str$", "str.");
-		strasse = WordUtils.capitalize(strasse, new char[] { ' ', '-' });
+
+		{
+			// Großschreibung aller Anfangsbuchstaben, AUSSER in den Hausnummerzusätzen
+
+			// Wo ist die erste Zahl?
+			Pattern firstNumP = RegexCache.getInstance().getPattern("\\b\\d");
+			int firstNumIdx = -1;
+			Matcher firstNumM = firstNumP.matcher(strasse);
+			if (firstNumM.find()) {
+				boolean moreFound = true;
+				while (moreFound && firstNumM.start() <= 2) {
+					moreFound = firstNumM.find();
+				}
+				firstNumIdx = firstNumM.start();
+			}
+
+			String s2 = "";
+			if (firstNumIdx > 2 && firstNumIdx < strasse.length() - 1) {
+				s2 = strasse.substring(firstNumIdx, strasse.length());
+				s2 = s2.toLowerCase();
+				s2 = s2.replaceAll("\\s+", "");
+				strasse = strasse.substring(0, firstNumIdx);
+			}
+			strasse = WordUtils.capitalize(strasse, new char[] { ' ', '-' });
+			strasse = strasse + s2;
+		}
+
 		return strasse;
 	}
-
 }

Modified: trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java
===================================================================
--- trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java	2012-03-11 13:27:01 UTC (rev 1894)
+++ trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java	2012-03-11 13:55:44 UTC (rev 1895)
@@ -267,7 +267,7 @@
 	@Test
 	public void testNormalizeOrt() {
 		// TODO schecht und klappt im PSQL nicht!!
-//		assertEquals("aaa", AddrStringUtil.normalizeOrt("aaaa (bbb)"));
+		// assertEquals("aaa", AddrStringUtil.normalizeOrt("aaaa (bbb)"));
 		assertEquals("hattersheimammain", AddrStringUtil.normalizeOrt("Hattersheim am Main"));
 		assertEquals("hattersheimammain", AddrStringUtil.normalizeOrt("Hattersheim a Main"));
 		assertEquals("hattersheimammain", AddrStringUtil.normalizeOrt("Hattersheim a. Main"));
@@ -328,9 +328,20 @@
 	public void testSaeubereStrassenname() {
 		assertEquals("Sternstr.", AddrStringUtil.saeubereStrassenname("Sternstraße"));
 		assertEquals("Sternstr.", AddrStringUtil.saeubereStrassenname("Sternstrasse"));
+		assertEquals("Sternstr.", AddrStringUtil.saeubereStrassenname("Sternstrasse"));
 		assertEquals("Hans-Wurststr. 3", AddrStringUtil.saeubereStrassenname("Hans - Wurststr 3"));
 		assertEquals("Hans-Wurststr. 3", AddrStringUtil.saeubereStrassenname("<br/>Hans - Wurststr 3<br/>"));
 		assertEquals("Hans-Wurststr. 3", AddrStringUtil.saeubereStrassenname("hans - wurststr 3"));
 		assertEquals("Hans-Wurststr.", AddrStringUtil.saeubereStrassenname("Hans - Wurststr"));
+
+		assertEquals("Lindenweg 12/0402", AddrStringUtil.saeubereStrassenname("Lindenweg 12/ 0402"));
+		assertEquals("Knobelsdorfstr. 6a-d", AddrStringUtil.saeubereStrassenname("Knobelsdorfstr. 6  a- d"));
+		assertEquals("Knobelsdorfstr. 6a-d", AddrStringUtil.saeubereStrassenname("Knobelsdorfstr. 6a- D"));
+		assertEquals("78er-Str. 45a-d", AddrStringUtil.saeubereStrassenname("78 er - Straße   45 A - d"));
 	}
+
+	@Test
+	public void testSaeubereStrassennameSuffix() throws Exception {
+
+	}
 }



More information about the Schmitzm-commits mailing list