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

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