I was glad Jan-Willem showed up. The result is a python plugin which can correct spelling from within JOSM. I just corrected 264 street names around Aarschot with it:
http://www.openstreetmap.org/browse/changeset/7794020 Somebody had some trouble finding the Shift key on his/her keyboard. This spelling checker also works for French street names. It still needs some refinement. Now it asks the same question over and over again for each segment and it should be made aware of the language a correction applies for. For the moment it only checks name and not name:nl/name:fr. But the real message is that Jan-Willem helped me over the initial difficulties of scripting the JOSM API with Python. So I'm really glad we met yesterday evening! Here is the code: #!/bin/jython > # > # Helps to check spelling in 'name' fields. > # > from javax.swing import JOptionPane > from org.openstreetmap.josm import Main > import org.openstreetmap.josm.command as Command > import org.openstreetmap.josm.data.osm.Node as Node > import org.openstreetmap.josm.data.osm.Way as Way > import org.openstreetmap.josm.data.osm.TagCollection as TagCollection > import org.openstreetmap.josm.data.osm.DataSet as DataSet > > corrections = [('Dr. ', 'Docteur '),('R. ', 'Rue '), ('Av. ', 'Avenue '), > ('Bd. ', 'Boulevard '), > ('Sq.', 'Square'), ('Pl.', 'Place'), > (' De ', ' de '), (' La ', ' la '), (' Du ', ' du '), (' Des > ', ' des '), > (' Au ', ' au '),(' Aux ', ' aux '),('À', 'à'),(' Den ',' > den '), > (" D'"," d'"), (" L'"," l'"), ("' ","'"), > ("Ecole ","École "), > (" Voor ", " voor "), (" Op ", " op "), (" Pour ", " pour > ")] > > logger = open("c:\debug.log", "w") #, encoding="utf-8") > commandsList = [] > > def getMapView(): > if Main.main and Main.main.map: > return Main.main.map.mapView > else: > return None > > def myOwnCapitalize(word): > # JOptionPane.showMessageDialog(Main.parent, word.decode('utf-8')) > if word: > return word[0].uppper() + word[1:] > > mv = getMapView() > > if mv and mv.editLayer and mv.editLayer.data: > selectedNodes = mv.editLayer.data.getSelectedNodes() > selectedWays = mv.editLayer.data.getWays() > selectedRelations = mv.editLayer.data.getSelectedRelations() > logger.write("nodes: %s\n"%selectedNodes) > #logger.write("ways: %s\n"%selectedWays) > logger.write("relations: %s\n"%selectedRelations) > if not(selectedNodes or selectedWays or selectedRelations): > JOptionPane.showMessageDialog(Main.parent, "Please select > something") > else: > for way in selectedWays: > if way.hasKey('name'): > name=str(way.get("name").encode('utf-8')) > # JOptionPane.showMessageDialog(Main.parent, > name.decode('utf-8')) > correctedName = u'' > for word in name.split(u" "): > # JOptionPane.showMessageDialog(Main.parent, > word.decode('utf-8')) > if "-" in word: > dashes = word.split("-") > correctedName += dashes[0].capitalize() > print(dashes) > for dash in dashes[1:]: > correctedName += "-" + dash[0].upper() + > dash[1:] > elif "'" in word and not("." in word): > apo=word.split("'") > correctedName += apo[0].capitalize() + "'" + > apo[1].capitalize() > elif "." in word or len(word)>1 and > word[1]==word[1].capitalize() or len(word)>2 and > word[2]==word[2].capitalize(): > correctedName += word > else: > correctedName += word[0].upper() + word[1:] > correctedName += ' ' > for wrongspelling, correction in corrections: > correctedName = correctedName.replace(wrongspelling, > correction) > correctedName = correctedName.strip() > if name != correctedName: > result = JOptionPane.showInputDialog(Main.parent, > "Previous name: " + name.decode('utf-8'), > 'Change spelling?', > JOptionPane.QUESTION_MESSAGE, > None, > None, > correctedName.decode('utf-8')) > # JOptionPane.showMessageDialog(Main.parent, result) > if result: > # logger.write("output: %s\n"%type(name)) > newWay = Way(way) > newWay.put("name", result) # .decode('utf-8')) > commandsList.append(Command.ChangeCommand(way, > newWay)) > if commandsList: > Main.main.undoRedo.add(Command.SequenceCommand("Change > spelling", commandsList)) > > # for primitive in selectedprimitives: > # logger.write("You have selected the following : %s\r\n" % > primitive) > > logger.close() > 2011/4/6 Jan-willem De Bleser <j...@thescrapyard.org> > On Wed, Apr 6, 2011 at 15:52, Jo <winfi...@gmail.com> wrote: > > I plan to go anyway. Doesn't really matter whether I sit and work there > or > > at home. I'm a happy camper as long as I have an internet connection... > If > > nobody shows up, I'll probably leave around 21h00. > > > > Polyglot > > > > I might be able to swing by for a bit. Will see when I get out of work. > > Cheers, > Jw > > _______________________________________________ > Talk-be mailing list > Talk-be@openstreetmap.org > http://lists.openstreetmap.org/listinfo/talk-be >
_______________________________________________ Talk-be mailing list Talk-be@openstreetmap.org http://lists.openstreetmap.org/listinfo/talk-be