> So here's what to do:
>
> 1. First, describe the code's purpose. Tell us, in a
> sentence or two, what it's supposed to do (i.e. what
> the goal of the program is).
>
> 2. Second, take the code you want to refactor.
>
> a. Make sure it runs properly in J.
>
> b. Ensure the example is stand alone. That is,
> if we type exactly what you post into J, we get
> exactly the same results as you. (So, for
> example, if you depend upon a global name, be
> sure to include the lines that define that
> global name).
>
> c. Include a couple of examples of its use (i.e.
> give us example arguments).
>
> 3. Third, ensure that your mail client doesn't intrude
> again. Right before you hit "send":
>
> a. Highlight the code in the email.
> b. Copy it.
> c. Start a new, fresh J, without any custom
> profile.
> d. Open a new, fresh script window (IJS).
> e. Paste the code.
> f. Run the window.
> g. Confirm you see the desired results.
>
> All this is kind of a hassle, but it does make it easier for us to
> understand your code and help with your problems.
>
> -Dan
>
Thanks a lot for helping me. The problem was with evaluating the condition
and I was able to solve it. I have almost refactored the code, now I have to
put it into loop. But I'll do what You suggest.
The code is used for generating a pseudo language. I have three syllable
frequency matrixes for this purpose. First matrix describes the frequencies
between syllables, eg how many times 'ma' is followed by 'ny'. The second
matrix contains the frequencies between syllable pairs and syllables, eg how
many times 'ge','ne' is followed by 'ra'. And the third matrix contains the
frequencies between syllable triples and syllables, eg how many times 'ge',
'ne', 'ra' is followed by 'te'.
The task is to generate language syllable after syllable, using triple
matrix as much as possible. If this is not possible (because there are huge
amount of triples and only 10000 of them are involved) then use couple
matrix and if this is also impossible then use syllable matrix. For testing
the code, randomly generated smaller matrixes can be used.
NB. Global variables
NB. Frequency matrixes
solos =: ?.10 10 $ 100
pairs =: ?.15 10 $ 100
terns =: ?.20 10 $ 100
NB. Pairs and terns corresponding to frequency matrixes rows
pairsyl =: ?.15 2 $ 10
ternsyl =: ?.20 3 $ 10
NB. Verb for generating the next syllable using the probability, argument is
a list
next =: 13 : '0 i.~(?+/y)>+/\y'
NB. Verb for making the argument for the next generation step from the
already generated text, containing index of triple, index of pair and index
of syllable
assign =: 13 : '((ternsyl i. _3 {. y), (pairsyl i. _2 {. y), {:y)'
NB. Different scenarios for next generation, including selecting the
necessary part from the argument
gen1 =: next@({&terns)@(0&{)
gen2 =: next@({&pairs)@(1&{)
gen3 =: next@({&solos)@(2&{)
NB. Condition for selecting the correct scenario
n =: 20 15 10
cond =: {.@(I.@(-.@(=&n)))
gen =: [EMAIL PROTECTED]
NB. First a triple will be selected randomly
text =: ternsyl {~?20
NB. Then create argument and generate next syllable
text =: text, gen assign text
This last sentence must be done as many times as the user says. How to put
the self assignment into loop?
Kairit Sirts
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm