I don't understand what your purpose is for these lists, but, as they seem
to be aligned with each other, a table would seem a more natural
representation.
For instance:
'whlang translations'=: ({.,&<}.) <;._1&>TAB,&.><;._2]0 : 0
English Svenska
Write your name Skriv ditt namn
Options Inställningar
)
whlang
+-------+-------+
|English|Svenska|
+-------+-------+
translations
+---------------+---------------+
|Write your name|Skriv ditt namn|
+---------------+---------------+
|Options |Inställningar |
+---------------+---------------+
translations{"1~whlang i. <'Svenska'
+---------------+-------------+
|Skriv ditt namn|Inställningar|
+---------------+-------------+
(translations{"1~whlang i. <'English'){~(translations{"1~whlang i.
<'Svenska') i. <'Inställningar'
+-------+
|Options|
+-------+
Encapsulating the logic of this last phrase, incorporating some
error-handling:
translate=: 4 : 0
assert. *./whlang e. x NB. x is from;to language
'from to'=. whlang i. x NB. y is phrase(s) to translate
y=. <^:(0=L.) y
(translations,<'?'){~to,&.>~y i.~translations{"1~from
)
('English';'Svenska') translate 'Options';'Taco'
+-------------+-+
|Inställningar|?|
+-------------+-+
On Fri, May 16, 2014 at 4:01 AM, Raul Miller <[email protected]> wrote:
> I have some questions:
>
> (*) Are you guaranteed that these lists will always be the same length?
>
> (*) Are you guaranteed that the entries will always be in order, with no
> missing values?
>
> (*) Is it possible that your text will have the delimiter (';' in this
> case) in the entries?
>
> (*) Do you care about redundant spaces (for example preceding or following
> the numbers or text)?
>
> (*) Are you in any danger of running out of memory (or disk space or time
> or whatever else) because you have so much data?
>
> Depending on the answers to these questions, you might need a different
> approach. For now, I'll assume answers for them them that makes the code
> the simplest.
>
> But what I think I would do is (a) encapsulate your manipulation logic in a
> verb, (b) use {. and }. with i. instead of cut, to split your lines (that
> way you are guaranteed to always split on the first occurrence of the
> delimiter), and (c) not reassign the variables (because that makes
> understanding and debugging slightly easier, in my opinion).
>
> In other words, given:
>
> ingl=:0 :0
> 1;English
> 2;Write your name
> 3;Options
> )
>
> sved=:0 :0
> 1;Svenska
> 2;Skriv ditt namn
> 3;Inställningar
> )
>
> package=:3 :0
> ';' package y
> :
> (({.~ ; (}.~>:)) i.&x);._2 y
> )
>
> I think I'd do it like this:
>
> (package ingl),. 1}."1 package sved
> ┌─┬───────────────┬───────────────┐
> │1│English │Svenska │
> ├─┼───────────────┼───────────────┤
> │2│Write your name│Skriv ditt namn│
> ├─┼───────────────┼───────────────┤
> │3│Options │Inställningar │
> └─┴───────────────┴───────────────┘
>
> Of course, there are other ways also (and, depending on your answers there
> might be much better ways).
>
> Thanks,
>
> --
> Raul
>
>
>
>
>
>
> On Fri, May 16, 2014 at 3:03 AM, Gian Medri <[email protected]> wrote:
>
> > Hi!
> >
> > I have 2 or more lists of substantives. The lists must be as simple as
> > possible, since they are done
> >
> > by a translator not familiar with computer languages.
> > From the lists I want to get a boxed matrix.
> > The numbers in each line of the list are only for reference purposes,
> > since the lists
> >
> > are normally hundreds of lines. I wonder if there are a better way to
> > solve the problem
> >
> > than in the example.
> >
> >
> >
> > cut=:' '&$: :([: -.&a: <;._2@,~)
> >
> > ingl=.(0 : 0)
> >
> > 1;English
> >
> > 2;Write your name
> >
> > 3;Options
> >
> > )
> >
> > ingl=. > ';' cut each <;._2 ingl
> >
> >
> >
> > sved=. (0 : 0)
> >
> > 1;Svenska
> >
> > 2;Skriv ditt namn
> >
> > 3;Inställningar
> >
> > )
> >
> > sved=.1{"1 > ';' cut each <;._2 sved
> >
> > ]matx=:ingl,.sved
> >
> >
> >
> > ┌─┬───────────────┬───────────────┐
> >
> > │1 │English │Svenska │
> >
> > ├─┼───────────────┼───────────────┤
> >
> > │2 │Write your name │Skriv ditt namn│
> >
> > ├─┼───────────────┼───────────────┤
> >
> > │3 │Options │Inställningar │
> >
> > └─┴───────────────┴───────────────┘
> >
> >
> >
> > Thanks,
> >
> > Gian Medri
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm