Exemple #1
0
 public Film(string n = "none", List<Actor> c = null, bool v = false)
 {
     Name = n;
     Cast = c;
     Visited = v;
     Connect = null;
 }
Exemple #2
0
        //works backwards and dumps the path into a stack to display it later in the proper order
        public int Path(Actor actor)
        {
            int degree = 1;
            Stack<Actor> a = new Stack<Actor>();
            Stack<Film> f = new Stack<Film>();
            Film temp = this.connect;
            a.Push(this);
            if (temp.connect == actor)      //this is the case if there is only one degree of separation
            {
                f.Push(temp);
                a.Push(actor);
            }
            else
            {
                while (temp.connect != actor)   //else go through path
                {
                    f.Push(temp);
                    a.Push(temp.connect);
                    temp = temp.connect.connect;
                }
                f.Push(temp);
                a.Push(temp.connect);
            }
            degree = f.Count;
            bool first = true;

            listView.Items.Clear();

            while (a.Count > 1)             //display the path
            {
                Actor tema = a.Pop();

                addWithImage(tema.name, "nm");

                //outputBox.AppendText(Environment.NewLine + imageurl);
                //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.imdb.com/find?q=damon%2C+matt&s=all");

                // execute the request
                //HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // we will read data via the response stream
                //Stream resStream = response.GetResponseStream();

                if (first)
                {
                    first = false;
                    listView.Items.Add("is in",0);
                }
                else
                    listView.Items.Add("who is in",0);
                outputBox.AppendText(Environment.NewLine + tema.name);
                outputBox.AppendText(Environment.NewLine + "|\n|");

                Film temf = f.Pop();
                addWithImage(temf.name, "tt");
                listView.Items.Add("with",1);
                outputBox.AppendText(Environment.NewLine + temf.name);
                outputBox.AppendText(Environment.NewLine + "|\n|");
            }
            Actor temaa = a.Pop();
            addWithImage(temaa.name, "nm");
            outputBox.AppendText(Environment.NewLine + temaa.name);
            outputBox.AppendText(Environment.NewLine + "degree of separation: " + degree);//show the degree of separation
            return degree;
        }
Exemple #3
0
        public int DegreeOfSeparation(Actor actor, int degree)
        {
            List<Actor> q = new List<Actor>();
            q.Add(this);
            while (q.Count > 0)
            {
                foreach (Film film in q[0].films)   //go through each film of this actor
                {
                    if (film.visited == false)  //checks if film has been checked already
                    {
                        film.visited = true;
                        film.connect = q[0];
                        foreach (Actor person in film.cast)     //Goes through the cast of each film
                        {
                            if (person.visited == false)    //checks if actor has been visited yet
                            {
                                person.connect = film;
                                person.visited = true;
                                if (person.name == actor.name)     //if actor connection found then use Path() to display path of separation
                                {
                                    person.Path(this);

                                    return 1;

                                }
                                q.Add(person);
                            }
                        }
                    }
                }

                q.RemoveAt(0);
            }
            return -1;
        }
Exemple #4
0
        private void DegreeOfSeparation(string seed, string separated)
        {
            //USER INTERFACE
            string input1 = seedActor;
            string input2 = separated;

            string[] words = input1.Split(' ');
            input1 = words[words.Length-1] + ",";
            for (int i = 0; i < words.Length - 1; i++)
            {
                input1 = input1 + " " + words[i];
            }
            Actor test = actors.Find(item => item.name == input1);
            if (test == null)
                test = actors.Find(item => item.name == input1 + " (I)");

            if (test == null)
            {
                int minDist = 1000;
                int tempDist = 0;
                Actor tempActor = new Actor();
                Actor bestMatch = new Actor();

                for (int i = 0; i < actors.Count; i++)
                {

                    if (input1[0] == actors[i].name[0] || Convert.ToInt16(input1[0]) - 32 == Convert.ToInt16(actors[i].name[0]))
                    {
                        if (actors[i].name.Length > 2)
                        {
                            if (actors[i].name[actors[i].name.Length - 3] == '(')
                                tempDist = tempActor.DamerauLevenshteinDistance(input1 + " (I)", actors[i].name);
                            else
                                tempDist = tempActor.DamerauLevenshteinDistance(input1, actors[i].name);
                        }
                        if (tempDist < minDist)
                        {
                            minDist = tempDist;
                            bestMatch = actors[i];
                        }
                    }
                }
                test = bestMatch;
            }

            words = input2.Split(' ');
            input2 = words[words.Length - 1] + ",";
            for (int i = 0; i < words.Length - 1; i++)
            {
                input2 = input2 + " " + words[i];
            }
            Actor queryActor = new Actor();
            queryActor.name = input2;

            Actor test2 = actors.Find(item => item.name == input2);
            if (test2 == null)
                test2 = actors.Find(item => item.name == input2 + " (I)");
            if (test2 == null)
            {
                int minDist = 1000;
                int tempDist = 0;
                Actor tempActor = new Actor();
                Actor bestMatch = new Actor();

                for (int i = 0; i < actors.Count; i++)
                {

                    if (input2[0] == actors[i].name[0] || Convert.ToInt16(input2[0]) - 32 == Convert.ToInt16(actors[i].name[0]))
                    {
                        if (actors[i].name.Length > 2)
                        {
                            if (actors[i].name[actors[i].name.Length - 3] == '(')
                                tempDist = tempActor.DamerauLevenshteinDistance(input2 + " (I)", actors[i].name);
                            else
                                tempDist = tempActor.DamerauLevenshteinDistance(input2, actors[i].name);
                        }
                        if (tempDist < minDist)
                        {
                            minDist = tempDist;
                            bestMatch = actors[i];
                        }
                    }
                }
                test2 = bestMatch;
            }

            if (test.name == test2.name)
                OutputBox.AppendText(Environment.NewLine + "\nDegree of separation is 0");
            else if (test.DegreeOfSeparation(test2, 1) != -1)
                OutputBox.AppendText(Environment.NewLine + "\ngood ");
            else
                OutputBox.AppendText(Environment.NewLine + "\nbad ");

            foreach(Actor a in actors)
            {
                a.visited = false;
            }
            foreach (Film f in films)
            {
                f.visited = false;
            }
        }
Exemple #5
0
        private void ImportActorsFilms()
        {
            //using (StreamReader r = new StreamReader(FilmFile))
            //{
            //    string line;
            //    int linecount = 0;
            //    while ((line = r.ReadLine()) != null)
            //    {
            //        linecount++;
            //        if (linecount % 10000 == 0)
            //        {
            //            OutputBox.AppendText(".");
            //        }

            //        films.Add(new Film(line, new List<Actor>()));

            //    }
            //}

            //OutputBox.AppendText(Environment.NewLine + "Imported Films");

            //takes our sample file and indexes it into film and actor objects
            using (StreamReader r = new StreamReader(ActorsFile))
            {
                //using (StreamWriter u = new StreamWriter(UpdatedFile))
                //{

                string line;
                bool newactor = true;
                Actor currentActor = new Actor();
                Film currentFilm = new Film();
                int linecount = 0;
                //int idcount = 0;
                int indx = 0;
                bool checkID = false;

                while ((line = r.ReadLine()) != null)
                {
                    linecount++;
                    if (linecount % 10000 == 0)
                    {
                        OutputBox.AppendText(Environment.NewLine + linecount);
                    }

                    if (line == "")
                    {
                      //  u.WriteLine("");
                        newactor = true;
                        continue;
                    }

                    if (newactor == true)
                    {
                      //  u.WriteLine(line);
                        currentActor = new Actor(line, new List<Film>(), OutputBox, listView1, imageList1);
                        actors.Add(currentActor);
                        newactor = false;
                    }
                    else
                    {
                        //u.WriteLine(line);
                        //int filmid = films.FindIndex(delegate(Film film) { return film.name.Equals(line); });

                        //if (filmid == -1)
                        //{
                            //  u.WriteLine(idcount);
                            //OutputBox.AppendText(Environment.NewLine + line + "Null when searched!!");
                            //  currentFilm = new Film(line, new List<Actor>());
                            //  films.Add(currentFilm);
                        //    idcount++;
                        //}
                        // else
                        // {
                            //   u.WriteLine(filmid);
                            //  currentFilm = films[filmid];
                        // }

                        //currentFilm.cast.Add(currentActor);
                        // currentActor.films.Add(currentFilm);
                        if (checkID == false)
                        {
                            currentFilm = new Film(line, new List<Actor>());
                            checkID = true;
                            continue;
                        }
                        if (checkID == true)
                        {
                            indx = Convert.ToInt32(line);
                            if (indx >= films.Count)
                            {
                                films.Add(currentFilm);
                            }
                            films[indx].cast.Add(currentActor);
                            currentActor.films.Add(films[indx]);
                            checkID = false;
                        }

                    }
                }
            }
            OutputBox.AppendText(Environment.NewLine + "Imported Actors");
        }