Discussion:
Creating Array - Auto Numeric
Sannyasin Brahmanathaswami via use-livecode
2018-09-18 15:41:19 UTC
Permalink
My head always breaks on complex array functions. I can't head around
this algorithm

Given a "quote" in a field

"Cut the apple. Cut the banana"

We get to location for each word (that is easy)

I want to analyse the quote by going through each word.

*----------*

*repeat* withx = 1tothenumberofwordsoffld"_quote"

# get the location of the word, put it into variable tWordLocation

put tWordLocation to the WordLocationA[x][??][tWordLocation]

end repeat

-------

that we end with

WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][2][500,320]
WordLocationA["banana"][2][500,320]

the "part" where incrementing the numeric key inside the repeat loop,
"inside" the key, I can't get.

BR
dunbarxx via use-livecode
2018-09-18 16:44:33 UTC
Permalink
Hi.

Is this what you want?

on mouseUp
repeat with y = 1 to the number of words of fld 1
select word y of fld 1
put the selectedLoc into wordLocationA[y][word y of fld 1]
end repeat
end mouseUp

I suspect not. Is it that you want the output to be:

WordLocationA["Cut"][100,320]
WordLocationA["the"][1][200,320]
WordLocationA["apple"][500,320]
WordLocationA["Cut"][300,320]
WordLocationA["the"][400,320]
WordLocationA["banana"][500,320]

If so, why use an array? Just:

on mouseUp
repeat with y = 1 to the number of words of fld 1
select word y of fld 1
put word y of fld 1 &","& the selectedLoc & return after locList
end repeat
end mouseUp

Craig Newman




--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html
dunbarxx via use-livecode
2018-09-18 16:47:31 UTC
Permalink
Also, be careful. The string:

"Cut the apple. Cut the banana"

contains only one word.

Craig



--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html
Klaus major-k via use-livecode
2018-09-18 16:49:46 UTC
Permalink
Hi Craig,
Post by Sannyasin Brahmanathaswami via use-livecode
"Cut the apple. Cut the banana"
contains only one word.
true, but also contains 6 TRUEWORDS! :-)
Post by Sannyasin Brahmanathaswami via use-livecode
Craig
Best

Klaus

--
Klaus Major
http://www.major-k.de
***@major-k.de
Tore Nilsen via use-livecode
2018-09-18 17:14:39 UTC
Permalink
You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.

Best regards
Tore Nilsen
Post by Sannyasin Brahmanathaswami via use-livecode
My head always breaks on complex array functions. I can't head around
this algorithm
Given a "quote" in a field
"Cut the apple. Cut the banana"
We get to location for each word (that is easy)
I want to analyse the quote by going through each word.
*----------*
*repeat* withx = 1tothenumberofwordsoffld"_quote"
# get the location of the word, put it into variable tWordLocation
put tWordLocation to the WordLocationA[x][??][tWordLocation]
end repeat
-------
that we end with
WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][2][500,320]
WordLocationA["banana"][2][500,320]
the "part" where incrementing the numeric key inside the repeat loop,
"inside" the key, I can't get.
BR
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Sannyasin Brahmanathaswami via use-livecode
2018-09-18 21:15:41 UTC
Permalink
Post by Tore Nilsen via use-livecode
You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.
Best regards
Tore Nilsen
Sannyasin Brahmanathaswami via use-livecode
2018-09-18 22:01:54 UTC
Permalink
Tore, must be talking about different things.

fld "tQuote" =

Cut the apple. Cut the banana.


I CAN manually create what we need

*on*mouseup

* put*"100,320"intoWordLocationsA["Cut"][1]

* put*"300,320"intoWordLocationsA["Cut"][2]

* put*"200,320"intoWordLocationsA["the"][1]

* put*"400,320"intoWordLocationsA["the"][2]

* put*"500,320"intoWordLocationsA["apple"][1]

* put*"700,320"intoWordLocationsA["banana"][1]

* put*thekeysofWordLocationsA

*end*mouseup


Craig has almost got it


*on*mouseUp

* repeat* withy = 1tothenumberofwordsoffld"tQuote"

* put*wordy offld"tQuote"intotWord

* select*wordy offldtQuote

* put*theselectedLocintowordLocationA[tWord][x]

* end* *repeat*

*end*mouseUp

# how to get "x" to increment? but only by each key in the array?

*on*mouseup

* repeat* withy = 1tothenumberofwordsoffld"tQuote"

* select*wordy offld"tQuote"

* put*wordy offld"tQuote"&"|"& theselectedLoc& crafterwordLocationsA

* end* *repeat*

* delete*char-1 ofwordLocationsA

* split*wordLocationsA bycrand"|"

* put*thekeysofwordLocationsA intofld"result"

*end*mouseUp

#only on location is saved (of course)
Post by Tore Nilsen via use-livecode
You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.
Best regards
Tore Nilsen
Post by Sannyasin Brahmanathaswami via use-livecode
My head always breaks on complex array functions. I can't head around
this algorithm
Given a "quote" in a field
"Cut the apple. Cut the banana"
We get to location for each word (that is easy)
I want to analyse the quote by going through each word.
*----------*
*repeat* withx = 1tothenumberofwordsoffld"_quote"
# get the location of the word, put it into variable tWordLocation
put tWordLocation to the WordLocationA[x][??][tWordLocation]
end repeat
-------
that we end with
WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][2][500,320]
WordLocationA["banana"][2][500,320]
the "part" where incrementing the numeric key inside the repeat loop,
"inside" the key, I can't get.
BR
Tore Nilsen via use-livecode
2018-09-18 22:14:24 UTC
Permalink
We are not talking about different things, but the same thing from different angles. I misinterpreted what you wanted to do from your example. What you do manually is creating an associative array with a numeric array as the values for each key in the associative array, which should work well. I should learn to read before I write, just as I should learn to listen for the questions before I give the answers. My students have told me as much, more than once! :-)


Best Regards
Tore
Post by Sannyasin Brahmanathaswami via use-livecode
Tore, must be talking about different things.
fld "tQuote" =
Cut the apple. Cut the banana.
I CAN manually create what we need
*on*mouseup
* put*"100,320"intoWordLocationsA["Cut"][1]
* put*"300,320"intoWordLocationsA["Cut"][2]
* put*"200,320"intoWordLocationsA["the"][1]
* put*"400,320"intoWordLocationsA["the"][2]
* put*"500,320"intoWordLocationsA["apple"][1]
* put*"700,320"intoWordLocationsA["banana"][1]
* put*thekeysofWordLocationsA
*end*mouseup
Craig has almost got it
*on*mouseUp
* repeat* withy = 1tothenumberofwordsoffld"tQuote"
* put*wordy offld"tQuote"intotWord
* select*wordy offldtQuote
* put*theselectedLocintowordLocationA[tWord][x]
* end* *repeat*
*end*mouseUp
# how to get "x" to increment? but only by each key in the array?
*on*mouseup
* repeat* withy = 1tothenumberofwordsoffld"tQuote"
* select*wordy offld"tQuote"
* put*wordy offld"tQuote"&"|"& theselectedLoc& crafterwordLocationsA
* end* *repeat*
* delete*char-1 ofwordLocationsA
* split*wordLocationsA bycrand"|"
* put*thekeysofwordLocationsA intofld"result"
*end*mouseUp
#only on location is saved (of course)
Post by Tore Nilsen via use-livecode
You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.
Best regards
Tore Nilsen
Post by Sannyasin Brahmanathaswami via use-livecode
My head always breaks on complex array functions. I can't head around
this algorithm
Given a "quote" in a field
"Cut the apple. Cut the banana"
We get to location for each word (that is easy)
I want to analyse the quote by going through each word.
*----------*
*repeat* withx = 1tothenumberofwordsoffld"_quote"
# get the location of the word, put it into variable tWordLocation
put tWordLocation to the WordLocationA[x][??][tWordLocation]
end repeat
-------
that we end with
WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][2][500,320]
WordLocationA["banana"][2][500,320]
the "part" where incrementing the numeric key inside the repeat loop,
"inside" the key, I can't get.
BR
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
J. Landman Gay via use-livecode
2018-09-18 22:57:09 UTC
Permalink
Post by Sannyasin Brahmanathaswami via use-livecode
# how to get "x" to increment? but only by each key in the array?
Okay, try this:

put fld 1 into tQuote
repeat with x = 1 to the number of truewords in tQuote
put the number of lines in keys(tWordLocationA[trueword x of
tQuote])+1 into tNum
put tWordLocation into tWordLocationA[trueword x of
tQuote][tNum][tWordLocation]
end repeat
--
Jacqueline Landman Gay | ***@hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Alex Tweedly via use-livecode
2018-09-18 23:59:45 UTC
Permalink
or,


   repeat for each trueword X in tQuote
      put (item 2 of the extents of tWordLocationA[X]) + 1 into t1
      put tWordLocation into tWordLocationA[X][t1]
   end repeat

Alex
Post by Sannyasin Brahmanathaswami via use-livecode
# how to get "x" to increment? but only by each key in the array?
  put fld 1 into tQuote
  repeat with x = 1 to the number of truewords in tQuote
    put the number of lines in keys(tWordLocationA[trueword x of
tQuote])+1 into tNum
    put tWordLocation into tWordLocationA[trueword x of
tQuote][tNum][tWordLocation]
  end repeat
Sannyasin Brahmanathaswami via use-livecode
2018-11-21 09:17:15 UTC
Permalink
On 9/18/18 7:15 AM, Tore Nilsen via use-livecode wrote:

You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.

Best regards
Tore Nilsen

But each these is unique

WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][1][500,320]
WordLocationA["banana"][1][500,320]

We may not be on the same page.

I can create a json file that export

J. Landman Gay via use-livecode
2018-09-18 21:42:48 UTC
Permalink
Post by Sannyasin Brahmanathaswami via use-livecode
I want to analyse the quote by going through each word.
*----------*
*repeat* withx = 1tothenumberofwordsoffld"_quote"
# get the location of the word, put it into variable tWordLocation
put tWordLocation to the WordLocationA[x][??][tWordLocation]
end repeat
-------
that we end with
WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][2][500,320]
WordLocationA["banana"][2][500,320]
I think this will get you close:

put fld 1 into tQuote
repeat with x = 1 to the number of truewords in tQuote
put tWordLocation into tWordLocationA[trueword x of
tQuote][x][tWordLocation]
end repeat

You could count word instances incrementally with more scripting, but
this short way gives you something similar. It stores the word position
to get this:

tWordLocationA["Cut"][1][100,320]
tWordLocationA["Cut"][4][300,320]
tWordLocationA["the"][2][200,320]
tWordLocationA["the"][5][400,320]
tWordLocationA["apple"][3][500,320]
tWordLocationA["banana"][6][500,320]

If you do want an incremental word count, check the number of elements
in each array key and add 1 to it instead of using "x" as the counter
when filling the array.
--
Jacqueline Landman Gay | ***@hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Richard Gaskin via use-livecode
2018-09-19 01:48:38 UTC
Permalink
When solving a problem with a given data structure makes your head hurt,
that may be an indication that your head's fine and the problem is with
the data structure. :)

Can you tell us a bit more about your goal with this?

In your example output, if we look at this line:

WordLocationA["Cut"][1][100,320]

What do these numbers signify?

And what will you be doing with this index once you have it?
--
Richard Gaskin
Fourth World Systems
Post by Sannyasin Brahmanathaswami via use-livecode
My head always breaks on complex array functions. I can't head around
this algorithm
Given a "quote" in a field
"Cut the apple. Cut the banana"
We get to location for each word (that is easy)
I want to analyse the quote by going through each word.
*----------*
*repeat* withx = 1tothenumberofwordsoffld"_quote"
# get the location of the word, put it into variable tWordLocation
put tWordLocation to the WordLocationA[x][??][tWordLocation]
end repeat
-------
that we end with
WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][2][500,320]
WordLocationA["banana"][2][500,320]
the "part" where incrementing the numeric key inside the repeat loop,
"inside" the key, I can't get.
Sannyasin Brahmanathaswami via use-livecode
2018-09-19 02:23:04 UTC
Permalink
Well Alex won with "extents"

in fact while he wrote that, I was in the User look at extents.'



Jacque does that some thing..

put the number of lines in keys

USE CASE

Jacque and created a puzzle together, it take quotes of various lengths,
creates image tiles of the words. Each tile has a customprop "uHomeLoc"
that has the location where it wants to be placed. It uHome is set to false.
The user drags the tile.
Close to home it snaps into place and its "uHome" is set true. It cannot move anter that.

That problem is a sentence having say "and" three times.

Each "and" can only "go home" in one location.
This is frustrating to users.

Say we need to tell this tile "and" that "any one of these location will serve as home"

I may end up switch to jacque model, which is to make "tile" be little fields,
one of each word.

But I use can the code for "images as tile" for to another game,
which is putting picture together.

BR
Post by Richard Gaskin via use-livecode
When solving a problem with a given data structure makes your head hurt,
that may be an indication that your head's fine and the problem is with
the data structure. :)
Can you tell us a bit more about your goal with this?
WordLocationA["Cut"][1][100,320]
What do these numbers signify?
And what will you be doing with this index once you have it?
--
Svasti Astu, Be Well!
Brahmanathaswami

Get the SivaSiva app, it's free:
https://www.himalayanacademy.com/apps/sivasiva
J. Landman Gay via use-livecode
2018-09-19 06:11:02 UTC
Permalink
I always forget about "extents". I like concise code, Alex wins. :)


--
Jacqueline Landman Gay | ***@hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
On September 18, 2018 9:25:02 PM Sannyasin Brahmanathaswami via
Post by Sannyasin Brahmanathaswami via use-livecode
Well Alex won with "extents"
Bob Sneidar via use-livecode
2018-09-19 23:15:35 UTC
Permalink
I was going to say something similar, but thought better of it. Sometimes you need to step back and ask yourself, "What exactly am I trying to do here", or a better question is, "How do I get from where I am to where I want to be (in terms of the data) with the least amount of fuss?"

Bob S
When solving a problem with a given data structure makes your head hurt, that may be an indication that your head's fine and the problem is with the data structure. :)
Sannyasin Brahmanathaswami via use-livecode
2018-09-20 01:39:39 UTC
Permalink
It my case it was "ignorance about arrays" that may my head hurt.

It would nice if the dictionary's "associations" include every keyword
related.

For example, search on array"

One find zero reference to

extents

But I found them the user guide
1) Chapter on Arrays
2) Section on Processing Text and Data
-- using arrays we can find out about:

combine
intersects
add
delete variable
divide
keys
element
matrix multiply
split
sum
tranpose
union

to keep it simple those could "Related" under

Associative Array.

( If there lesson on how to contribute to the dictionary?)
Post by Bob Sneidar via use-livecode
I was going to say something similar, but thought better of it. Sometimes you need to step back and ask yourself, "What exactly am I trying to do here", or a better question is, "How do I get from where I am to where I want to be (in terms of the data) with the least amount of fuss?"
Bob S
When solving a problem with a given data structure makes your head hurt, that may be an indication that your head's fine and the problem is with the data structure. :)
--
Svasti Astu, Be Well!
Brahmanathaswami

Get the SivaSiva app, it's free:
https://www.himalayanacademy.com/apps/sivasiva
Loading...