Hi Everyone,
I have a project from school which is a console application that takes hard-coded items and process those inside of one of my custom class which intherit from a list of strings. Then, it processes those items and apply the Apriori Algorithm (I cannot use any existent package or libraries but to implement it on my own and it's working using hard-coded data).
I am having problems changing the code to read it the data from a file and proceed with the rest of the implementation. I tried everything but am still not able to make it work.
I am trying to pass/have the array passed into my class the same way I did with hard-coded; if works then I don't need to make changes to my classes and even the algorithm implementation.
What I am trying to do is to read the data from a file line by line and take each word and put into my class (custom list class) the same way as I passed the data as hard-coded but I am not able to have exactly the same structure which won't work well further in the process.
I am under the impression that is not possible to have the data structured the same way while using hard-coded data or from an input file.
input file:
ink pen cheese bag
milk pen juice cheese
milk juice
juice milk cheese
My main/program.cs (please noticed that the hard-coded commented out works well):
string[] lines = File.ReadLines("../../InputApriori.txt").ToArray();
foreach (var line in lines)
{
Console.WriteLine(line);
itemsDataList.Add(new DataSets() { line });
}
Console.WriteLine("\n");
/* // OPTION A
string Aitem1 = "ink";
string Aitem2 = "pen";
string Aitem3 = "cheese";
string Aitem4 = "bag";
string Aitem5 = "milk";
string Aitem6 = "juice";
itemsDataList.Add(new DataSets() { Aitem1, Aitem2, Aitem3, Aitem4 });
itemsDataList.Add(new DataSets() { Aitem5, Aitem2, Aitem6, Aitem3 });
itemsDataList.Add(new DataSets() { Aitem5, Aitem6 });
itemsDataList.Add(new DataSets() { Aitem6, Aitem5, Aitem3 }); */
According to Visual Studio Community 2015 debugger:
In the debugger (watch window) the hard- coded displayed under my class (itemsDataList) the following:
=>itemsDataList ==> Count = 4
=>[0] count = 4 "if I click in the arrow of it, it has the following under it"
[0] = "ink"
[1] = "pen"
[2] = "cheese"
[3] ="bag"
=>[1] count = 4 ...
[0] = "milk"
[1] = "pen"
[2] = "juice"
[3] ="cheese"
=>[2] count = 2 ...
[0] = "milk"
[1] = "juice"
=>[3] count = 3 ...
[0] = "juice"
[1] = "milk"
[2] = "cheese"
While reading the data from a file as in the code provided, the itemsDataList class in the watch window/debubber displays as follows:
=>itemsDataList ==> Count = 4
=>[0] count = 1 ...
[0] = "ink pen cheese bag"
=>[1] count = 1 ...
[0] = "milk pen juice cheese"
=>[2] count = 1 ...
[0] = "milk juice"
=>[3] count = 1 ...
[0] = "juice milk cheese"
I really appreciate your help. Thanks in advance.