Esempio n. 1
0
        public List <Group> readGT(List <Frame> frames)
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            List <Group> groups = new List <Group>();

            string[] gtLines = null;

            //read lines from gt file
            try
            {
                gtLines = File.ReadAllLines(GtFile);
            }
            catch (FileNotFoundException e)
            {
                Console.Write("Error file gt: ");
                Console.WriteLine(e.Message);
            }

            int i = 0;

            while (i < gtLines?.Length)
            {
                //first line has to be a frame header
                Match m = Regex.Match(gtLines[i], framePattern);
                if (m.Success)
                {
                    int id = Int32.Parse(m.Groups[1].Value); //frame id
                    int n  = Int32.Parse(m.Groups[2].Value); //frame groups

                    // trova il frame con ID == id
                    Frame currentFrame = frames.Find(x => x.IdFrame == id);
                    Group newGroup     = FactoryGroup.createGroup(currentFrame);

                    for (int j = 1; j <= n; j++) //for each subgroup
                    {
                        List <Person> peopleGroup = new List <Person>();
                        string[]      elements    = gtLines[i + j].Split(new Char[] { ' ' }); //space is the separator
                        foreach (string s in elements)
                        {
                            int    personId = Int32.Parse(s);
                            Person p        = currentFrame.getPersonById(personId);
                            peopleGroup.Add(p);
                        }

                        newGroup.addSubGroup(peopleGroup);
                    }
                    //add the new grouping
                    groups.Add(newGroup);
                    //update i
                    i = i + n + 1;
                }
                else
                {
                    i++;
                }
            }
            Debug.WriteLine("Parser: Groups created: " + groups.Count + " grouping");
            return(groups);
        }