Skip to main content
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

Best answer by takashi

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)

View original
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

8 replies

david_r
Celebrity

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.


mark2atsafe
Safer
Forum|alt.badge.img+59

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.

 


takashi
Celebrity
  • Best Answer
  • June 16, 2017

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)


takashi
Celebrity

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. 

 


takashi
Celebrity

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

 

 


takashi
Celebrity

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.