Question

FME Challenge: Transformer Naming Part II



Show first post

57 replies

Userlevel 2
Badge +17

An experiment for XML lovers :-) This workspace extracts required transformer names and 3-letter codes from the transformers list (txt) using XQuery expressions, and then outputs the result as an HTML table.

[Updated] unique-3-letter-code-to-html-3.fmwt (FME 2017.0)

0684Q00000ArL3lQAF.png

0684Q00000ArL5TQAV.png

You can specify the number of characters per a code via a published user parameter named N.

(: XMLTemplater ROOT Template Expression :)let $s := <s>{fme:process-features("SUB")}</s>let $t := <t>{    for $code in fn:distinct-values({for $x in $s/xformer return $x/@code})    let $names := {for $x in $s/xformer[@code=$code] return $x/@name}    where fn:count($names) eq 1    return <xformer name="{$names[1]}" code="{$code}" />}</t>return <table>    <thead>        <th>No.</th><th>Transformer</th><th>Unique $(N)-Letter Codes</th><th>Count</th>    </thead>    <tbody>{        for $name at $i in fn:distinct-values({for $x in $t/xformer return $x/@name})        let $codes := {for $x in $t/xformer[@name=$name] return $x/@code}        return <tr>            <td>{$i}</td>            <td>{$name}</td>            <td>{fn:string-join($codes, ",")}</td>            <td>{fn:count($codes)}</td>        </tr>        }        <tr>            <td/>            <td/>            <td>Total Number of Unique $(N)-Letter Codes</td>            <td>{fn:count($t/xformer)}</td>        </tr>    </tbody></table>
(: XMLTemplater SUB Template Expression :)let $n := $(N)for $code in fn:distinct-values({    let $src := fn:upper-case(fme:get-attribute("text_line_data"))    for $i in (1 to fn:string-length($src) - $n + 1)    return fn:substring($src, $i, $n),    let $src := fn:replace(fme:get-attribute("text_line_data"), "[a-z]", "")    for $i in (1 to fn:string-length($src) - $n + 1)    return fn:substring($src, $i, $n)})return <xformer name="{fme:get-attribute("text_line_data")}" code="{$code}"/>
Userlevel 2
Badge +17

I created a custom transformer to do that: [2017-07-08 Update: Please see the latest comment]

I updated the custom transformers so that digits [0-9] will be considered as Camel-Case characters.

 

If you have installed the previous custom transformers (ThreeLetterEnumerator, NLetterEntryEnumerator), once delete them from Transformer Gallery, then open this template that contains new implementations.

 

fme-challenge-transformer-naming-part-ii.fmwt

 

Userlevel 4
Badge +13

I am in awe of all of you. Very very impressive.

Userlevel 1
Badge +18

If you allow numbers and also the AutodeskA360Connector trick: 743 codes for 316 unique transformers

challenge3chars.fmwt

Without the AutodeskA360Connector trick :738 codes for 316 unique transformers

challenge3charsii.fmwt

If it's only allowed to have letters: 720 codes for 309 unique transformers

challengeonlyletters.fmwt

All workspaces contain 10 transformers.

Userlevel 4
Badge +25

So a late Saturday evening revision because I just couldn't let it go! I re-read some of the comments and realised I wasn't accounting for numeric values in the unique values. But I had read the following:

 

 

"The challenge is to scan that list and generate as many unique three-letter codes as you can."

 

 

Letters not number otherwise it might have said characters ;)

So my revised new total is 735 unique values containing a mix of numbers and letters, for 316 Transformers @Mark2AtSafe

Good point. I guess I wasn't thinking about numbers when I wrote the challenge. But yes, it should say unique characters.

 

Userlevel 4
Badge +25
This is awesome work everyone. I will check out the results and award prizes when I'm back from vacation in a couple of weeks.

 

 

Userlevel 2
Badge +17

Looks like no one has suggested this approach to enumerate N-characters codes.

[Correction] I missed that this approach has been suggested by @egomm already.

  1. Create N copies of the source string.
  2. Remove leading (N-1) characters from Nth string.
  3. Extract every N-characters substring with the StringSearcher.

fme-challenge-transformer-naming-part-ii-2.fmwt

Something extra:

Reply