Dan Schimo
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 .
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
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 .
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
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>
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>
ASKER
gdemaria
I tried doing this with the actual names of the objects..
I am getting a "Parameter validation error for the REPLACE function. "
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#">
should have been...
replace(data[2].v,badword,goodWord)>
ASKER
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 .
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(correctedT
<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?
ASKER
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
, 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>
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,C OLLECTION, CONDITION, DELIMITERS ,ENDROW,FI LE,FROM,IN DEX,ITEM,L IST,QUERY, STARTROW,S TEP,TO.
Attribute validation error for tag CFLOOP.
It does not allow the attribute(s) DELIMITER. The valid attribute(s) are ARRAY,CHARACTERS,CHARSET,C
It does not allow the attribute(s) DELIMITER. The valid attribute(s) are
ARRAY,CHARACTERS,CHARSET,C
ASKER
Sorry , I didn't get the last bit
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry abt tht I did not pay attanetion to the response...
yes the logic worked...
yes the logic worked...
ASKER
Thanks for the Help Both gdemaria and _agx
have a gr8 weekend !!
have a gr8 weekend !!
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>