January 05, 2018
On Friday, 5 January 2018 at 17:59:32 UTC, thedeemon wrote:
>     Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of tuples

Sorry, I meant tuple of arrays, of course.
January 06, 2018
On Friday, 5 January 2018 at 18:00:34 UTC, thedeemon wrote:
> On Friday, 5 January 2018 at 17:59:32 UTC, thedeemon wrote:
>>     Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of tuples
>
> Sorry, I meant tuple of arrays, of course.

Hi Deemon,

 Thank you very much, I tested your code, initially the code did not produce the expected output, and found an issue in the the key line of code as below, after updating the output was as expected. Can you please let me know how to change the array from standard array to container array.

auto ks = col.map!(v => col.countUntil(v)).array; // Your code(col.countUntil)
auto ks = col.map!(v => vals.countUntil(v)).array; // Changed code(vals.countUntil)

From,
Vino.B
January 06, 2018
On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:
> On Friday, 5 January 2018 at 18:00:34 UTC, thedeemon wrote:
>> On Friday, 5 January 2018 at 17:59:32 UTC, thedeemon wrote:
>>>     Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of tuples
>>
>> Sorry, I meant tuple of arrays, of course.
>
> Hi Deemon,
>
>  Thank you very much, I tested your code, initially the code did not produce the expected output, and found an issue in the the key line of code as below, after updating the output was as expected. Can you please let me know how to change the array from standard array to container array.
>
> auto ks = col.map!(v => col.countUntil(v)).array; // Your code(col.countUntil)
> auto ks = col.map!(v => vals.countUntil(v)).array; // Changed code(vals.countUntil)
>
> From,
> Vino.B

Hi Deemon,

Was able to convert 50% of the code to container array and facing some issue

import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta: AliasSeq;
import std.container.array;

alias ColumnTypes = AliasSeq!(string, string, int);
alias Arr(T) = Array!T;

auto readData() {
auto file = File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\TColRead.csv", "r");
Arr!(Tuple!ColumnTypes) res;
foreach (record; file.byLineCopy.joiner("\n").csvReader!(Tuple!ColumnTypes))
	{ res.insertBack(record); }	
return tuple(res[]);   // replace this line with writeln(res[]); gives the expected output
}

auto compress(T)(Array!T col) {
	Arr!int ks; Array!T vals;
    vals.insertBack(sort(col.dup[]).uniq);
	ks.insertBack(col.map!(v => vals.countUntil(v)));
	return tuple(vals, ks);
}

void main() {
   auto columns = readData();
   foreach(i, ColT; ColumnTypes) {               //Facing some issue at this point
		auto vk = compress(columns[i]);
		writeln(vk[0][], vk[1][]);
	}
}


From,
Vino.B

January 06, 2018
On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:
> On Friday, 5 January 2018 at 18:00:34 UTC, thedeemon wrote:
>> On Friday, 5 January 2018 at 17:59:32 UTC, thedeemon wrote:
>>>     Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of tuples
>>
>> Sorry, I meant tuple of arrays, of course.
>
> Hi Deemon,
>
>  Thank you very much, I tested your code, initially the code did not produce the expected output, and found an issue in the the key line of code as below, after updating the output was as expected. Can you please let me know how to change the array from standard array to container array.

Here's a version with Array, it's very similar:

import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta;
import std.file : readText;
import std.container.array;

alias ColumnTypes = AliasSeq!(string, string, int);

auto readData(string fname) { // returns tuple of Arrays
    Tuple!( staticMap!(Array, ColumnTypes) ) res;
    foreach (record; fname.readText.csvReader!(Tuple!ColumnTypes)('\t'))
        foreach(i, T; ColumnTypes)
            res[i].insert(record[i]);
    return res;
}

auto compress(T)(ref Array!T col) {
    auto vals = Array!T( sort(col.dup[]).uniq );
    auto ks = Array!ptrdiff_t( col[].map!(v => vals[].countUntil(v)) );
    return tuple(vals, ks);
}

void main() {
    auto columns = readData("data.csv");
    foreach(i, ColT; ColumnTypes) {
        auto vk = compress(columns[i]);
        writeln(vk[0][]); //output data,   you can write files here
        writeln(vk[1][]); //output indices
    }
}

January 07, 2018
On Saturday, 6 January 2018 at 15:32:14 UTC, thedeemon wrote:
> On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:
>> [...]
>
> Here's a version with Array, it's very similar:
>
> import std.algorithm: countUntil, joiner, sort, uniq, map;
> import std.csv: csvReader;
> import std.stdio: File, writeln;
> import std.typecons: Tuple, tuple;
> import std.meta;
> import std.file : readText;
> import std.container.array;
>
> [...]

Hi Deemon,

 Thank you very much, moving to second phase.

From,
Vino.B
January 07, 2018
On Sunday, 7 January 2018 at 12:09:32 UTC, Vino wrote:
> On Saturday, 6 January 2018 at 15:32:14 UTC, thedeemon wrote:
>> On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:
>>> [...]
>>
>> Here's a version with Array, it's very similar:
>>
>> import std.algorithm: countUntil, joiner, sort, uniq, map;
>> import std.csv: csvReader;
>> import std.stdio: File, writeln;
>> import std.typecons: Tuple, tuple;
>> import std.meta;
>> import std.file : readText;
>> import std.container.array;
>>
>> [...]
>
> Hi Deemon,
>
>  Thank you very much, moving to second phase.
>
> From,
> Vino.B

Hi Deemon,

 Just noticed that the output writes the data and key as 2 values , but the requirnment is to write to six files, e.g

Data File 1
["Baker", "John", "Johnson", "Jones", "Miller", "Millers", "Millman", "Zsuwalski"]

Key File 1
[4, 1, 6, 7, 0, 4, 3, 4, 2, 1, 6, 5]

Data File 2
["America", "Austrilia", "Canada", "Chile", "China", "India", "Japan", "Netherlands"]

Key File 2
[0, 5, 1, 6, 4, 2, 1, 5, 7, 0, 4, 3]

Data File 3
[18, 21, 23, 42, 45]

Key File 3
[2, 3, 1, 4, 4, 2, 0, 1, 3, 3, 3, 2]

From,
Vino.B
January 07, 2018
On Sunday, 7 January 2018 at 12:59:10 UTC, Vino wrote:
>  Just noticed that the output writes the data and key as 2 values , but the requirnment is to write to six files, e.g

That's the part you can implement yourself. Just replace those writelns with writing to corresponding files.
January 07, 2018
On Sunday, 7 January 2018 at 17:23:20 UTC, thedeemon wrote:
> On Sunday, 7 January 2018 at 12:59:10 UTC, Vino wrote:
>>  Just noticed that the output writes the data and key as 2 values , but the requirnment is to write to six files, e.g
>
> That's the part you can implement yourself. Just replace those writelns with writing to corresponding files.

HI Deemon,

 I tried to manipulate the writeln's as below but the output is not as expected as it prints the data in row wise, where as we need it in column wise.

writeln(vk[0][0]);

Baker
America
18

From,
Vino.B
January 08, 2018
On Sunday, 7 January 2018 at 17:30:26 UTC, Vino wrote:

>  I tried to manipulate the writeln's as below but the output is not as expected as it prints the data in row wise, where as we need it in column wise.

You've said before you need 6 different files, not some tables.
Also, after the "compression" data columns will have different length. How exactly do you want to combine them into a table?
January 08, 2018
On Monday, 8 January 2018 at 05:38:44 UTC, thedeemon wrote:
> On Sunday, 7 January 2018 at 17:30:26 UTC, Vino wrote:
>
>>  I tried to manipulate the writeln's as below but the output is not as expected as it prints the data in row wise, where as we need it in column wise.
>
> You've said before you need 6 different files, not some tables.
> Also, after the "compression" data columns will have different length. How exactly do you want to combine them into a table?

Hi Deemon,

  The output required is like this,

(1) Read a table data form the csv file

John, America,23
John, India, 22
Astro, Canada, 21

2) Sort and remove the duplicates from each column by column

Take a copy of each column and sort and remove the duplicates (col.dup) and store the resultant data of each column in seprate files like below.

Column 1 ( Store the data to text Datafille1)
Astro
John

Column 2 ( Store the data to text Datafille2)
America
Canada
India

Column 3 ( Store the data to text Datafille3)
21
22
23

Using the function countUntil find the keys for each of the column and store the result of each column in another files.

Key for column to text Keyfille1
original column1[].map!(v => Sorted Column1[].countUntil(v)) );

Key for column to text Keyfille2
original column2[].map!(v => Sorted Column2[].countUntil(v)) );

Key for column to text Keyfille3
original column3[].map!(v => Sorted Column3[].countUntil(v)) );


From,
Vino.B