Changeset 15763 in osm for applications/editors/josm/plugins/czechaddress/src
- Timestamp:
- 2009-06-08T01:23:58+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/CzechAddressPlugin.java
r15649 r15763 69 69 continue; 70 70 71 System.err.println(name);72 71 Logger.getLogger(name).setLevel(Level.FINE); 73 72 Logger.getLogger(name).addHandler(fileHandler); … … 83 82 public CzechAddressPlugin() { 84 83 84 /*boolean x; 85 x = StringUtils.matchAbbrev("Ahoj lidi", "Ahoj lidi"); 86 System.out.println(x ? "Match" : "Differ"); 87 x = StringUtils.matchAbbrev("Bož. Němcové", "Boženy Němca."); 88 System.out.println(x ? "Match" : "Differ");*/ 89 85 90 addStatusListener(this); 86 91 … … 102 107 103 108 // Fill the database in separate thread. 104 Thread t = new Thread() { @Override public void run() { 109 Thread t = new Thread("CzechAddress: DB preload") { 110 @Override public void run() { 105 111 super.run(); 106 112 try { -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/StringUtils.java
r15582 r15763 2 2 3 3 import java.text.Normalizer; 4 import java.util.ArrayList; 5 import java.util.List; 4 6 import org.openstreetmap.josm.data.coor.LatLon; 5 7 … … 57 59 */ 58 60 public static boolean matchAbbrev(String s1, String s2) { 59 String[] parts1 = anglicize(s1).split(" +");60 String[] parts2 = anglicize(s2).split(" +");61 61 62 if (parts1.length != parts2.length) 62 s1 = anglicize(s1); 63 s2 = anglicize(s2); 64 List<Integer> beg1 = new ArrayList<Integer>(4); 65 List<Integer> beg2 = new ArrayList<Integer>(4); 66 67 char lastChar = ' '; 68 for (int i=0; i<s1.length(); i++) { 69 if (s1.charAt(i) != ' ' && lastChar == ' ') 70 beg1.add(i); 71 lastChar = s1.charAt(i); 72 } 73 74 lastChar = ' '; 75 for (int i=0; i<s2.length(); i++) { 76 if (s2.charAt(i) != ' ' && lastChar == ' ') 77 beg2.add(i); 78 lastChar = s2.charAt(i); 79 } 80 81 if (beg1.size() != beg2.size()) 63 82 return false; 64 83 65 for (int i=0; i<parts1.length; i++) { 66 String part1 = parts1[i]; 67 String part2 = parts2[i]; 84 for (int i=0; i<beg1.size(); i++) { 68 85 69 i f (part1.charAt(part1.length()-1) == '.')70 part1 = part1.substring(0, part1.length()-1);86 int pos1 = beg1.get(i); 87 int pos2 = beg2.get(i); 71 88 72 if (part2.charAt(part2.length()-1) == '.') 73 part2 = part2.substring(0, part2.length()-1); 89 boolean doContinue = false; 90 while (pos1 < s1.length() && pos2 < s2.length()) { 91 if (s1.charAt(pos1) == '.' || s2.charAt(pos2) == '.') 92 {doContinue = true; break;} 93 if (s1.charAt(pos1) == ' ' && s2.charAt(pos2) == ' ') 94 {doContinue = true; break;} 74 95 75 int minLen = Math.min(part1.length(), part2.length());76 part1 = part1.substring(0, minLen).toUpperCase();77 part2 = part2.substring(0, minLen).toUpperCase();96 if (Character.toUpperCase(s1.charAt(pos1)) != 97 Character.toUpperCase(s2.charAt(pos2))) 98 return false; 78 99 79 if (!part1.equals(part2)) 100 pos1++; 101 pos2++; 102 } 103 if (doContinue) continue; 104 105 if (pos1 >= s1.length() ^ pos2 >= s2.length()) 80 106 return false; 81 107 } 108 82 109 return true; 83 110 } … … 93 120 */ 94 121 public static String capitalize(String s) { 122 if (s == null) return null; 95 123 96 if (s == null) 97 return s; 98 99 String result = ""; 100 124 char[] charr = s.toCharArray(); 101 125 char last = ' '; 102 for (char ch : s.toCharArray()) { 126 char ch = last; 127 for (int i=0; i<charr.length; i++) { 128 ch = charr[i]; 103 129 if ((last >= 'a') && (last <= 'ž') || 104 130 (last >= 'A') && (last <= 'Ž')) … … 107 133 ch = Character.toTitleCase(ch); 108 134 109 last = ch; 110 result = result + ch; 135 last = charr[i] = ch; 111 136 } 112 137 113 138 String[] noCapitalize = { "Nad", "Pod", "U", "Na", "Z" }; 139 String result = String.valueOf(charr); 140 114 141 for (String noc : noCapitalize) 115 142 result = result.replaceAll(" "+noc+" ", " "+noc.toLowerCase()+" "); 116 117 143 return result; 118 144 } … … 129 155 public static String anglicize(String str) { 130 156 String strNFD = Normalizer.normalize(str, Normalizer.Form.NFD); 131 StringBuilder sb = new StringBuilder(); 157 StringBuilder sb = new StringBuilder(str.length()); 132 158 for (char ch : strNFD.toCharArray()) { 133 159 if (Character.getType(ch) != Character.NON_SPACING_MARK) { -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ElementWithHouses.java
r15582 r15763 18 18 } 19 19 20 protected List<House> houses = new ArrayList<House>(); 20 protected List<House> houses = new ArrayList<House>(30); 21 21 22 22 /** -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/Reasoner.java
r15582 r15763 312 312 */ 313 313 private int getQ(OsmPrimitive prim, AddressElement elem) { 314 315 // TODO: This is a workaround. We should not be here at all. 316 if (elemMatchIndex.get(elem) == null) return MATCH_NOMATCH; 317 if (primMatchIndex.get(prim) == null) return MATCH_NOMATCH; 318 314 319 assert primMatchIndex.get(prim).get(elem) 315 320 == elemMatchIndex.get(elem).get(prim); … … 466 471 public Set<AddressElement> getCandidates(OsmPrimitive prim) { 467 472 473 Set<AddressElement> result = new HashSet<AddressElement>(); 474 if (primMatchIndex.get(prim) == null) return result; 475 468 476 int best = MATCH_NOMATCH; 469 477 for (AddressElement elem : primMatchIndex.get(prim).keySet()) { … … 473 481 } 474 482 475 Set<AddressElement> result = new HashSet<AddressElement>();476 477 483 for (AddressElement elem : primMatchIndex.get(prim).keySet()) { 478 484 int cand = primMatchIndex.get(prim).get(elem); … … 499 505 public Set<OsmPrimitive> getCandidates(AddressElement elem) { 500 506 507 Set<OsmPrimitive> result = new HashSet<OsmPrimitive>(); 508 if (elemMatchIndex.get(elem) == null) return result; 509 501 510 int best = MATCH_NOMATCH; 502 511 for (OsmPrimitive prim : elemMatchIndex.get(elem).keySet()) { … … 505 514 best = cand; 506 515 } 507 508 Set<OsmPrimitive> result = new HashSet<OsmPrimitive>();509 516 510 517 for (OsmPrimitive prim : elemMatchIndex.get(elem).keySet()) { … … 539 546 540 547 Map<AddressElement, Integer> matches = primMatchIndex.get(prim); 548 if (matches == null) return null; 541 549 AddressElement bestE = null; 542 550 int bestQ = MATCH_NOMATCH; … … 578 586 579 587 Map<OsmPrimitive, Integer> matches = elemMatchIndex.get(elem); 588 if (matches == null) return null; 580 589 OsmPrimitive bestE = null; 581 590 int bestQ = MATCH_NOMATCH; -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/MvcrParser.java
r15582 r15763 40 40 Attributes attributes) throws SAXException { 41 41 42 // ========== PARSING HOUSE ========== // 43 if (name.equals("a")) { 44 45 String cp = attributes.getValue("p"); 46 String co = attributes.getValue("o"); 47 if ((cp == null) && (co == null)) 48 return; 49 50 ElementWithHouses topElem = curStreet; 51 if (topElem == null) topElem = curSuburb; 52 if (topElem == null) topElem = curViToCi; 53 if (topElem == null) topElem = curRegion; 54 55 topElem.addHouse(new House(cp, co)); 56 return; 57 } 58 59 // ========== PARSING STREET ========== // 60 if (name.equals("ulice")) { 61 String nazev = attributes.getValue("nazev"); 62 63 // If the street filter is on, apply it! 64 if (filStreet != null && !nazev.equals(filStreet)) { 65 curStreet = null; 66 return; 67 } 68 69 ElementWithStreets topElem = curSuburb; 70 if (topElem == null) topElem = curViToCi; 71 if (topElem == null) topElem = curRegion; 72 73 //curStreet = topElem.findStreet(attributes.getValue("nazev")); 74 //if (curStreet == null) { 75 curStreet = new Street(capitalize(nazev)); 76 // System.out.println("Parser: " + curStreet); 77 topElem.addStreet(curStreet); 78 //} 79 return; 80 } 81 82 // ========== PARSING SUBURB ========== // 83 if (name.equals("cast")) { 84 if (curViToCi == null) 85 return; 86 87 String nazev = attributes.getValue("nazev"); 88 89 // If the suburb filter is on, apply it! 90 if (filSuburb != null && !nazev.equals(filSuburb)) { 91 curSuburb = null; 92 curStreet = null; 93 return; 94 } 95 96 //curSuburb = curViToCi.findSuburb(attributes.getValue("nazev")); 97 //if (curSuburb == null) { 98 curSuburb = new Suburb(capitalize(nazev)); 99 // System.out.println("Parser: " + curSuburb); 100 curViToCi.addSuburb(curSuburb); 101 //} 102 return; 103 } 104 105 // ========== PARSING ViToCi ========== // 106 if (name.equals("obec")) { 107 108 String nazev = attributes.getValue("nazev"); 109 110 // If the viToCi filter is on, apply it! 111 if (filViToCi != null && !nazev.equals(filViToCi)) { 112 curViToCi = null; 113 curSuburb = null; 114 curStreet = null; 115 return; 116 } 117 118 //curViToCi = curRegion.findViToCi(attributes.getValue("nazev")); 119 //if (curViToCi == null) { 120 curViToCi = new ViToCi(capitalize(nazev)); 121 // System.out.println("Parser: " + curViToCi); 122 curRegion.addViToCi(curViToCi); 123 //} 124 return; 125 } 126 42 127 // ========== PARSING REGION ========== // 43 128 if (name.equals("oblast")) { … … 65 150 target.regions.add(curRegion); 66 151 //} 67 } 68 69 // Everything must belong to some region 70 if (curRegion == null) 71 return; 72 73 // ========== PARSING ViToCi ========== // 74 if (name.equals("obec")) { 75 76 // If the viToCi filter is on, apply it! 77 if (filViToCi != null && !attributes.getValue("nazev").equals(filViToCi)) { 78 curViToCi = null; 79 curSuburb = null; 80 curStreet = null; 81 return; 82 } 83 84 //curViToCi = curRegion.findViToCi(attributes.getValue("nazev")); 85 //if (curViToCi == null) { 86 curViToCi = new ViToCi(capitalize(attributes.getValue("nazev"))); 87 // System.out.println("Parser: " + curViToCi); 88 curRegion.addViToCi(curViToCi); 89 //} 90 } 91 92 // ========== PARSING SUBURB ========== // 93 if (name.equals("cast")) { 94 if (curViToCi == null) 95 return; 96 97 // If the suburb filter is on, apply it! 98 if (filSuburb != null && !attributes.getValue("nazev").equals(filSuburb)) { 99 curSuburb = null; 100 curStreet = null; 101 return; 102 } 103 104 //curSuburb = curViToCi.findSuburb(attributes.getValue("nazev")); 105 //if (curSuburb == null) { 106 curSuburb = new Suburb(capitalize(attributes.getValue("nazev"))); 107 // System.out.println("Parser: " + curSuburb); 108 curViToCi.addSuburb(curSuburb); 109 //} 110 } 111 112 // ========== PARSING STREET ========== // 113 if (name.equals("ulice")) { 114 115 // If the street filter is on, apply it! 116 if (filStreet != null && !attributes.getValue("nazev").equals(filStreet)) { 117 curStreet = null; 118 return; 119 } 120 121 ElementWithStreets topElem = curSuburb; 122 if (topElem == null) topElem = curViToCi; 123 if (topElem == null) topElem = curRegion; 124 125 //curStreet = topElem.findStreet(attributes.getValue("nazev")); 126 //if (curStreet == null) { 127 curStreet = new Street(capitalize(attributes.getValue("nazev"))); 128 // System.out.println("Parser: " + curStreet); 129 topElem.addStreet(curStreet); 130 //} 131 132 } 133 134 // ========== PARSING HOUSE ========== // 135 if (name.equals("a")) { 136 137 if ( (attributes.getValue("p") == null) 138 && (attributes.getValue("o") == null)) 139 return; 140 141 ElementWithHouses topElem = curStreet; 142 if (topElem == null) topElem = curSuburb; 143 if (topElem == null) topElem = curViToCi; 144 if (topElem == null) topElem = curRegion; 145 146 topElem.addHouse(new House(attributes.getValue("p"), 147 attributes.getValue("o"))); 152 return; 148 153 } 149 154 }
Note:
See TracChangeset
for help on using the changeset viewer.