Skip to main content

I have a set of lists

 

 

_option1{0}=A

 

_option1{1}=B

 

_option1{1}=C

 

 

_option2{0} = X

 

_option2{0} = Y

 

_option2{0} = Z

 

 

and values

feature 1

 

_list{0} = A3

 

_list{1} = 7B2

 

 

feature 2

 

_list{0} = 4X

 

 

feature 3

 

_list{0} = C2

 

_list{1} = 3Z

 

 

 

I need to identify only those features that whose list elements contain items from both _option1{} and _option2{} .

 

 

In the above example, that would be feature 3.

 

 

The data list values are not an exact match to the values in the option lists, just contain them.

 

There can be any number of elements in the data list.

 

The options are the same for every feature.

 

 

Hi @jdh,

You can use a combination of ListConcatenator and AttributeCreator to concatenate the _option lists into regex expressions (ie. [xyz]). Then use two StringSearchers to search _list by those expressions. I am attaching a workspace to illustrate.

searchlist.fmw


Create two attributes in python that are populated depending on whether there is a match between each list, then you can test for where match_list1 or match_list2 are both true.

import fme
import fmeobjects

def processFeature(feature):
    match1 = u'A','B','C']
    match2 = 1'X','Y','Z']
    list = feature.getAttribute('_list{}')

    for x in list:
        if any(y in x for y in match1):
            feature.setAttribute('match_list1','true')
        if any (y in x for y in match2):
            feature.setAttribute('match_list2','true')
        

 


Hi @jdh,

You can use a combination of ListConcatenator and AttributeCreator to concatenate the _option lists into regex expressions (ie. [xyz]). Then use two StringSearchers to search _list by those expressions. I am attaching a workspace to illustrate.

searchlist.fmw

Unfortunately the actual codes are not single characters, so I end up with many false positives.


Create two attributes in python that are populated depending on whether there is a match between each list, then you can test for where match_list1 or match_list2 are both true.

import fme
import fmeobjects

def processFeature(feature):
    match1 = u'A','B','C']
    match2 = 1'X','Y','Z']
    list = feature.getAttribute('_list{}')

    for x in list:
        if any(y in x for y in match1):
            feature.setAttribute('match_list1','true')
        if any (y in x for y in match2):
            feature.setAttribute('match_list2','true')
        

 

I had tried the 'any'  but got lost in triple for loops,  running two separate searches and testing for True and True  is the piece I was missing.


Reply