I'm back on track with the scripting plugin. I created a Jython script that
helps to find probable spelling errors in street names. It's quite specific
in that it supports the bilingual status of Brussels.
#!/bin/jython
#
# Spell checking.py - Helps to locate probable spell errors
#
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 = {'fr': [('Dr. ', 'Docteur '),('R. ', 'Rue '), ('Av. ',
'Avenue '), ('Bd. ', 'Boulevard '),
('Sq.', 'Square'), ('Pl.', 'Place'),
(' De ', ' de '), (' Le ', ' le '), (' La ', ' la '),
(' Du ', ' du '), (' Des ', ' des '), (' Les ', ' les '),
(' Au ', ' au '),(' Aux ', ' aux '),('À', 'à'),(' Den
',' den '), ( Sur , sur ),
( D', d'), ( L', l'), (' ,'),
(Ecole ,École ), (Eglise, Église),
(Chateau, Château), (Cable, Câble), (General, Général)],
'nl': [( Voor , voor ), ( Op , op ), ( Pour ,
pour ), ( Naar , naar ), ( Ter , ter ), ( En , en ), ( Van
, van ),
('T , 't ), ('S , 's ), (-Ter-, -ter-),
( Het , het ),
( Straat, straat), ( Weg, weg), ( Laan,
laan), ( Steenweg, steenweg),
( Baan, baan), (Oudebaan, Oude Baan),
(Grotebaan, Grote Baan),
(de Lijn, De Lijn)]}
commandsList = []
streetnames = {}
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].upper() + word[1:]
else:
return u
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()
if not(selectedNodes or selectedWays or selectedRelations):
JOptionPane.showMessageDialog(Main.parent, Please select
something)
else:
for way in selectedWays:
for isoLang in ['nl', 'fr', '']:
correctedName = result = u''
if isoLang:
nameColonIso = 'name:' + isoLang
else:
nameColonIso = 'name'
if way.hasKey(nameColonIso):
name=str(way.get(nameColonIso).encode('utf-8'))
if name in streetnames:
if streetnames[name] == 'ignore':
continue
else:
correctedName = streetnames[name]
else:
Main.main.getCurrentDataSet().setSelected(way)
# dummy = mv.editLayer.data.getSelected()
#
mv.zoomTo(Main.main.getEditLayer().data.getSelected())
# JOptionPane.showMessageDialog(Main.parent,
name.decode('utf-8'))
for subname in name.split(;):
for word in subname.split( ):
if word:
if - in word and len(word)1:
dashes = word.split(-)
correctedName +=
myOwnCapitalize(dashes[0])
for dash in dashes[1:]:
# if dash[0] == ' ':
# correctedName += u- +
myOwnCapitalize(dash[1:])
# else:
correctedName += u- +
myOwnCapitalize(dash.strip())
elif ' in word and not(. in word):
apo=word.split(')
if apo[0]: correctedName +=
myOwnCapitalize(apo[0])
correctedName += '
if apo[1]: correctedName +=
myOwnCapitalize(apo[1])
elif . in word or len(word)1 and
word[1]==word[1].upper() or len(word)2 and word[2]==word[2].upper():
correctedName += word
else:
correctedName +=
myOwnCapitalize(word)
correctedName += ' '
correctedName = correctedName.strip() + ';'