LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Longest Exact Match

    Employee
    Posted 02-01-2011 08:59

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: zon


    Hi,
    I'm trying to find the longest exact match between a destination number and a group of country codes. For example:
    DESTINATION NUMBER = 005518352XXXXX
    Country Code 0055 is Brazil. But in my country codes group, i've not only 0055, but also all other country codes inside 0055 to distinguise from fixed or mobile destinations (for instance, 005511 (fixed destin), 0055007 (mobile destin) and so on).
    So I want to match to the longest country code in this group. In this case, the longest would be 005518.
    The code i wrote first was this:
    ------------------------------
    if not inRec:
    return False
    dest = inRec['DESTINATION']
    found = False
    i=0
    while not found and i<len(self.destHash):
    prefix = self.destHash[i]
    if dest.startswith(prefix):
    found = True
    rec = self.lookupList[i]
    i = i+1
    outRec = self.outputs[0].newRecord()
    outRec._copyFrom(inRec)
    if found:
    outRec["NIVEL_1"] = rec["NIVEL_1"]
    outRec["NIVEL_2"] = rec["NIVEL_2"]
    outRec["NIVEL_3"] = rec["NIVEL_3"]
    outRec["COSTBAND_ID_RES"] = rec["COSTBAND_ID_RES"]
    outRec["COSTCODE"] = rec["COSTCODE"]
    outRec["COSTCODE_NAME"] = rec["COSTCODE_NAME"]
    outRec["PI-O"] = rec["PI-O"]
    self.outputs[0].write(outRec)
    return True
    ----------------------------------
    But this way, is not returning the longest. Am I doing something wrong? Can someone help me with this subject?

    Best Regards,
    Natanael Moreira


  • 2.  RE: Longest Exact Match

    Employee
    Posted 02-01-2011 10:04

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mgajdosik

    Hi,

    what I did for international number plan match was that I identify the length of the prefixes in number plan first, then split these into multiple outputs and then join the longest one to the data, the orphans are then joined to the 2nd longest etc. see the attached node, it is customer specific, so you may need to remove couple of nodes and update the fieldnames.

    Marek
    Attachments:
    example.brg


  • 3.  RE: Longest Exact Match

    Employee
    Posted 02-01-2011 10:59

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: zon

    Originally posted by: mgajdosik
    					

    Hi,

    what I did for international number plan match was that I identify the length of the prefixes in number plan first, then split these into multiple outputs and then join the longest one to the data, the orphans are then joined to the 2nd longest etc. see the attached node, it is customer specific, so you may need to remove couple of nodes and update the fieldnames.

    Marek
    Thanks Marek. That idea will work for sure.
    But I was trying to use a less object way to do it, using the Python Implementation Node. The code I posted is inside that node. What I really need is to change the python code. Can you help?

    I tried to change it by assign 12 (the longest country code) to variable "i" and change the while statement for "i>2" (because the shortest country code is 3) and "i=i-1".
    I don't know if just by changing that, should work. The way I wright it first, he searches starting with the shortest instead of the longest. This way, maybe it goes the other way around.


  • 4.  RE: Longest Exact Match

    Employee
    Posted 02-02-2011 05:31

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mgajdosik

    You should definitely start with longest matches and get to shortest. As an example dominican republic starts with +1688944 (made up) and if you start with the shortest then you will find match to USA instead of Dominican Rep., which is not right, so I guess just changing order in your script from longest to shortest should bring correct results.


    Marek


  • 5.  RE: Longest Exact Match

    Employee
    Posted 02-16-2011 05:55

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: zon

    I've tried to change the code to this:
    ------------------------------
    if not inRec:
    return False
    dest = inRec['DESTINATION']
    found = False
    i=12
    while not found and i>2:
    prefix = self.destHash[i]
    if dest.startswith(prefix):
    found = True
    rec = self.lookupList[i]
    i = i-1
    outRec = self.outputs[0].newRecord()
    outRec._copyFrom(inRec)
    if found:
    outRec["NIVEL_1"] = rec["NIVEL_1"]
    outRec["NIVEL_2"] = rec["NIVEL_2"]
    outRec["NIVEL_3"] = rec["NIVEL_3"]
    outRec["COSTBAND_ID_RES"] = rec["COSTBAND_ID_RES"]
    outRec["COSTCODE"] = rec["COSTCODE"]
    outRec["COSTCODE_NAME"] = rec["COSTCODE_NAME"]
    outRec["PI-O"] = rec["PI-O"]
    self.outputs[0].write(outRec)
    return True
    ----------------------------------

    But is not working. Have I done something wrong while changing the i value?

    Best Regards,

    ZON


  • 6.  RE: Longest Exact Match

    Employee
    Posted 04-04-2011 10:10

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mgajdosik

    Could you please post the sample data input files along with the python node you try to use?