Skip to main content
I have a set of shapefiles.  For each project, the shapefile names and the attribution names of the shapefiles are different.  I want a workbench to search the attribution of all shapefiles, for a particular word/term.  For discussion purposes, say I want to find the word 'password'.  I don't really need to do anything with the data, I just need to determine if the 'password' exists in the data anywhere. 

 

 

I've played around with Schema readers and Feature readers, but haven't found a solution yet.  It's almost like I need a way to rename the attribution names to something generic like 'att1', 'att2', 'att3', etc...so that I can run a simple testfilter.  But with the attribution names changing with each dataset, I'm not sure how this would be accomplished.
Hi,

 

 

One possible way I can think of is to use the TclCaller or the PythonCaller.

 

 

This script example for the TclCaller returns 1 when the word "password" exists in attributes of the input feature, otherwise it returns 0. The returned value will be set to an attribute (named "_result" by default).

 

------ proc findParticularWord {} {   set pattern tformat {^(.*\\s)?(%s)(\\s.*)?$} "password"]   foreach name hFME_AttributeNames] {     if { regexp $pattern $FME_GetAttribute $name]]} {       return 1     }   }   return 0 } ------ If there are 2 or more target words, replace "password" with pipe (|) seperated words. e.g. "foo|bar|foobar".   The same processing can be performed using the PythonCaller with this script. ----- import fmeobjects, re   def findParticularWord(feature):     pattern = '^(.*\\\\s)?(%s)(\\\\s.*)?$' % 'password'     result = 0     for name in feature.getAllAttributeNames():         value = str(feature.getAttribute(name)) # note         if re.match(pattern, value):             result = 1             break     feature.setAttribute('_result', result) ----- Note: If attributes can contain "unicode" type string, "str" function may throw an error saying <UnicodeEncodeError>. See here about this issue: PythonCaller: Use logMessageString Problems with Encoding http://fmepedia.safe.com/AnswersQuestionDetail?id=906a0000000coj6AAA

 

 

Takashi
David is right. I missed the AttributeExploder.

 

Thank you for making it notice.

 

 

I think it's efficient to use the AttributeExploder with "List" for "Exploding Type" parameter and concatenate the list elements (ListConcatenator) before the StringSearcher. But I noticed that the AttributeExploder doesn't expose the list name, even if I set "List" to "Exploding Type" (FME 2013 SP4, maybe bug?).

 

If you set "List" type, the AttributeExposer will have to be added to expose the list attribute.
When using the AttributeExploder in list mode, I can't access the list afterwards even with an AttributeExposer.  This seems like a bug to me.  I get the same result in FME 2013SP1 build 13450, and FME2012 build 12212.
I tested in FME 2013 SP4 Build 13547.

 

If I type manually the following list attribute names in "Attributes to Expose" of the AttributeExposer, can get the expected result. These names are default settings of the AttributeExploder, I didn't edit them.

 

_attr_list{}._attr_name

 

_attr_list{}._attr_value

 


Thank you...that worked well.
If you use the AttributeExploder in List mode, the ListSearchear (Search Type: First regular expression match) can be also used to search attribute having the particular word.
oops, there is a bug on the ListSearcher with regular expression... ListSearcher cannot handle the regular Expression "^1$|^9$|^10$" http://fmepedia.safe.com/articles/Error_Unexpected_Behavior/ListSearcher-cannot-handle-regular-Expression

Reply