public void AddExpression(string[] keywords, string[] responses, string[] contexts, ExpressionLocation location, ExpressionType type) { Expression newKey = new Expression(keywords, location, type, responses, contexts); AddExpression(newKey); }
private void AddNewExpression() { io.WriteLine("PLEASE WRITE THE NEW EXPRESION FOLLOWING THE"); io.WriteLine("THE DATABASE RULES :"); io.WriteLine("Ok. So what is the keywords that match this expression ?\nSeparate them with comas and write upper-case."); io.Write("> "); string[] keywords = io.ReadLine().Split(','); io.WriteLine("And what should I respond to that ?\nSeparate them with comas and write upper-case."); io.Write("> "); string[] resps = io.ReadLine().Split(','); io.WriteLine("In what contexts should I respond this ?\nSeparate them with comas and write upper-case."); io.Write("> "); string[] contexts = io.ReadLine().Split(','); io.WriteLine("What is this expression's type ? (1-knowledge, 2-comm.)"); ExpressionType type = io.ReadLine() == "1" ? ExpressionType.Knowledge : ExpressionType.Communication; io.WriteLine("What is this expression's location ?\nbegmid, alone, midend or irr ?"); io.Write("> "); string input = io.ReadLine(); ExpressionLocation location = input == "alone" ? ExpressionLocation.Alone : input == "begmid" ? ExpressionLocation.BeginOrMiddle : input == "medend" ? ExpressionLocation.MiddleOrEnd : ExpressionLocation.IsIrrelevant; Expression expr = new Expression(keywords, location, type, resps, contexts); database.AddExpression(expr, true); }
public UserInput(IO io, Expression quitExpr) { this.io = io; this.quitExpr = quitExpr; this.response = string.Empty; this.lastResponse = string.Empty; }
public void AddExpression(string[] keywords, string[] responses, string[] contexts, ExpressionType type, ExpressionLocation location, bool changer = false) { Expression newExpression = new Expression(keywords, location, type, responses, contexts); AddExpression(newExpression, changer); }
private string GetRequestedKnowledge(string userInput, Expression match) { string expr = match.Keywords[new Random().Next(match.Keywords.Length)]; if (KnowledgeAtEnd(expr)) return userInput.Substring(expr.Length - 2).Trim(); int dollarPos = expr.IndexOf('$'); string nextWord = GetNextWordAfterKnowledge(expr); return userInput.Substring(dollarPos, nextWord.Length).Trim(); }
public void AddExpression(Expression newKey) { Expressions.Add(newKey); }
public static bool UserWantsToQuit(Expression quit, string userInput) { return quit.Keywords.Contains(userInput); }
private void DoExtractionProcess(ref string type, string location, Expression expr) { int z = 0; for (int i = 0; i < 3; z++, i++) { int p = i + readIndex; if (databaseLines[p].StartsWith(KEYWORDS)) ExtractKeywords(expr, p); if (databaseLines[p].StartsWith(RESPONSES)) ExtractResponses(expr, p); if (databaseLines[p].StartsWith(CONTEXTS)) ExtractContexts(expr, p); if (databaseLines[p].StartsWith(TYPE)) ExtractType(ref type, p); if (databaseLines[p].StartsWith(LOCATION)) ExtractLocation(location, p); } readIndex += z - 1; }
private Expression GetNewExpression() { string type = string.Empty; string location = string.Empty; Expression expr = new Expression(); DoExtractionProcess(ref type, location, expr); expr.Type = GetExpressionType(type); expr.Location = GetExpressionLocation(location); return expr; }
private void ExtractResponses(Expression expr, int actualPos) { expr.Responses = databaseLines[actualPos].Substring(RESPONSES.Length).Split(SEPARATION); }
private void ExtractKeywords(Expression expr, int actualPos) { expr.Keywords = databaseLines[actualPos].Substring(KEYWORDS.Length).Split(SEPARATION); }
private void ExtractContexts(Expression expr, int actualPos) { expr.Contexts = databaseLines[actualPos].Substring(CONTEXTS.Length).Split(SEPARATION); }
public void AddExpression(Expression expression, bool changer = false) { if (changer) changed = true; expressions.AddExpression(expression); }
private bool EligibleAsResponse(Expression expr, string keyword) { string ui = StringHelper.InsertSpacesBAF(userInput); int keywordPosition = ui.IndexOf(StringHelper.InsertSpacesBAF(keyword)); if (keywordPosition != KEYWORD_NOT_FOUND_IN_INPUT) { if (WrongLocation(keyword, expr.Location, keywordPosition)) return false; if (WrongContext(expr.Contexts)) return false; return true; } return false; }
private void AddExpressionResponsesToResponseList(Expression expr) { foreach (string response in expr.Responses) if (!availableResponses.Contains(response)) availableResponses.Add(response); }
private void GetCommunicationResponses(Expression expr) { foreach (string keyword in expr.Keywords) if (EligibleAsResponse(expr, keyword)) AddExpressionResponsesToResponseList(expr); }