Dan Schimo
asked on
Coldfusion Create the Structure of Arrays with a Distinct suggestions Words
Hello Experts!
During one of my request for help , I have asked for a logic to convert an xml to Struct of arrays and it was very helpful ...
Related Question
Now we need an update the logic to contain ONLY DISTINCT values in the ARRAY
Please help ...
<suggestions elapsed-time="PT0.010333S" >
<term original="dissorder">
<suggestion levenschtein-dist="1">Diso rder</sugg estion>
<suggestion levenschtein-dist="1">diso rder</sugg estion>
<suggestion levenschtein-dist="2">Diso rders</sug gestion>
<suggestion levenschtein-dist="2">diso rders</sug gestion>
<suggestion levenschtein-dist="2">dist orter</sug gestion>
</term>
<term original="sleep">
<suggestion levenschtein-dist="0">Slee p</suggest ion>
<suggestion levenschtein-dist="0">slee p</suggest ion>
<suggestion levenschtein-dist="1">asle ep</sugges tion>
<suggestion levenschtein-dist="1">seep </suggesti on>
<suggestion levenschtein-dist="1">slee ps</sugges tion>
</term>
</suggestions>
During one of my request for help , I have asked for a logic to convert an xml to Struct of arrays and it was very helpful ...
Related Question
Now we need an update the logic to contain ONLY DISTINCT values in the ARRAY
Please help ...
<suggestions elapsed-time="PT0.010333S"
<term original="dissorder">
<suggestion levenschtein-dist="1">Diso
<suggestion levenschtein-dist="1">diso
<suggestion levenschtein-dist="2">Diso
<suggestion levenschtein-dist="2">diso
<suggestion levenschtein-dist="2">dist
</term>
<term original="sleep">
<suggestion levenschtein-dist="0">Slee
<suggestion levenschtein-dist="0">slee
<suggestion levenschtein-dist="1">asle
<suggestion levenschtein-dist="1">seep
<suggestion levenschtein-dist="1">slee
</term>
</suggestions>
<cfset terms = xmlSearch(xmlfile, "/suggestions/term")>
<cfset results = structNew()>
<cfloop array="#terms#" index="term">
<cfset zeroLev = xmlSearch(term, "*[@levenschtein-dist='0']")>
<cfif ArrayLen(zeroLev) EQ 0 >
<cfset key = term.XmlAttributes.original >
<cfset results[key] = []>
<cfloop array="#term.xmlChildren#" index="child">
<cfset arrayAppend(results[key], child.xmlText)>
</cfloop>
</cfif>
</cfloop>
Create-Struct-array-from-XML.jpg
CF8 or CF9? Also is it important to maintain the order of the array?
ASKER
Cf8
ASKER
Cf8 , yes order of the array is important as I am assigning the 1st word in the array as an suggestion
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> CF has arrayFind. But in CF8 you have to do it the long way.
Correction: CF9 has arrayFind ...
Correction: CF9 has arrayFind ...
ASKER
Works Like a Charm as usual , Could you please shed some light on the chr(7) used in the Code . If you have got some Time....
--Thanks
-Dan.S
--Thanks
-Dan.S
Sure. With list functions you must pick a delimiter that doesn't appear within the data or you get the wrong results. chr(7) is the non-printable bell character. It's very unlikely it'll appear in your data. So it makes a pretty safe delimiter.