Problem parsing data and create new collection
Hi all,
I have a programming problem, which have difficulty to find a good solution for. This is the info:
Goal:
--
Given an input file in plain text, each line specifying a "path", build an in-memory
ontology (directed graph) that can be queried against.
Specification:
--
Input:
Raw text file, each line being a "path" or "class" in the ontology.
The lines are of the format:
RootName|PathElementName|PathElementName|....|LeafName
For example:
Film|Tapes|Media
Represents one concept of 'Media', namely that 'Media' is a type of 'Tapes', which is a type of 'Film'.
Names that contain commas or ampersands should be split up.
For example:
Film,Movies|Tapes|Media,Film
Will become the four paths in the ontology:
Film|Tapes|Media
Film|Tapes|Film
Movies|Tapes|Media
Movies|Tapes|Film
My solution: (I don抰 paste the actually lines of program here):
I parsed the input based on 搢?which gives me an String[] fields:
For this ex.: Film,Movies|Tapes|Media,Film
fields[] = {[Film,Movies], [Tapes], [Media,Film]}
For each member if the fields[], we need to parse the element based on ',', which gives us a new String[]. So for
the above ex. with three members, we will have 3 new String[]. We can keep each in an ArrayList, which means we will have an ArrayList when the members are array. Then we can operate on each array.
*/
List parsedFields =new ArrayList();
for (int a = 0; a < fields.lenght; a++)
{
String patternStr =",";
String[] commaFields = fileds[a].split(patternStr);
ParsedFields.add(commaFields);
}
/*At this point I have an ArrayList: parsedFileds which has as many members as our original array: fields[]. Each member is an array by itself.
parsedFileds --> [{film, movies}, {tapes}, {media, film}]
I tried to go thru each array in turn and create ArrayList like:
[film, tapes, media]
[film, tapes, film]
[movies, tapes, media]
[movies, tapes, film]
I have difficulty to find a good solution to create the above arraylists, I needed to create many loops, ?and I find it very confusing. Does anybody can think of any solution that can help me accomplish this task? Any help is greatly appreciated.

