Changeset 15763 in osm for applications
- Timestamp:
- 2009-06-08T01:23:58+02:00 (15 years ago)
- Location:
- applications/editors/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/czechaddress/build.xml
r15707 r15763 1 1 <project name="czechaddress" default="dist" basedir="."> 2 2 <property name="josm" location="../../core/dist/josm-custom.jar"/> 3 <property name="josm.classpath" value="../../core/build"/> 3 4 <property name="plugin.dist.dir" value="../../dist"/> 4 5 <property name="plugin.build.dir" value="build"/> 5 6 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/> 7 <property name="plugin.manifest" value="${plugin.build.dir}/org/openstreetmap/josm/plugins/czechaddress/MANIFEST.MF"/> 6 8 <property name="ant.build.javac.target" value="1.5"/> 9 10 11 12 <target name="clean" description="Removes all build files and the plugins's jar"> 13 <delete dir="${plugin.build.dir}"/> 14 <delete file="${plugin.jar}"/> 15 </target> 16 17 18 7 19 <target name="init"> 8 20 <mkdir dir="${plugin.build.dir}"/> 21 <mkdir dir="${plugin.dist.dir}"/> 9 22 </target> 10 <target name="compile" depends="init"> 11 <echo message="creating ${plugin.jar}"/> 12 <javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}"> 23 24 25 26 <target name="compile" depends="init" 27 description="Compile the plugin and make it ready for running"> 28 29 <fail message="You must firstly compile the JOSM itself"><condition><not> 30 <resourcecount count="1" when="ge"> 31 <fileset id="josm" dir="${josm.classpath}"/> 32 </resourcecount> 33 </not></condition></fail> 34 35 <javac srcdir="src" 36 classpath="${josm}" 37 debug="true" 38 destdir="${plugin.build.dir}"> 13 39 <compilerarg value="-Xlint:deprecation"/> 14 40 <compilerarg value="-Xlint:unchecked"/> 15 41 </javac> 16 </target> 17 <target name="dist" depends="compile,revision"> 42 18 43 <copy todir="${plugin.build.dir}/images"> 19 44 <fileset dir="images"/> 20 45 </copy> 21 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 22 <manifest> 23 <attribute name="Author" value="Radomír Černoch"/> 24 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin"/> 25 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 26 <attribute name="Plugin-Description" value="Creating and handling address nodes and buildings within Czech Republic."/> 27 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/SlippyMap"/> 28 <attribute name="Plugin-Mainversion" value="1607"/> 29 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 30 </manifest> 31 </jar> 46 47 <manifest file="${plugin.manifest}"> 48 <attribute name="Author" value="Radomír Černoch"/> 49 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin"/> 50 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 51 <attribute name="Plugin-Description" value="Creating and handling address nodes and buildings within Czech Republic."/> 52 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/Cz:JOSM/Plugins/CzechAddress"/> 53 <attribute name="Plugin-Mainversion" value="1607"/> 54 <!--<attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>--> 55 <attribute name="Plugin-Version" value="0.2.2"/> 56 </manifest> 57 32 58 </target> 59 60 61 62 <target name="dist" depends="compile"> 63 <jar destfile="${plugin.jar}" 64 basedir ="${plugin.build.dir}" 65 manifest="${plugin.build.dir}/org/openstreetmap/josm/plugins/czechaddress/MANIFEST.MF"/> 66 </target> 67 68 69 33 70 <target name="revision"> 34 71 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> … … 41 78 <delete file="REVISION"/> 42 79 </target> 43 <target name="clean"> 44 <delete dir="${plugin.build.dir}"/> 45 <delete file="${plugin.jar}"/> 46 </target> 80 81 82 47 83 <target name="install" depends="dist"> 48 84 <property environment="env"/> 49 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">50 <and>51 <os family="windows"/>52 < /and>85 <condition property="josm.plugins.dir" 86 value="${env.APPDATA}/JOSM/plugins" 87 else="${user.home}/.josm/plugins"> 88 <and><os family="windows"/></and> 53 89 </condition> 54 90 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 55 91 </target> 92 93 94 95 <target name="run" depends="compile"> 96 <fail message="You must firstly compile the JOSM itself"><condition><not> 97 <resourcecount count="1" when="gt"> 98 <fileset id="josm" dir="${josm.classpath}" includes="*"/> 99 </resourcecount> 100 </not></condition></fail> 101 102 <java classname="JOSM" fork="true"> 103 <jvmarg value="-Xmx1024m"/> 104 <jvmarg value="-Xdebug"/> 105 <jvmarg value="-ea"/> 106 <classpath> 107 <pathelement location="${plugin.build.dir}"/> 108 <pathelement path="${java.class.path}"/> 109 </classpath> 110 <classpath> 111 <pathelement location="${josm}"/> 112 <pathelement path="${java.class.path}"/> 113 </classpath> 114 </java> 115 </target> 116 117 118 119 <target name="profile" depends="compile" description="Profile CzechAddress"> 120 <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail> 121 <nbprofiledirect> 122 <classpath><pathelement location="${plugin.build.dir}"/></classpath> 123 </nbprofiledirect> 124 <java classname="JOSM" fork="true"> 125 <jvmarg value="${profiler.info.jvmargs.agent}"/> 126 <jvmarg value="-Xmx1024m"/> 127 <classpath> 128 <pathelement location="${plugin.build.dir}"/> 129 <pathelement path="${java.class.path}"/> 130 </classpath> 131 <classpath> 132 <pathelement location="${josm}"/> 133 <pathelement path="${java.class.path}"/> 134 </classpath> 135 </java> 136 </target> 56 137 </project> -
applications/editors/josm/plugins/czechaddress/nbproject
- Property svn:ignore
-
old new 1 1 .project.xml.swp 2 private
-
- Property svn:ignore
-
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.