Link to home
Start Free TrialLog in
Avatar of Dan Schimo
Dan SchimoFlag for United States of America

asked on

update an existing array of struct with the struct of array

Hello Experts,

i am need of urgent help where i have a array of Struc whose struct element has to updated by the First array of the Struct of arrays.
Attached is the Image of both .
   User generated image
The KEY "V" in the First Dump(array) needs to be replaced by the Second array below it. in such a way that Eg : dissorder in the First array should be replaced by the "Disorder" of the fiirst element in the Array
Avatar of gdemaria
gdemaria
Flag of United States of America image

Your first array structure (in red) is showing two array positions, but you don't say what to do with the 2nd position.  So I have done nothing with it.

This code will look at the V location of the array at position 1 to determin the badword, it will look for the bad word in a structure called Words and take the 1st position from the array that it contains...

<cfset pos= 1>

<cfset badword= data[pos].v>
<cfif structKeyExists(words, badword)>
       <cfset data[pos].v = words[badword][1]>
</cfif>
Perhaps this is what you wanted.

This grabs the misspelled word from the red structure (i called data)
looks for it in the second structure of word suggestions (i called words)

It then replaces the v value of the 1st and 2nd element of the red array with the correctly spelled word....

<cfset badword = data[1].v>
<cfif structKeyExists(words, badword)>
   <cfset goodWord = words[badword][1]>
   <cfset data[1].v = goodWord>
   <cfset data[2].v = replace(data[2].v,goodWord)>
</cfif>
Avatar of Dan Schimo

ASKER

gdemaria

I tried doing this with the actual names of the objects..
 I am getting a "Parameter validation error for the REPLACE function. "
<cfset badword = arguments.searchData.arrCriteria[1].v>
<cfif structKeyExists(correctedTerms, badword)>
   <cfset goodWord = correctedTerms[badword][1]>
   <cfset arguments.searchData.arrCriteria[1].v = goodWord>
   <cfset arguments.searchData.arrCriteria[2].v = replace(arguments.searchData.arrCriteria[2].v,goodWord)>
</cfif>

	<cfdump var="#arguments.searchData.arrCriteria#">

Open in new window


should have been...

   replace(data[2].v,badword,goodWord)>
That works :)  But , the Array Len are not static,

I.e the data array can be any number of rows the sturct in it and also the suggetions (Words) can be of any number of structures. How will we go forward in this case .

We already handle the CorrectedWords part, it doesn't loop, we are simply looking to find the bad word on the list and grab the #1 option of correctedWords, that is done in these two lines...


<cfif structKeyExists(correctedTerms, badword)>
    <cfset goodWord = correctedTerms[badword][1]>


But what about the first structure, in your first example it seems that array position 2 was just an expantion of position 1 (they both were for the same incorrect word).

Can you explain the structure of this array?

Sorry for the Confusion , The position 2 of the First array is not the Expansion . it could be of any number of words

, eg,  first array
 arraypos[2].V = mispeeled Direcktor meerger

then all the 3 words need to be replaced with the reference to the good words struct

<cfloop index="pos" from="1" to="#arrayLen(arguments.searchData.arrCriteria)#">
  <cfset badwordList = arguments.searchData.arrCriteria[pos].v>
  <cfloop index="badWord" list="#badWordList#">
     <cfif structKeyExists(correctedTerms, badword)>
       <cfset goodWord = correctedTerms[badword][1]>
       <cfset arguments.searchData.arrCriteria[pos].v = replace(arguments.searchData.arrCriteria[pos].v,goodWord)>
     </cfif>
  </cfloop>
</cfloop>

Open in new window

User generated image
gdemaria
if you see the screen shot the logic has missed the "dissorder" in the 2 Position of the First array ...
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry but I could get to the Error ,

Attribute validation error for tag CFLOOP.

It does not allow the attribute(s) DELIMITER. The valid attribute(s) are ARRAY,CHARACTERS,CHARSET,COLLECTION,CONDITION,DELIMITERS,ENDROW,FILE,FROM,INDEX,ITEM,LIST,QUERY,STARTROW,STEP,TO.


It does not allow the attribute(s) DELIMITER. The valid attribute(s) are


ARRAY,CHARACTERS,CHARSET,COLLECTION,CONDITION,DELIMITERS,ENDROW,FILE,FROM,INDEX,ITEM,LIST,QUERY,STARTROW,STEP,TO.


Sorry , I didn't get the last bit
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry abt tht I did not pay attanetion to the response...

yes the logic worked...
Thanks for the Help Both gdemaria and _agx
have a gr8 weekend !!