// Start the Front-Chain process public override bool Algorithm() { while (Agenda.Count != 0) { // Pop the first element at agenda and temporarily store it at p string p = Agenda[0]; Entailed.Add(p); Agenda.RemoveAt(0); for (int i = 0; i < Clauses.Count; i++) { if (Contains(Clauses[i], p)) { //Decrement Count at i and checks if zero if ((--Count[i]) == 0) { // Get the Conclusion string head = Regex.Split(Clauses[i], "=>")[1]; // Check if reach ask if (head.Equals(Ask)) { return(true); } Agenda.Add(head); } } } } // Cannot be entailed return(false); }
public void EmptyCalendarToUser(Account user) { foreach (CalendarEvent calendarEvent in Agenda.ToList()) { if (calendarEvent.AccountEmail == "") { if (calendarEvent.GetType() == typeof(SchoolEvent)) { SchoolEvent schoolEvent = (SchoolEvent)calendarEvent; CalendarEventDatabase.InsertCalendarEvent(new SchoolEvent(schoolEvent.Titel, schoolEvent.Notes, schoolEvent.StartDate, schoolEvent.EndDate, schoolEvent.Subject, schoolEvent.Assignment, user.EmailAdress)); Agenda.Remove(schoolEvent); Agenda.Add(CalendarEventDatabase.CheckCalendarDatabase(schoolEvent.Titel, schoolEvent.StartDate, schoolEvent.EndDate, user.EmailAdress)); } else if (calendarEvent.GetType() == typeof(GameEvent)) { GameEvent GameEvent = (GameEvent)calendarEvent; CalendarEventDatabase.InsertCalendarEvent(new GameEvent(GameEvent.Titel, GameEvent.Notes, GameEvent.StartDate, GameEvent.EndDate, GameEvent.GameName, user.EmailAdress)); Agenda.Remove(GameEvent); Agenda.Add(CalendarEventDatabase.CheckCalendarDatabase(GameEvent.Titel, GameEvent.StartDate, GameEvent.EndDate, user.EmailAdress)); } else { CalendarEventDatabase.InsertCalendarEvent(new CalendarEvent(calendarEvent.Titel, calendarEvent.Notes, calendarEvent.StartDate, calendarEvent.EndDate, user.EmailAdress)); Agenda.Remove(calendarEvent); Agenda.Add(CalendarEventDatabase.CheckCalendarDatabase(calendarEvent.Titel, calendarEvent.StartDate, calendarEvent.EndDate, user.EmailAdress)); } } } }
public void Add(int priority, Action action) { if (_shutdown) { return; } _agenda.Add(priority, action); // _fiber.Add(() => _agenda.Run()); }
public void Init(string tell) /* This is the agents set up. It sets up: * - the list of all symbols * - all the clauses for the knowledge base * - the facts about the world */ { string[] sentances = tell.Split(';'); for (int i = 0; i < sentances.Length - 1; i++) { if (!sentances[i].Contains("=>")) // Checks to see if its a fact. eg b; { if (!Agenda.Contains(sentances[i])) // If the symbol is not already in the Symbols list { Agenda.Add(sentances[i]); // Adds this symbol to the symbols list } if (!Facts.Contains(sentances[i])) // Checks if Facts already contains the symbol { Facts.Add(sentances[i]); // Adds the symbol to the list of symbols that are true } } else { // If it gets here; the current string is a Clause Clauses.Add(sentances[i]); string[] splitImp = sentances[i].Split("=>"); // Splits clause into pre-implication and post-implecation if (!splitImp[0].Contains("&")) // if pre-implecation does not have & { for (int j = 0; j < splitImp.Length; j++) // loop through clause { if (!Agenda.Contains(splitImp[j])) // if agenda doesnt contain the symbol { Agenda.Add(splitImp[j]); // add symbols } } } else { // Pre-imp contains & string[] splitLogic = splitImp[0].Split("&"); // split by logical separators for (int j = 0; j < splitLogic.Length; j++) // loop through strings split { if (!Agenda.Contains(splitLogic[j])) { Agenda.Add(splitLogic[j]); // add symbols to symbols base } if (!Agenda.Contains(splitImp[1])) { Agenda.Add(splitImp[1]); } } } } } }
public bool BCentails() { while (Agenda.Count > 0) { // take the first item and process it string q = Agenda[Agenda.Count - 1]; Agenda.RemoveAt(Agenda.Count - 1); if (q != Ask) { if (!Entailed.Contains(q)) { Entailed.Insert(0, q); } } if (!(Facts.Contains(q))) { List <string> prem = new List <string>(); // for each of the clauses... for (int i = 0; i < Clauses.Count; i++) { // .... that contain p in its premise if (ClauseContains(Clauses[i], q, 1)) { List <string> temp = GetPremises(Clauses[i]); for (int j = 0; j < temp.Count; j++) { prem.Add(temp[j]); } } } if (prem.Count == 0) { return(false); } else { for (int i = 0; i < prem.Count; i++) { if (!Entailed.Contains(prem[i])) { Agenda.Add(prem[i]); } } } } } // while end return(true); }
// method which sets up initial values for forward chaining // takes in string representing KB and seperates symbols and // clauses, calculates count etc ... public void Init(string tell) { string[] sentances = tell.Split(';'); for (int i = 0; i < sentances.Length; i++) { if (!sentances[i].Contains("=>")) { Agenda.Add(sentances[i]); } else { // add sentances Clauses.Add(sentances[i]); Count.Add(sentances[i].Split('&').Length); } } }
public bool AddCalendarEvent(string titel, string notes, DateTime startdate, DateTime enddate, string subject, string assignment, string gamename, string email) { CalendarEvent calendarEvent = new CalendarEvent(titel, notes, startdate, enddate, email); if (subject != null && assignment != null) { calendarEvent = new SchoolEvent(titel, notes, startdate, enddate, subject, assignment, email); } else if (gamename != null) { calendarEvent = new GameEvent(titel, notes, startdate, enddate, gamename, email); } if (Agenda.Contains(calendarEvent) == false) { if (calendarEvent.AccountEmail != "") { try { if (CalendarEventDatabase.CheckCalendarDatabase(titel, startdate, enddate, email) == null) { CalendarEventDatabase.InsertCalendarEvent(calendarEvent); Agenda.Add(CalendarEventDatabase.CheckCalendarDatabase(titel, startdate, enddate, email)); return(true); } else { throw new PlannerExceptions("Event already exist"); } } catch (Exception) { throw; } } else { Agenda.Add(calendarEvent); return(true); } } else { throw new PlannerExceptions("Appiontment already exist in agenda"); } }
// FC algorithm public bool FCentails() { // loop through while there are unprocessed facts while (Agenda.Count > 0) { // take the first item and process it string p = Agenda[0]; Agenda.RemoveAt(0); // add to entailed :: List of symbols already processed Entailed.Add(p); if (p == Ask) { return(true); } // for each of the clauses... for (int i = 0; i < Clauses.Count; i++) { // .... that contain p in its premise if (ClauseContains(Clauses[i], p, 0)) { // reduce count : unknown elements in each premise int j = Count[i]; Count[i] = --j; // all the elements in the premise are now known if (Count[i] == 0) { string[] separatingChars = { "=>" }; string head = Clauses[i].Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries)[1]; if (head.Equals(Ask)) { return(true); } if (!Entailed.Contains(head)) { Agenda.Add(head); } } } } } // if we arrive here then ask cannot entailed return(false); }
private void OnAgendaChanged(AgendaChangedEvent agendaChangedEventArgs) { DispatcherHelper.CheckBeginInvokeOnUI(() => { Agenda.Clear(); foreach (var day in agendaChangedEventArgs.NewAgenda) { var dayVM = new DayViewModel { Date = day.Date, Day = DateToStringUtility.GetDayString(day.Date), Events = CreateEventViewModels(day.Events) }; Agenda.Add(dayVM); } }); }
public override void BuildKB(string tell) { // Split tell into list of strings List <string> sentences = tell.Split(';').ToList(); for (int i = 0; i < sentences.Count; i++) { //Look for Inference if (sentences[i].Contains("=>")) { //If true, add to clause and count the conjuctions (A&B or Z) Clauses.Add(sentences[i].ToLower()); Count.Add(sentences[i].Split('&').Length); } else if (!sentences[i].Trim().Equals("")) //If false and not empty, add to agenda { Agenda.Add(sentences[i].ToLower()); SingleStatement.Add(sentences[i].ToLower()); } } //add every symbol into the agenda including the deuplicated //the deuplication will be remove in the next step for (int i = 0; i < Clauses.Count; i++) { string statement = Clauses[i]; string aftermise = Regex.Split(statement, "=>")[1]; AllSymbolBeenIndicated.Add(aftermise); //Console.WriteLine(aftermise); statement = statement.Replace("=>", " ").Replace("&", " "); string[] temp = statement.Split(' '); for (int j = 0; j < temp.Length; j++) { if (!Agenda.Contains(temp[j])) //Check for Duplicates { Agenda.Add(temp[j]); } } } BuildTheModels(); }
// Build Knowledge Base public override void BuildKB(string tell) { // Split tell into list of strings List <string> sentences = tell.Split(';').ToList(); // Remove the last element which is empty due to split. sentences.RemoveAt(sentences.Count - 1); for (int i = 0; i < sentences.Count; i++) { //Look for Inference if (sentences[i].Contains("=>")) { //If true, add to clause and count the conjuctions (A&B or Z) Clauses.Add(sentences[i]); Count.Add(sentences[i].Split('&').Length); } else { //If false, add to agenda Agenda.Add(sentences[i]); } } }
public IEnumerable <AgendaClass> GetAgenda() { try { var rows = NpoiSheet.LastRowNum; var columns = NpoiSheet.GetRow(0).LastCellNum; var attributes = typeof(AgendaClass).GetProperties() .Where(p => Attribute.IsDefined(p, typeof(DescriptionAttribute))); if (columns < attributes.Count()) { throw new Exception("Wrong number of columns"); } var columnsOrder = new Dictionary <int, string>(); for (var i = 0; i < columns; i++) { columnsOrder.Add(i, NpoiSheet.GetRow(0).GetCell(i).StringCellValue); } for (var i = 1; i < rows; i++) { var ag = new AgendaClass(); foreach (var propertyInfo in ag.GetType() .GetProperties() .Where(p => Attribute.IsDefined(p, typeof(DescriptionAttribute)))) { var att = propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), true)[0] as DescriptionAttribute; var columnNumber = columnsOrder.FirstOrDefault(x => x.Value == att?.Description); if (!propertyInfo.CanWrite) { continue; } string val = string.Empty; try { var type = NpoiSheet.GetRow(i).GetCell(columnNumber.Key).CellType; switch (type) { case CellType.String: val = NpoiSheet.GetRow(i).GetCell(columnNumber.Key).StringCellValue; break; case CellType.Numeric: val = NpoiSheet.GetRow(i).GetCell(columnNumber.Key).DateCellValue.ToString(); break; } } catch { continue; } propertyInfo.SetValue(ag, val, null); } Agenda.Add(ag); } } catch { throw new HttpException(404, " :("); } return(Agenda); }