Solved

Normalisation of street name with Python or Any Transformer


Hi,

I am having problem to find a suitable way to normalise Street Name in my geodatabase.

Example of Street Name to be normalised;

Example List of abbrivations to search and replace;

Any idea how to solve it either with a transformer or Python Script.

Many Thanks!

Abdul

icon

Best answer by takashi 16 June 2017, 09:44

View original

8 replies

Userlevel 4

Your captures aren't showing, but in general you can use a series of StringReplacer transformers to search and replace text inside e.g. street name attribute.

Userlevel 4
Badge +25

Your captures aren't showing, but in general you can use a series of StringReplacer transformers to search and replace text inside e.g. street name attribute.

Also there are some address postcode validators in the FME Hub that might be of use.

 

 

Your captures aren't showing, but in general you can use a series of StringReplacer transformers to search and replace text inside e.g. street name attribute.

str-name-and-normalization-list-sample.xlsx

 

Hi David,

Thanks for your answer but they are so many about 100s and if I do with StringReplacer it will be much work and mess :). we have a python module for this problem from an other collegue but I can not intergrate it into FME because have not worked with Python.

Attach you can find the sample data.

 

Userlevel 2
Badge +17

Hope this works fine!

0684Q00000ArKDtQAN.png

# PythonCaller Script Example (Python 2.7 only)
class FeatureProcessor(object):
    def __init__(self):
        self.map = None
        
    def input(self,feature):
        if self.map == None:
            search = feature.getAttribute('_map{}.To Search')
            change = feature.getAttribute('_map{}.To change')
            self.map = zip(search, change)
            
        name = feature.getAttribute('Street Name')
        for src, dst in self.map:
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)
# PythonCaller Script Example (works with both Python 2.7 and 3.5)
class FeatureProcessor(object):
    def __init__(self):
        self.search = None
        self.change = None
        
    def input(self,feature):
        if self.search == None:
            self.search = feature.getAttribute('_map{}.To Search')
            self.change = feature.getAttribute('_map{}.To change')
            
        name = feature.getAttribute('Street Name')
        for src, dst in zip(self.search, self.change):
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)

Userlevel 2
Badge +17

Hope this works fine!

0684Q00000ArKDtQAN.png

# PythonCaller Script Example (Python 2.7 only)
class FeatureProcessor(object):
    def __init__(self):
        self.map = None
        
    def input(self,feature):
        if self.map == None:
            search = feature.getAttribute('_map{}.To Search')
            change = feature.getAttribute('_map{}.To change')
            self.map = zip(search, change)
            
        name = feature.getAttribute('Street Name')
        for src, dst in self.map:
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)
# PythonCaller Script Example (works with both Python 2.7 and 3.5)
class FeatureProcessor(object):
    def __init__(self):
        self.search = None
        self.change = None
        
    def input(self,feature):
        if self.search == None:
            self.search = feature.getAttribute('_map{}.To Search')
            self.change = feature.getAttribute('_map{}.To change')
            
        name = feature.getAttribute('Street Name')
        for src, dst in zip(self.search, self.change):
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)

hmm, I don't know why the script doesn't change any string with Python 3.5, though it seems to work fine with Python 2.7.

 

Hope this works fine!

0684Q00000ArKDtQAN.png

# PythonCaller Script Example (Python 2.7 only)
class FeatureProcessor(object):
    def __init__(self):
        self.map = None
        
    def input(self,feature):
        if self.map == None:
            search = feature.getAttribute('_map{}.To Search')
            change = feature.getAttribute('_map{}.To change')
            self.map = zip(search, change)
            
        name = feature.getAttribute('Street Name')
        for src, dst in self.map:
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)
# PythonCaller Script Example (works with both Python 2.7 and 3.5)
class FeatureProcessor(object):
    def __init__(self):
        self.search = None
        self.change = None
        
    def input(self,feature):
        if self.search == None:
            self.search = feature.getAttribute('_map{}.To Search')
            self.change = feature.getAttribute('_map{}.To change')
            
        name = feature.getAttribute('Street Name')
        for src, dst in zip(self.search, self.change):
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)

Dear @takashi,

 

Thanks a lot. It is sort of working. 

 

Userlevel 2
Badge +17

Dear @takashi,

 

Thanks a lot. It is sort of working.

 

Good to hear.

 

Note that the previous script works only with Python 2.7. I added another script that works with both Python 2.7 and Python 3.5

 

 

Userlevel 2
Badge +17

Hope this works fine!

0684Q00000ArKDtQAN.png

# PythonCaller Script Example (Python 2.7 only)
class FeatureProcessor(object):
    def __init__(self):
        self.map = None
        
    def input(self,feature):
        if self.map == None:
            search = feature.getAttribute('_map{}.To Search')
            change = feature.getAttribute('_map{}.To change')
            self.map = zip(search, change)
            
        name = feature.getAttribute('Street Name')
        for src, dst in self.map:
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)
# PythonCaller Script Example (works with both Python 2.7 and 3.5)
class FeatureProcessor(object):
    def __init__(self):
        self.search = None
        self.change = None
        
    def input(self,feature):
        if self.search == None:
            self.search = feature.getAttribute('_map{}.To Search')
            self.change = feature.getAttribute('_map{}.To change')
            
        name = feature.getAttribute('Street Name')
        for src, dst in zip(self.search, self.change):
            name = name.replace(src, dst)
            
        feature.setAttribute('Normalized', name)
        self.pyoutput(feature)

OK. The behavior of "zip" function in Python 3.5 was different from Python 2.7. It's the reason why the previous script didn't work with Python 3.5 interpreter.

 

Reply