Ejemplo n.º 1
0
        public void AddExpression(string[] keywords, string[] responses, string[] contexts,
            ExpressionLocation location, ExpressionType type)
        {
            Expression newKey = new Expression(keywords, location, type, responses, contexts);

            AddExpression(newKey);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public UserInput(IO io, Expression quitExpr)
 {
     this.io = io;
     this.quitExpr = quitExpr;
     this.response = string.Empty;
     this.lastResponse = string.Empty;
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
 public void AddExpression(Expression newKey)
 {
     Expressions.Add(newKey);
 }
Ejemplo n.º 7
0
 public static bool UserWantsToQuit(Expression quit, string userInput)
 {
     return quit.Keywords.Contains(userInput);
 }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
 private void ExtractResponses(Expression expr, int actualPos)
 {
     expr.Responses = databaseLines[actualPos].Substring(RESPONSES.Length).Split(SEPARATION);
 }
Ejemplo n.º 11
0
 private void ExtractKeywords(Expression expr, int actualPos)
 {
     expr.Keywords = databaseLines[actualPos].Substring(KEYWORDS.Length).Split(SEPARATION);
 }
Ejemplo n.º 12
0
 private void ExtractContexts(Expression expr, int actualPos)
 {
     expr.Contexts = databaseLines[actualPos].Substring(CONTEXTS.Length).Split(SEPARATION);
 }
Ejemplo n.º 13
0
        public void AddExpression(Expression expression, bool changer = false)
        {
            if (changer) changed = true;

            expressions.AddExpression(expression);
        }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
0
 private void AddExpressionResponsesToResponseList(Expression expr)
 {
     foreach (string response in expr.Responses)
         if (!availableResponses.Contains(response))
             availableResponses.Add(response);
 }
Ejemplo n.º 16
0
 private void GetCommunicationResponses(Expression expr)
 {
     foreach (string keyword in expr.Keywords)
         if (EligibleAsResponse(expr, keyword))
             AddExpressionResponsesToResponseList(expr);
 }