Take a look at mapped file database
Lab: Mapped Files Database
To advance the lab, select menu Studio|Advance or the
corresponding shortcut.
-- (1 of 42) Mapped File Database ---------------------------
-- (10 of 42) Mapped File Database (ctd) --------------------
Every field has a format verb of the form field...
)
sample=: ?.5$ROWS NB. 5 random rows
sample{lic NB. numeric encoding of license plates
1099312 1335802 1116512 1425816 1189866
licfmt sample NB. formatted lic values
+-------+
|21EE423|
|244AD13|
|222BA23|
|253AD2B|
|22DEDBB|
+-------+
licfmt
3 : '<(10 10 10 10 10 10 10#:y{lic){LICVALS'
sample
906146 535755 22079 612852 42854
2010/2/19 Alex Rufon <[email protected]>:
> I know I've been on this path before but how did you guys do the conversion
> from string to numbers (and vice versa) in APL? Can we replicated this in J?
>
> Right now, I'm doing this by making a global vector of unique strings I've
> encountered.
> DICTIONARY_z_ =: < every a.
>
> search=: verb define
> data=. , boxopen y.
> DICTIONARY_z_=: ~. DICTIONARY_z_,data
> DICTIONARY_z_ i. boxopen y.
> )
>
> NB. boxopen is defined as:
> NB. boxopen=: <^:(L. = 0:)
>
>
> NB. Sample string data
> [data=. (;: 'aa c3 d5 ae af ax ac ee'),<'The answer is 42'
> +--+--+--+--+--+--+--+--+----------------+
> |aa|c3|d5|ae|af|ax|ac|ee|The answer is 42|
> +--+--+--+--+--+--+--+--+----------------+
>
> NB. Test data is 2 dimensions
> [testdata=. 8 3 $ data
> +--+--+----------------+
> |aa|c3|d5 |
> +--+--+----------------+
> |ae|af|ax |
> +--+--+----------------+
> |ac|ee|The answer is 42|
> +--+--+----------------+
> |aa|c3|d5 |
> +--+--+----------------+
> |ae|af|ax |
> +--+--+----------------+
> |ac|ee|The answer is 42|
> +--+--+----------------+
> |aa|c3|d5 |
> +--+--+----------------+
> |ae|af|ax |
> +--+--+----------------+
>
> NB. Numeric equivalent of the strings
> [asnumbers=. search testdata
> 265 257 258
> 266 267 268
> 269 263 264
> 265 257 258
> 266 267 268
> 269 263 264
> 265 257 258
> 266 267 268
>
> NB. Check if the numbers convert to strings
> asnumbers { DICTIONARY
> +--+--+----------------+
> |aa|c3|d5 |
> +--+--+----------------+
> |ae|af|ax |
> +--+--+----------------+
> |ac|ee|The answer is 42|
> +--+--+----------------+
> |aa|c3|d5 |
> +--+--+----------------+
> |ae|af|ax |
> +--+--+----------------+
> |ac|ee|The answer is 42|
> +--+--+----------------+
> |aa|c3|d5 |
> +--+--+----------------+
> |ae|af|ax |
> +--+--+----------------+
>
> NB. Switch the columns
> DICTIONARY {~ 1 2 1 { "1 asnumbers
> +--+----------------+--+
> |c3|d5 |c3|
> +--+----------------+--+
> |af|ax |af|
> +--+----------------+--+
> |ee|The answer is 42|ee|
> +--+----------------+--+
> |c3|d5 |c3|
> +--+----------------+--+
> |af|ax |af|
> +--+----------------+--+
> |ee|The answer is 42|ee|
> +--+----------------+--+
> |c3|d5 |c3|
> +--+----------------+--+
> |af|ax |af|
> +--+----------------+--+
>
> NB. Only get rows that's equal to 'aa' in the first column
> [akey=. search 'aa'
> 265
> [arows=. akey = {. "1 asnumbers
> 1 0 0 1 0 0 1 0
> DICTIONARY {~ arows # asnumbers
> +--+--+--+
> |aa|c3|d5|
> +--+--+--+
> |aa|c3|d5|
> +--+--+--+
> |aa|c3|d5|
> +--+--+--+
>
> NB. Or simply
> DICTIONARY {~ asnumbers #~ (search 'aa') = {. "1 asnumbers
> +--+--+--+
> |aa|c3|d5|
> +--+--+--+
> |aa|c3|d5|
> +--+--+--+
> |aa|c3|d5|
> +--+--+--+
>
> As you can see, it works. But I'm curious if there is another (better?) was
> to do it. The only requirement is that the numbers generated can be processed
> to get the original strings.
>
> Thanks.
>
> r/Alex
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On
> Behalf Of Björn Helgason
> Sent: Wednesday, February 17, 2010 5:59 PM
> To: Chat forum
> Subject: Re: [Jchat] Multiple cores
>
> 2010/2/17 Alex Rufon <[email protected]>:
>> But I'm still transferring and loading a lot of data on the sub processes
>> and this is when I got this idea of converting strings to numbers.
>
> It was/is a common practice in APL to convert strings to numbers and
> work with the numbers (integers) until you needed to present the
> results in human readable form.
>
> There are huge databases built every night at many companies building
> such inverted databases to work on with APL systems.
>
> The APL inverted processes built this way are very fast and worth the
> slow processes doing the inversion.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Björn Helgason, Verkfræðingur
Fornustekkum II
781 Hornafirði
Po Box 127,801 Selfoss ,
t-póst: [email protected]
gsm: +3546985532
sími: +3544781286
http://groups.google.com/group/J-Programming
Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
góður kennari getur stigið á tær án þess að glansinn fari af skónum
/|_ .-----------------------------------.
,' .\ / | Með léttri lund verður |
,--' _,' | Dagurinn í dag |
/ / | Enn betri en gærdagurinn |
( -. | `-----------------------------------'
| ) | (\_ _/)
(`-. '--.) (='.'=) ♖♘♗♕♔♙
`. )----' (")_(") ☃☠
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm