/// <summary> /// Gets the collection of terminal elements that can appear as the first element /// after the dot in the given LR Item. If next element, named T, is a terminal, then First(item) = {T} /// </summary> /// <example> /// With Grammar: /// S -> A /// A -> A + B /// A -> a /// B -> b /// First(S -> •A): {'a'} /// First(A -> •A + B): {'a'} /// First(A -> A • + B): {'+'} /// First(B -> b): {'b'} /// </example> /// <param name="item"></param> /// <returns></returns> public IEnumerable <Terminal <T> > First(LRItem <T> item) { //get the next element and evaluate if it is a terminal or non terminal GrammarElement <T> nextElement = item.GetNextElement(); //if nextElement is a Terminal then return {T} if (nextElement is Terminal <T> ) { return new[] { (Terminal <T>)nextElement } } ; //otherwise find all of the productions that have nextElement on the LHS. Production <T> production = Productions.First(p => p.NonTerminal == item.LeftHandSide && p.DerivedElements.SequenceEqual(item.ProductionElements)); var firstElements = new List <Terminal <T> >(); if (production.DerivedElements.Count > 0) { if (!production.DerivedElements[item.DotIndex].Equals(production.NonTerminal)) { GrammarElement <T> productionItem = production.GetElement(item.DotIndex); if (productionItem != null) { //if it is a Terminal add to first elements if (productionItem is Terminal <T> ) { firstElements.Add((Terminal <T>)productionItem); } //otherwise add First(new LRItem(production)) of all of the productions where the LHS == productionItem else { foreach (LRItem <T> i in Productions.Where(p => p.NonTerminal.Equals(productionItem)).Select(p => new LRItem <T>(0, p))) { firstElements.AddRange(First(i)); } } } } } return(firstElements.Distinct()); }
public static void LoadLogs() { var vidlog = new VideoLog(); dynamic productions = new Productions(); dynamic episodes = new Episodes(); dynamic orderItems = new OrderItems(); dynamic channels = new Channels(); var orders = new Orders(); var rand = new Random(); Console.WriteLine("Deleting logs..."); vidlog.Delete(); foreach (var order in orders.All()) { //pull the orderItems var items = orderItems.Find(OrderID: order.ID); //loop the items foreach (var item in items) { var slug = item.SKU; if (slug == "yearly") { Console.WriteLine("Loading Productions and Episodes for Annual..."); //create a download log for each production and episode foreach (var p in productions.All()) { var eps = episodes.Find(ProductionID: p.ID); foreach (var e in eps) { var log = new { Slug = item.SKU, EpisodeNumber = e.Number, Email = order.Email, //the download file for the episode FileName = p.Slug + "_" + e.Number + ".zip", FileSize = e.HDFileSize, //1 day lag LogDate = order.CreatedAt.AddDays(1), OrderItemID = item.ID }; vidlog.Insert(log); } } } else if (slug == "monthly") { //create a stream log for each production and episode Console.WriteLine("Loading Productions and Episodes for Monthly..."); foreach (var p in productions.All()) { var eps = episodes.Find(ProductionID: p.ID); foreach (var e in eps) { var log = new { Slug = item.SKU, EpisodeNumber = e.Number, Email = order.Email, //the download file for the episode FileName = p.Slug + "_" + e.Number + ".flv", FileSize = e.StreamFileSize, //1 day lag LogDate = order.CreatedAt.AddDays(1), OrderItemID = item.ID }; vidlog.Insert(log); } } } else { var p = productions.First(Slug: item.SKU); var eps = episodes.Find(ProductionID: p.ID); Console.WriteLine("Loading log for {0}...", p.Slug); foreach (var e in eps) { var log = new { Slug = item.SKU, EpisodeNumber = e.Number, Email = order.Email, //the download file for the episode FileName = p.Slug + "_" + e.Number + ".zip", FileSize = e.HDFileSize, //1 day lag LogDate = order.CreatedAt.AddDays(1), OrderItemID = item.ID }; vidlog.Insert(log); } } } } }