コード例 #1
0
        // Order List of Authors based on the times they appear and return it truncated
        private static Dictionary <string, AuthorClass> OrderRanking(List <Authors> authorList)
        {
            try
            {
                // Use dictionary to store information <AuthorName, AuthorClass>
                var map = new Dictionary <string, AuthorClass>();

                // Give a score to the author based on the times they appear
                for (int i = 0; i < authorList.Count; ++i)
                {
                    Authors authors = authorList[i];
                    for (int j = 0; j < authors.Author.Count; ++j)
                    {
                        string authorName = authors.Author[j].Text;

                        if (map.ContainsKey(authorName))  // Author already inside the dictionary
                        {
                            AuthorClass author = map.GetValueOrDefault(authorName);
                            author.IncreaseScore();
                            author.SetPublicationYear(authors.Author[j].LastYear);
                            author.AddVenue(authors.Author[j].Venue);
                        }
                        else // New Author
                        {
                            authors.Author[j].Score = 1;
                            authors.Author[j].AddVenue(authors.Author[j].Venue);
                            map.Add(authorName, authors.Author[j]);
                        }
                    }
                }

                return(map);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #2
0
        // Return a list of the authors extracted from a query by year
        private static List <Authors> AddListByYear(string venue, int year)
        {
            // Create new list
            List <Authors> authorList = new List <Authors>();

            try
            {
                // Parse year to string
                string yearToString = year.ToString();

                // Build Query
                string query = QueryBuilder.BuildQueryVenueYear(venue, yearToString);

                // Send request
                string response = SendRequest(query);

                // Parse response into JSON
                JObject search = JObject.Parse(response);

                // Get JSON result objects into a list
                List <JToken> results = search["result"]["hits"]["hit"].Children().ToList();

                // Serialize JSON results into .NET objects
                foreach (JToken result in results)
                {
                    try
                    {
                        string authorString  = result["info"]["authors"].ToString();
                        int    numberAuthors = Regex.Matches(authorString, "text").Count;

                        if (numberAuthors == 1)
                        {
                            string      authorClassString = result["info"]["authors"]["author"].ToString();
                            AuthorClass author            = JsonConvert.DeserializeObject <AuthorClass>(authorClassString);

                            // Set año de publicacion para un autor
                            author.SetPublicationYear(year);

                            // Set venue del autor
                            author.Venue = venue;

                            List <AuthorClass> tempAuthorList = new List <AuthorClass>()
                            {
                                author
                            };

                            authorList.Add(new Authors(tempAuthorList));
                        }
                        else
                        {
                            Authors authors = JsonConvert.DeserializeObject <Authors>(authorString);

                            // Set año de la publicacion y venue para todos los autores de la publicacion
                            foreach (AuthorClass au in authors.Author)
                            {
                                au.SetPublicationYear(year);
                                au.Venue = venue;
                            }

                            authorList.Add(authors);
                        }
                    }catch (Exception)
                    {
                        continue;
                    }
                }

                return(authorList);
            }
            catch (Exception)
            {
                return(authorList);
            }
        }