I don't know exactly if there is a tool for this or a maybe a python script could be more suitable. I want to compare string elements from a field (POI_NAME) with another string element in another field (ROTULO). Find attached an screenshot.

My goal, AT LEAST, is to have a YES/NO matching, but It could be fantastic having a % of matching. Do anyone know anything about?

enter image description here

I tried something like this:

Python code

But it doesn't work.

After editing the code, to:

New code

We can see that it does not working well (BECAUSE IT HAS SPECIAL CHARS AND SPACES):

enter image description here


First of all, you should compare your string in a case insensitive way. EDIT: I also add .strip() in case you have blank spaces in your string.

POI_name.lower().strip() == ROTULO.lower().strip()

Because Python is case sensitive and ROTULO is in capital letter

For further comparison, this is more a Python question. For instance, have a look at this post an SO, which uses pylevenshtein

EDIT: I've tried this (from Wikibooks), and it worked nicely (the larger the value, the more different are the words

def lev(a, b):
    if not a: return len(b)
    if not b: return len(a)
    return min(lev(a[1:], b[1:])+(a[0] != b[0]), lev(a[1:], b)+1, lev(a, b[1:])+1) 
  • I looked up for this issue you mentioned @radouxju, but still doesn't working. – juasmilla May 12 '14 at 9:38
  • @juasmilla "doesn't work" is far less helpful to people trying to help you than if you can say what is not working e.g. it gives an error, and what that precise error message is; or it updates the wrong rows; or it does not update all the rows; or it did not update any rows; etc; etc – PolyGeo May 12 '14 at 9:46
  • Sorry you we're right. I forgot to edit my first question with this new income. Editing...just a sec. – juasmilla May 12 '14 at 9:48
  • 2
    I've tested my code and it worked with me. Is it possible that you have special characters or spaces ? Maybe you could try to compare the length of the field values (len(!POI_name!)-len(!ROTULO!) ) for debugging. – radouxju May 12 '14 at 10:05
  • @radouxju as you said, I've found special chars and spaces... so this is not as simple as I thought.I'll have a look to the post you mentioned (pylevenshtein) but, unfortunatelly, I do not really know if could use its code in ArcGIS 10 field calculator. – juasmilla May 12 '14 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.